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

LibraryTabActivity opens book using intent instead of firect call of FBReader methods

This commit is contained in:
Nikolay Pultsin 2010-10-15 17:24:43 +01:00
parent 9c6ebbf038
commit 55e8dd6c90
3 changed files with 35 additions and 3 deletions

View file

@ -45,6 +45,7 @@ import org.geometerplus.zlibrary.ui.android.R;
import org.geometerplus.fbreader.bookmodel.BookModel;
import org.geometerplus.fbreader.fbreader.ActionCode;
import org.geometerplus.fbreader.library.Library;
public final class FBReader extends ZLAndroidActivity {
static FBReader Instance;
@ -82,6 +83,10 @@ public final class FBReader extends ZLAndroidActivity {
private static TextSearchButtonPanel myTextSearchPanel;
private static NavigationButtonPanel myNavigatePanel;
protected String fileNameForEmptyUri() {
return Library.getHelpFile().getPath();
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);

View file

@ -19,17 +19,22 @@
package org.geometerplus.android.fbreader;
import java.io.File;
import android.app.*;
import android.os.Bundle;
import android.view.*;
import android.widget.*;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import org.geometerplus.zlibrary.ui.android.R;
import org.geometerplus.zlibrary.core.tree.ZLTree;
import org.geometerplus.zlibrary.core.options.ZLStringOption;
import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
import org.geometerplus.fbreader.fbreader.FBReader;
import org.geometerplus.fbreader.bookmodel.BookModel;
@ -242,12 +247,24 @@ public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuIt
finish();
final Book book = ((BookTree)tree).Book;
if (!book.equals(myCurrentBook)) {
((FBReader)FBReader.Instance()).openBook(book, null);
ZLFile physicalFile = book.File.getPhysicalFile();
startActivity(getFBReaderIntent(physicalFile != null ? new File(physicalFile.getPath()) : null));
}
return true;
}
}
private Intent getFBReaderIntent(final File file) {
final Intent intent = new Intent(getApplicationContext(), org.geometerplus.android.fbreader.FBReader.class);
intent.setAction(Intent.ACTION_VIEW);
if (file != null) {
intent.setData(Uri.fromFile(file));
} else {
intent.setData(Uri.EMPTY);
}
return intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
}
private static final int OPEN_BOOK_ITEM_ID = 0;
private static final int DELETE_BOOK_ITEM_ID = 1;

View file

@ -48,6 +48,16 @@ public abstract class ZLAndroidActivity extends Activity {
state.putInt(ORIENTATION_CHANGE_COUNTER_KEY, myChangeCounter);
}
protected abstract String fileNameForEmptyUri();
private String fileNameFromUri(Uri uri) {
if (Uri.EMPTY.equals(uri)) {
return fileNameForEmptyUri();
} else {
return uri.getPath();
}
}
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
@ -69,7 +79,7 @@ public abstract class ZLAndroidActivity extends Activity {
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
final Uri uri = intent.getData();
if (uri != null) {
fileToOpen = uri.getPath();
fileToOpen = fileNameFromUri(uri);
final String scheme = uri.getScheme();
if ("content".equals(scheme)) {
final File file = new File(fileToOpen);
@ -127,7 +137,7 @@ public abstract class ZLAndroidActivity extends Activity {
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
final Uri uri = intent.getData();
if (uri != null) {
fileToOpen = uri.getPath();
fileToOpen = fileNameFromUri(uri);
}
intent.setData(null);
}