mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
SearchResult`s authors are displayed
git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@1327 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
199df4b4a3
commit
05a1024195
4 changed files with 113 additions and 23 deletions
|
@ -33,6 +33,9 @@ import android.net.Uri;
|
|||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
||||
import org.geometerplus.fbreader.network.*;
|
||||
import org.geometerplus.fbreader.network.tree.SearchResultTree;
|
||||
|
||||
import org.geometerplus.android.fbreader.ZLTreeAdapter;
|
||||
|
||||
|
||||
public class NetworkSearchActivity extends Activity {
|
||||
|
@ -54,9 +57,11 @@ public class NetworkSearchActivity extends Activity {
|
|||
private class SearchHandler extends ItemsLoadingHandler {
|
||||
|
||||
private final SearchResult myResult;
|
||||
private boolean doExpand;
|
||||
|
||||
public SearchHandler(SearchResult result) {
|
||||
myResult = result;
|
||||
doExpand = true;
|
||||
}
|
||||
|
||||
public void onUpdateItems(List<NetworkLibraryItem> items) {
|
||||
|
@ -74,6 +79,17 @@ public class NetworkSearchActivity extends Activity {
|
|||
if (NetworkLibraryActivity.Instance != null) {
|
||||
NetworkLibraryActivity.Instance.resetTree();
|
||||
}
|
||||
|
||||
if (doExpand && NetworkLibraryActivity.Instance != null) {
|
||||
final SearchResultTree tree = library.getSearchResultTree();
|
||||
if (tree != null) {
|
||||
ZLTreeAdapter adapter = NetworkLibraryActivity.Instance.getAdapter();
|
||||
if (adapter != null) {
|
||||
adapter.expandOrCollapseTree(tree);
|
||||
}
|
||||
doExpand = !tree.hasChildren();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onFinish(String errorMessage) {
|
||||
|
@ -139,6 +155,9 @@ public class NetworkSearchActivity extends Activity {
|
|||
library.setSearchResult(result);
|
||||
library.invalidate();
|
||||
library.synchronize();
|
||||
if (NetworkLibraryActivity.Instance != null) {
|
||||
NetworkLibraryActivity.Instance.resetTree();
|
||||
}
|
||||
|
||||
final SearchHandler handler = new SearchHandler(result);
|
||||
NetworkLibraryActivity.Instance.startItemsLoading(
|
||||
|
|
|
@ -52,6 +52,7 @@ public class NetworkLibrary {
|
|||
private boolean myUpdateAccountDependents;
|
||||
|
||||
private SearchResult mySearchResult;
|
||||
private SearchResultTree mySearchResultTree;
|
||||
|
||||
private static class LinksComparator implements Comparator<NetworkLink> {
|
||||
public int compare(NetworkLink link1, NetworkLink link2) {
|
||||
|
@ -133,6 +134,10 @@ public class NetworkLibrary {
|
|||
mySearchResult = searchResult;
|
||||
}
|
||||
|
||||
public SearchResultTree getSearchResultTree() {
|
||||
return mySearchResultTree;
|
||||
}
|
||||
|
||||
private void makeUpToDate() {
|
||||
final LinkedList<FBTree> toRemove = new LinkedList<FBTree>();
|
||||
|
||||
|
@ -184,15 +189,11 @@ public class NetworkLibrary {
|
|||
}
|
||||
}
|
||||
|
||||
SearchResultTree srTree = null;
|
||||
|
||||
while (currentNode != null || nodeIterator.hasNext()) {
|
||||
if (currentNode == null) {
|
||||
currentNode = nodeIterator.next();
|
||||
}
|
||||
if (currentNode instanceof SearchResultTree) {
|
||||
srTree = (SearchResultTree) currentNode;
|
||||
} else {
|
||||
if (currentNode != mySearchResultTree) {
|
||||
toRemove.add(currentNode);
|
||||
}
|
||||
currentNode = null;
|
||||
|
@ -200,31 +201,24 @@ public class NetworkLibrary {
|
|||
}
|
||||
|
||||
if (mySearchResult == null || mySearchResult.empty()) {
|
||||
if (srTree != null) {
|
||||
toRemove.add(srTree);
|
||||
if (mySearchResultTree != null) {
|
||||
toRemove.add(mySearchResultTree);
|
||||
mySearchResultTree = null;
|
||||
}
|
||||
} else {
|
||||
if (srTree != null && srTree.Result != mySearchResult) {
|
||||
toRemove.add(srTree);
|
||||
srTree = null;
|
||||
if (mySearchResultTree != null && mySearchResultTree.Result != mySearchResult) {
|
||||
toRemove.add(mySearchResultTree);
|
||||
mySearchResultTree = null;
|
||||
}
|
||||
if (srTree == null) {
|
||||
srTree = new SearchResultTree(myRootTree, mySearchResult); // at nodeCount ???
|
||||
// TODO: create subnodes
|
||||
} else {
|
||||
// TODO: update subnodes
|
||||
if (mySearchResultTree == null) {
|
||||
mySearchResultTree = new SearchResultTree(myRootTree, mySearchResult); // at nodeCount ???
|
||||
}
|
||||
//NetworkNodesFactory::createSubnodes(srNode, result);
|
||||
mySearchResultTree.updateSubTrees();
|
||||
}
|
||||
|
||||
for (FBTree tree: toRemove) {
|
||||
tree.removeSelf();
|
||||
}
|
||||
|
||||
/*if (srNode != null) {
|
||||
srNode->open(false);
|
||||
srNode->expandOrCollapseSubtree();
|
||||
}*/
|
||||
}
|
||||
|
||||
private void updateAccountDependents() {
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.geometerplus.fbreader.network.*;
|
|||
public class NetworkAuthorTree extends NetworkTree {
|
||||
|
||||
public final NetworkBookItem.AuthorData Author;
|
||||
public int BooksNumber; // TODO hide this field
|
||||
|
||||
|
||||
NetworkAuthorTree(NetworkTree parent, NetworkBookItem.AuthorData author) {
|
||||
|
|
|
@ -26,8 +26,8 @@ import org.geometerplus.zlibrary.core.image.ZLFileImage;
|
|||
import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile;
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
||||
import org.geometerplus.fbreader.network.NetworkTree;
|
||||
import org.geometerplus.fbreader.network.SearchResult;
|
||||
import org.geometerplus.fbreader.tree.FBTree;
|
||||
import org.geometerplus.fbreader.network.*;
|
||||
|
||||
|
||||
public class SearchResultTree extends NetworkTree {
|
||||
|
@ -54,4 +54,80 @@ public class SearchResultTree extends NetworkTree {
|
|||
ZLResourceFile file = ZLResourceFile.createResourceFile("data/searchresult.png");
|
||||
return new ZLFileImage("image/png", file);
|
||||
}
|
||||
|
||||
public void updateSubTrees() {
|
||||
final LinkedList<FBTree> toRemove = new LinkedList<FBTree>();
|
||||
|
||||
ListIterator<FBTree> nodeIterator = subTrees().listIterator();
|
||||
FBTree currentNode = null;
|
||||
int nodeCount = 0;
|
||||
|
||||
final ArrayList<NetworkBookItem.AuthorData> authors = new ArrayList<NetworkBookItem.AuthorData>();
|
||||
authors.addAll(Result.BooksMap.keySet());
|
||||
|
||||
for (int i = 0; i < authors.size(); ++i) {
|
||||
NetworkBookItem.AuthorData currentItem = authors.get(i);
|
||||
boolean processed = false;
|
||||
while (currentNode != null || nodeIterator.hasNext()) {
|
||||
if (currentNode == null) {
|
||||
currentNode = nodeIterator.next();
|
||||
}
|
||||
if (!(currentNode instanceof NetworkAuthorTree)) {
|
||||
currentNode = null;
|
||||
++nodeCount;
|
||||
continue;
|
||||
}
|
||||
NetworkAuthorTree child = (NetworkAuthorTree) currentNode;
|
||||
if (child.Author.equals(currentItem)) {
|
||||
LinkedList<NetworkBookItem> authorBooks = Result.BooksMap.get(currentItem);
|
||||
if (child.BooksNumber != authorBooks.size()) { // TODO: implement by child's method
|
||||
//update author's books
|
||||
child.BooksNumber = authorBooks.size(); // TODO: move into child's update code
|
||||
}
|
||||
currentNode = null;
|
||||
++nodeCount;
|
||||
processed = true;
|
||||
break;
|
||||
} else {
|
||||
boolean found = false;
|
||||
for (int j = i + 1; j < authors.size(); ++j) {
|
||||
if (child.Author.equals(authors.get(j))) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
toRemove.add(currentNode);
|
||||
currentNode = null;
|
||||
++nodeCount;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
final int nextIndex = nodeIterator.nextIndex();
|
||||
if (!processed) {
|
||||
LinkedList<NetworkBookItem> authorBooks = Result.BooksMap.get(currentItem);
|
||||
if (authorBooks.size() != 0) {
|
||||
NetworkAuthorTree child = new NetworkAuthorTree(this, currentItem);
|
||||
//update author's books
|
||||
child.BooksNumber = authorBooks.size(); // TODO: move into child's update code
|
||||
++nodeCount;
|
||||
nodeIterator = subTrees().listIterator(nextIndex + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (currentNode != null || nodeIterator.hasNext()) {
|
||||
if (currentNode == null) {
|
||||
currentNode = nodeIterator.next();
|
||||
}
|
||||
toRemove.add(currentNode);
|
||||
currentNode = null;
|
||||
}
|
||||
|
||||
for (FBTree tree: toRemove) {
|
||||
tree.removeSelf();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue