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

fixed book opening

This commit is contained in:
Nikolay Pultsin 2013-01-20 02:39:31 +04:00
parent f56ccb5307
commit 53c146e532
7 changed files with 144 additions and 174 deletions

View file

@ -46,7 +46,7 @@ public class BookmarksActivity extends TabActivity implements MenuItem.OnMenuIte
private static final int EDIT_ITEM_ID = 1;
private static final int DELETE_ITEM_ID = 2;
private final BookCollectionShadow myCollection = new BookCollectionShadow(this);
private final BookCollectionShadow myCollection = new BookCollectionShadow();
private List<Bookmark> myAllBooksBookmarks;
private final List<Bookmark> myThisBookBookmarks = new LinkedList<Bookmark>();
@ -112,7 +112,7 @@ public class BookmarksActivity extends TabActivity implements MenuItem.OnMenuIte
protected void onStart() {
super.onStart();
myCollection.bindToService(new Runnable() {
myCollection.bindToService(this, new Runnable() {
public void run() {
if (myAllBooksBookmarks == null) {
init();

View file

@ -56,7 +56,8 @@ import org.geometerplus.android.fbreader.tips.TipsActivity;
import org.geometerplus.android.util.UIUtil;
public final class FBReader extends Activity {
public static final String BOOK_PATH_KEY = "BookPath";
public static final String ACTION_OPEN_BOOK = "android.fbreader.action.VIEW";
public static final String BOOK_KEY = "fbreader.book";
public static final int REQUEST_PREFERENCES = 1;
public static final int REQUEST_BOOK_INFO = 2;
@ -70,6 +71,9 @@ public final class FBReader extends Activity {
return (ZLAndroidLibrary)ZLAndroidLibrary.Instance();
}
private FBReaderApp myFBReaderApp;
private Book myBook;
private int myFullScreenFlag;
private static final String PLUGIN_ACTION_PREFIX = "___";
@ -81,17 +85,16 @@ public final class FBReader extends Activity {
final ArrayList<PluginApi.ActionInfo> actions = getResultExtras(true).<PluginApi.ActionInfo>getParcelableArrayList(PluginApi.PluginInfo.KEY);
if (actions != null) {
synchronized (myPluginActions) {
final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance();
int index = 0;
while (index < myPluginActions.size()) {
fbReader.removeAction(PLUGIN_ACTION_PREFIX + index++);
myFBReaderApp.removeAction(PLUGIN_ACTION_PREFIX + index++);
}
myPluginActions.addAll(actions);
index = 0;
for (PluginApi.ActionInfo info : myPluginActions) {
fbReader.addAction(
myFBReaderApp.addAction(
PLUGIN_ACTION_PREFIX + index++,
new RunPluginAction(FBReader.this, fbReader, info.getId())
new RunPluginAction(FBReader.this, myFBReaderApp, info.getId())
);
}
}
@ -99,15 +102,38 @@ public final class FBReader extends Activity {
}
};
private ZLFile fileFromIntent(Intent intent) {
String filePath = intent.getStringExtra(BOOK_PATH_KEY);
if (filePath == null) {
private synchronized void openBook(Intent intent, Runnable action, boolean force) {
if (!force && myBook != null) {
return;
}
myBook = SerializerUtil.deserializeBook(intent.getStringExtra(BOOK_KEY));
if (myBook == null) {
final Uri data = intent.getData();
if (data != null) {
filePath = data.getPath();
myBook = createBookForFile(ZLFile.createFileByPath(data.getPath()));
}
}
return filePath != null ? ZLFile.createFileByPath(filePath) : null;
myFBReaderApp.openBook(myBook, null, action);
}
private Book createBookForFile(ZLFile file) {
if (file == null) {
return null;
}
Book book = myFBReaderApp.Collection.getBookByFile(file);
if (book != null) {
return book;
}
if (file.isArchive()) {
for (ZLFile child : file.children()) {
book = myFBReaderApp.Collection.getBookByFile(child);
if (book != null) {
return book;
}
}
}
return null;
}
private Runnable getPostponedInitAction() {
@ -123,14 +149,6 @@ public final class FBReader extends Activity {
};
}
private BookCollectionShadow getCollection() {
return (BookCollectionShadow)((FBReaderApp)FBReaderApp.Instance()).Collection;
}
private void init(Runnable action) {
getCollection().bindToService(action);
}
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
@ -144,26 +162,15 @@ public final class FBReader extends Activity {
getZLibrary().setActivity(this);
final ZLAndroidApplication androidApplication = (ZLAndroidApplication)getApplication();
myFBReaderApp = (FBReaderApp)FBReaderApp.Instance();
if (myFBReaderApp == null) {
myFBReaderApp = new FBReaderApp(new BookCollectionShadow());
}
if (androidApplication.myMainWindow == null) {
final FBReaderApp fbreader = createApplication();
androidApplication.myMainWindow = new ZLAndroidApplicationWindow(fbreader);
fbreader.initWindow();
androidApplication.myMainWindow = new ZLAndroidApplicationWindow(myFBReaderApp);
myFBReaderApp.initWindow();
}
init(new Runnable() {
public void run() {
new Thread() {
public void run() {
FBReaderApp.Instance().openFile(fileFromIntent(getIntent()), getPostponedInitAction());
FBReaderApp.Instance().getViewWidget().repaint();
}
}.start();
FBReaderApp.Instance().getViewWidget().repaint();
}
});
final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance();
final ZLAndroidLibrary zlibrary = (ZLAndroidLibrary)ZLibrary.Instance();
myFullScreenFlag =
zlibrary.ShowStatusBarOption.getValue() ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN;
@ -171,46 +178,46 @@ public final class FBReader extends Activity {
WindowManager.LayoutParams.FLAG_FULLSCREEN, myFullScreenFlag
);
if (fbReader.getPopupById(TextSearchPopup.ID) == null) {
new TextSearchPopup(fbReader);
if (myFBReaderApp.getPopupById(TextSearchPopup.ID) == null) {
new TextSearchPopup(myFBReaderApp);
}
if (fbReader.getPopupById(NavigationPopup.ID) == null) {
new NavigationPopup(fbReader);
if (myFBReaderApp.getPopupById(NavigationPopup.ID) == null) {
new NavigationPopup(myFBReaderApp);
}
if (fbReader.getPopupById(SelectionPopup.ID) == null) {
new SelectionPopup(fbReader);
if (myFBReaderApp.getPopupById(SelectionPopup.ID) == null) {
new SelectionPopup(myFBReaderApp);
}
fbReader.addAction(ActionCode.SHOW_LIBRARY, new ShowLibraryAction(this, fbReader));
fbReader.addAction(ActionCode.SHOW_PREFERENCES, new ShowPreferencesAction(this, fbReader));
fbReader.addAction(ActionCode.SHOW_BOOK_INFO, new ShowBookInfoAction(this, fbReader));
fbReader.addAction(ActionCode.SHOW_TOC, new ShowTOCAction(this, fbReader));
fbReader.addAction(ActionCode.SHOW_BOOKMARKS, new ShowBookmarksAction(this, fbReader));
fbReader.addAction(ActionCode.SHOW_NETWORK_LIBRARY, new ShowNetworkLibraryAction(this, fbReader));
myFBReaderApp.addAction(ActionCode.SHOW_LIBRARY, new ShowLibraryAction(this, myFBReaderApp));
myFBReaderApp.addAction(ActionCode.SHOW_PREFERENCES, new ShowPreferencesAction(this, myFBReaderApp));
myFBReaderApp.addAction(ActionCode.SHOW_BOOK_INFO, new ShowBookInfoAction(this, myFBReaderApp));
myFBReaderApp.addAction(ActionCode.SHOW_TOC, new ShowTOCAction(this, myFBReaderApp));
myFBReaderApp.addAction(ActionCode.SHOW_BOOKMARKS, new ShowBookmarksAction(this, myFBReaderApp));
myFBReaderApp.addAction(ActionCode.SHOW_NETWORK_LIBRARY, new ShowNetworkLibraryAction(this, myFBReaderApp));
fbReader.addAction(ActionCode.SHOW_MENU, new ShowMenuAction(this, fbReader));
fbReader.addAction(ActionCode.SHOW_NAVIGATION, new ShowNavigationAction(this, fbReader));
fbReader.addAction(ActionCode.SEARCH, new SearchAction(this, fbReader));
fbReader.addAction(ActionCode.SHARE_BOOK, new ShareBookAction(this, fbReader));
myFBReaderApp.addAction(ActionCode.SHOW_MENU, new ShowMenuAction(this, myFBReaderApp));
myFBReaderApp.addAction(ActionCode.SHOW_NAVIGATION, new ShowNavigationAction(this, myFBReaderApp));
myFBReaderApp.addAction(ActionCode.SEARCH, new SearchAction(this, myFBReaderApp));
myFBReaderApp.addAction(ActionCode.SHARE_BOOK, new ShareBookAction(this, myFBReaderApp));
fbReader.addAction(ActionCode.SELECTION_SHOW_PANEL, new SelectionShowPanelAction(this, fbReader));
fbReader.addAction(ActionCode.SELECTION_HIDE_PANEL, new SelectionHidePanelAction(this, fbReader));
fbReader.addAction(ActionCode.SELECTION_COPY_TO_CLIPBOARD, new SelectionCopyAction(this, fbReader));
fbReader.addAction(ActionCode.SELECTION_SHARE, new SelectionShareAction(this, fbReader));
fbReader.addAction(ActionCode.SELECTION_TRANSLATE, new SelectionTranslateAction(this, fbReader));
fbReader.addAction(ActionCode.SELECTION_BOOKMARK, new SelectionBookmarkAction(this, fbReader));
myFBReaderApp.addAction(ActionCode.SELECTION_SHOW_PANEL, new SelectionShowPanelAction(this, myFBReaderApp));
myFBReaderApp.addAction(ActionCode.SELECTION_HIDE_PANEL, new SelectionHidePanelAction(this, myFBReaderApp));
myFBReaderApp.addAction(ActionCode.SELECTION_COPY_TO_CLIPBOARD, new SelectionCopyAction(this, myFBReaderApp));
myFBReaderApp.addAction(ActionCode.SELECTION_SHARE, new SelectionShareAction(this, myFBReaderApp));
myFBReaderApp.addAction(ActionCode.SELECTION_TRANSLATE, new SelectionTranslateAction(this, myFBReaderApp));
myFBReaderApp.addAction(ActionCode.SELECTION_BOOKMARK, new SelectionBookmarkAction(this, myFBReaderApp));
fbReader.addAction(ActionCode.PROCESS_HYPERLINK, new ProcessHyperlinkAction(this, fbReader));
myFBReaderApp.addAction(ActionCode.PROCESS_HYPERLINK, new ProcessHyperlinkAction(this, myFBReaderApp));
fbReader.addAction(ActionCode.SHOW_CANCEL_MENU, new ShowCancelMenuAction(this, fbReader));
myFBReaderApp.addAction(ActionCode.SHOW_CANCEL_MENU, new ShowCancelMenuAction(this, myFBReaderApp));
fbReader.addAction(ActionCode.SET_SCREEN_ORIENTATION_SYSTEM, new SetScreenOrientationAction(this, fbReader, ZLibrary.SCREEN_ORIENTATION_SYSTEM));
fbReader.addAction(ActionCode.SET_SCREEN_ORIENTATION_SENSOR, new SetScreenOrientationAction(this, fbReader, ZLibrary.SCREEN_ORIENTATION_SENSOR));
fbReader.addAction(ActionCode.SET_SCREEN_ORIENTATION_PORTRAIT, new SetScreenOrientationAction(this, fbReader, ZLibrary.SCREEN_ORIENTATION_PORTRAIT));
fbReader.addAction(ActionCode.SET_SCREEN_ORIENTATION_LANDSCAPE, new SetScreenOrientationAction(this, fbReader, ZLibrary.SCREEN_ORIENTATION_LANDSCAPE));
myFBReaderApp.addAction(ActionCode.SET_SCREEN_ORIENTATION_SYSTEM, new SetScreenOrientationAction(this, myFBReaderApp, ZLibrary.SCREEN_ORIENTATION_SYSTEM));
myFBReaderApp.addAction(ActionCode.SET_SCREEN_ORIENTATION_SENSOR, new SetScreenOrientationAction(this, myFBReaderApp, ZLibrary.SCREEN_ORIENTATION_SENSOR));
myFBReaderApp.addAction(ActionCode.SET_SCREEN_ORIENTATION_PORTRAIT, new SetScreenOrientationAction(this, myFBReaderApp, ZLibrary.SCREEN_ORIENTATION_PORTRAIT));
myFBReaderApp.addAction(ActionCode.SET_SCREEN_ORIENTATION_LANDSCAPE, new SetScreenOrientationAction(this, myFBReaderApp, ZLibrary.SCREEN_ORIENTATION_LANDSCAPE));
if (ZLibrary.Instance().supportsAllOrientations()) {
fbReader.addAction(ActionCode.SET_SCREEN_ORIENTATION_REVERSE_PORTRAIT, new SetScreenOrientationAction(this, fbReader, ZLibrary.SCREEN_ORIENTATION_REVERSE_PORTRAIT));
fbReader.addAction(ActionCode.SET_SCREEN_ORIENTATION_REVERSE_LANDSCAPE, new SetScreenOrientationAction(this, fbReader, ZLibrary.SCREEN_ORIENTATION_REVERSE_LANDSCAPE));
myFBReaderApp.addAction(ActionCode.SET_SCREEN_ORIENTATION_REVERSE_PORTRAIT, new SetScreenOrientationAction(this, myFBReaderApp, ZLibrary.SCREEN_ORIENTATION_REVERSE_PORTRAIT));
myFBReaderApp.addAction(ActionCode.SET_SCREEN_ORIENTATION_REVERSE_LANDSCAPE, new SetScreenOrientationAction(this, myFBReaderApp, ZLibrary.SCREEN_ORIENTATION_REVERSE_LANDSCAPE));
}
}
@ -245,31 +252,25 @@ public final class FBReader extends Activity {
protected void onNewIntent(final Intent intent) {
final String action = intent.getAction();
final Uri data = intent.getData();
final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance();
if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) {
super.onNewIntent(intent);
} else if (Intent.ACTION_VIEW.equals(action) || "android.fbreader.action.VIEW".equals(action)) {
FBReaderApp.Instance().openFile(fileFromIntent(intent), null);
init(new Runnable() {
public void run() {
FBReaderApp.Instance().openFile(fileFromIntent(intent), null);
}
});
} else if (Intent.ACTION_VIEW.equals(action) || ACTION_OPEN_BOOK.equals(action)) {
openBook(intent, null, true);
} else if (Intent.ACTION_VIEW.equals(action)
&& data != null && "fbreader-action".equals(data.getScheme())) {
fbReader.runAction(data.getEncodedSchemeSpecificPart(), data.getFragment());
myFBReaderApp.runAction(data.getEncodedSchemeSpecificPart(), data.getFragment());
} else if (Intent.ACTION_SEARCH.equals(action)) {
final String pattern = intent.getStringExtra(SearchManager.QUERY);
final Runnable runnable = new Runnable() {
public void run() {
final TextSearchPopup popup = (TextSearchPopup)fbReader.getPopupById(TextSearchPopup.ID);
final TextSearchPopup popup = (TextSearchPopup)myFBReaderApp.getPopupById(TextSearchPopup.ID);
popup.initPosition();
fbReader.TextSearchPatternOption.setValue(pattern);
if (fbReader.getTextView().search(pattern, true, false, false, false) != 0) {
myFBReaderApp.TextSearchPatternOption.setValue(pattern);
if (myFBReaderApp.getTextView().search(pattern, true, false, false, false) != 0) {
runOnUiThread(new Runnable() {
public void run() {
fbReader.showPopup(popup.getId());
myFBReaderApp.showPopup(popup.getId());
}
});
} else {
@ -288,16 +289,23 @@ public final class FBReader extends Activity {
}
}
@Override
protected void onRestart() {
super.onRestart();
getCollection().bindToService(null);
}
@Override
protected void onStart() {
super.onStart();
((BookCollectionShadow)myFBReaderApp.Collection).bindToService(this, new Runnable() {
public void run() {
new Thread() {
public void run() {
openBook(getIntent(), getPostponedInitAction(), false);
myFBReaderApp.getViewWidget().repaint();
}
}.start();
myFBReaderApp.getViewWidget().repaint();
}
});
initPluginActions();
final ZLAndroidLibrary zlibrary = (ZLAndroidLibrary)ZLibrary.Instance();
@ -311,19 +319,17 @@ public final class FBReader extends Activity {
SetScreenOrientationAction.setOrientation(this, zlibrary.OrientationOption.getValue());
final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance();
final RelativeLayout root = (RelativeLayout)findViewById(R.id.root_view);
((PopupPanel)fbReader.getPopupById(TextSearchPopup.ID)).setPanelInfo(this, root);
((PopupPanel)fbReader.getPopupById(NavigationPopup.ID)).setPanelInfo(this, root);
((PopupPanel)fbReader.getPopupById(SelectionPopup.ID)).setPanelInfo(this, root);
((PopupPanel)myFBReaderApp.getPopupById(TextSearchPopup.ID)).setPanelInfo(this, root);
((PopupPanel)myFBReaderApp.getPopupById(NavigationPopup.ID)).setPanelInfo(this, root);
((PopupPanel)myFBReaderApp.getPopupById(SelectionPopup.ID)).setPanelInfo(this, root);
}
private void initPluginActions() {
final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance();
synchronized (myPluginActions) {
int index = 0;
while (index < myPluginActions.size()) {
fbReader.removeAction(PLUGIN_ACTION_PREFIX + index++);
myFBReaderApp.removeAction(PLUGIN_ACTION_PREFIX + index++);
}
myPluginActions.clear();
}
@ -371,8 +377,7 @@ public final class FBReader extends Activity {
super.onResume();
switchWakeLock(
getZLibrary().BatteryLevelToTurnScreenOffOption.getValue() <
FBReaderApp.Instance().getBatteryLevel()
getZLibrary().BatteryLevelToTurnScreenOffOption.getValue() < myFBReaderApp.getBatteryLevel()
);
myStartTimer = true;
final int brightnessLevel =
@ -388,98 +393,90 @@ public final class FBReader extends Activity {
registerReceiver(myBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
PopupPanel.restoreVisibilities(FBReaderApp.Instance());
PopupPanel.restoreVisibilities(myFBReaderApp);
ApiServerImplementation.sendEvent(this, ApiListener.EVENT_READ_MODE_OPENED);
}
@Override
protected void onPause() {
unregisterReceiver(myBatteryInfoReceiver);
FBReaderApp.Instance().stopTimer();
myFBReaderApp.stopTimer();
switchWakeLock(false);
if (getZLibrary().DisableButtonLightsOption.getValue()) {
setButtonLight(true);
}
FBReaderApp.Instance().onWindowClosing();
myFBReaderApp.onWindowClosing();
super.onPause();
}
@Override
protected void onStop() {
ApiServerImplementation.sendEvent(this, ApiListener.EVENT_READ_MODE_CLOSED);
PopupPanel.removeAllWindows(FBReaderApp.Instance(), this);
getCollection().unbind();
PopupPanel.removeAllWindows(myFBReaderApp, this);
((BookCollectionShadow)myFBReaderApp.Collection).unbind();
super.onStop();
}
@Override
public void onLowMemory() {
FBReaderApp.Instance().onWindowClosing();
myFBReaderApp.onWindowClosing();
super.onLowMemory();
}
private FBReaderApp createApplication() {
return new FBReaderApp(new BookCollectionShadow(this));
}
@Override
public boolean onSearchRequested() {
final FBReaderApp fbreader = (FBReaderApp)FBReaderApp.Instance();
final FBReaderApp.PopupPanel popup = fbreader.getActivePopup();
fbreader.hideActivePopup();
final FBReaderApp.PopupPanel popup = myFBReaderApp.getActivePopup();
myFBReaderApp.hideActivePopup();
final SearchManager manager = (SearchManager)getSystemService(SEARCH_SERVICE);
manager.setOnCancelListener(new SearchManager.OnCancelListener() {
public void onCancel() {
if (popup != null) {
fbreader.showPopup(popup.getId());
myFBReaderApp.showPopup(popup.getId());
}
manager.setOnCancelListener(null);
}
});
startSearch(fbreader.TextSearchPatternOption.getValue(), true, null, false);
startSearch(myFBReaderApp.TextSearchPatternOption.getValue(), true, null, false);
return true;
}
public void showSelectionPanel() {
final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance();
final ZLTextView view = fbReader.getTextView();
((SelectionPopup)fbReader.getPopupById(SelectionPopup.ID))
final ZLTextView view = myFBReaderApp.getTextView();
((SelectionPopup)myFBReaderApp.getPopupById(SelectionPopup.ID))
.move(view.getSelectionStartY(), view.getSelectionEndY());
fbReader.showPopup(SelectionPopup.ID);
myFBReaderApp.showPopup(SelectionPopup.ID);
}
public void hideSelectionPanel() {
final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance();
final FBReaderApp.PopupPanel popup = fbReader.getActivePopup();
final FBReaderApp.PopupPanel popup = myFBReaderApp.getActivePopup();
if (popup != null && popup.getId() == SelectionPopup.ID) {
fbReader.hideActivePopup();
myFBReaderApp.hideActivePopup();
}
}
private void onPreferencesUpdate(int resultCode, Book book) {
if (book != null) {
getCollection().saveBook(book, true);
myFBReaderApp.Collection.saveBook(book, true);
}
final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance();
switch (resultCode) {
case RESULT_DO_NOTHING:
break;
case RESULT_REPAINT:
{
AndroidFontUtil.clearFontCache();
final BookModel model = fbReader.Model;
final BookModel model = myFBReaderApp.Model;
if (model != null && book != null) {
if (model.Book != null) {
model.Book = book;
ZLTextHyphenator.Instance().load(model.Book.getLanguage());
}
}
fbReader.clearTextCaches();
fbReader.getViewWidget().repaint();
myFBReaderApp.clearTextCaches();
myFBReaderApp.getViewWidget().repaint();
break;
}
case RESULT_RELOAD_BOOK:
fbReader.reloadBook(book);
myFBReaderApp.reloadBook(book);
break;
}
}
@ -492,13 +489,13 @@ public final class FBReader extends Activity {
onPreferencesUpdate(resultCode, BookInfoActivity.bookByIntent(data));
break;
case REQUEST_CANCEL_MENU:
((FBReaderApp)FBReaderApp.Instance()).runCancelAction(resultCode - 1);
myFBReaderApp.runCancelAction(resultCode - 1);
break;
}
}
public void navigate() {
((NavigationPopup)FBReaderApp.Instance().getPopupById(NavigationPopup.ID)).runNavigation();
((NavigationPopup)myFBReaderApp.getPopupById(NavigationPopup.ID)).runNavigation();
}
private Menu addSubMenu(Menu menu, String id) {
@ -566,18 +563,17 @@ public final class FBReader extends Activity {
}
void addSelectionBookmark() {
final FBReaderApp fbReader = (FBReaderApp)FBReaderApp.Instance();
final FBView fbView = fbReader.getTextView();
final FBView fbView = myFBReaderApp.getTextView();
final String text = fbView.getSelectedText();
final Bookmark bookmark = new Bookmark(
fbReader.Model.Book,
myFBReaderApp.Model.Book,
fbView.getModel().getId(),
fbView.getSelectionStartPosition(),
text,
true
);
fbReader.Collection.saveBookmark(bookmark);
myFBReaderApp.Collection.saveBookmark(bookmark);
fbView.clearSelection();
UIUtil.showMessageText(
@ -629,7 +625,7 @@ public final class FBReader extends Activity {
}
}
if (myStartTimer) {
FBReaderApp.Instance().startTimer();
myFBReaderApp.startTimer();
myStartTimer = false;
}
}

View file

@ -102,8 +102,8 @@ public class BookInfoActivity extends Activity {
} else {
startActivity(
new Intent(getApplicationContext(), FBReader.class)
.setAction(Intent.ACTION_VIEW)
.putExtra(FBReader.BOOK_PATH_KEY, myBook.File.getPath())
.setAction(FBReader.ACTION_OPEN_BOOK)
.putExtra(FBReader.BOOK_KEY, SerializerUtil.serialize(myBook))
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
);
}

View file

@ -57,7 +57,7 @@ public class LibraryActivity extends TreeActivity implements MenuItem.OnMenuItem
super.onCreate(icicle);
if (myLibrary == null) {
myLibrary = new Library(new BookCollectionShadow(this));
myLibrary = new Library(new BookCollectionShadow());
myLibrary.addChangeListener(this);
}
@ -75,7 +75,7 @@ public class LibraryActivity extends TreeActivity implements MenuItem.OnMenuItem
@Override
protected void onStart() {
super.onStart();
((BookCollectionShadow)myLibrary.Collection).bindToService(new Runnable() {
((BookCollectionShadow)myLibrary.Collection).bindToService(this, new Runnable() {
public void run() {
myLibrary.init();
}
@ -255,8 +255,8 @@ public class LibraryActivity extends TreeActivity implements MenuItem.OnMenuItem
private void openBook(Book book) {
startActivity(
new Intent(getApplicationContext(), FBReader.class)
.setAction(Intent.ACTION_VIEW)
.putExtra(FBReader.BOOK_PATH_KEY, book.File.getPath())
.setAction(FBReader.ACTION_OPEN_BOOK)
.putExtra(FBReader.BOOK_KEY, SerializerUtil.serialize(book))
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
);
}

View file

@ -36,7 +36,7 @@ import org.geometerplus.fbreader.book.*;
import org.geometerplus.android.fbreader.api.TextPosition;
public class BookCollectionShadow extends AbstractBookCollection implements ServiceConnection {
private final Context myContext;
private Context myContext;
private volatile LibraryInterface myInterface;
private Runnable myOnBindAction;
@ -60,12 +60,8 @@ public class BookCollectionShadow extends AbstractBookCollection implements Serv
}
};
public BookCollectionShadow(Context context) {
myContext = context;
}
public synchronized void bindToService(Runnable onBindAction) {
if (myInterface != null) {
public synchronized void bindToService(Context context, Runnable onBindAction) {
if (myInterface != null && myContext == context) {
if (onBindAction != null) {
onBindAction.run();
}
@ -73,19 +69,21 @@ public class BookCollectionShadow extends AbstractBookCollection implements Serv
if (onBindAction != null) {
myOnBindAction = onBindAction;
}
myContext.bindService(
new Intent(myContext, LibraryService.class),
context.bindService(
new Intent(context, LibraryService.class),
this,
LibraryService.BIND_AUTO_CREATE
);
myContext = context;
}
}
public void unbind() {
if (myInterface != null) {
if (myContext != null && myInterface != null) {
myContext.unregisterReceiver(myReceiver);
myContext.unbindService(this);
myInterface = null;
myContext.unregisterReceiver(myReceiver);
myContext = null;
}
}
@ -318,9 +316,11 @@ public class BookCollectionShadow extends AbstractBookCollection implements Serv
myOnBindAction.run();
myOnBindAction = null;
}
if (myContext != null) {
myContext.registerReceiver(myReceiver, new IntentFilter(LibraryService.BOOK_EVENT_ACTION));
myContext.registerReceiver(myReceiver, new IntentFilter(LibraryService.BUILD_EVENT_ACTION));
}
}
// method from ServiceConnection interface
public synchronized void onServiceDisconnected(ComponentName name) {

View file

@ -337,30 +337,6 @@ public final class FBReaderApp extends ZLApplication {
setView(BookTextView);
}
private Book createBookForFile(ZLFile file) {
if (file == null) {
return null;
}
Book book = Collection.getBookByFile(file);
if (book != null) {
return book;
}
if (file.isArchive()) {
for (ZLFile child : file.children()) {
book = Collection.getBookByFile(child);
if (book != null) {
return book;
}
}
}
return null;
}
@Override
public void openFile(ZLFile file, Runnable postAction) {
openBook(createBookForFile(file), null, postAction);
}
public void onWindowClosing() {
storePosition();
}

View file

@ -176,8 +176,6 @@ public abstract class ZLApplication {
public void onWindowClosing() {
}
public abstract void openFile(ZLFile file, Runnable postAction);
//Action
static abstract public class ZLAction {
public boolean isVisible() {