mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
code simplification
This commit is contained in:
parent
06522921a2
commit
63e99307bd
4 changed files with 27 additions and 31 deletions
|
@ -127,11 +127,11 @@ abstract class BaseActivity extends ListActivity {
|
||||||
final FBTreeInfo info = myInfoMap.get(tree);
|
final FBTreeInfo info = myInfoMap.get(tree);
|
||||||
if (info != null && info.CoverResourceId != -1) {
|
if (info != null && info.CoverResourceId != -1) {
|
||||||
return info.CoverResourceId;
|
return info.CoverResourceId;
|
||||||
|
} else if (((LibraryTree)tree).getBook() != null) {
|
||||||
|
return R.drawable.ic_list_library_book;
|
||||||
} else if (tree instanceof FileTree) {
|
} else if (tree instanceof FileTree) {
|
||||||
final FileTree fileTree = (FileTree)tree;
|
final FileTree fileTree = (FileTree)tree;
|
||||||
if (fileTree.getBook() != null) {
|
if (fileTree.getFile().isDirectory()) {
|
||||||
return R.drawable.ic_list_library_book;
|
|
||||||
} else if (fileTree.getFile().isDirectory()) {
|
|
||||||
if (fileTree.getFile().isReadable()) {
|
if (fileTree.getFile().isReadable()) {
|
||||||
return R.drawable.ic_list_library_folder;
|
return R.drawable.ic_list_library_folder;
|
||||||
} else {
|
} else {
|
||||||
|
@ -146,8 +146,6 @@ abstract class BaseActivity extends ListActivity {
|
||||||
return R.drawable.ic_list_library_author;
|
return R.drawable.ic_list_library_author;
|
||||||
} else if (tree instanceof TagTree) {
|
} else if (tree instanceof TagTree) {
|
||||||
return R.drawable.ic_list_library_tag;
|
return R.drawable.ic_list_library_tag;
|
||||||
} else if (tree instanceof BookTree) {
|
|
||||||
return R.drawable.ic_list_library_book;
|
|
||||||
} else {
|
} else {
|
||||||
return R.drawable.ic_list_library_books;
|
return R.drawable.ic_list_library_books;
|
||||||
}
|
}
|
||||||
|
@ -155,14 +153,13 @@ abstract class BaseActivity extends ListActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onListItemClick(ListView listView, View view, int position, long rowId) {
|
protected void onListItemClick(ListView listView, View view, int position, long rowId) {
|
||||||
final FBTree tree = getListAdapter().getItem(position);
|
final LibraryTree tree = (LibraryTree)getListAdapter().getItem(position);
|
||||||
if (tree instanceof FileTree) {
|
final Book book = tree.getBook();
|
||||||
final FileTree fileTree = (FileTree)tree;
|
if (book != null) {
|
||||||
final ZLFile file = fileTree.getFile();
|
showBookInfo(book);
|
||||||
final Book book = fileTree.getBook();
|
} else if (tree instanceof FileTree) {
|
||||||
if (book != null) {
|
final ZLFile file = ((FileTree)tree).getFile();
|
||||||
showBookInfo(book);
|
if (!file.isReadable()) {
|
||||||
} else if (!file.isReadable()) {
|
|
||||||
UIUtil.showErrorMessage(this, "permissionDenied");
|
UIUtil.showErrorMessage(this, "permissionDenied");
|
||||||
} else if (file.isDirectory() || file.isArchive()) {
|
} else if (file.isDirectory() || file.isArchive()) {
|
||||||
startActivityForResult(
|
startActivityForResult(
|
||||||
|
@ -172,8 +169,6 @@ abstract class BaseActivity extends ListActivity {
|
||||||
CHILD_LIST_REQUEST
|
CHILD_LIST_REQUEST
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if (tree instanceof BookTree) {
|
|
||||||
showBookInfo(((BookTree)tree).Book);
|
|
||||||
} else {
|
} else {
|
||||||
final FBTreeInfo info = myInfoMap.get(tree);
|
final FBTreeInfo info = myInfoMap.get(tree);
|
||||||
if (info != null && info.Action != null) {
|
if (info != null && info.Action != null) {
|
||||||
|
@ -189,8 +184,9 @@ abstract class BaseActivity extends ListActivity {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tree instanceof BookTree) {
|
final Book book = ((LibraryTree)tree).getBook();
|
||||||
return mySelectedBook.equals(((BookTree)tree).Book);
|
if (book != null) {
|
||||||
|
return mySelectedBook.equals(book);
|
||||||
} else if (tree instanceof AuthorTree) {
|
} else if (tree instanceof AuthorTree) {
|
||||||
return mySelectedBook.authors().contains(((AuthorTree)tree).Author);
|
return mySelectedBook.authors().contains(((AuthorTree)tree).Author);
|
||||||
} else if (tree instanceof TitleTree) {
|
} else if (tree instanceof TitleTree) {
|
||||||
|
@ -215,12 +211,7 @@ abstract class BaseActivity extends ListActivity {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final ZLFile file = fileTree.getFile();
|
final ZLFile file = fileTree.getFile();
|
||||||
final String path = file.getPath();
|
String prefix = file.getPath();
|
||||||
if (mySelectedBookPath.equals(path)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
String prefix = path;
|
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
if (!prefix.endsWith("/")) {
|
if (!prefix.endsWith("/")) {
|
||||||
prefix += '/';
|
prefix += '/';
|
||||||
|
@ -303,14 +294,9 @@ abstract class BaseActivity extends ListActivity {
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
final int position = ((AdapterView.AdapterContextMenuInfo)item.getMenuInfo()).position;
|
final int position = ((AdapterView.AdapterContextMenuInfo)item.getMenuInfo()).position;
|
||||||
final FBTree tree = getListAdapter().getItem(position);
|
final Book book = ((LibraryTree)getListAdapter().getItem(position)).getBook();
|
||||||
if (tree instanceof BookTree) {
|
if (book != null) {
|
||||||
return onContextItemSelected(item.getItemId(), ((BookTree)tree).Book);
|
return onContextItemSelected(item.getItemId(), book);
|
||||||
} else if (tree instanceof FileTree) {
|
|
||||||
final Book book = ((FileTree)tree).getBook();
|
|
||||||
if (book != null) {
|
|
||||||
return onContextItemSelected(item.getItemId(), book);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return super.onContextItemSelected(item);
|
return super.onContextItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,11 @@ public class BookTree extends LibraryTree {
|
||||||
return Book.getTitle();
|
return Book.getTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Book getBook() {
|
||||||
|
return Book;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getStringId() {
|
protected String getStringId() {
|
||||||
return getName();
|
return getName();
|
||||||
|
|
|
@ -104,6 +104,7 @@ public class FileTree extends LibraryTree {
|
||||||
return myFile;
|
return myFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Book getBook() {
|
public Book getBook() {
|
||||||
return Book.getByFile(myFile);
|
return Book.getByFile(myFile);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,10 @@ public abstract class LibraryTree extends FBTree {
|
||||||
return getName();
|
return getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Book getBook() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
TagTree createTagSubTree(Tag tag) {
|
TagTree createTagSubTree(Tag tag) {
|
||||||
return new TagTree(this, tag);
|
return new TagTree(this, tag);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue