mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
fixed NetworkTree.Key.equals; "get NetworkTree by key" method
This commit is contained in:
parent
d096a3456a
commit
05461052e6
3 changed files with 54 additions and 28 deletions
|
@ -28,6 +28,7 @@ import android.content.Intent;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||||
|
|
||||||
|
import org.geometerplus.fbreader.network.NetworkLibrary;
|
||||||
import org.geometerplus.fbreader.network.NetworkTree;
|
import org.geometerplus.fbreader.network.NetworkTree;
|
||||||
import org.geometerplus.fbreader.network.tree.*;
|
import org.geometerplus.fbreader.network.tree.*;
|
||||||
|
|
||||||
|
@ -36,7 +37,6 @@ public class NetworkCatalogActivity extends NetworkBaseActivity implements UserR
|
||||||
public static final String CATALOG_KEY_KEY = "org.geometerplus.android.fbreader.network.CatalogKey";
|
public static final String CATALOG_KEY_KEY = "org.geometerplus.android.fbreader.network.CatalogKey";
|
||||||
|
|
||||||
private NetworkTree myTree;
|
private NetworkTree myTree;
|
||||||
private NetworkTree.Key myCatalogKey;
|
|
||||||
private volatile boolean myInProgress;
|
private volatile boolean myInProgress;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -57,14 +57,16 @@ public class NetworkCatalogActivity extends NetworkBaseActivity implements UserR
|
||||||
throw new RuntimeException("Catalog Level was not specified!!!");
|
throw new RuntimeException("Catalog Level was not specified!!!");
|
||||||
}
|
}
|
||||||
|
|
||||||
myCatalogKey = (NetworkTree.Key)intent.getSerializableExtra(CATALOG_KEY_KEY);
|
final NetworkLibrary library = NetworkLibrary.Instance();
|
||||||
if (myCatalogKey == null) {
|
final NetworkTree.Key key = (NetworkTree.Key)intent.getSerializableExtra(CATALOG_KEY_KEY);
|
||||||
throw new RuntimeException("Catalog Key was not specified!!!");
|
myTree = library.getTreeByKey(key);
|
||||||
|
|
||||||
|
System.err.println("KEY = " + key);
|
||||||
|
if (myTree == null) {
|
||||||
|
throw new RuntimeException("Tree not found for key " + key);
|
||||||
}
|
}
|
||||||
|
|
||||||
myTree = networkView.getOpenedTree(level);
|
networkView.setOpenedActivity(key, this);
|
||||||
|
|
||||||
networkView.setOpenedActivity(myCatalogKey, this);
|
|
||||||
|
|
||||||
setListAdapter(new CatalogAdapter());
|
setListAdapter(new CatalogAdapter());
|
||||||
getListView().invalidateViews();
|
getListView().invalidateViews();
|
||||||
|
@ -113,8 +115,8 @@ public class NetworkCatalogActivity extends NetworkBaseActivity implements UserR
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
if (myTree != null && myCatalogKey != null && NetworkView.Instance().isInitialized()) {
|
if (myTree != null && NetworkView.Instance().isInitialized()) {
|
||||||
NetworkView.Instance().setOpenedActivity(myCatalogKey, null);
|
NetworkView.Instance().setOpenedActivity(myTree.getUniqueKey(), null);
|
||||||
}
|
}
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
@ -220,7 +222,7 @@ public class NetworkCatalogActivity extends NetworkBaseActivity implements UserR
|
||||||
private void doStopLoading() {
|
private void doStopLoading() {
|
||||||
if (NetworkView.Instance().isInitialized()) {
|
if (NetworkView.Instance().isInitialized()) {
|
||||||
final ItemsLoadingRunnable runnable =
|
final ItemsLoadingRunnable runnable =
|
||||||
NetworkView.Instance().getItemsLoadingRunnable(myCatalogKey);
|
NetworkView.Instance().getItemsLoadingRunnable(myTree.getUniqueKey());
|
||||||
if (runnable != null) {
|
if (runnable != null) {
|
||||||
runnable.interruptLoading();
|
runnable.interruptLoading();
|
||||||
}
|
}
|
||||||
|
|
|
@ -417,6 +417,23 @@ public class NetworkLibrary {
|
||||||
return myRootTree;
|
return myRootTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NetworkTree getTreeByKey(NetworkTree.Key key) {
|
||||||
|
if (key.Parent == null) {
|
||||||
|
return key.equals(myRootTree.getUniqueKey()) ? myRootTree : null;
|
||||||
|
}
|
||||||
|
final NetworkTree parentTree = getTreeByKey(key.Parent);
|
||||||
|
if (parentTree == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
for (FBTree tree : parentTree.subTrees()) {
|
||||||
|
final NetworkTree nTree = (NetworkTree)tree;
|
||||||
|
if (key.equals(nTree.getUniqueKey())) {
|
||||||
|
return nTree;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public void simpleSearch(String pattern, final NetworkOperationData.OnNewItemListener listener) throws ZLNetworkException {
|
public void simpleSearch(String pattern, final NetworkOperationData.OnNewItemListener listener) throws ZLNetworkException {
|
||||||
LinkedList<ZLNetworkRequest> requestList = new LinkedList<ZLNetworkRequest>();
|
LinkedList<ZLNetworkRequest> requestList = new LinkedList<ZLNetworkRequest>();
|
||||||
LinkedList<NetworkOperationData> dataList = new LinkedList<NetworkOperationData>();
|
LinkedList<NetworkOperationData> dataList = new LinkedList<NetworkOperationData>();
|
||||||
|
|
|
@ -21,7 +21,7 @@ package org.geometerplus.fbreader.network;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.io.*;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.constants.MimeTypes;
|
import org.geometerplus.zlibrary.core.constants.MimeTypes;
|
||||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||||
|
@ -32,18 +32,15 @@ public abstract class NetworkTree extends FBTree {
|
||||||
public static final Key SearchKey = new Key(null, "@Search");
|
public static final Key SearchKey = new Key(null, "@Search");
|
||||||
|
|
||||||
public static class Key implements Serializable {
|
public static class Key implements Serializable {
|
||||||
private Key myParent;
|
final Key Parent;
|
||||||
private String myId;
|
final String Id;
|
||||||
|
|
||||||
private Key(Key parent, String id) {
|
private Key(Key parent, String id) {
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
throw new IllegalArgumentException("NetworkTree string id must be non-null");
|
throw new IllegalArgumentException("NetworkTree string id must be non-null");
|
||||||
}
|
}
|
||||||
myParent = parent;
|
Parent = parent;
|
||||||
myId = id;
|
Id = id;
|
||||||
}
|
|
||||||
|
|
||||||
private Key() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -55,25 +52,34 @@ public abstract class NetworkTree extends FBTree {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final NetworkTree.Key key = (NetworkTree.Key)other;
|
final NetworkTree.Key key = (NetworkTree.Key)other;
|
||||||
return myParent == key.myParent && myId.equals(key.myId);
|
if (Parent == null) {
|
||||||
|
return key.Parent == null && Id.equals(key.Id);
|
||||||
|
}
|
||||||
|
return Id.equals(key.Id) && Parent.equals(key.Parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return myId.hashCode();
|
return Id.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return Parent == null ? Id : Parent.toString() + " :: " + Id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
private void writeObject(ObjectOutputStream os) throws IOException {
|
private void writeObject(ObjectOutputStream os) throws IOException {
|
||||||
if (myParent != null) {
|
if (Parent != null) {
|
||||||
myParent.writeObject(os);
|
Parent.writeObject(os);
|
||||||
}
|
}
|
||||||
os.writeBytes(myId);
|
os.writeBytes(Id);
|
||||||
os.writeBytes("\000");
|
os.writeBytes("\000");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readObject(ObjectInputStream is) throws IOException, ClassNotFoundException {
|
private void readObject(ObjectInputStream is) throws IOException, ClassNotFoundException {
|
||||||
myParent = null;
|
Parent = null;
|
||||||
myId = null;
|
Id = null;
|
||||||
|
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
try {
|
try {
|
||||||
|
@ -82,16 +88,17 @@ public abstract class NetworkTree extends FBTree {
|
||||||
if (c != '\000') {
|
if (c != '\000') {
|
||||||
builder.append(c);
|
builder.append(c);
|
||||||
} else {
|
} else {
|
||||||
if (myId != null) {
|
if (Id != null) {
|
||||||
myParent = new Key(myParent, myId);
|
Parent = new Key(Parent, Id);
|
||||||
}
|
}
|
||||||
myId = builder.toString();
|
Id = builder.toString();
|
||||||
builder.delete(0, builder.length());
|
builder.delete(0, builder.length());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
protected NetworkTree() {
|
protected NetworkTree() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue