mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
More changes to fbreader/network core
This commit is contained in:
parent
62d6b0525f
commit
acf00d5706
15 changed files with 95 additions and 47 deletions
|
@ -51,4 +51,9 @@ public class AddCustomCatalogItemTree extends NetworkTree implements ZLAndroidTr
|
||||||
public int getCoverResourceId() {
|
public int getCoverResourceId() {
|
||||||
return R.drawable.ic_list_plus;
|
return R.drawable.ic_list_plus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUniqueKey() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,12 +226,7 @@ class NetworkBookActions extends NetworkTreeActions {
|
||||||
|
|
||||||
|
|
||||||
private void showBooks(NetworkBaseActivity activity, NetworkTree tree) {
|
private void showBooks(NetworkBaseActivity activity, NetworkTree tree) {
|
||||||
String key = null;
|
final String key = tree.getUniqueKey();
|
||||||
if (tree instanceof NetworkAuthorTree) {
|
|
||||||
key = PACKAGE + ".Authors:" + ((NetworkAuthorTree) tree).Author.DisplayName;
|
|
||||||
} else if (tree instanceof NetworkSeriesTree) {
|
|
||||||
key = PACKAGE + ".Series:" + ((NetworkSeriesTree) tree).SeriesTitle;
|
|
||||||
}
|
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
NetworkView.Instance().openTree(activity, tree, key);
|
NetworkView.Instance().openTree(activity, tree, key);
|
||||||
}
|
}
|
||||||
|
|
|
@ -172,11 +172,12 @@ class NetworkCatalogActions extends NetworkTreeActions {
|
||||||
final NetworkCatalogTree catalogTree = (NetworkCatalogTree) tree;
|
final NetworkCatalogTree catalogTree = (NetworkCatalogTree) tree;
|
||||||
final NetworkCatalogItem item = catalogTree.Item;
|
final NetworkCatalogItem item = catalogTree.Item;
|
||||||
|
|
||||||
final String catalogUrl = item.URLByType.get(NetworkCatalogItem.URL_CATALOG);
|
final String key = tree.getUniqueKey();
|
||||||
final boolean isLoading = (catalogUrl != null) ?
|
final boolean isLoading = (key != null) ?
|
||||||
NetworkView.Instance().containsItemsLoadingRunnable(catalogUrl) : false;
|
NetworkView.Instance().containsItemsLoadingRunnable(key) : false;
|
||||||
|
|
||||||
prepareOptionsItem(menu, RELOAD_ITEM_ID, catalogUrl != null && !isLoading);
|
prepareOptionsItem(menu, RELOAD_ITEM_ID,
|
||||||
|
item.URLByType.get(NetworkCatalogItem.URL_CATALOG) != null && !isLoading);
|
||||||
|
|
||||||
boolean signIn = false;
|
boolean signIn = false;
|
||||||
boolean signOut = false;
|
boolean signOut = false;
|
||||||
|
@ -399,11 +400,11 @@ class NetworkCatalogActions extends NetworkTreeActions {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doExpandCatalog(final NetworkBaseActivity activity, final NetworkCatalogTree tree) {
|
public void doExpandCatalog(final NetworkBaseActivity activity, final NetworkCatalogTree tree) {
|
||||||
final String url = tree.Item.URLByType.get(NetworkCatalogItem.URL_CATALOG);
|
final String key = tree.getUniqueKey();
|
||||||
if (url == null) {
|
if (key == null) {
|
||||||
throw new RuntimeException("That's impossible!!!");
|
throw new RuntimeException("Catalog tree has null unique key. That's impossible!!!");
|
||||||
}
|
}
|
||||||
NetworkView.Instance().tryResumeLoading(activity, tree, url, new Runnable() {
|
NetworkView.Instance().tryResumeLoading(activity, tree, key, new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
boolean resumeNotLoad = false;
|
boolean resumeNotLoad = false;
|
||||||
if (tree.hasChildren()) {
|
if (tree.hasChildren()) {
|
||||||
|
@ -411,7 +412,7 @@ class NetworkCatalogActions extends NetworkTreeActions {
|
||||||
if (tree.Item.supportsResumeLoading()) {
|
if (tree.Item.supportsResumeLoading()) {
|
||||||
resumeNotLoad = true;
|
resumeNotLoad = true;
|
||||||
} else {
|
} else {
|
||||||
NetworkView.Instance().openTree(activity, tree, url);
|
NetworkView.Instance().openTree(activity, tree, key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -421,15 +422,15 @@ class NetworkCatalogActions extends NetworkTreeActions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final ExpandCatalogHandler handler = new ExpandCatalogHandler(tree, url);
|
final ExpandCatalogHandler handler = new ExpandCatalogHandler(tree, key);
|
||||||
NetworkView.Instance().startItemsLoading(
|
NetworkView.Instance().startItemsLoading(
|
||||||
activity,
|
activity,
|
||||||
url,
|
key,
|
||||||
new ExpandCatalogRunnable(handler, tree, true, resumeNotLoad)
|
new ExpandCatalogRunnable(handler, tree, true, resumeNotLoad)
|
||||||
);
|
);
|
||||||
processExtraData(activity, tree.Item.extraData(), new Runnable() {
|
processExtraData(activity, tree.Item.extraData(), new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
NetworkView.Instance().openTree(activity, tree, url);
|
NetworkView.Instance().openTree(activity, tree, key);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -437,20 +438,20 @@ class NetworkCatalogActions extends NetworkTreeActions {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doReloadCatalog(NetworkBaseActivity activity, final NetworkCatalogTree tree) {
|
public void doReloadCatalog(NetworkBaseActivity activity, final NetworkCatalogTree tree) {
|
||||||
final String url = tree.Item.URLByType.get(NetworkCatalogItem.URL_CATALOG);
|
final String key = tree.getUniqueKey();
|
||||||
if (url == null) {
|
if (key == null) {
|
||||||
throw new RuntimeException("That's impossible!!!");
|
throw new RuntimeException("Catalog tree has null unique key. That's impossible!!!");
|
||||||
}
|
}
|
||||||
if (NetworkView.Instance().containsItemsLoadingRunnable(url)) {
|
if (NetworkView.Instance().containsItemsLoadingRunnable(key)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tree.ChildrenItems.clear();
|
tree.ChildrenItems.clear();
|
||||||
tree.clear();
|
tree.clear();
|
||||||
NetworkView.Instance().fireModelChangedAsync();
|
NetworkView.Instance().fireModelChangedAsync();
|
||||||
final ExpandCatalogHandler handler = new ExpandCatalogHandler(tree, url);
|
final ExpandCatalogHandler handler = new ExpandCatalogHandler(tree, key);
|
||||||
NetworkView.Instance().startItemsLoading(
|
NetworkView.Instance().startItemsLoading(
|
||||||
activity,
|
activity,
|
||||||
url,
|
key,
|
||||||
new ExpandCatalogRunnable(handler, tree, false, false)
|
new ExpandCatalogRunnable(handler, tree, false, false)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@ import android.content.Intent;
|
||||||
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.network.NetworkTree;
|
import org.geometerplus.fbreader.network.NetworkTree;
|
||||||
import org.geometerplus.fbreader.network.NetworkCatalogItem;
|
|
||||||
import org.geometerplus.fbreader.network.tree.*;
|
import org.geometerplus.fbreader.network.tree.*;
|
||||||
|
|
||||||
public class NetworkCatalogActivity extends NetworkBaseActivity implements UserRegistrationConstants {
|
public class NetworkCatalogActivity extends NetworkBaseActivity implements UserRegistrationConstants {
|
||||||
|
@ -112,21 +111,6 @@ public class NetworkCatalogActivity extends NetworkBaseActivity implements UserR
|
||||||
setProgressBarIndeterminateVisibility(myInProgress);
|
setProgressBarIndeterminateVisibility(myInProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getNetworkTreeKey(NetworkTree tree, boolean recursive) {
|
|
||||||
if (tree instanceof NetworkCatalogTree) {
|
|
||||||
return ((NetworkCatalogTree) tree).Item.URLByType.get(NetworkCatalogItem.URL_CATALOG);
|
|
||||||
} else if (tree instanceof SearchItemTree) {
|
|
||||||
return NetworkSearchActivity.SEARCH_RUNNABLE_KEY;
|
|
||||||
} else if (recursive && tree.Parent instanceof NetworkTree) {
|
|
||||||
if (tree instanceof NetworkAuthorTree
|
|
||||||
|| tree instanceof NetworkSeriesTree) {
|
|
||||||
return getNetworkTreeKey((NetworkTree) tree.Parent, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
if (myTree != null && myCatalogKey != null && NetworkView.Instance().isInitialized()) {
|
if (myTree != null && myCatalogKey != null && NetworkView.Instance().isInitialized()) {
|
||||||
|
@ -200,10 +184,18 @@ public class NetworkCatalogActivity extends NetworkBaseActivity implements UserR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getLoadableNetworkTreeKey(NetworkTree tree) {
|
||||||
|
if ((tree instanceof NetworkAuthorTree || tree instanceof NetworkSeriesTree)
|
||||||
|
&& tree.Parent instanceof NetworkTree) {
|
||||||
|
return getLoadableNetworkTreeKey((NetworkTree) tree.Parent);
|
||||||
|
}
|
||||||
|
return tree.getUniqueKey();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onModelChanged() {
|
public void onModelChanged() {
|
||||||
final NetworkView networkView = NetworkView.Instance();
|
final NetworkView networkView = NetworkView.Instance();
|
||||||
final String key = getNetworkTreeKey(myTree, true);
|
final String key = getLoadableNetworkTreeKey(myTree);
|
||||||
myInProgress = key != null && networkView.isInitialized() && networkView.containsItemsLoadingRunnable(key);
|
myInProgress = key != null && networkView.isInitialized() && networkView.containsItemsLoadingRunnable(key);
|
||||||
getListView().invalidateViews();
|
getListView().invalidateViews();
|
||||||
|
|
||||||
|
@ -227,7 +219,7 @@ public class NetworkCatalogActivity extends NetworkBaseActivity implements UserR
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doStopLoading() {
|
private void doStopLoading() {
|
||||||
final String key = getNetworkTreeKey(myTree, false);
|
final String key = myCatalogKey;
|
||||||
if (key != null && NetworkView.Instance().isInitialized()) {
|
if (key != null && NetworkView.Instance().isInitialized()) {
|
||||||
final ItemsLoadingRunnable runnable = NetworkView.Instance().getItemsLoadingRunnable(key);
|
final ItemsLoadingRunnable runnable = NetworkView.Instance().getItemsLoadingRunnable(key);
|
||||||
if (runnable != null) {
|
if (runnable != null) {
|
||||||
|
|
|
@ -217,11 +217,15 @@ public class NetworkLibraryActivity extends NetworkBaseActivity {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean searchIsInProgress() {
|
||||||
|
return NetworkView.Instance().containsItemsLoadingRunnable(
|
||||||
|
NetworkSearchActivity.SEARCH_RUNNABLE_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
super.onPrepareOptionsMenu(menu);
|
super.onPrepareOptionsMenu(menu);
|
||||||
final boolean searchInProgress = NetworkView.Instance().containsItemsLoadingRunnable(NetworkSearchActivity.SEARCH_RUNNABLE_KEY);
|
menu.findItem(MENU_SEARCH).setEnabled(!searchIsInProgress());
|
||||||
menu.findItem(MENU_SEARCH).setEnabled(!searchInProgress);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,7 +293,7 @@ public class NetworkLibraryActivity extends NetworkBaseActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onSearchRequested() {
|
public boolean onSearchRequested() {
|
||||||
if (NetworkView.Instance().containsItemsLoadingRunnable(NetworkSearchActivity.SEARCH_RUNNABLE_KEY)) {
|
if (searchIsInProgress()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final NetworkLibrary library = NetworkLibrary.Instance();
|
final NetworkLibrary library = NetworkLibrary.Instance();
|
||||||
|
|
|
@ -36,7 +36,7 @@ import org.geometerplus.fbreader.network.*;
|
||||||
|
|
||||||
public class NetworkSearchActivity extends Activity {
|
public class NetworkSearchActivity extends Activity {
|
||||||
|
|
||||||
public static final String SEARCH_RUNNABLE_KEY = "org.geometerplus.android.fbreader.network.NetworkSearchActivity";
|
static final String SEARCH_RUNNABLE_KEY = "org.geometerplus.android.fbreader.network.NetworkSearchActivity";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
|
|
|
@ -33,6 +33,7 @@ import android.view.Menu;
|
||||||
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.network.*;
|
import org.geometerplus.fbreader.network.*;
|
||||||
|
import org.geometerplus.fbreader.network.tree.NetworkCatalogTree;
|
||||||
|
|
||||||
class NetworkView {
|
class NetworkView {
|
||||||
private static NetworkView ourInstance;
|
private static NetworkView ourInstance;
|
||||||
|
@ -177,7 +178,7 @@ class NetworkView {
|
||||||
return getItemsLoadingRunnable(key) != null;
|
return getItemsLoadingRunnable(key) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tryResumeLoading(NetworkBaseActivity activity, NetworkTree tree, String key, Runnable expandRunnable) {
|
public void tryResumeLoading(NetworkBaseActivity activity, NetworkCatalogTree tree, String key, Runnable expandRunnable) {
|
||||||
final ItemsLoadingRunnable runnable = getItemsLoadingRunnable(key);
|
final ItemsLoadingRunnable runnable = getItemsLoadingRunnable(key);
|
||||||
if (runnable != null && runnable.tryResumeLoading()) {
|
if (runnable != null && runnable.tryResumeLoading()) {
|
||||||
openTree(activity, tree, key);
|
openTree(activity, tree, key);
|
||||||
|
|
|
@ -73,4 +73,9 @@ class RefillAccountTree extends NetworkTree implements ZLAndroidTree {
|
||||||
public int getCoverResourceId() {
|
public int getCoverResourceId() {
|
||||||
return R.drawable.ic_list_library_wallet;
|
return R.drawable.ic_list_library_wallet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUniqueKey() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,4 +102,9 @@ public class SearchItemTree extends NetworkTree implements ZLAndroidTree {
|
||||||
public NetworkLibraryItem getHoldedItem() {
|
public NetworkLibraryItem getHoldedItem() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUniqueKey() {
|
||||||
|
return NetworkSearchActivity.SEARCH_RUNNABLE_KEY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,6 +90,12 @@ public abstract class NetworkTree extends FBTree {
|
||||||
|
|
||||||
public abstract NetworkLibraryItem getHoldedItem();
|
public abstract NetworkLibraryItem getHoldedItem();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns unique identifier which can be used in NetworkView methods
|
||||||
|
* @return unique String instance
|
||||||
|
*/
|
||||||
|
public abstract String getUniqueKey();
|
||||||
|
|
||||||
public void removeItems(Set<NetworkLibraryItem> items) {
|
public void removeItems(Set<NetworkLibraryItem> items) {
|
||||||
if (items.isEmpty() || subTrees().isEmpty()) {
|
if (items.isEmpty() || subTrees().isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -123,4 +123,9 @@ public class NetworkAuthorTree extends NetworkTree {
|
||||||
public NetworkLibraryItem getHoldedItem() {
|
public NetworkLibraryItem getHoldedItem() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUniqueKey() {
|
||||||
|
return "org.geometerplus.fbreader.network.tree.Authors:" + Author.DisplayName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,4 +72,9 @@ public class NetworkBookTree extends NetworkTree {
|
||||||
public NetworkLibraryItem getHoldedItem() {
|
public NetworkLibraryItem getHoldedItem() {
|
||||||
return Book;
|
return Book;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUniqueKey() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,4 +167,10 @@ public class NetworkCatalogTree extends NetworkTree {
|
||||||
ChildrenItems.removeAll(items);
|
ChildrenItems.removeAll(items);
|
||||||
super.removeItems(items);
|
super.removeItems(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUniqueKey() {
|
||||||
|
// FIXME: URL can be the same for POST queries!!!
|
||||||
|
return Item.URLByType.get(NetworkCatalogItem.URL_CATALOG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,4 +98,17 @@ public class NetworkSeriesTree extends NetworkTree {
|
||||||
removeSelf();
|
removeSelf();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUniqueKey() {
|
||||||
|
final StringBuilder buffer = new StringBuilder();
|
||||||
|
|
||||||
|
final String parentKey = ((NetworkTree)Parent).getUniqueKey();
|
||||||
|
if (parentKey != null) {
|
||||||
|
buffer.append(parentKey).append("///");
|
||||||
|
}
|
||||||
|
buffer.append("org.geometerplus.fbreader.network.tree.Series:").append(SeriesTitle);
|
||||||
|
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,4 +32,9 @@ public final class RootTree extends NetworkTree {
|
||||||
public NetworkLibraryItem getHoldedItem() {
|
public NetworkLibraryItem getHoldedItem() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUniqueKey() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue