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

NG library view: in progress

This commit is contained in:
Nikolay Pultsin 2010-11-21 23:52:36 +00:00
parent 2ac3ecd573
commit b218f22e18
8 changed files with 125 additions and 51 deletions

View file

@ -20,9 +20,11 @@
package org.geometerplus.android.fbreader;
import java.util.LinkedList;
import java.io.File;
import android.app.SearchManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
@ -34,6 +36,7 @@ import android.widget.TextView;
import org.geometerplus.zlibrary.core.application.ZLApplication;
import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.core.view.ZLView;
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
import org.geometerplus.zlibrary.text.model.ZLTextModel;
import org.geometerplus.zlibrary.text.view.ZLTextFixedPosition;
import org.geometerplus.zlibrary.text.view.ZLTextPosition;
@ -48,6 +51,8 @@ import org.geometerplus.fbreader.fbreader.ActionCode;
import org.geometerplus.fbreader.library.Library;
public final class FBReader extends ZLAndroidActivity {
public static final String BOOK_PATH_KEY = "BookPath";
final static int REPAINT_CODE = 1;
static FBReader Instance;
@ -85,9 +90,33 @@ public final class FBReader extends ZLAndroidActivity {
private static TextSearchButtonPanel myTextSearchPanel;
private static NavigationButtonPanel myNavigatePanel;
private String fileNameFromUri(Uri uri) {
if (uri.equals(Uri.parse("file:///"))) {
return Library.getHelpFile().getPath();
} else {
return uri.getPath();
}
}
@Override
protected String fileNameForEmptyUri() {
return Library.getHelpFile().getPath();
protected ZLFile fileFromIntent(Intent intent) {
String fileToOpen = intent.getStringExtra(BOOK_PATH_KEY);
//intent.putExtra(BOOK_PATH_KEY, (String)null);
if (fileToOpen == null && Intent.ACTION_VIEW.equals(intent.getAction())) {
final Uri uri = intent.getData();
if (uri != null) {
fileToOpen = fileNameFromUri(uri);
final String scheme = uri.getScheme();
if ("content".equals(scheme)) {
final File file = new File(fileToOpen);
if (!file.exists()) {
fileToOpen = file.getParent();
}
}
}
intent.setData(null);
}
return fileToOpen != null ? ZLFile.createFileByPath(fileToOpen) : null;
}
@Override
@ -188,11 +217,11 @@ public final class FBReader extends ZLAndroidActivity {
}
}
protected ZLApplication createApplication(String fileName) {
protected ZLApplication createApplication(ZLFile file) {
if (SQLiteBooksDatabase.Instance() == null) {
new SQLiteBooksDatabase("READER");
}
return new FBReaderApp(fileName);
return new FBReaderApp(file != null ? file.getPath() : null);
}
@Override

View file

@ -41,7 +41,7 @@ class ShowLibraryAction extends FBAction {
final BookModel model = Reader.Model;
Intent intent = new Intent(myBaseActivity.getApplicationContext(), LibraryTopLevelActivity.class);
if (model != null && model.Book != null) {
//intent.putExtra(LibraryTopLevelActivity.CURRENT_BOOK_PATH_KEY, model.Book.File.getPath());
intent.putExtra(LibraryTopLevelActivity.SELECTED_BOOK_PATH_KEY, model.Book.File.getPath());
}
myBaseActivity.startActivity(intent);
}

View file

@ -39,12 +39,16 @@ import org.geometerplus.zlibrary.ui.android.R;
import org.geometerplus.android.fbreader.tree.ZLAndroidTree;
public class LibraryBaseActivity extends ListActivity {
abstract class LibraryBaseActivity extends ListActivity {
public static final String SELECTED_BOOK_PATH_KEY = "SelectedBookPath";
protected final ZLResource myResource = ZLResource.resource("libraryView");
protected String mySelectedBookPath;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
mySelectedBookPath = getIntent().getStringExtra(SELECTED_BOOK_PATH_KEY);
}
@Override

View file

@ -23,11 +23,11 @@ import android.os.Bundle;
import org.geometerplus.fbreader.library.Library;
public class LibraryRecentActivity extends LibraryBaseActivity {
public class LibraryRecentActivity extends LibraryTreeActivity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setListAdapter(new LibraryAdapter(new Library().recentBooks().subTrees()));
setListAdapter(new LibraryAdapter(LibraryTopLevelActivity.Library.recentBooks().subTrees()));
}
}

View file

@ -29,6 +29,7 @@ import android.widget.ListView;
import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.fbreader.tree.FBTree;
import org.geometerplus.fbreader.library.Library;
import org.geometerplus.zlibrary.ui.android.R;
@ -36,6 +37,8 @@ import org.geometerplus.android.fbreader.SQLiteBooksDatabase;
import org.geometerplus.android.fbreader.tree.ZLAndroidTree;
public class LibraryTopLevelActivity extends LibraryBaseActivity {
static Library Library;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
@ -43,6 +46,9 @@ public class LibraryTopLevelActivity extends LibraryBaseActivity {
if (SQLiteBooksDatabase.Instance() == null) {
new SQLiteBooksDatabase("LIBRARY_NG");
}
if (Library == null) {
Library = new Library();
}
final ArrayList<FBTree> items = new ArrayList<FBTree>();
items.add(new TopLevelTree(
@ -58,10 +64,12 @@ public class LibraryTopLevelActivity extends LibraryBaseActivity {
R.drawable.ic_tab_library_recent,
new Runnable() {
public void run() {
startActivity(new Intent(
final Intent intent = new Intent(
LibraryTopLevelActivity.this,
LibraryRecentActivity.class
));
);
intent.putExtra(SELECTED_BOOK_PATH_KEY, mySelectedBookPath);
startActivity(intent);
}
}
));
@ -92,6 +100,12 @@ public class LibraryTopLevelActivity extends LibraryBaseActivity {
setListAdapter(new LibraryAdapter(items));
}
@Override
public void onDestroy() {
Library = null;
super.onDestroy();
}
@Override
public void onListItemClick(ListView listView, View view, int position, long rowId) {
TopLevelTree tree = (TopLevelTree)((LibraryAdapter)getListAdapter()).getItem(position);

View file

@ -0,0 +1,59 @@
/*
* Copyright (C) 2010 Geometer Plus <contact@geometerplus.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
package org.geometerplus.android.fbreader.library;
import java.io.File;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.ListView;
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
import org.geometerplus.fbreader.library.Book;
import org.geometerplus.fbreader.library.LibraryTree;
import org.geometerplus.fbreader.library.BookTree;
import org.geometerplus.android.fbreader.FBReader;
abstract class LibraryTreeActivity extends LibraryBaseActivity {
@Override
public void onListItemClick(ListView listView, View view, int position, long rowId) {
LibraryTree tree = (LibraryTree)((LibraryAdapter)getListAdapter()).getItem(position);
if (tree instanceof BookTree) {
final Book book = ((BookTree)tree).Book;
startActivity(getFBReaderIntent(book.File));
}
}
private Intent getFBReaderIntent(final ZLFile file) {
final Intent intent = new Intent(getApplicationContext(), FBReader.class);
intent.setAction(Intent.ACTION_VIEW);
final ZLFile physicalFile = file.getPhysicalFile();
if (physicalFile != null) {
intent.setData(Uri.fromFile(new File(physicalFile.getPath())));
} else {
intent.setData(Uri.parse("file:///"));
}
intent.putExtra(FBReader.BOOK_PATH_KEY, file.getPath());
return intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
}
}

View file

@ -131,6 +131,9 @@ public final class FBReaderApp extends ZLApplication {
}
public void openBook(final Book book, final Bookmark bookmark) {
if (bookmark == null & book.File.getPath().equals(Model.Book.File.getPath())) {
return;
}
ZLDialogManager.Instance().wait("loadingBook", new Runnable() {
public void run() {
openBookInternal(book, bookmark);

View file

@ -19,10 +19,8 @@
package org.geometerplus.zlibrary.ui.android.library;
import java.io.File;
import java.lang.reflect.*;
import android.net.Uri;
import android.app.Activity;
import android.os.Bundle;
import android.content.*;
@ -38,7 +36,7 @@ import org.geometerplus.zlibrary.ui.android.R;
import org.geometerplus.zlibrary.ui.android.application.ZLAndroidApplicationWindow;
public abstract class ZLAndroidActivity extends Activity {
protected abstract ZLApplication createApplication(String fileName);
protected abstract ZLApplication createApplication(ZLFile file);
private static final String REQUESTED_ORIENTATION_KEY = "org.geometerplus.zlibrary.ui.android.library.androidActiviy.RequestedOrientation";
private static final String ORIENTATION_CHANGE_COUNTER_KEY = "org.geometerplus.zlibrary.ui.android.library.androidActiviy.ChangeCounter";
@ -50,16 +48,6 @@ public abstract class ZLAndroidActivity extends Activity {
state.putInt(ORIENTATION_CHANGE_COUNTER_KEY, myChangeCounter);
}
protected abstract String fileNameForEmptyUri();
private String fileNameFromUri(Uri uri) {
if (uri.equals(Uri.parse("file:///"))) {
return fileNameForEmptyUri();
} else {
return uri.getPath();
}
}
private void setScreenBrightnessAuto() {
final WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.screenBrightness = -1.0f;
@ -96,24 +84,7 @@ public abstract class ZLAndroidActivity extends Activity {
}
}
private String extractFileNameFromIntent(Intent intent) {
String fileToOpen = null;
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
final Uri uri = intent.getData();
if (uri != null) {
fileToOpen = fileNameFromUri(uri);
final String scheme = uri.getScheme();
if ("content".equals(scheme)) {
final File file = new File(fileToOpen);
if (!file.exists()) {
fileToOpen = file.getParent();
}
}
}
intent.setData(null);
}
return fileToOpen;
}
protected abstract ZLFile fileFromIntent(Intent intent);
@Override
public void onCreate(Bundle state) {
@ -132,14 +103,13 @@ public abstract class ZLAndroidActivity extends Activity {
getLibrary().setActivity(this);
final String fileToOpen = extractFileNameFromIntent(getIntent());
final ZLFile fileToOpen = fileFromIntent(getIntent());
if (((ZLAndroidApplication)getApplication()).myMainWindow == null) {
ZLApplication application = createApplication(fileToOpen);
((ZLAndroidApplication)getApplication()).myMainWindow = new ZLAndroidApplicationWindow(application);
application.initWindow();
} else if (fileToOpen != null) {
ZLApplication.Instance().openFile(ZLFile.createFileByPath(fileToOpen));
} else {
ZLApplication.Instance().openFile(fileToOpen);
}
ZLApplication.Instance().repaintView();
}
@ -236,12 +206,7 @@ public abstract class ZLAndroidActivity extends Activity {
@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
final String fileToOpen = extractFileNameFromIntent(intent);
if (fileToOpen != null) {
ZLApplication.Instance().openFile(ZLFile.createFileByPath(fileToOpen));
}
ZLApplication.Instance().openFile(fileFromIntent(getIntent()));
ZLApplication.Instance().repaintView();
}