diff --git a/src/org/geometerplus/android/fbreader/network/NetworkLibraryActivity.java b/src/org/geometerplus/android/fbreader/network/NetworkLibraryActivity.java index a4893f64c..4dc5cfe1c 100644 --- a/src/org/geometerplus/android/fbreader/network/NetworkLibraryActivity.java +++ b/src/org/geometerplus/android/fbreader/network/NetworkLibraryActivity.java @@ -266,7 +266,9 @@ public class NetworkLibraryActivity extends NetworkBaseActivity { } private static boolean searchIsInProgress() { - return NetworkView.Instance().containsItemsLoadingRunnable(NetworkTree.SearchKey); + return NetworkView.Instance().containsItemsLoadingRunnable( + NetworkLibrary.Instance().getSearchItemTree().getUniqueKey() + ); } @Override diff --git a/src/org/geometerplus/android/fbreader/network/NetworkSearchActivity.java b/src/org/geometerplus/android/fbreader/network/NetworkSearchActivity.java index 94fac197a..4b9496160 100644 --- a/src/org/geometerplus/android/fbreader/network/NetworkSearchActivity.java +++ b/src/org/geometerplus/android/fbreader/network/NetworkSearchActivity.java @@ -86,7 +86,7 @@ public class NetworkSearchActivity extends Activity { myTree.setSearchResult(null); } else { myTree.updateSubTrees(); - afterUpdateCatalog(errorMessage, myTree.getSearchResult().empty()); + afterUpdateCatalog(errorMessage, myTree.getSearchResult().isEmpty()); } if (NetworkView.Instance().isInitialized()) { NetworkView.Instance().fireModelChangedAsync(); @@ -103,20 +103,29 @@ public class NetworkSearchActivity extends Activity { } else if (childrenEmpty) { boxResource = dialogResource.getResource("emptySearchResults"); msg = boxResource.getResource("message").getValue(); + } else { + return; } - if (msg != null) { - if (NetworkView.Instance().isInitialized()) { - final NetworkCatalogActivity activity = NetworkView.Instance().getOpenedActivity(NetworkTree.SearchKey); - if (activity != null) { - final ZLResource buttonResource = dialogResource.getResource("button"); - new AlertDialog.Builder(activity) - .setTitle(boxResource.getResource("title").getValue()) - .setMessage(msg) - .setIcon(0) - .setPositiveButton(buttonResource.getResource("ok").getValue(), null) - .create().show(); - } - } + + if (!NetworkView.Instance().isInitialized()) { + return; + } + + final SearchItemTree tree = NetworkLibrary.Instance().getSearchItemTree(); + if (tree == null) { + return; + } + + final NetworkCatalogActivity activity = + NetworkView.Instance().getOpenedActivity(tree.getUniqueKey()); + if (activity != null) { + final ZLResource buttonResource = dialogResource.getResource("button"); + new AlertDialog.Builder(activity) + .setTitle(boxResource.getResource("title").getValue()) + .setMessage(msg) + .setIcon(0) + .setPositiveButton(buttonResource.getResource("ok").getValue(), null) + .create().show(); } } } @@ -145,26 +154,24 @@ public class NetworkSearchActivity extends Activity { final NetworkLibrary library = NetworkLibrary.Instance(); library.NetworkSearchPatternOption.setValue(pattern); - if (NetworkView.Instance().containsItemsLoadingRunnable(NetworkTree.SearchKey)) { + final SearchItemTree tree = library.getSearchItemTree(); + if (tree == null || + NetworkView.Instance().containsItemsLoadingRunnable(tree.getUniqueKey())) { return; } final String summary = ZLResource.resource("networkView").getResource("searchResults").getValue().replace("%s", pattern); final SearchResult result = new SearchResult(summary); - /* - final SearchItemTree tree = NetworkView.Instance().getSearchItemTree(); - tree.setSearchResult(result); NetworkView.Instance().fireModelChangedAsync(); final SearchHandler handler = new SearchHandler(tree); NetworkView.Instance().startItemsLoading( this, - NetworkTree.SearchKey, + tree.getUniqueKey(), new SearchRunnable(handler, pattern) ); NetworkView.Instance().openTree(this, tree); - */ } } diff --git a/src/org/geometerplus/android/fbreader/network/SearchItemActions.java b/src/org/geometerplus/android/fbreader/network/SearchItemActions.java index 3bf28b663..043cf73ff 100644 --- a/src/org/geometerplus/android/fbreader/network/SearchItemActions.java +++ b/src/org/geometerplus/android/fbreader/network/SearchItemActions.java @@ -39,7 +39,7 @@ class SearchItemActions extends NetworkTreeActions { @Override public String getTreeTitle(NetworkTree tree) { - final SearchResult result = ((SearchItemTree) tree).getSearchResult(); + final SearchResult result = ((SearchItemTree)tree).getSearchResult(); if (result != null) { return result.Summary; } @@ -50,7 +50,7 @@ class SearchItemActions extends NetworkTreeActions { public void buildContextMenu(Activity activity, ContextMenu menu, NetworkTree tree) { menu.setHeaderTitle(tree.getName()); - final boolean isLoading = NetworkView.Instance().containsItemsLoadingRunnable(NetworkTree.SearchKey); + final boolean isLoading = NetworkView.Instance().containsItemsLoadingRunnable(tree.getUniqueKey()); if (!isLoading) { addMenuItem(menu, RUN_SEARCH_ITEM_ID, "search"); @@ -61,7 +61,7 @@ class SearchItemActions extends NetworkTreeActions { @Override public int getDefaultActionCode(NetworkBaseActivity activity, NetworkTree tree) { - final boolean isLoading = NetworkView.Instance().containsItemsLoadingRunnable(NetworkTree.SearchKey); + final boolean isLoading = NetworkView.Instance().containsItemsLoadingRunnable(tree.getUniqueKey()); if (!isLoading) { return RUN_SEARCH_ITEM_ID; } diff --git a/src/org/geometerplus/fbreader/network/NetworkLibrary.java b/src/org/geometerplus/fbreader/network/NetworkLibrary.java index 7b9211847..51f790cb5 100644 --- a/src/org/geometerplus/fbreader/network/NetworkLibrary.java +++ b/src/org/geometerplus/fbreader/network/NetworkLibrary.java @@ -149,6 +149,7 @@ public class NetworkLibrary { } private final RootTree myRootTree = new RootTree(); + private SearchItemTree mySearchItemTree; private boolean myChildrenAreInvalid = true; private boolean myUpdateVisibility; @@ -364,7 +365,7 @@ public class NetworkLibrary { tree.removeSelf(); } new AddCustomCatalogItemTree(myRootTree); - new SearchItemTree(myRootTree, 0); + mySearchItemTree = new SearchItemTree(myRootTree, 0); } private void updateVisibility() { @@ -390,6 +391,10 @@ public class NetworkLibrary { return myRootTree; } + public SearchItemTree getSearchItemTree() { + return mySearchItemTree; + } + public NetworkTree getTreeByKey(NetworkTree.Key key) { if (key.Parent == null) { return key.equals(myRootTree.getUniqueKey()) ? myRootTree : null; diff --git a/src/org/geometerplus/fbreader/network/NetworkTree.java b/src/org/geometerplus/fbreader/network/NetworkTree.java index 50524143f..cb13a446f 100644 --- a/src/org/geometerplus/fbreader/network/NetworkTree.java +++ b/src/org/geometerplus/fbreader/network/NetworkTree.java @@ -29,8 +29,6 @@ import org.geometerplus.zlibrary.core.image.ZLImage; import org.geometerplus.fbreader.tree.FBTree; public abstract class NetworkTree extends FBTree { - public static final Key SearchKey = new Key(null, "@Search"); - public static class Key implements Serializable { final Key Parent; final String Id; diff --git a/src/org/geometerplus/fbreader/network/SearchResult.java b/src/org/geometerplus/fbreader/network/SearchResult.java index 68e4ae717..70a7fd413 100644 --- a/src/org/geometerplus/fbreader/network/SearchResult.java +++ b/src/org/geometerplus/fbreader/network/SearchResult.java @@ -23,13 +23,12 @@ import java.util.LinkedHashMap; import java.util.LinkedList; public class SearchResult { - public final String Summary; - public final LinkedHashMap> BooksMap; + public final LinkedHashMap> BooksMap = + new LinkedHashMap>(); public SearchResult(String summary) { Summary = summary; - BooksMap = new LinkedHashMap>(); } public void addBook(NetworkBookItem book) { @@ -43,7 +42,7 @@ public class SearchResult { } } - public boolean empty() { + public boolean isEmpty() { return BooksMap.size() == 0; } }