mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 19:42:17 +02:00
code simplification
This commit is contained in:
parent
48de79c40f
commit
348c749054
6 changed files with 20 additions and 56 deletions
|
@ -25,10 +25,9 @@ import android.view.Menu;
|
|||
import android.view.ContextMenu;
|
||||
|
||||
import org.geometerplus.fbreader.network.NetworkTree;
|
||||
|
||||
import org.geometerplus.fbreader.network.AddCustomCatalogItemTree;
|
||||
|
||||
class AddCustomCatalogItemActions extends NetworkTreeActions {
|
||||
|
||||
public static final int RUN_ITEM_ID = 0;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -474,7 +474,6 @@ class NetworkCatalogActions extends NetworkTreeActions {
|
|||
private void removeCustomLink(ICustomNetworkLink link) {
|
||||
final NetworkLibrary library = NetworkLibrary.Instance();
|
||||
library.removeCustomLink(link);
|
||||
library.updateChildren();
|
||||
library.synchronize();
|
||||
NetworkView.Instance().fireModelChangedAsync();
|
||||
}
|
||||
|
|
|
@ -91,7 +91,6 @@ public class NetworkLibraryActivity extends NetworkBaseActivity {
|
|||
public void run() {
|
||||
final NetworkLibrary library = NetworkLibrary.Instance();
|
||||
library.addCustomLink(link);
|
||||
library.updateChildren();
|
||||
library.synchronize();
|
||||
NetworkView.Instance().fireModelChangedAsync();
|
||||
getListView().invalidateViews();
|
||||
|
@ -227,7 +226,7 @@ public class NetworkLibraryActivity extends NetworkBaseActivity {
|
|||
if (!NetworkView.Instance().isInitialized()) {
|
||||
return 0;
|
||||
}
|
||||
return myTree.subTrees().size() + 2; // subtrees + <search item> + <add custom catalog item>
|
||||
return myTree.subTrees().size() + 1; // subtrees + <search item>
|
||||
}
|
||||
|
||||
public final NetworkTree getItem(int position) {
|
||||
|
@ -236,8 +235,6 @@ public class NetworkLibraryActivity extends NetworkBaseActivity {
|
|||
return NetworkView.Instance().getSearchItemTree();
|
||||
} else if (position > 0 && position <= size) {
|
||||
return (NetworkTree)myTree.subTrees().get(position - 1);
|
||||
} else if (position == size + 1) {
|
||||
return NetworkView.Instance().getAddCustomCatalogItemTree();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -319,7 +316,6 @@ public class NetworkLibraryActivity extends NetworkBaseActivity {
|
|||
}
|
||||
}
|
||||
library.setActiveLanguageCodes(newActiveCodes);
|
||||
library.invalidateChildren();
|
||||
library.synchronize();
|
||||
NetworkView.Instance().fireModelChanged();
|
||||
}
|
||||
|
|
|
@ -71,7 +71,6 @@ class NetworkView {
|
|||
|
||||
final NetworkTree root = library.getRootTree();
|
||||
mySearchItem = new SearchItemTree(root);
|
||||
myAddCustomCatalogItem = new AddCustomCatalogItemTree(root);
|
||||
|
||||
myInitialized = true;
|
||||
}
|
||||
|
@ -297,13 +296,8 @@ class NetworkView {
|
|||
*/
|
||||
|
||||
private SearchItemTree mySearchItem;
|
||||
private AddCustomCatalogItemTree myAddCustomCatalogItem;
|
||||
|
||||
public SearchItemTree getSearchItemTree() {
|
||||
return mySearchItem;
|
||||
}
|
||||
|
||||
public AddCustomCatalogItemTree getAddCustomCatalogItemTree() {
|
||||
return myAddCustomCatalogItem;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.android.fbreader.network;
|
||||
package org.geometerplus.fbreader.network;
|
||||
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
|
@ -119,6 +119,7 @@ public class NetworkLibrary {
|
|||
allCodes.removeAll(languageCodes());
|
||||
allCodes.addAll(codes);
|
||||
activeLanguageCodesOption().setValue(commaSeparatedString(allCodes));
|
||||
invalidateChildren();
|
||||
}
|
||||
|
||||
private String commaSeparatedString(Collection<String> codes) {
|
||||
|
@ -149,8 +150,7 @@ public class NetworkLibrary {
|
|||
|
||||
private final RootTree myRootTree = new RootTree();
|
||||
|
||||
private boolean myUpdateChildren = true;
|
||||
private boolean myInvalidateChildren;
|
||||
private boolean myChildrenAreInvalid = true;
|
||||
private boolean myUpdateVisibility;
|
||||
|
||||
private NetworkLibrary() {
|
||||
|
@ -188,24 +188,6 @@ public class NetworkLibrary {
|
|||
);
|
||||
}
|
||||
|
||||
/*testDate(new ATOMUpdated(2010, 1, 1, 1, 0, 0, 0, 2, 0),
|
||||
new ATOMUpdated(2009, 12, 31, 23, 0, 0, 0, 0, 0));
|
||||
testDate(new ATOMUpdated(2010, 12, 31, 23, 40, 0, 0, -1, -30),
|
||||
new ATOMUpdated(2011, 1, 1, 1, 10, 0, 0, 0, 0));
|
||||
testDate(new ATOMUpdated(2010, 1, 31, 23, 40, 0, 0, -1, -30),
|
||||
new ATOMUpdated(2010, 2, 1, 1, 10, 0, 0, 0, 0));
|
||||
testDate(new ATOMUpdated(2010, 2, 28, 23, 40, 0, 0, -1, -30),
|
||||
new ATOMUpdated(2010, 3, 1, 1, 10, 0, 0, 0, 0));
|
||||
testDate(new ATOMUpdated(2012, 2, 28, 23, 40, 0, 0, -1, -30),
|
||||
new ATOMUpdated(2012, 2, 29, 1, 10, 0, 0, 0, 0));
|
||||
testDate(new ATOMUpdated(2012, 2, 15, 23, 40, 0, 0, -1, -30),
|
||||
new ATOMUpdated(2012, 2, 16, 1, 10, 0, 0, 0, 0));
|
||||
testDate(new ATOMUpdated(2012, 2, 15, 23, 40, 1, 0, 3, 30),
|
||||
new ATOMUpdated(2012, 2, 15, 23, 40, 0, 0, 3, 30));
|
||||
testDate(new ATOMUpdated(2012, 2, 15, 23, 40, 0, 0, 3, 30),
|
||||
new ATOMUpdated(2012, 2, 15, 23, 40, 1, 0, 3, 30));
|
||||
testDate(new ATOMUpdated(2012, 2, 15, 23, 40, 0, 0.001f, 3, 30),
|
||||
new ATOMUpdated(2012, 2, 15, 23, 40, 0, 0, 3, 30));*/
|
||||
myIsAlreadyInitialized = true;
|
||||
}
|
||||
|
||||
|
@ -272,7 +254,7 @@ public class NetworkLibrary {
|
|||
synchronized (myLinks) {
|
||||
removeAllLoadedLinks();
|
||||
myLinks.addAll(myBackgroundLinks);
|
||||
updateChildren();
|
||||
invalidateChildren();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -291,30 +273,22 @@ public class NetworkLibrary {
|
|||
}
|
||||
|
||||
public void invalidateChildren() {
|
||||
myInvalidateChildren = true;
|
||||
}
|
||||
|
||||
public void updateChildren() {
|
||||
myUpdateChildren = true;
|
||||
myChildrenAreInvalid = true;
|
||||
}
|
||||
|
||||
public void invalidateVisibility() {
|
||||
myUpdateVisibility = true;
|
||||
}
|
||||
|
||||
private static boolean linkIsInvalid(INetworkLink link, INetworkLink nodeLink) {
|
||||
if (link instanceof ICustomNetworkLink) {
|
||||
if (link != nodeLink) {
|
||||
throw new RuntimeException("Two equal custom links!!! That's impossible");
|
||||
}
|
||||
return ((ICustomNetworkLink) link).hasChanges();
|
||||
}
|
||||
return !link.equals(nodeLink);
|
||||
private static boolean linkIsChanged(INetworkLink link) {
|
||||
return
|
||||
link instanceof ICustomNetworkLink &&
|
||||
((ICustomNetworkLink)link).hasChanges();
|
||||
}
|
||||
|
||||
private static void makeValid(INetworkLink link) {
|
||||
if (link instanceof ICustomNetworkLink) {
|
||||
((ICustomNetworkLink) link).resetChanges();
|
||||
((ICustomNetworkLink)link).resetChanges();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -340,9 +314,9 @@ public class NetworkLibrary {
|
|||
++nodeCount;
|
||||
continue;
|
||||
}
|
||||
final INetworkLink nodeLink = ((NetworkCatalogTree) currentNode).Item.Link;
|
||||
final INetworkLink nodeLink = ((NetworkCatalogTree)currentNode).Item.Link;
|
||||
if (link == nodeLink) {
|
||||
if (linkIsInvalid(link, nodeLink)) {
|
||||
if (linkIsChanged(link)) {
|
||||
toRemove.add(currentNode);
|
||||
} else {
|
||||
processed = true;
|
||||
|
@ -359,7 +333,7 @@ public class NetworkLibrary {
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (newNodeLink == null || linkIsInvalid(newNodeLink, nodeLink)) {
|
||||
if (newNodeLink == null || linkIsChanged(nodeLink)) {
|
||||
toRemove.add(currentNode);
|
||||
currentNode = null;
|
||||
++nodeCount;
|
||||
|
@ -390,6 +364,7 @@ public class NetworkLibrary {
|
|||
for (FBTree tree : toRemove) {
|
||||
tree.removeSelf();
|
||||
}
|
||||
new AddCustomCatalogItemTree(myRootTree);
|
||||
}
|
||||
|
||||
private void updateVisibility() {
|
||||
|
@ -402,9 +377,8 @@ public class NetworkLibrary {
|
|||
}
|
||||
|
||||
public void synchronize() {
|
||||
if (myUpdateChildren || myInvalidateChildren) {
|
||||
myUpdateChildren = false;
|
||||
myInvalidateChildren = false;
|
||||
if (myChildrenAreInvalid) {
|
||||
myChildrenAreInvalid = false;
|
||||
makeUpToDate();
|
||||
}
|
||||
if (myUpdateVisibility) {
|
||||
|
@ -499,6 +473,7 @@ public class NetworkLibrary {
|
|||
}
|
||||
}
|
||||
NetworkDatabase.Instance().saveCustomLink(link);
|
||||
invalidateChildren();
|
||||
}
|
||||
|
||||
public void removeCustomLink(ICustomNetworkLink link) {
|
||||
|
@ -506,6 +481,7 @@ public class NetworkLibrary {
|
|||
myLinks.remove(link);
|
||||
}
|
||||
NetworkDatabase.Instance().deleteCustomLink(link);
|
||||
invalidateChildren();
|
||||
}
|
||||
|
||||
public boolean hasCustomLinkTitle(String title, INetworkLink exceptFor) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue