mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
LibraryTabActivity opens book using intent instead of firect call of FBReader methods
This commit is contained in:
parent
9c6ebbf038
commit
55e8dd6c90
3 changed files with 35 additions and 3 deletions
|
@ -45,6 +45,7 @@ import org.geometerplus.zlibrary.ui.android.R;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||||
import org.geometerplus.fbreader.fbreader.ActionCode;
|
import org.geometerplus.fbreader.fbreader.ActionCode;
|
||||||
|
import org.geometerplus.fbreader.library.Library;
|
||||||
|
|
||||||
public final class FBReader extends ZLAndroidActivity {
|
public final class FBReader extends ZLAndroidActivity {
|
||||||
static FBReader Instance;
|
static FBReader Instance;
|
||||||
|
@ -82,6 +83,10 @@ public final class FBReader extends ZLAndroidActivity {
|
||||||
private static TextSearchButtonPanel myTextSearchPanel;
|
private static TextSearchButtonPanel myTextSearchPanel;
|
||||||
private static NavigationButtonPanel myNavigatePanel;
|
private static NavigationButtonPanel myNavigatePanel;
|
||||||
|
|
||||||
|
protected String fileNameForEmptyUri() {
|
||||||
|
return Library.getHelpFile().getPath();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
|
|
|
@ -19,17 +19,22 @@
|
||||||
|
|
||||||
package org.geometerplus.android.fbreader;
|
package org.geometerplus.android.fbreader;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import android.app.*;
|
import android.app.*;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.ui.android.R;
|
import org.geometerplus.zlibrary.ui.android.R;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.tree.ZLTree;
|
import org.geometerplus.zlibrary.core.tree.ZLTree;
|
||||||
import org.geometerplus.zlibrary.core.options.ZLStringOption;
|
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.fbreader.fbreader.FBReader;
|
import org.geometerplus.fbreader.fbreader.FBReader;
|
||||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||||
|
@ -242,12 +247,24 @@ 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.equals(myCurrentBook)) {
|
||||||
((FBReader)FBReader.Instance()).openBook(book, null);
|
ZLFile physicalFile = book.File.getPhysicalFile();
|
||||||
|
startActivity(getFBReaderIntent(physicalFile != null ? new File(physicalFile.getPath()) : null));
|
||||||
}
|
}
|
||||||
return true;
|
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 OPEN_BOOK_ITEM_ID = 0;
|
||||||
private static final int DELETE_BOOK_ITEM_ID = 1;
|
private static final int DELETE_BOOK_ITEM_ID = 1;
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,16 @@ public abstract class ZLAndroidActivity extends Activity {
|
||||||
state.putInt(ORIENTATION_CHANGE_COUNTER_KEY, myChangeCounter);
|
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
|
@Override
|
||||||
public void onCreate(Bundle state) {
|
public void onCreate(Bundle state) {
|
||||||
super.onCreate(state);
|
super.onCreate(state);
|
||||||
|
@ -69,7 +79,7 @@ public abstract class ZLAndroidActivity extends Activity {
|
||||||
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
||||||
final Uri uri = intent.getData();
|
final Uri uri = intent.getData();
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
fileToOpen = uri.getPath();
|
fileToOpen = fileNameFromUri(uri);
|
||||||
final String scheme = uri.getScheme();
|
final String scheme = uri.getScheme();
|
||||||
if ("content".equals(scheme)) {
|
if ("content".equals(scheme)) {
|
||||||
final File file = new File(fileToOpen);
|
final File file = new File(fileToOpen);
|
||||||
|
@ -127,7 +137,7 @@ public abstract class ZLAndroidActivity extends Activity {
|
||||||
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
||||||
final Uri uri = intent.getData();
|
final Uri uri = intent.getData();
|
||||||
if (uri != null) {
|
if (uri != null) {
|
||||||
fileToOpen = uri.getPath();
|
fileToOpen = fileNameFromUri(uri);
|
||||||
}
|
}
|
||||||
intent.setData(null);
|
intent.setData(null);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue