1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 02:39:23 +02:00

LibraryTabActivity has no references to FBReader.Instance()

This commit is contained in:
Nikolay Pultsin 2010-10-15 21:25:16 +01:00
parent 7773eb42b7
commit de0b72d0cd
6 changed files with 40 additions and 23 deletions

View file

@ -21,7 +21,6 @@ package org.geometerplus.android.fbreader;
import android.app.Activity; import android.app.Activity;
import org.geometerplus.fbreader.fbreader.FBReader;
import org.geometerplus.fbreader.library.*; import org.geometerplus.fbreader.library.*;
public class BookSearchActivity extends SearchActivity { public class BookSearchActivity extends SearchActivity {
@ -48,9 +47,9 @@ public class BookSearchActivity extends SearchActivity {
@Override @Override
boolean runSearch(final String pattern) { boolean runSearch(final String pattern) {
final FBReader fbreader = (FBReader)FBReader.Instance(); final LibraryTabActivity parentActivity = LibraryTabActivity.Instance;
fbreader.BookSearchPatternOption.setValue(pattern); parentActivity.BookSearchPatternOption.setValue(pattern);
myTree = LibraryTabActivity.Instance.library().searchBooks(pattern); myTree = parentActivity.library().searchBooks(pattern);
return myTree.hasChildren(); return myTree.hasChildren();
} }

View file

@ -83,6 +83,7 @@ public final class FBReader extends ZLAndroidActivity {
private static TextSearchButtonPanel myTextSearchPanel; private static TextSearchButtonPanel myTextSearchPanel;
private static NavigationButtonPanel myNavigatePanel; private static NavigationButtonPanel myNavigatePanel;
@Override
protected String fileNameForEmptyUri() { protected String fileNameForEmptyUri() {
return Library.getHelpFile().getPath(); return Library.getHelpFile().getPath();
} }

View file

@ -36,17 +36,19 @@ import org.geometerplus.zlibrary.core.options.ZLStringOption;
import org.geometerplus.zlibrary.core.resources.ZLResource; import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.core.filesystem.ZLFile; import org.geometerplus.zlibrary.core.filesystem.ZLFile;
import org.geometerplus.fbreader.fbreader.FBReader;
import org.geometerplus.fbreader.bookmodel.BookModel;
import org.geometerplus.fbreader.library.*; import org.geometerplus.fbreader.library.*;
import org.geometerplus.fbreader.tree.FBTree; import org.geometerplus.fbreader.tree.FBTree;
public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuItemClickListener { public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuItemClickListener {
public static final String CURRENT_BOOK_PATH_KEY = "LibraryCurrentBookPath";
static LibraryTabActivity Instance; static LibraryTabActivity Instance;
final ZLStringOption BookSearchPatternOption = new ZLStringOption("BookSearch", "Pattern", "");
final ZLStringOption mySelectedTabOption = new ZLStringOption("TabActivity", "SelectedTab", ""); final ZLStringOption mySelectedTabOption = new ZLStringOption("TabActivity", "SelectedTab", "");
private final ZLResource myResource = ZLResource.resource("libraryView"); private final ZLResource myResource = ZLResource.resource("libraryView");
private Book myCurrentBook; private String myCurrentBookPath;
private Library myLibrary; private Library myLibrary;
@ -61,11 +63,6 @@ public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuIt
return (ListView)findViewById(viewId); return (ListView)findViewById(viewId);
} }
private void setCurrentBook() {
final BookModel model = ((FBReader)FBReader.Instance()).Model;
myCurrentBook = (model != null) ? model.Book : null;
}
private void createDefaultTabs() { private void createDefaultTabs() {
new LibraryAdapter(createTab("byAuthor", R.id.by_author, R.drawable.ic_tab_library_author), myLibrary.byAuthor(), Type.TREE); new LibraryAdapter(createTab("byAuthor", R.id.by_author, R.drawable.ic_tab_library_author), myLibrary.byAuthor(), Type.TREE);
new LibraryAdapter(createTab("byTag", R.id.by_tag, R.drawable.ic_tab_library_tag), myLibrary.byTag(), Type.TREE); new LibraryAdapter(createTab("byTag", R.id.by_tag, R.drawable.ic_tab_library_tag), myLibrary.byTag(), Type.TREE);
@ -73,6 +70,12 @@ public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuIt
findViewById(R.id.search_results).setVisibility(View.GONE); findViewById(R.id.search_results).setVisibility(View.GONE);
} }
private boolean isSelectedItem(FBTree tree) {
return
(tree instanceof BookTree) &&
((BookTree)tree).Book.File.getPath().equals(myCurrentBookPath);
}
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
@ -85,7 +88,8 @@ public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuIt
myLibrary.clear(); myLibrary.clear();
myLibrary.synchronize(); myLibrary.synchronize();
setCurrentBook(); final Intent intent = getIntent();
myCurrentBookPath = intent.getStringExtra(CURRENT_BOOK_PATH_KEY);
requestWindowFeature(Window.FEATURE_NO_TITLE); requestWindowFeature(Window.FEATURE_NO_TITLE);
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL); setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
@ -153,8 +157,7 @@ public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuIt
@Override @Override
public boolean onSearchRequested() { public boolean onSearchRequested() {
final FBReader fbreader = (FBReader)FBReader.Instance(); startSearch(BookSearchPatternOption.getValue(), true, null, false);
startSearch(fbreader.BookSearchPatternOption.getValue(), true, null, false);
return true; return true;
} }
@ -192,11 +195,11 @@ public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuIt
} }
private ZLTree<?> findFirstSelectedItem() { private ZLTree<?> findFirstSelectedItem() {
if (myCurrentBook == null) { if (myCurrentBookPath == null) {
return null; return null;
} }
for (FBTree tree : myLibraryTree) { for (FBTree tree : myLibraryTree) {
if ((tree instanceof BookTree) && ((BookTree)tree).Book.equals(myCurrentBook)) { if (isSelectedItem(tree)) {
return tree; return tree;
} }
} }
@ -207,7 +210,7 @@ public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuIt
final View view = (convertView != null) ? convertView : final View view = (convertView != null) ? convertView :
LayoutInflater.from(parent.getContext()).inflate(R.layout.library_tree_item, parent, false); LayoutInflater.from(parent.getContext()).inflate(R.layout.library_tree_item, parent, false);
final LibraryTree tree = (LibraryTree)getItem(position); final LibraryTree tree = (LibraryTree)getItem(position);
if ((tree instanceof BookTree) && ((BookTree)tree).Book.equals(myCurrentBook)) { if (isSelectedItem(tree)) {
view.setBackgroundColor(0xff808080); view.setBackgroundColor(0xff808080);
} else { } else {
view.setBackgroundColor(0); view.setBackgroundColor(0);
@ -246,7 +249,7 @@ public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuIt
} }
finish(); finish();
final Book book = ((BookTree)tree).Book; final Book book = ((BookTree)tree).Book;
if (!book.equals(myCurrentBook)) { if (!book.File.getPath().equals(myCurrentBookPath)) {
ZLFile physicalFile = book.File.getPhysicalFile(); ZLFile physicalFile = book.File.getPhysicalFile();
startActivity(getFBReaderIntent(physicalFile != null ? new File(physicalFile.getPath()) : null)); startActivity(getFBReaderIntent(physicalFile != null ? new File(physicalFile.getPath()) : null));
} }

View file

@ -33,8 +33,6 @@ import org.geometerplus.fbreader.library.Bookmark;
import org.geometerplus.fbreader.optionsDialog.OptionsDialog; import org.geometerplus.fbreader.optionsDialog.OptionsDialog;
public final class FBReader extends ZLApplication { public final class FBReader extends ZLApplication {
public final ZLStringOption BookSearchPatternOption =
new ZLStringOption("BookSearch", "Pattern", "");
public final ZLStringOption TextSearchPatternOption = public final ZLStringOption TextSearchPatternOption =
new ZLStringOption("TextSearch", "Pattern", ""); new ZLStringOption("TextSearch", "Pattern", "");
public final ZLStringOption BookmarkSearchPatternOption = public final ZLStringOption BookmarkSearchPatternOption =

View file

@ -19,7 +19,10 @@
package org.geometerplus.fbreader.fbreader; package org.geometerplus.fbreader.fbreader;
import java.util.HashMap;
import org.geometerplus.fbreader.library.Library; import org.geometerplus.fbreader.library.Library;
import org.geometerplus.fbreader.bookmodel.BookModel;
import org.geometerplus.android.fbreader.LibraryTabActivity; import org.geometerplus.android.fbreader.LibraryTabActivity;
@ -33,9 +36,14 @@ class ShowLibraryAction extends FBAction {
public void run() { public void run() {
final ZLAndroidDialogManager dialogManager = final ZLAndroidDialogManager dialogManager =
(ZLAndroidDialogManager)ZLAndroidDialogManager.Instance(); (ZLAndroidDialogManager)ZLAndroidDialogManager.Instance();
final HashMap<String,String> data = new HashMap<String,String>();
final BookModel model = Reader.Model;
if (model != null) {
data.put(LibraryTabActivity.CURRENT_BOOK_PATH_KEY, model.Book.File.getPath());
}
Runnable action = new Runnable() { Runnable action = new Runnable() {
public void run() { public void run() {
dialogManager.runActivity(LibraryTabActivity.class); dialogManager.runActivity(LibraryTabActivity.class, data);
} }
}; };
dialogManager.wait("loadingBookList", action); dialogManager.wait("loadingBookList", action);

View file

@ -50,8 +50,16 @@ public class ZLAndroidDialogManager extends ZLDialogManager {
activity.startActivity(intent); activity.startActivity(intent);
} }
public void runActivity(Class<?> activityClass, Map<String,String> data) {
Intent intent = new Intent(myActivity.getApplicationContext(), activityClass);
for (Map.Entry<String,String> entry : data.entrySet()) {
intent.putExtra(entry.getKey(), entry.getValue());
}
myActivity.startActivity(intent);
}
public void runActivity(Class<?> activityClass) { public void runActivity(Class<?> activityClass) {
myActivity.startActivity(new Intent(myActivity, activityClass)); runActivity(activityClass, Collections.<String,String>emptyMap());
} }
public void showInformationBox(String key, String message) { public void showInformationBox(String key, String message) {