mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 10:19:33 +02:00
Library: keys instead of \000-separated strings
This commit is contained in:
parent
3b0179460c
commit
31b3f2607e
6 changed files with 51 additions and 64 deletions
|
@ -53,6 +53,7 @@ abstract class BaseActivity extends ListActivity {
|
|||
protected static final int RESULT_DO_INVALIDATE_VIEWS = 1;
|
||||
|
||||
static final String TREE_PATH_KEY = "TreePath";
|
||||
private static final String TREE_KEY_KEY = "TreeKey";
|
||||
static final String PARAMETER_KEY = "Parameter";
|
||||
|
||||
static final String PATH_FILE_TREE = "fileTree";
|
||||
|
@ -63,8 +64,8 @@ abstract class BaseActivity extends ListActivity {
|
|||
protected final ZLResource myResource = ZLResource.resource("libraryView");
|
||||
protected String mySelectedBookPath;
|
||||
private Book mySelectedBook;
|
||||
private String myTreePathString;
|
||||
protected String[] myTreePath;
|
||||
protected FBTree.Key myTreeKey;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
|
@ -80,8 +81,9 @@ abstract class BaseActivity extends ListActivity {
|
|||
startService(new Intent(getApplicationContext(), InitializationService.class));
|
||||
}
|
||||
|
||||
myTreePathString = getIntent().getStringExtra(TREE_PATH_KEY);
|
||||
myTreePath = myTreePathString != null ? myTreePathString.split("\000") : new String[0];
|
||||
final String treePathString = getIntent().getStringExtra(TREE_PATH_KEY);
|
||||
myTreePath = treePathString != null ? treePathString.split("\000") : new String[0];
|
||||
myTreeKey = (FBTree.Key)getIntent().getSerializableExtra(TREE_KEY_KEY);
|
||||
|
||||
mySelectedBookPath = getIntent().getStringExtra(SELECTED_BOOK_PATH_KEY);
|
||||
mySelectedBook = null;
|
||||
|
@ -124,7 +126,7 @@ abstract class BaseActivity extends ListActivity {
|
|||
} else if (tree instanceof BookTree) {
|
||||
showBookInfo(((BookTree)tree).Book);
|
||||
} else {
|
||||
new OpenTreeRunnable(LibraryInstance, myTreePathString + "\000" + tree.getName()).run();
|
||||
new OpenTreeRunnable(LibraryInstance, tree.getUniqueKey()).run();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -281,11 +283,11 @@ abstract class BaseActivity extends ListActivity {
|
|||
}
|
||||
|
||||
protected class StartTreeActivityRunnable implements Runnable {
|
||||
private final String myTreePath;
|
||||
private final FBTree.Key myTreeKey;
|
||||
private final String myParameter;
|
||||
|
||||
public StartTreeActivityRunnable(String treePath, String parameter) {
|
||||
myTreePath = treePath;
|
||||
public StartTreeActivityRunnable(FBTree.Key key, String parameter) {
|
||||
myTreeKey = key;
|
||||
myParameter = parameter;
|
||||
}
|
||||
|
||||
|
@ -293,7 +295,7 @@ abstract class BaseActivity extends ListActivity {
|
|||
startActivityForResult(
|
||||
new Intent(BaseActivity.this, LibraryTreeActivity.class)
|
||||
.putExtra(SELECTED_BOOK_PATH_KEY, mySelectedBookPath)
|
||||
.putExtra(TREE_PATH_KEY, myTreePath)
|
||||
.putExtra(TREE_KEY_KEY, myTreeKey)
|
||||
.putExtra(PARAMETER_KEY, myParameter),
|
||||
CHILD_LIST_REQUEST
|
||||
);
|
||||
|
@ -304,12 +306,12 @@ abstract class BaseActivity extends ListActivity {
|
|||
private final Library myLibrary;
|
||||
private final Runnable myPostRunnable;
|
||||
|
||||
public OpenTreeRunnable(Library library, String treePath) {
|
||||
this(library, treePath, null);
|
||||
public OpenTreeRunnable(Library library, FBTree.Key key) {
|
||||
this(library, key, null);
|
||||
}
|
||||
|
||||
public OpenTreeRunnable(Library library, String treePath, String parameter) {
|
||||
this(library, new StartTreeActivityRunnable(treePath, parameter));
|
||||
public OpenTreeRunnable(Library library, FBTree.Key key, String parameter) {
|
||||
this(library, new StartTreeActivityRunnable(key, parameter));
|
||||
}
|
||||
|
||||
public OpenTreeRunnable(Library library, Runnable postRunnable) {
|
||||
|
|
|
@ -47,7 +47,7 @@ public class LibraryTopLevelActivity extends LibraryBaseActivity {
|
|||
Library.ROOT_FAVORITES,
|
||||
myResource.getResource(Library.ROOT_FAVORITES),
|
||||
R.drawable.ic_list_library_favorites,
|
||||
new OpenTreeRunnable(LibraryInstance, new StartTreeActivityRunnable(Library.ROOT_FAVORITES, null) {
|
||||
new OpenTreeRunnable(LibraryInstance, new StartTreeActivityRunnable(FBTree.Key.createRootKey(Library.ROOT_FAVORITES), null) {
|
||||
public void run() {
|
||||
if (LibraryInstance.favorites().hasChildren()) {
|
||||
super.run();
|
||||
|
@ -84,7 +84,7 @@ public class LibraryTopLevelActivity extends LibraryBaseActivity {
|
|||
key,
|
||||
myResource.getResource(key),
|
||||
imageId,
|
||||
new OpenTreeRunnable(LibraryInstance, key)
|
||||
new OpenTreeRunnable(LibraryInstance, FBTree.Key.createRootKey(key))
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ public class LibraryTopLevelActivity extends LibraryBaseActivity {
|
|||
myResource.getResource(Library.ROOT_SEARCH_RESULTS),
|
||||
pattern,
|
||||
R.drawable.ic_list_library_books,
|
||||
new OpenTreeRunnable(LibraryInstance, Library.ROOT_SEARCH_RESULTS, pattern)
|
||||
new OpenTreeRunnable(LibraryInstance, FBTree.Key.createRootKey(Library.ROOT_SEARCH_RESULTS), pattern)
|
||||
);
|
||||
adapter.add(0, mySearchResultsItem);
|
||||
getListView().invalidateViews();
|
||||
|
|
|
@ -51,39 +51,18 @@ public class LibraryTreeActivity extends LibraryBaseActivity {
|
|||
}
|
||||
|
||||
String title = null;
|
||||
if (myTreePath.length == 1) {
|
||||
title = myResource.getResource(myTreePath[0]).getResource("summary").getValue();
|
||||
if (myTreeKey.Parent == null) {
|
||||
title = myResource.getResource(myTreeKey.Id).getResource("summary").getValue();
|
||||
final String parameter = intent.getStringExtra(PARAMETER_KEY);
|
||||
if (parameter != null) {
|
||||
title = title.replace("%s", parameter);
|
||||
}
|
||||
} else {
|
||||
title = myTreePath[myTreePath.length - 1];
|
||||
title = myTreeKey.Id;
|
||||
}
|
||||
setTitle(title);
|
||||
|
||||
FBTree tree = null;
|
||||
if (Library.ROOT_RECENT.equals(myTreePath[0])) {
|
||||
tree = LibraryInstance.recentBooks();
|
||||
} else if (Library.ROOT_SEARCH_RESULTS.equals(myTreePath[0])) {
|
||||
tree = LibraryInstance.searchResults();
|
||||
} else if (Library.ROOT_BY_AUTHOR.equals(myTreePath[0])) {
|
||||
tree = LibraryInstance.byAuthor();
|
||||
} else if (Library.ROOT_BY_TITLE.equals(myTreePath[0])) {
|
||||
tree = LibraryInstance.byTitle();
|
||||
} else if (Library.ROOT_BY_TAG.equals(myTreePath[0])) {
|
||||
tree = LibraryInstance.byTag();
|
||||
} else if (Library.ROOT_FAVORITES.equals(myTreePath[0])) {
|
||||
tree = LibraryInstance.favorites();
|
||||
}
|
||||
|
||||
for (int i = 1; i < myTreePath.length; ++i) {
|
||||
if (tree == null) {
|
||||
break;
|
||||
}
|
||||
tree = tree.getSubTreeByName(myTreePath[i]);
|
||||
}
|
||||
|
||||
final FBTree tree = LibraryInstance.getLibraryTree(myTreeKey);
|
||||
if (tree != null) {
|
||||
final ListAdapter adapter = new ListAdapter(this, tree.subTrees());
|
||||
setSelection(adapter.getFirstSelectedItemIndex());
|
||||
|
|
|
@ -61,6 +61,17 @@ public final class Library {
|
|||
return root;
|
||||
}
|
||||
|
||||
public LibraryTree getLibraryTree(LibraryTree.Key key) {
|
||||
if (key == null) {
|
||||
return null;
|
||||
}
|
||||
if (key.Parent == null) {
|
||||
return getRootTree(key.Id);
|
||||
}
|
||||
final LibraryTree parentTree = getLibraryTree(key.Parent);
|
||||
return parentTree != null ? (LibraryTree)parentTree.getSubTree(key.Id) : null;
|
||||
}
|
||||
|
||||
public boolean hasState(int state) {
|
||||
return myState >= state || myInterrupted;
|
||||
}
|
||||
|
|
|
@ -418,13 +418,7 @@ public class NetworkLibrary {
|
|||
if (parentTree == null) {
|
||||
return null;
|
||||
}
|
||||
for (FBTree tree : parentTree.subTrees()) {
|
||||
final NetworkTree nTree = (NetworkTree)tree;
|
||||
if (key.equals(nTree.getUniqueKey())) {
|
||||
return nTree;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return parentTree != null ? (NetworkTree)parentTree.getSubTree(key.Id) : null;
|
||||
}
|
||||
|
||||
public void simpleSearch(String pattern, final NetworkOperationData.OnNewItemListener listener) throws ZLNetworkException {
|
||||
|
|
|
@ -30,6 +30,10 @@ public abstract class FBTree extends ZLTree<FBTree> implements Comparable<FBTree
|
|||
public static class Key implements Serializable {
|
||||
private static final long serialVersionUID = -6500763093522202052L;
|
||||
|
||||
public static Key createRootKey(String id) {
|
||||
return new Key(null, id);
|
||||
}
|
||||
|
||||
public final Key Parent;
|
||||
public final String Id;
|
||||
|
||||
|
@ -72,6 +76,14 @@ public abstract class FBTree extends ZLTree<FBTree> implements Comparable<FBTree
|
|||
super();
|
||||
}
|
||||
|
||||
protected FBTree(FBTree parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
protected FBTree(FBTree parent, int position) {
|
||||
super(parent, position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns unique identifier which can be used in NetworkView methods
|
||||
* @return unique Key instance
|
||||
|
@ -89,28 +101,17 @@ public abstract class FBTree extends ZLTree<FBTree> implements Comparable<FBTree
|
|||
*/
|
||||
protected abstract String getStringId();
|
||||
|
||||
protected FBTree(FBTree parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
protected FBTree(FBTree parent, int position) {
|
||||
super(parent, position);
|
||||
}
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
public final FBTree getSubTreeByName(String name) {
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
for (FBTree t : subTrees()) {
|
||||
if (name.equals(t.getName())) {
|
||||
return t;
|
||||
public FBTree getSubTree(String id) {
|
||||
for (FBTree tree : subTrees()) {
|
||||
if (id.equals(tree.getStringId())) {
|
||||
return tree;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract String getName();
|
||||
|
||||
protected String getSortKey() {
|
||||
return getName();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue