1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 10:49:24 +02:00

Network tree classes & Network Adapter have been added

git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@1060 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
Vasiliy Bout 2010-02-24 20:51:27 +00:00
parent 30e9f8dae0
commit 1cddf78fa1
12 changed files with 404 additions and 14 deletions

View file

@ -21,6 +21,8 @@ package org.geometerplus.fbreader.network;
import java.util.*;
import org.geometerplus.fbreader.tree.FBTree;
import org.geometerplus.fbreader.network.tree.*;
public class NetworkLibrary {
private static NetworkLibrary ourInstance;
@ -33,17 +35,32 @@ public class NetworkLibrary {
}
private List<NetworkLink> myLinks;
private final ArrayList<NetworkLink> myLinks = new ArrayList<NetworkLink>();
private final RootTree myRootTree = new RootTree();
private boolean myUpdateChildren = true;
private static class DummyCatalogItem extends NetworkCatalogItem {
public DummyCatalogItem(NetworkLink link, String title, String summary) {
super(link, title, summary, VisibilityType.ALWAYS);
}
@Override
public String loadChildren(List<NetworkLibraryItem> children) {
return "";
}
}
public NetworkLibrary() {
myLinks.add(new NetworkLink("feedbooks.com") {
public NetworkLibraryItem libraryItem() {
return new NetworkLibraryItem(this, "Feedbooks catalog", "feedbooks online catalog");
return new DummyCatalogItem(this, "Feedbooks catalog", "feedbooks online catalog");
}
});
myLinks.add(new NetworkLink("litres.ru") {
public NetworkLibraryItem libraryItem() {
return new NetworkLibraryItem(this, "Litres catalog", "litres online catalog");
return new DummyCatalogItem(this, "Litres catalog", "litres online catalog");
}
});
}
@ -52,4 +69,105 @@ public class NetworkLibrary {
return Collections.unmodifiableList(myLinks);
}
public void invalidate() {
myUpdateChildren = true;
}
private void makeUpToDate() {
final List<FBTree> toRemove = new LinkedList<FBTree>();
Iterator<FBTree> nodeIterator = myRootTree.iterator();
FBTree currentNode = null;
int nodeCount = 0;
for (int i = 0; i < myLinks.size(); ++i) {
NetworkLink link = myLinks.get(i);
if (!link.OnOption.getValue()) {
continue;
}
boolean processed = false;
while (currentNode != null || nodeIterator.hasNext()) {
if (currentNode == null) {
currentNode = nodeIterator.next();
}
if (!(currentNode instanceof NetworkCatalogTree)) {
currentNode = null;
continue;
}
final NetworkLink nodeLink = ((NetworkCatalogTree)currentNode).Item.Link;
if (nodeLink == link) {
currentNode = null;
++nodeCount;
processed = true;
break;
} else {
boolean found = false;
for (int j = i + 1; j < myLinks.size(); ++j) {
if (nodeLink == myLinks.get(j)) {
found = true;
break;
}
}
if (!found) {
toRemove.add(currentNode);
currentNode = null;
++nodeCount;
} else {
break;
}
}
}
if (!processed) {
NetworkCatalogRootTree ptr = new NetworkCatalogRootTree(myRootTree, link, nodeCount++);
//ptr.item().onDisplayItem();
}
}
/*SearchResultNode srNode = null;
while (nodeIterator.hasNext()) {
FBTree node = nodeIterator.next();
++nodeCount;
if (node instanceof SearchResultNode) {
srNode = (SearchResultNode) node;
} else {
toRemove.add(node);
}
}
final SearchResult searchResult = SearchResult.lastSearchResult();
NetworkBookCollection result = searchResult.collection();
if (result.isNull()) {
if (srNode != 0) {
toRemove.add(srNode);
}
} else if (srNode == null || srNode->searchResult() != result) {
if (srNode != null) {
toRemove.add(srNode);
}
srNode = new SearchResultNode(myRootTree, result, searchResult.summary()); // at nodeCount ??? or not???
NetworkNodesFactory::createSubnodes(srNode, result);
}*/
for (FBTree tree : toRemove) {
tree.removeSelf();
}
/*if (srNode != null) {
srNode->open(false);
srNode->expandOrCollapseSubtree();
}*/
}
public void synchronize() {
if (myUpdateChildren) {
myUpdateChildren = false;
makeUpToDate();
}
}
public NetworkTree getTree() {
synchronize();
return myRootTree;
}
}