mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +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;
|
protected static final int RESULT_DO_INVALIDATE_VIEWS = 1;
|
||||||
|
|
||||||
static final String TREE_PATH_KEY = "TreePath";
|
static final String TREE_PATH_KEY = "TreePath";
|
||||||
|
private static final String TREE_KEY_KEY = "TreeKey";
|
||||||
static final String PARAMETER_KEY = "Parameter";
|
static final String PARAMETER_KEY = "Parameter";
|
||||||
|
|
||||||
static final String PATH_FILE_TREE = "fileTree";
|
static final String PATH_FILE_TREE = "fileTree";
|
||||||
|
@ -63,8 +64,8 @@ abstract class BaseActivity extends ListActivity {
|
||||||
protected final ZLResource myResource = ZLResource.resource("libraryView");
|
protected final ZLResource myResource = ZLResource.resource("libraryView");
|
||||||
protected String mySelectedBookPath;
|
protected String mySelectedBookPath;
|
||||||
private Book mySelectedBook;
|
private Book mySelectedBook;
|
||||||
private String myTreePathString;
|
|
||||||
protected String[] myTreePath;
|
protected String[] myTreePath;
|
||||||
|
protected FBTree.Key myTreeKey;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
|
@ -80,8 +81,9 @@ abstract class BaseActivity extends ListActivity {
|
||||||
startService(new Intent(getApplicationContext(), InitializationService.class));
|
startService(new Intent(getApplicationContext(), InitializationService.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
myTreePathString = getIntent().getStringExtra(TREE_PATH_KEY);
|
final String treePathString = getIntent().getStringExtra(TREE_PATH_KEY);
|
||||||
myTreePath = myTreePathString != null ? myTreePathString.split("\000") : new String[0];
|
myTreePath = treePathString != null ? treePathString.split("\000") : new String[0];
|
||||||
|
myTreeKey = (FBTree.Key)getIntent().getSerializableExtra(TREE_KEY_KEY);
|
||||||
|
|
||||||
mySelectedBookPath = getIntent().getStringExtra(SELECTED_BOOK_PATH_KEY);
|
mySelectedBookPath = getIntent().getStringExtra(SELECTED_BOOK_PATH_KEY);
|
||||||
mySelectedBook = null;
|
mySelectedBook = null;
|
||||||
|
@ -124,7 +126,7 @@ abstract class BaseActivity extends ListActivity {
|
||||||
} else if (tree instanceof BookTree) {
|
} else if (tree instanceof BookTree) {
|
||||||
showBookInfo(((BookTree)tree).Book);
|
showBookInfo(((BookTree)tree).Book);
|
||||||
} else {
|
} 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 {
|
protected class StartTreeActivityRunnable implements Runnable {
|
||||||
private final String myTreePath;
|
private final FBTree.Key myTreeKey;
|
||||||
private final String myParameter;
|
private final String myParameter;
|
||||||
|
|
||||||
public StartTreeActivityRunnable(String treePath, String parameter) {
|
public StartTreeActivityRunnable(FBTree.Key key, String parameter) {
|
||||||
myTreePath = treePath;
|
myTreeKey = key;
|
||||||
myParameter = parameter;
|
myParameter = parameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +295,7 @@ abstract class BaseActivity extends ListActivity {
|
||||||
startActivityForResult(
|
startActivityForResult(
|
||||||
new Intent(BaseActivity.this, LibraryTreeActivity.class)
|
new Intent(BaseActivity.this, LibraryTreeActivity.class)
|
||||||
.putExtra(SELECTED_BOOK_PATH_KEY, mySelectedBookPath)
|
.putExtra(SELECTED_BOOK_PATH_KEY, mySelectedBookPath)
|
||||||
.putExtra(TREE_PATH_KEY, myTreePath)
|
.putExtra(TREE_KEY_KEY, myTreeKey)
|
||||||
.putExtra(PARAMETER_KEY, myParameter),
|
.putExtra(PARAMETER_KEY, myParameter),
|
||||||
CHILD_LIST_REQUEST
|
CHILD_LIST_REQUEST
|
||||||
);
|
);
|
||||||
|
@ -304,12 +306,12 @@ abstract class BaseActivity extends ListActivity {
|
||||||
private final Library myLibrary;
|
private final Library myLibrary;
|
||||||
private final Runnable myPostRunnable;
|
private final Runnable myPostRunnable;
|
||||||
|
|
||||||
public OpenTreeRunnable(Library library, String treePath) {
|
public OpenTreeRunnable(Library library, FBTree.Key key) {
|
||||||
this(library, treePath, null);
|
this(library, key, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OpenTreeRunnable(Library library, String treePath, String parameter) {
|
public OpenTreeRunnable(Library library, FBTree.Key key, String parameter) {
|
||||||
this(library, new StartTreeActivityRunnable(treePath, parameter));
|
this(library, new StartTreeActivityRunnable(key, parameter));
|
||||||
}
|
}
|
||||||
|
|
||||||
public OpenTreeRunnable(Library library, Runnable postRunnable) {
|
public OpenTreeRunnable(Library library, Runnable postRunnable) {
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class LibraryTopLevelActivity extends LibraryBaseActivity {
|
||||||
Library.ROOT_FAVORITES,
|
Library.ROOT_FAVORITES,
|
||||||
myResource.getResource(Library.ROOT_FAVORITES),
|
myResource.getResource(Library.ROOT_FAVORITES),
|
||||||
R.drawable.ic_list_library_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() {
|
public void run() {
|
||||||
if (LibraryInstance.favorites().hasChildren()) {
|
if (LibraryInstance.favorites().hasChildren()) {
|
||||||
super.run();
|
super.run();
|
||||||
|
@ -84,7 +84,7 @@ public class LibraryTopLevelActivity extends LibraryBaseActivity {
|
||||||
key,
|
key,
|
||||||
myResource.getResource(key),
|
myResource.getResource(key),
|
||||||
imageId,
|
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),
|
myResource.getResource(Library.ROOT_SEARCH_RESULTS),
|
||||||
pattern,
|
pattern,
|
||||||
R.drawable.ic_list_library_books,
|
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);
|
adapter.add(0, mySearchResultsItem);
|
||||||
getListView().invalidateViews();
|
getListView().invalidateViews();
|
||||||
|
|
|
@ -51,39 +51,18 @@ public class LibraryTreeActivity extends LibraryBaseActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
String title = null;
|
String title = null;
|
||||||
if (myTreePath.length == 1) {
|
if (myTreeKey.Parent == null) {
|
||||||
title = myResource.getResource(myTreePath[0]).getResource("summary").getValue();
|
title = myResource.getResource(myTreeKey.Id).getResource("summary").getValue();
|
||||||
final String parameter = intent.getStringExtra(PARAMETER_KEY);
|
final String parameter = intent.getStringExtra(PARAMETER_KEY);
|
||||||
if (parameter != null) {
|
if (parameter != null) {
|
||||||
title = title.replace("%s", parameter);
|
title = title.replace("%s", parameter);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
title = myTreePath[myTreePath.length - 1];
|
title = myTreeKey.Id;
|
||||||
}
|
}
|
||||||
setTitle(title);
|
setTitle(title);
|
||||||
|
|
||||||
FBTree tree = null;
|
final FBTree tree = LibraryInstance.getLibraryTree(myTreeKey);
|
||||||
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]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tree != null) {
|
if (tree != null) {
|
||||||
final ListAdapter adapter = new ListAdapter(this, tree.subTrees());
|
final ListAdapter adapter = new ListAdapter(this, tree.subTrees());
|
||||||
setSelection(adapter.getFirstSelectedItemIndex());
|
setSelection(adapter.getFirstSelectedItemIndex());
|
||||||
|
|
|
@ -61,6 +61,17 @@ public final class Library {
|
||||||
return root;
|
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) {
|
public boolean hasState(int state) {
|
||||||
return myState >= state || myInterrupted;
|
return myState >= state || myInterrupted;
|
||||||
}
|
}
|
||||||
|
|
|
@ -418,13 +418,7 @@ public class NetworkLibrary {
|
||||||
if (parentTree == null) {
|
if (parentTree == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (FBTree tree : parentTree.subTrees()) {
|
return parentTree != null ? (NetworkTree)parentTree.getSubTree(key.Id) : null;
|
||||||
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 {
|
||||||
|
|
|
@ -30,6 +30,10 @@ public abstract class FBTree extends ZLTree<FBTree> implements Comparable<FBTree
|
||||||
public static class Key implements Serializable {
|
public static class Key implements Serializable {
|
||||||
private static final long serialVersionUID = -6500763093522202052L;
|
private static final long serialVersionUID = -6500763093522202052L;
|
||||||
|
|
||||||
|
public static Key createRootKey(String id) {
|
||||||
|
return new Key(null, id);
|
||||||
|
}
|
||||||
|
|
||||||
public final Key Parent;
|
public final Key Parent;
|
||||||
public final String Id;
|
public final String Id;
|
||||||
|
|
||||||
|
@ -72,6 +76,14 @@ public abstract class FBTree extends ZLTree<FBTree> implements Comparable<FBTree
|
||||||
super();
|
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
|
* Returns unique identifier which can be used in NetworkView methods
|
||||||
* @return unique Key instance
|
* @return unique Key instance
|
||||||
|
@ -89,28 +101,17 @@ public abstract class FBTree extends ZLTree<FBTree> implements Comparable<FBTree
|
||||||
*/
|
*/
|
||||||
protected abstract String getStringId();
|
protected abstract String getStringId();
|
||||||
|
|
||||||
protected FBTree(FBTree parent) {
|
public FBTree getSubTree(String id) {
|
||||||
super(parent);
|
for (FBTree tree : subTrees()) {
|
||||||
|
if (id.equals(tree.getStringId())) {
|
||||||
|
return tree;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
protected FBTree(FBTree parent, int position) {
|
return null;
|
||||||
super(parent, position);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String getName();
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getSortKey() {
|
protected String getSortKey() {
|
||||||
return getName();
|
return getName();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue