From 4ca3322524cffdf1c93f26ff194aea11ff35bc85 Mon Sep 17 00:00:00 2001 From: Nikolay Pultsin Date: Thu, 14 Jul 2011 22:15:57 +0100 Subject: [PATCH] code cleanup --- .../fbreader/library/LibraryActivity.java | 67 +++++++------------ 1 file changed, 26 insertions(+), 41 deletions(-) diff --git a/src/org/geometerplus/android/fbreader/library/LibraryActivity.java b/src/org/geometerplus/android/fbreader/library/LibraryActivity.java index f5599ddca..9b2f8da8c 100644 --- a/src/org/geometerplus/android/fbreader/library/LibraryActivity.java +++ b/src/org/geometerplus/android/fbreader/library/LibraryActivity.java @@ -44,31 +44,22 @@ import org.geometerplus.android.fbreader.FBReader; import org.geometerplus.android.fbreader.BookInfoActivity; public class LibraryActivity extends BaseActivity implements MenuItem.OnMenuItemClickListener { - static final String TREE_KEY_KEY = "TreeKey"; + public static final String TREE_KEY_KEY = "TreeKey"; public static final String SELECTED_BOOK_PATH_KEY = "SelectedBookPath"; - protected static final int CHILD_LIST_REQUEST = 0; - protected static final int BOOK_INFO_REQUEST = 1; - - protected static final int RESULT_DONT_INVALIDATE_VIEWS = 0; - protected static final int RESULT_DO_INVALIDATE_VIEWS = 1; - - static BooksDatabase DatabaseInstance; static Library LibraryInstance; - static final ZLStringOption BookSearchPatternOption = - new ZLStringOption("BookSearch", "Pattern", ""); + private BooksDatabase myDatabase; - protected String mySelectedBookPath; private Book mySelectedBook; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); - DatabaseInstance = SQLiteBooksDatabase.Instance(); - if (DatabaseInstance == null) { - DatabaseInstance = new SQLiteBooksDatabase(this, "LIBRARY"); + myDatabase = SQLiteBooksDatabase.Instance(); + if (myDatabase == null) { + myDatabase = new SQLiteBooksDatabase(this, "LIBRARY"); } if (LibraryInstance == null) { LibraryInstance = new Library(); @@ -83,10 +74,10 @@ public class LibraryActivity extends BaseActivity implements MenuItem.OnMenuItem ); setTitle(getCurrentTree().getTreeTitle()); - mySelectedBookPath = getIntent().getStringExtra(SELECTED_BOOK_PATH_KEY); + final String selectedBookPath = getIntent().getStringExtra(SELECTED_BOOK_PATH_KEY); mySelectedBook = null; - if (mySelectedBookPath != null) { - final ZLFile file = ZLFile.createFileByPath(mySelectedBookPath); + if (selectedBookPath != null) { + final ZLFile file = ZLFile.createFileByPath(selectedBookPath); if (file != null) { mySelectedBook = Book.getByFile(file); } @@ -109,15 +100,6 @@ public class LibraryActivity extends BaseActivity implements MenuItem.OnMenuItem return lTree.isSelectable() && lTree.containsBook(mySelectedBook); } - protected void openBook(Book book) { - startActivity( - new Intent(getApplicationContext(), FBReader.class) - .setAction(Intent.ACTION_VIEW) - .putExtra(FBReader.BOOK_PATH_KEY, book.File.getPath()) - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - ); - } - @Override protected void onListItemClick(ListView listView, View view, int position, long rowId) { final LibraryTree tree = (LibraryTree)getListAdapter().getItem(position); @@ -129,6 +111,11 @@ public class LibraryActivity extends BaseActivity implements MenuItem.OnMenuItem } } + // + // show BookInfoActivity + // + private static final int BOOK_INFO_REQUEST = 1; + protected void showBookInfo(Book book) { startActivityForResult( new Intent(getApplicationContext(), BookInfoActivity.class) @@ -139,28 +126,17 @@ public class LibraryActivity extends BaseActivity implements MenuItem.OnMenuItem @Override protected void onActivityResult(int requestCode, int returnCode, Intent intent) { - if (requestCode == CHILD_LIST_REQUEST && returnCode == RESULT_DO_INVALIDATE_VIEWS) { - if (getCurrentTree() instanceof FileTree) { - startUpdate(); - } - getListView().invalidateViews(); - } else if (requestCode == BOOK_INFO_REQUEST) { + if (requestCode == BOOK_INFO_REQUEST) { getListView().invalidateViews(); } } - private void startUpdate() { - new Thread(new Runnable() { - public void run() { - getCurrentTree().waitForOpening(); - getListAdapter().replaceAll(getCurrentTree().subTrees()); - } - }).start(); - } - // // Search // + static final ZLStringOption BookSearchPatternOption = + new ZLStringOption("BookSearch", "Pattern", ""); + @Override protected void onNewIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { @@ -263,6 +239,15 @@ public class LibraryActivity extends BaseActivity implements MenuItem.OnMenuItem return false; } + private void openBook(Book book) { + startActivity( + new Intent(getApplicationContext(), FBReader.class) + .setAction(Intent.ACTION_VIEW) + .putExtra(FBReader.BOOK_PATH_KEY, book.File.getPath()) + .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) + ); + } + // // Options menu //