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

catalog's items hiding has been implemented

git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@1135 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
Vasiliy Bout 2010-03-23 18:56:21 +00:00
parent 0a5bd768cf
commit 1744d5c718
4 changed files with 111 additions and 7 deletions

View file

@ -3,7 +3,7 @@ DONE переместить в главном меню наверх (вмест
DONE пункт меню "delete sample"
DONE BookDownloaderService - i18n
DONE указывать HTTP-agent = "FBReader/<version>(java)" -- номер версии смотреть, как в диалоге About
* прятать Profile (прятать запрещенные каталоги)
DONE прятать Profile (прятать запрещенные каталоги)
* при щелчке на книжку - сделать default action, и о нем спрашивать.
* асинхронная загрузка каталогов

View file

@ -263,8 +263,9 @@ public class NetworkLibraryActivity extends ListActivity implements MenuItem.OnM
private void updateCatalogChildren(NetworkCatalogTree tree) {
tree.clear();
ArrayList<NetworkLibraryItem> children = new ArrayList<NetworkLibraryItem>();
ArrayList<NetworkLibraryItem> children = tree.ChildrenItems;
children.clear();
LoadSubCatalogRunnable loader = new LoadSubCatalogRunnable(tree.Item, children);
loader.executeWithUI();
if (loader.hasErrors()) {
@ -296,8 +297,8 @@ public class NetworkLibraryActivity extends ListActivity implements MenuItem.OnM
} else {
NetworkTreeFactory.fillAuthorNode(tree, children);
}
//NetworkLibrary.invalidateAccountDependents();
//NetworkLibrary.synchronize();
NetworkLibrary.Instance().invalidateAccountDependents();
NetworkLibrary.Instance().synchronize();
}

View file

@ -43,6 +43,7 @@ public class NetworkLibrary {
private final RootTree myRootTree = new RootTree();
private boolean myUpdateChildren = true;
private boolean myUpdateAccountDependents;
private static class LinksComparator implements Comparator<NetworkLink> {
public int compare(NetworkLink link1, NetworkLink link2) {
@ -90,10 +91,14 @@ public class NetworkLibrary {
myUpdateChildren = true;
}
public void invalidateAccountDependents() {
myUpdateAccountDependents = true;
}
private void makeUpToDate() {
final LinkedList<FBTree> toRemove = new LinkedList<FBTree>();
Iterator<FBTree> nodeIterator = myRootTree.iterator();
Iterator<FBTree> nodeIterator = myRootTree.subTrees().iterator();
FBTree currentNode = null;
int nodeCount = 0;
@ -109,6 +114,7 @@ public class NetworkLibrary {
}
if (!(currentNode instanceof NetworkCatalogTree)) {
currentNode = null;
++nodeCount;
continue;
}
final NetworkLink nodeLink = ((NetworkCatalogTree)currentNode).Item.Link;
@ -165,7 +171,7 @@ public class NetworkLibrary {
NetworkNodesFactory::createSubnodes(srNode, result);
}*/
for (FBTree tree : toRemove) {
for (FBTree tree: toRemove) {
tree.removeSelf();
}
@ -175,11 +181,24 @@ public class NetworkLibrary {
}*/
}
private void updateAccountDependents() {
for (FBTree tree: myRootTree.subTrees()) {
if (!(tree instanceof NetworkCatalogTree)) {
continue;
}
((NetworkCatalogTree) tree).updateAccountDependents();
}
}
public void synchronize() {
if (myUpdateChildren) {
myUpdateChildren = false;
makeUpToDate();
}
if (myUpdateAccountDependents) {
myUpdateAccountDependents = false;
updateAccountDependents();
}
}
public NetworkTree getTree() {

View file

@ -21,12 +21,15 @@ package org.geometerplus.fbreader.network.tree;
import java.util.*;
import org.geometerplus.zlibrary.core.util.ZLBoolean3;
import org.geometerplus.fbreader.tree.FBTree;
import org.geometerplus.fbreader.network.*;
public class NetworkCatalogTree extends NetworkTree {
public final NetworkCatalogItem Item;
public final ArrayList<NetworkLibraryItem> ChildrenItems = new ArrayList<NetworkLibraryItem>();
NetworkCatalogTree(RootTree parent, NetworkCatalogItem item, int position) {
super(parent, position);
@ -50,4 +53,85 @@ public class NetworkCatalogTree extends NetworkTree {
}
return Item.Summary;
}
private boolean processAccountDependent(NetworkCatalogItem item) {
if (item.Visibility == NetworkCatalogItem.VISIBLE_ALWAYS) {
return true;
}
final NetworkLink link = item.Link;
if (link.authenticationManager() == null) {
return false;
}
return link.authenticationManager().isAuthorised(true).Status != ZLBoolean3.B3_FALSE;
}
public void updateAccountDependents() {
final LinkedList<FBTree> toRemove = new LinkedList<FBTree>();
Iterator<FBTree> nodeIterator = subTrees().iterator();
FBTree currentNode = null;
int nodeCount = 0;
for (int i = 0; i < ChildrenItems.size(); ++i) {
NetworkLibraryItem currentItem = ChildrenItems.get(i);
if (!(currentItem instanceof NetworkCatalogItem)) {
continue;
}
boolean processed = false;
while (currentNode != null || nodeIterator.hasNext()) {
if (currentNode == null) {
currentNode = nodeIterator.next();
}
if (!(currentNode instanceof NetworkCatalogTree)) {
currentNode = null;
++nodeCount;
continue;
}
NetworkCatalogTree child = (NetworkCatalogTree) currentNode;
if (child.Item == currentItem) {
if (processAccountDependent(child.Item)) {
child.updateAccountDependents();
} else {
toRemove.add(child);
}
currentNode = null;
++nodeCount;
processed = true;
break;
} else {
boolean found = false;
for (int j = i + 1; j < ChildrenItems.size(); ++j) {
if (child.Item == ChildrenItems.get(j)) {
found = true;
break;
}
}
if (!found) {
toRemove.add(currentNode);
currentNode = null;
++nodeCount;
} else {
break;
}
}
}
if (!processed && processAccountDependent((NetworkCatalogItem) currentItem)) {
NetworkTreeFactory.createNetworkTree(this, currentItem, nodeCount++);
}
}
while (currentNode != null || nodeIterator.hasNext()) {
if (currentNode == null) {
currentNode = nodeIterator.next();
}
if (currentNode instanceof NetworkCatalogTree) {
toRemove.add(currentNode);
}
currentNode = null;
}
for (FBTree tree: toRemove) {
tree.removeSelf();
}
}
}