mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 02:39:23 +02:00
packages/class renaming:
collection -> library BookCollection -> Library BookDescription -> Book bookmarks have been added git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@957 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
be07efdc92
commit
2b41a177b1
57 changed files with 930 additions and 568 deletions
|
@ -19,6 +19,12 @@
|
|||
<node name="collapseTree" value="Collapse tree"/>
|
||||
<node name="readText" value="Read book text"/>
|
||||
</node>
|
||||
<node name="bookmarksView">
|
||||
<node name="new" value="New bookmark"/>
|
||||
<node name="open" value="Open"/>
|
||||
<node name="edit" value="Edit"/>
|
||||
<node name="delete" value="Delete"/>
|
||||
</node>
|
||||
<node name="menu">
|
||||
<node name="preferences-old" value="Settings (old)"/>
|
||||
<node name="preferences" value="Settings"/>
|
||||
|
@ -46,7 +52,7 @@
|
|||
<node name="rotate" value="Rotate Screen"/>
|
||||
<node name="toggleFullscreen" value="Full Screen"/>
|
||||
</node>
|
||||
<node name="quit" value="Close"/>
|
||||
<node name="bookmarks" value="Bookmarks"/>
|
||||
</node>
|
||||
<node name="dialog">
|
||||
<node name="BookInfo">
|
||||
|
|
|
@ -19,6 +19,12 @@
|
|||
<node name="collapseTree" value="Свернуть ветвь дерева"/>
|
||||
<node name="readText" value="Читать главу"/>
|
||||
</node>
|
||||
<node name="bookmarksView">
|
||||
<node name="new" value="Добавить закладку"/>
|
||||
<node name="open" value="Открыть"/>
|
||||
<node name="edit" value="Изменить"/>
|
||||
<node name="delete" value="Стереть"/>
|
||||
</node>
|
||||
<node name="menu">
|
||||
<node name="preferences" value="Настройки"/>
|
||||
<node name="bookInfo" value="О книге"/>
|
||||
|
@ -44,6 +50,7 @@
|
|||
<node name="rotate" value="Повернуть"/>
|
||||
<node name="toggleFullscreen" value="На весь экран"/>
|
||||
</node>
|
||||
<node name="bookmarks" value="Закладки"/>
|
||||
</node>
|
||||
<node name="dialog">
|
||||
<node name="BookInfo">
|
||||
|
|
|
@ -26,12 +26,10 @@
|
|||
<activity android:name="org.geometerplus.android.fbreader.LibraryTabActivity" android:configChanges="orientation|keyboardHidden">
|
||||
<meta-data android:name="android.app.default_searchable" android:value="org.geometerplus.android.fbreader.BookSearchActivity" />
|
||||
</activity>
|
||||
<activity android:name="org.geometerplus.android.fbreader.TOCActivity" android:configChanges="orientation|keyboardHidden">
|
||||
</activity>
|
||||
<activity android:name="org.geometerplus.android.fbreader.preferences.PreferenceActivity" android:configChanges="orientation|keyboardHidden">
|
||||
</activity>
|
||||
<activity android:name="org.geometerplus.android.fbreader.preferences.BookInfoActivity" android:configChanges="orientation|keyboardHidden">
|
||||
</activity>
|
||||
<activity android:name="org.geometerplus.android.fbreader.TOCActivity" android:configChanges="orientation|keyboardHidden" />
|
||||
<activity android:name="org.geometerplus.android.fbreader.BookmarksActivity" android:configChanges="orientation|keyboardHidden" />
|
||||
<activity android:name="org.geometerplus.android.fbreader.preferences.PreferenceActivity" android:configChanges="orientation|keyboardHidden" />
|
||||
<activity android:name="org.geometerplus.android.fbreader.preferences.BookInfoActivity" android:configChanges="orientation|keyboardHidden" />
|
||||
<activity android:name="org.geometerplus.android.fbreader.BookDownloader" android:theme="@android:style/Theme.Dialog" android:configChanges="orientation|keyboardHidden">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<menubar>
|
||||
<item id="library"/>
|
||||
<item id="toc"/>
|
||||
<item id="bookmarks"/>
|
||||
<item id="search"/>
|
||||
<item id="preferences"/>
|
||||
<item id="preferences-old"/>
|
||||
<item id="bookInfo"/>
|
||||
<submenu id="navigate">
|
||||
<item id="gotoHome"/>
|
||||
<item id="gotoSectionStart"/>
|
||||
|
@ -9,10 +16,4 @@
|
|||
<item id="undo"/>
|
||||
<item id="redo"/>
|
||||
</submenu>
|
||||
<item id="library"/>
|
||||
<item id="toc"/>
|
||||
<item id="search"/>
|
||||
<item id="preferences"/>
|
||||
<item id="preferences-old"/>
|
||||
<item id="bookInfo"/>
|
||||
</menubar>
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 250 B After Width: | Height: | Size: 272 B |
Binary file not shown.
Before Width: | Height: | Size: 242 B After Width: | Height: | Size: 264 B |
BIN
platform/android/icons/tree/plus.png
Normal file
BIN
platform/android/icons/tree/plus.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 298 B |
BIN
platform/android/icons/tree/strut.png
Normal file
BIN
platform/android/icons/tree/strut.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 177 B |
25
platform/android/res/layout/bookmark_item.xml
Normal file
25
platform/android/res/layout/bookmark_item.xml
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:paddingLeft="5dip"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
<ImageView
|
||||
android:id="@+id/bookmark_item_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="fill_parent"
|
||||
android:singleLine="true"
|
||||
/>
|
||||
<TextView
|
||||
android:id="@+id/bookmark_item_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_marginLeft="5dip"
|
||||
android:layout_marginTop="5dip"
|
||||
android:layout_marginBottom="5dip"
|
||||
android:gravity="center_vertical|left"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
/>
|
||||
</LinearLayout>
|
|
@ -22,10 +22,10 @@ package org.geometerplus.android.fbreader;
|
|||
import android.app.Activity;
|
||||
|
||||
import org.geometerplus.fbreader.fbreader.FBReader;
|
||||
import org.geometerplus.fbreader.collection.*;
|
||||
import org.geometerplus.fbreader.library.*;
|
||||
|
||||
public class BookSearchActivity extends SearchActivity {
|
||||
private CollectionTree myTree;
|
||||
private LibraryTree myTree;
|
||||
|
||||
@Override
|
||||
void onSuccess() {
|
||||
|
@ -50,7 +50,7 @@ public class BookSearchActivity extends SearchActivity {
|
|||
boolean runSearch(final String pattern) {
|
||||
final FBReader fbreader = (FBReader)FBReader.Instance();
|
||||
fbreader.BookSearchPatternOption.setValue(pattern);
|
||||
myTree = BookCollection.Instance().searchBooks(pattern);
|
||||
myTree = Library.Instance().searchBooks(pattern);
|
||||
return myTree.hasChildren();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,177 @@
|
|||
/*
|
||||
* Copyright (C) 2009 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;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
import android.content.Context;
|
||||
import android.app.ListActivity;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
import org.geometerplus.zlibrary.text.view.impl.*;
|
||||
|
||||
import org.geometerplus.zlibrary.ui.android.R;
|
||||
|
||||
import org.geometerplus.fbreader.fbreader.FBReader;
|
||||
import org.geometerplus.fbreader.library.*;
|
||||
|
||||
public class BookmarksActivity extends ListActivity {
|
||||
private static final int OPEN_ITEM_ID = 0;
|
||||
private static final int EDIT_ITEM_ID = 1;
|
||||
private static final int DELETE_ITEM_ID = 2;
|
||||
|
||||
private BookmarkList myBookmarks;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
myBookmarks = new BookmarkList(((FBReader)FBReader.Instance()).Model.Book);
|
||||
final BookmarksAdapter adapter = new BookmarksAdapter();
|
||||
final ListView listView = getListView();
|
||||
listView.setAdapter(adapter);
|
||||
listView.setOnItemClickListener(adapter);
|
||||
listView.setOnCreateContextMenuListener(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
myBookmarks.save();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item) {
|
||||
final int position = ((AdapterView.AdapterContextMenuInfo)item.getMenuInfo()).position;
|
||||
switch (item.getItemId()) {
|
||||
case OPEN_ITEM_ID:
|
||||
gotoBookmark(position - 1);
|
||||
return true;
|
||||
case EDIT_ITEM_ID:
|
||||
// TODO: implement
|
||||
return true;
|
||||
case DELETE_ITEM_ID:
|
||||
myBookmarks.removeBookmark(position - 1);
|
||||
getListView().invalidateViews();
|
||||
getListView().requestLayout();
|
||||
return true;
|
||||
}
|
||||
return super.onContextItemSelected(item);
|
||||
}
|
||||
|
||||
private void addBookmark() {
|
||||
ZLTextWordCursor cursor = ((FBReader)FBReader.Instance()).BookTextView.getStartCursor();
|
||||
if (!cursor.isNull()) {
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
final ZLTextPosition position = new ZLTextPosition(cursor);
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
int wordCounter = 0;
|
||||
cursor = new ZLTextWordCursor(cursor);
|
||||
|
||||
mainLoop:
|
||||
do {
|
||||
for (; !cursor.isEndOfParagraph(); cursor.nextWord()) {
|
||||
final ZLTextElement element = cursor.getElement();
|
||||
if (element instanceof ZLTextWord) {
|
||||
final ZLTextWord word = (ZLTextWord)element;
|
||||
if (builder.length() > 0) {
|
||||
builder.append(" ");
|
||||
}
|
||||
builder.append(word.Data, word.Offset, word.Length);
|
||||
if (++wordCounter >= 10) {
|
||||
break mainLoop;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while ((builder.length() == 0) && cursor.nextParagraph());
|
||||
|
||||
// TODO: text edit dialog
|
||||
myBookmarks.addNewBookmark(builder.toString(), position);
|
||||
getListView().invalidateViews();
|
||||
getListView().requestLayout();
|
||||
}
|
||||
|
||||
private void gotoBookmark(int index) {
|
||||
myBookmarks.gotoBookmark(index, ((FBReader)FBReader.Instance()).BookTextView);
|
||||
finish();
|
||||
}
|
||||
|
||||
private final class BookmarksAdapter extends BaseAdapter implements AdapterView.OnItemClickListener, View.OnCreateContextMenuListener {
|
||||
BookmarksAdapter() {
|
||||
}
|
||||
|
||||
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
final int position = ((AdapterView.AdapterContextMenuInfo)menuInfo).position;
|
||||
if (position > 0) {
|
||||
menu.setHeaderTitle(getItem(position).getText());
|
||||
final ZLResource resource = ZLResource.resource("bookmarksView");
|
||||
menu.add(0, OPEN_ITEM_ID, 0, resource.getResource("open").getValue());
|
||||
menu.add(0, EDIT_ITEM_ID, 0, resource.getResource("edit").getValue());
|
||||
menu.add(0, DELETE_ITEM_ID, 0, resource.getResource("delete").getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
final View view = (convertView != null) ? convertView :
|
||||
LayoutInflater.from(parent.getContext()).inflate(R.layout.bookmark_item, parent, false);
|
||||
((ImageView)view.findViewById(R.id.bookmark_item_icon)).setImageResource(
|
||||
(position > 0) ? R.drawable.tree_icon_strut : R.drawable.tree_icon_plus
|
||||
);
|
||||
((TextView)view.findViewById(R.id.bookmark_item_text)).setText(
|
||||
(position > 0) ?
|
||||
getItem(position).getText() :
|
||||
ZLResource.resource("bookmarksView").getResource("new").getValue()
|
||||
);
|
||||
return view;
|
||||
}
|
||||
|
||||
public final boolean areAllItemsEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public final boolean isEnabled(int position) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public final long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
public final Bookmark getItem(int position) {
|
||||
return (position > 0) ? myBookmarks.get(position - 1) : null;
|
||||
}
|
||||
|
||||
public final int getCount() {
|
||||
return myBookmarks.size() + 1;
|
||||
}
|
||||
|
||||
public final void onItemClick(AdapterView parent, View view, int position, long id) {
|
||||
if (position == 0) {
|
||||
addBookmark();
|
||||
} else {
|
||||
gotoBookmark(position - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,7 +31,7 @@ import org.geometerplus.zlibrary.core.options.ZLStringOption;
|
|||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
||||
import org.geometerplus.fbreader.fbreader.FBReader;
|
||||
import org.geometerplus.fbreader.collection.*;
|
||||
import org.geometerplus.fbreader.library.*;
|
||||
|
||||
public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuItemClickListener {
|
||||
static LibraryTabActivity Instance;
|
||||
|
@ -54,16 +54,16 @@ public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuIt
|
|||
final TabHost host = getTabHost();
|
||||
LayoutInflater.from(this).inflate(R.layout.library, host.getTabContentView(), true);
|
||||
|
||||
new LibraryAdapter(createTab("byAuthor", R.id.by_author), BookCollection.Instance().collectionByAuthor());
|
||||
new LibraryAdapter(createTab("byTag", R.id.by_tag), BookCollection.Instance().collectionByTag());
|
||||
new LibraryAdapter(createTab("recent", R.id.recent), BookCollection.Instance().recentBooks());
|
||||
new LibraryAdapter(createTab("byAuthor", R.id.by_author), Library.Instance().byAuthor());
|
||||
new LibraryAdapter(createTab("byTag", R.id.by_tag), Library.Instance().byTag());
|
||||
new LibraryAdapter(createTab("recent", R.id.recent), Library.Instance().recentBooks());
|
||||
findViewById(R.id.search_results).setVisibility(View.GONE);
|
||||
|
||||
host.setCurrentTabByTag(mySelectedTabOption.getValue());
|
||||
}
|
||||
|
||||
private LibraryAdapter mySearchResultsAdapter;
|
||||
void showSearchResultsTab(CollectionTree tree) {
|
||||
void showSearchResultsTab(LibraryTree tree) {
|
||||
if (mySearchResultsAdapter == null) {
|
||||
mySearchResultsAdapter =
|
||||
new LibraryAdapter(createTab("searchResults", R.id.search_results), tree);
|
||||
|
@ -88,7 +88,7 @@ public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuIt
|
|||
public void onStop() {
|
||||
mySelectedTabOption.setValue(getTabHost().getCurrentTabTag());
|
||||
Instance = null;
|
||||
BookCollection.Instance().clear();
|
||||
Library.Instance().clear();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
|
@ -124,17 +124,17 @@ public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuIt
|
|||
}
|
||||
|
||||
private final class LibraryAdapter extends ZLTreeAdapter {
|
||||
private final CollectionTree myCollectionTree;
|
||||
private final LibraryTree myLibraryTree;
|
||||
|
||||
LibraryAdapter(ListView view, CollectionTree tree) {
|
||||
LibraryAdapter(ListView view, LibraryTree tree) {
|
||||
super(view, tree);
|
||||
myCollectionTree = tree;
|
||||
myLibraryTree = tree;
|
||||
}
|
||||
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
final View view = (convertView != null) ? convertView :
|
||||
LayoutInflater.from(parent.getContext()).inflate(R.layout.library_tree_item, parent, false);
|
||||
final CollectionTree tree = (CollectionTree)getItem(position);
|
||||
final LibraryTree tree = (LibraryTree)getItem(position);
|
||||
setIcon((ImageView)view.findViewById(R.id.library_tree_item_icon), tree);
|
||||
((TextView)view.findViewById(R.id.library_tree_item_name)).setText(tree.getName());
|
||||
((TextView)view.findViewById(R.id.library_tree_item_childrenlist)).setText(tree.getSecondString());
|
||||
|
@ -147,7 +147,7 @@ public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuIt
|
|||
}
|
||||
finish();
|
||||
final FBReader fbreader = (FBReader)FBReader.Instance();
|
||||
fbreader.openBook(((BookTree)tree).Description);
|
||||
fbreader.openBook(((BookTree)tree).Book);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,9 +30,10 @@ import android.database.Cursor;
|
|||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.dialogs.ZLDialogManager;
|
||||
import org.geometerplus.zlibrary.core.options.ZLStringOption;
|
||||
import org.geometerplus.zlibrary.text.view.impl.ZLTextPosition;
|
||||
import org.geometerplus.zlibrary.ui.android.library.ZLAndroidApplication;
|
||||
|
||||
import org.geometerplus.fbreader.collection.*;
|
||||
import org.geometerplus.fbreader.library.*;
|
||||
|
||||
final class SQLiteBooksDatabase extends BooksDatabase {
|
||||
private final SQLiteDatabase myDatabase;
|
||||
|
@ -44,7 +45,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
|
||||
private void migrate() {
|
||||
final int version = myDatabase.getVersion();
|
||||
if (version >= 5) {
|
||||
if (version >= 6) {
|
||||
return;
|
||||
}
|
||||
ZLDialogManager.Instance().wait((version == 0) ? "creatingBooksDatabase" : "updatingBooksDatabase", new Runnable() {
|
||||
|
@ -64,12 +65,14 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
updateTables4();
|
||||
case 5:
|
||||
updateTables5();
|
||||
case 6:
|
||||
updateTables6();
|
||||
}
|
||||
myDatabase.setTransactionSuccessful();
|
||||
myDatabase.endTransaction();
|
||||
|
||||
myDatabase.execSQL("VACUUM");
|
||||
myDatabase.setVersion(5);
|
||||
myDatabase.setVersion(6);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -92,22 +95,37 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
}
|
||||
}
|
||||
|
||||
private static void bindDate(SQLiteStatement statement, int index, Date value) {
|
||||
if (value != null) {
|
||||
statement.bindLong(index, value.getTime());
|
||||
} else {
|
||||
statement.bindNull(index);
|
||||
}
|
||||
}
|
||||
|
||||
private static Date getDate(Cursor cursor, int index) {
|
||||
if (cursor.isNull(index)) {
|
||||
return null;
|
||||
}
|
||||
return new Date(cursor.getLong(index));
|
||||
}
|
||||
|
||||
private static final String BOOKS_TABLE = "Books";
|
||||
private static final String[] BOOKS_COLUMNS = { "book_id", "encoding", "language", "title" };
|
||||
private static final String FILE_NAME_CONDITION = "file_name = ?";
|
||||
protected long loadBook(BookDescription description) {
|
||||
protected long loadBook(Book book) {
|
||||
final Cursor cursor = myDatabase.query(
|
||||
BOOKS_TABLE,
|
||||
BOOKS_COLUMNS,
|
||||
FILE_NAME_CONDITION, new String[] { description.File.getPath() },
|
||||
FILE_NAME_CONDITION, new String[] { book.File.getPath() },
|
||||
null, null, null, null
|
||||
);
|
||||
long id = -1;
|
||||
if (cursor.moveToNext()) {
|
||||
id = cursor.getLong(0);
|
||||
description.setEncoding(cursor.getString(1));
|
||||
description.setLanguage(cursor.getString(2));
|
||||
description.setTitle(cursor.getString(3));
|
||||
book.setEncoding(cursor.getString(1));
|
||||
book.setLanguage(cursor.getString(2));
|
||||
book.setTitle(cursor.getString(3));
|
||||
}
|
||||
cursor.close();
|
||||
return id;
|
||||
|
@ -135,21 +153,21 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
cursor.close();
|
||||
}
|
||||
|
||||
protected Map<String,BookDescription> listBooks() {
|
||||
protected Map<String,Book> listBooks() {
|
||||
Cursor cursor = myDatabase.rawQuery(
|
||||
"SELECT book_id,file_name,title,encoding,language FROM Books", null
|
||||
);
|
||||
final int count = cursor.getCount();
|
||||
final HashMap<Long,BookDescription> booksById = new HashMap<Long,BookDescription>(count);
|
||||
final HashMap<String,BookDescription> booksByFilename = new HashMap<String,BookDescription>(count);
|
||||
final HashMap<Long,Book> booksById = new HashMap<Long,Book>(count);
|
||||
final HashMap<String,Book> booksByFilename = new HashMap<String,Book>(count);
|
||||
while (cursor.moveToNext()) {
|
||||
final long id = cursor.getLong(0);
|
||||
final String fileName = cursor.getString(1);
|
||||
final BookDescription description = createDescription(
|
||||
final Book book = createBook(
|
||||
id, fileName, cursor.getString(2), cursor.getString(3), cursor.getString(4)
|
||||
);
|
||||
booksById.put(id, description);
|
||||
booksByFilename.put(fileName, description);
|
||||
booksById.put(id, book);
|
||||
booksByFilename.put(fileName, book);
|
||||
}
|
||||
cursor.close();
|
||||
|
||||
|
@ -168,7 +186,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
"SELECT book_id,author_id FROM BookAuthor ORDER BY author_index", null
|
||||
);
|
||||
while (cursor.moveToNext()) {
|
||||
BookDescription book = booksById.get(cursor.getLong(0));
|
||||
Book book = booksById.get(cursor.getLong(0));
|
||||
if (book != null) {
|
||||
Author author = authorById.get(cursor.getLong(1));
|
||||
if (author != null) {
|
||||
|
@ -180,7 +198,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
|
||||
cursor = myDatabase.rawQuery("SELECT book_id,tag_id FROM BookTag", null);
|
||||
while (cursor.moveToNext()) {
|
||||
BookDescription book = booksById.get(cursor.getLong(0));
|
||||
Book book = booksById.get(cursor.getLong(0));
|
||||
if (book != null) {
|
||||
addTag(book, getTagById(cursor.getLong(1)));
|
||||
}
|
||||
|
@ -200,7 +218,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
"SELECT book_id,series_id,book_index FROM BookSeries", null
|
||||
);
|
||||
while (cursor.moveToNext()) {
|
||||
BookDescription book = booksById.get(cursor.getLong(0));
|
||||
Book book = booksById.get(cursor.getLong(0));
|
||||
if (book != null) {
|
||||
String series = seriesById.get(cursor.getLong(1));
|
||||
if (series != null) {
|
||||
|
@ -606,6 +624,41 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
return ids;
|
||||
}
|
||||
|
||||
private SQLiteStatement myDeleteBookmarksStatement;
|
||||
private SQLiteStatement myInsertBookmarkStatement;
|
||||
protected void saveBookmarks(final long bookId, final List<Bookmark> list) {
|
||||
if (myDeleteBookmarksStatement == null) {
|
||||
myDeleteBookmarksStatement = myDatabase.compileStatement(
|
||||
"DELETE FROM Bookmarks WHERE book_id = ?"
|
||||
);
|
||||
myInsertBookmarkStatement = myDatabase.compileStatement(
|
||||
"INSERT INTO Bookmarks (book_id,bookmark_text,creation_time,modification_time,access_time,access_counter,paragraph,word,char) VALUES (?,?,?,?,?,?,?,?,?)"
|
||||
);
|
||||
}
|
||||
executeAsATransaction(new Runnable() {
|
||||
public void run() {
|
||||
myDeleteBookmarksStatement.bindLong(1, bookId);
|
||||
myDeleteBookmarksStatement.execute();
|
||||
if (list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
myInsertBookmarkStatement.bindLong(1, bookId);
|
||||
for (Bookmark bookmark : list) {
|
||||
myInsertBookmarkStatement.bindString(2, bookmark.getText());
|
||||
bindDate(myInsertBookmarkStatement, 3, bookmark.getTime(Bookmark.CREATION));
|
||||
bindDate(myInsertBookmarkStatement, 4, bookmark.getTime(Bookmark.MODIFICATION));
|
||||
bindDate(myInsertBookmarkStatement, 5, bookmark.getTime(Bookmark.ACCESS));
|
||||
myInsertBookmarkStatement.bindLong(6, bookmark.getAccessCount());
|
||||
final ZLTextPosition position = bookmark.getPosition();
|
||||
myInsertBookmarkStatement.bindLong(7, position.ParagraphIndex);
|
||||
myInsertBookmarkStatement.bindLong(8, position.WordIndex);
|
||||
myInsertBookmarkStatement.bindLong(9, position.CharIndex);
|
||||
myInsertBookmarkStatement.execute();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void createTables() {
|
||||
myDatabase.execSQL(
|
||||
"CREATE TABLE Books(" +
|
||||
|
@ -716,5 +769,38 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
|||
}
|
||||
|
||||
private void updateTables5() {
|
||||
myDatabase.execSQL(
|
||||
"CREATE TABLE Bookmarks(" +
|
||||
"book_id INTEGER NOT NULL REFERENCES Books(book_id)," +
|
||||
"bookmark_text TEXT NOT NULL," +
|
||||
"creation_time INTEGER NOT NULL," +
|
||||
"modification_time INTEGER," +
|
||||
"access_time INTEGER," +
|
||||
"access_counter INTEGER NOT NULL," +
|
||||
"paragraph INTEGER NOT NULL," +
|
||||
"word INTEGER NOT NULL," +
|
||||
"char INTEGER NOT NULL)");
|
||||
}
|
||||
|
||||
private void updateTables6() {
|
||||
}
|
||||
|
||||
protected void listBookmarks(long bookId, List<Bookmark> list) {
|
||||
Cursor cursor = myDatabase.rawQuery(
|
||||
"SELECT bookmark_text,creation_time,modification_time,access_time,access_counter,paragraph,word,char FROM Bookmarks WHERE book_id = ?", new String[] { "" + bookId }
|
||||
);
|
||||
while (cursor.moveToNext()) {
|
||||
list.add(createBookmark(
|
||||
cursor.getString(0),
|
||||
getDate(cursor, 1),
|
||||
getDate(cursor, 2),
|
||||
getDate(cursor, 3),
|
||||
(int)cursor.getLong(4),
|
||||
(int)cursor.getLong(5),
|
||||
(int)cursor.getLong(6),
|
||||
(int)cursor.getLong(7)
|
||||
));
|
||||
}
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.geometerplus.android.fbreader;
|
|||
import android.os.*;
|
||||
import android.app.*;
|
||||
import android.content.Intent;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
import org.geometerplus.zlibrary.core.dialogs.ZLDialogManager;
|
||||
|
@ -40,21 +41,14 @@ abstract class SearchActivity extends Activity {
|
|||
}
|
||||
};
|
||||
final Handler failureHandler = new Handler() {
|
||||
private AlertDialog myAlertDialog;
|
||||
public void handleMessage(Message message) {
|
||||
switch (message.what) {
|
||||
case 0:
|
||||
onFailure();
|
||||
myAlertDialog =
|
||||
new AlertDialog.Builder(getParentActivity()).setMessage(
|
||||
ZLResource.resource("errorMessage").getResource(getFailureMessageResourceKey()).getValue()
|
||||
).create();
|
||||
myAlertDialog.show();
|
||||
break;
|
||||
case 1:
|
||||
myAlertDialog.dismiss();
|
||||
break;
|
||||
}
|
||||
Toast.makeText(
|
||||
getParentActivity(),
|
||||
ZLResource.resource("errorMessage").getResource(
|
||||
getFailureMessageResourceKey()
|
||||
).getValue(),
|
||||
Toast.LENGTH_SHORT
|
||||
).show();
|
||||
}
|
||||
};
|
||||
ZLDialogManager.Instance().wait(getWaitMessageResourceKey(), new Runnable() {
|
||||
|
@ -63,15 +57,6 @@ abstract class SearchActivity extends Activity {
|
|||
successHandler.sendEmptyMessage(0);
|
||||
} else {
|
||||
failureHandler.sendEmptyMessage(0);
|
||||
new Thread(new Runnable() {
|
||||
public synchronized void run() {
|
||||
try {
|
||||
wait(3000);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
failureHandler.sendEmptyMessage(1);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -124,7 +124,7 @@ public class TOCActivity extends ListActivity {
|
|||
final TOCTree.Reference reference = tree.getReference();
|
||||
if (reference != null) {
|
||||
final FBReader fbreader = (FBReader)ZLApplication.Instance();
|
||||
fbreader.BookTextView.gotoParagraphSafe(reference.Model, reference.ParagraphIndex);
|
||||
fbreader.BookTextView.gotoParagraphSafe(reference.ParagraphIndex);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,28 +30,28 @@ import org.geometerplus.zlibrary.core.language.ZLLanguageList;
|
|||
import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator;
|
||||
|
||||
import org.geometerplus.fbreader.fbreader.FBReader;
|
||||
import org.geometerplus.fbreader.collection.BookDescription;
|
||||
import org.geometerplus.fbreader.library.Book;
|
||||
|
||||
class BookTitlePreference extends ZLStringPreference {
|
||||
private final BookDescription myDescription;
|
||||
private final Book myBook;
|
||||
|
||||
BookTitlePreference(Context context, ZLResource rootResource, String resourceKey, BookDescription description) {
|
||||
BookTitlePreference(Context context, ZLResource rootResource, String resourceKey, Book book) {
|
||||
super(context, rootResource, resourceKey);
|
||||
myDescription = description;
|
||||
setValue(description.getTitle());
|
||||
myBook = book;
|
||||
setValue(book.getTitle());
|
||||
}
|
||||
|
||||
public void accept() {
|
||||
myDescription.setTitle(getValue());
|
||||
myBook.setTitle(getValue());
|
||||
}
|
||||
}
|
||||
|
||||
class LanguagePreference extends ZLStringListPreference {
|
||||
private final BookDescription myDescription;
|
||||
private final Book myBook;
|
||||
|
||||
LanguagePreference(Context context, ZLResource rootResource, String resourceKey, BookDescription description) {
|
||||
LanguagePreference(Context context, ZLResource rootResource, String resourceKey, Book book) {
|
||||
super(context, rootResource, resourceKey);
|
||||
myDescription = description;
|
||||
myBook = book;
|
||||
final TreeMap<String,String> map = new TreeMap<String,String>();
|
||||
for (String code : ZLLanguageList.languageCodes()) {
|
||||
map.put(ZLLanguageList.languageName(code), code);
|
||||
|
@ -68,7 +68,7 @@ class LanguagePreference extends ZLStringListPreference {
|
|||
codes[size] = "other";
|
||||
names[size] = ZLLanguageList.languageName(codes[size]);
|
||||
setLists(codes, names);
|
||||
String language = myDescription.getLanguage();
|
||||
String language = myBook.getLanguage();
|
||||
if (language == null) {
|
||||
language = "other";
|
||||
}
|
||||
|
@ -79,12 +79,12 @@ class LanguagePreference extends ZLStringListPreference {
|
|||
|
||||
public void accept() {
|
||||
final String value = getValue();
|
||||
myDescription.setLanguage((value.length() != 0) ? value : null);
|
||||
myBook.setLanguage((value.length() != 0) ? value : null);
|
||||
}
|
||||
}
|
||||
|
||||
public class BookInfoActivity extends ZLPreferenceActivity {
|
||||
private BookDescription myDescription;
|
||||
private Book myBook;
|
||||
|
||||
public BookInfoActivity() {
|
||||
super("BookInfo");
|
||||
|
@ -93,17 +93,17 @@ public class BookInfoActivity extends ZLPreferenceActivity {
|
|||
@Override
|
||||
protected void init() {
|
||||
final Category commonCategory = new Category(null);
|
||||
myDescription = ((FBReader)FBReader.Instance()).Model.Description;
|
||||
commonCategory.addPreference(new BookTitlePreference(this, commonCategory.getResource(), "title", myDescription));
|
||||
commonCategory.addPreference(new LanguagePreference(this, commonCategory.getResource(), "language", myDescription));
|
||||
myBook = ((FBReader)FBReader.Instance()).Model.Book;
|
||||
commonCategory.addPreference(new BookTitlePreference(this, commonCategory.getResource(), "title", myBook));
|
||||
commonCategory.addPreference(new LanguagePreference(this, commonCategory.getResource(), "language", myBook));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
if (myDescription.save()) {
|
||||
if (myBook.save()) {
|
||||
((FBReader)FBReader.Instance()).clearTextCaches();
|
||||
ZLTextHyphenator.Instance().load(myDescription.getLanguage());
|
||||
ZLTextHyphenator.Instance().load(myBook.getLanguage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,40 +26,34 @@ import org.geometerplus.zlibrary.core.image.*;
|
|||
|
||||
import org.geometerplus.zlibrary.text.model.*;
|
||||
|
||||
import org.geometerplus.fbreader.collection.BookDescription;
|
||||
import org.geometerplus.fbreader.library.Book;
|
||||
import org.geometerplus.fbreader.formats.*;
|
||||
|
||||
public final class BookModel {
|
||||
public final BookDescription Description;
|
||||
public final Book Book;
|
||||
public final ZLTextPlainModel BookTextModel = new ZLTextPlainModel(65536, "/sdcard/Books/.FBReader", "cache");
|
||||
public final TOCTree TOCTree = new TOCTree();
|
||||
|
||||
private final HashMap<String,ZLTextPlainModel> myFootnotes = new HashMap<String,ZLTextPlainModel>();
|
||||
private final HashMap myInternalHyperlinks = new HashMap();
|
||||
private final ArrayList myBookTextModels;
|
||||
|
||||
private final ZLImageMap myImageMap = new ZLImageMap();
|
||||
|
||||
public class Label {
|
||||
public final int ParagraphIndex;
|
||||
public final ZLTextModel Model;
|
||||
|
||||
public final int ModelIndex;
|
||||
public final int ParagraphIndex;
|
||||
|
||||
Label(ZLTextModel model, int paragraphIndex) {
|
||||
ParagraphIndex = paragraphIndex;
|
||||
Model = model;
|
||||
ModelIndex = myBookTextModels.indexOf(model);
|
||||
ParagraphIndex = paragraphIndex;
|
||||
}
|
||||
}
|
||||
|
||||
public BookModel(final BookDescription description) {
|
||||
myBookTextModels = new ArrayList();
|
||||
myBookTextModels.add(BookTextModel);
|
||||
Description = description;
|
||||
FormatPlugin plugin = PluginCollection.instance().getPlugin(description.File);
|
||||
public BookModel(final Book book) {
|
||||
Book = book;
|
||||
FormatPlugin plugin = PluginCollection.instance().getPlugin(book.File);
|
||||
if (plugin != null) {
|
||||
plugin.readModel(description, this);
|
||||
plugin.readModel(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,14 +91,4 @@ public final class BookModel {
|
|||
void addImage(String id, ZLImage image) {
|
||||
myImageMap.put(id, image);
|
||||
}
|
||||
|
||||
public ZLTextPlainModel addBookTextModel() {
|
||||
ZLTextPlainModel bookTextModel = new ZLTextPlainModel(65536, "/sdcard/Books/.FBReader", "cache" + myBookTextModels.size());
|
||||
myBookTextModels.add(bookTextModel);
|
||||
return bookTextModel;
|
||||
}
|
||||
|
||||
public ArrayList getBookTextModels() {
|
||||
return myBookTextModels;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -326,13 +326,4 @@ public class BookReader {
|
|||
myCurrentTextModel.addFixedHSpace(length);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
public final void setNewTextModel() {
|
||||
myCurrentTextModel = Model.addBookTextModel();
|
||||
}
|
||||
|
||||
public final void addHyperlinkLabel(String label, int modelNumber, int paragraphNumber) {
|
||||
Model.addHyperlinkLabel(label, (ZLTextModel) Model.getBookTextModels().get(modelNumber), paragraphNumber);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ public interface ActionCode {
|
|||
String UNDO = "undo";
|
||||
String REDO = "redo";
|
||||
String SHOW_CONTENTS = "toc";
|
||||
String SHOW_BOOKMARKS = "bookmarks";
|
||||
String SEARCH = "search";
|
||||
String FIND_PREVIOUS = "findPrevious";
|
||||
String FIND_NEXT = "findNext";
|
||||
|
|
|
@ -45,7 +45,7 @@ public class BookTextView extends FBView {
|
|||
private ZLIntegerOption myWordIndexOption;
|
||||
private ZLIntegerOption myCharIndexOption;
|
||||
|
||||
private ArrayList myPositionStack = new ArrayList();
|
||||
private ArrayList<ZLTextPosition> myPositionStack = new ArrayList<ZLTextPosition>();
|
||||
private int myCurrentPointInStack;
|
||||
|
||||
private String myFileName;
|
||||
|
@ -54,7 +54,9 @@ public class BookTextView extends FBView {
|
|||
super(context);
|
||||
}
|
||||
|
||||
public void setModels(ArrayList<ZLTextModel> models, String fileName) {
|
||||
public void setModel(ZLTextModel model, String fileName) {
|
||||
super.setModel(model);
|
||||
|
||||
myFileName = fileName;
|
||||
|
||||
myPositionStack.clear();
|
||||
|
@ -62,91 +64,52 @@ public class BookTextView extends FBView {
|
|||
final int stackSize = new ZLIntegerRangeOption(fileName, BUFFER_SIZE, 0, MAX_UNDO_STACK_SIZE, 0).getValue();
|
||||
myCurrentPointInStack = new ZLIntegerRangeOption(fileName, POSITION_IN_BUFFER, 0, (stackSize == 0) ? 0 : (stackSize - 1), 0).getValue();
|
||||
|
||||
if (models != null) {
|
||||
if (model != null) {
|
||||
final ZLIntegerOption option = new ZLIntegerOption(fileName, "", 0);
|
||||
final int size = models.size();
|
||||
for (int i = 0; i < stackSize; ++i) {
|
||||
// option.changeName(MODEL_PREFIX + i);
|
||||
// final int modelIndex = option.getValue();
|
||||
option.changeName(PARAGRAPH_PREFIX + i);
|
||||
int paragraphIndex = option.getValue();
|
||||
int modelIndex = -1;
|
||||
int paragraphsNumber = 0;
|
||||
while (paragraphIndex >= 0 && paragraphsNumber != 1) {
|
||||
modelIndex++;
|
||||
paragraphsNumber = modelIndex >= 0 && modelIndex < size ?
|
||||
((ZLTextModel)models.get(modelIndex)).getParagraphsNumber() + 1 : 1;
|
||||
paragraphIndex -= paragraphsNumber;
|
||||
}
|
||||
paragraphIndex += paragraphsNumber;
|
||||
option.changeName(WORD_PREFIX + i);
|
||||
final int wordIndex = option.getValue();
|
||||
option.changeName(CHAR_PREFIX + i);
|
||||
final int charIndex = option.getValue();
|
||||
myPositionStack.add(new Position(modelIndex, paragraphIndex, wordIndex, charIndex));
|
||||
}
|
||||
myPositionStack.add(new ZLTextPosition(paragraphIndex, wordIndex, charIndex));
|
||||
}
|
||||
if (!myPositionStack.isEmpty()) {
|
||||
super.setModels(models, ((Position)myPositionStack.get(myCurrentPointInStack)).ModelIndex);
|
||||
} else {
|
||||
super.setModels(models, 0);
|
||||
gotoPosition(myPositionStack.get(myCurrentPointInStack));
|
||||
}
|
||||
if ((getModel() != null) && (!myPositionStack.isEmpty())) {
|
||||
gotoPosition((Position)myPositionStack.get(myCurrentPointInStack));
|
||||
}
|
||||
}
|
||||
|
||||
protected void onPaintInfoPrepared() {
|
||||
if (myPositionStack.isEmpty()) {
|
||||
myPositionStack.add(new Position(myCurrentModelIndex, getStartCursor()));
|
||||
myPositionStack.add(new ZLTextPosition(getStartCursor()));
|
||||
} else {
|
||||
((Position)myPositionStack.get(myCurrentPointInStack)).set(getStartCursor());
|
||||
((Position)myPositionStack.get(myCurrentPointInStack)).ModelIndex = myCurrentModelIndex;
|
||||
myPositionStack.get(myCurrentPointInStack).set(getStartCursor());
|
||||
}
|
||||
}
|
||||
|
||||
void scrollToHome() {
|
||||
final ZLTextWordCursor cursor = getStartCursor();
|
||||
if (!cursor.isNull() && cursor.isStartOfParagraph() && cursor.getParagraphCursor().Index == 0
|
||||
&& myCurrentModelIndex == 0) {
|
||||
if (!cursor.isNull() && cursor.isStartOfParagraph() && cursor.getParagraphCursor().Index == 0) {
|
||||
return;
|
||||
}
|
||||
final int modelIndexToCheck = myCurrentModelIndex;
|
||||
setModelIndex(0);
|
||||
final Position position = new Position(modelIndexToCheck, cursor);
|
||||
final ZLTextPosition position = new ZLTextPosition(cursor);
|
||||
gotoParagraph(0, false);
|
||||
gotoPosition(0, 0, 0);
|
||||
preparePaintInfo();
|
||||
savePosition(position, 0, getStartCursor());
|
||||
savePosition(position, getStartCursor());
|
||||
ZLApplication.Instance().repaintView();
|
||||
}
|
||||
|
||||
//TODO: remove
|
||||
void gotoParagraphSafe(int paragraphIndex) {
|
||||
// gotoParagraphSafe(paragraphIndex, myCurrentModelIndex);
|
||||
public void gotoParagraphSafe(int paragraphIndex) {
|
||||
preparePaintInfo();
|
||||
final ZLTextWordCursor cursor = getStartCursor();
|
||||
if (!cursor.isNull()) {
|
||||
final Position position = new Position(myCurrentModelIndex, cursor);
|
||||
final ZLTextPosition position = new ZLTextPosition(cursor);
|
||||
gotoParagraph(paragraphIndex, false);
|
||||
preparePaintInfo();
|
||||
savePosition(position, myCurrentModelIndex, getStartCursor());
|
||||
}
|
||||
}
|
||||
|
||||
public void gotoParagraphSafe(ZLTextModel model, int paragraphIndex) {
|
||||
gotoParagraphSafe(getModelList().indexOf(model), paragraphIndex);
|
||||
}
|
||||
|
||||
void gotoParagraphSafe(int modelIndex, int paragraphIndex) {
|
||||
preparePaintInfo();
|
||||
final ZLTextWordCursor cursor = getStartCursor();
|
||||
if (!cursor.isNull()) {
|
||||
final Position position = new Position(myCurrentModelIndex, cursor);
|
||||
setModelIndex(modelIndex);
|
||||
gotoParagraph(paragraphIndex, false);
|
||||
preparePaintInfo();
|
||||
savePosition(position, modelIndex, getStartCursor());
|
||||
savePosition(position, getStartCursor());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,12 +163,11 @@ public class BookTextView extends FBView {
|
|||
return this.myFileName;
|
||||
}
|
||||
|
||||
protected void savePosition(Position position) {
|
||||
protected void savePosition(ZLTextPosition position) {
|
||||
if (myPositionStack.isEmpty()) {
|
||||
preparePaintInfo();
|
||||
}
|
||||
Position currentPosition =
|
||||
(Position)myPositionStack.get(myCurrentPointInStack);
|
||||
final ZLTextPosition currentPosition = myPositionStack.get(myCurrentPointInStack);
|
||||
while (myPositionStack.size() > myCurrentPointInStack) {
|
||||
myPositionStack.remove(myPositionStack.size() - 1);
|
||||
}
|
||||
|
@ -215,14 +177,6 @@ public class BookTextView extends FBView {
|
|||
myPositionStack.remove(0);
|
||||
}
|
||||
myCurrentPointInStack = myPositionStack.size() - 1;
|
||||
|
||||
/*
|
||||
for (Object p : myPositionStack) {
|
||||
System.out.print(((Position) p).ModelIndex + ","
|
||||
+ ((Position) p).ParagraphIndex + "; ");
|
||||
}
|
||||
System.out.println("current position " + myCurrentPointInStack);
|
||||
*/
|
||||
}
|
||||
|
||||
void saveState() {
|
||||
|
@ -249,24 +203,13 @@ public class BookTextView extends FBView {
|
|||
|
||||
final ZLIntegerOption option = new ZLIntegerOption(group, "", 0);
|
||||
for (int i = 0; i < myPositionStack.size(); ++i) {
|
||||
Position position = (Position)myPositionStack.get(i);
|
||||
final ZLTextPosition position = myPositionStack.get(i);
|
||||
option.changeName(PARAGRAPH_PREFIX + i);
|
||||
int paragraphIndex = position.ParagraphIndex + position.ModelIndex;
|
||||
final ArrayList models = getModelList();
|
||||
for (int j = 0; j < position.ModelIndex; j++) {
|
||||
paragraphIndex += ((ZLTextModel)models.get(j)).getParagraphsNumber();
|
||||
}
|
||||
|
||||
option.setValue(paragraphIndex);
|
||||
|
||||
option.setValue(position.ParagraphIndex);
|
||||
option.changeName(CHAR_PREFIX + i);
|
||||
option.setValue(position.CharIndex);
|
||||
|
||||
option.changeName(WORD_PREFIX + i);
|
||||
option.setValue(position.WordIndex);
|
||||
|
||||
// option.changeName(MODEL_PREFIX + i);
|
||||
// option.setValue(position.ModelIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -275,15 +218,8 @@ public class BookTextView extends FBView {
|
|||
}
|
||||
|
||||
void undoPageMove() {
|
||||
gotoPosition((Position)myPositionStack.get(--myCurrentPointInStack));
|
||||
gotoPosition(myPositionStack.get(--myCurrentPointInStack));
|
||||
ZLApplication.Instance().repaintView();
|
||||
/*
|
||||
for (Object p : myPositionStack) {
|
||||
System.out.print(((Position) p).ModelIndex + ","
|
||||
+ ((Position) p).ParagraphIndex + "; ");
|
||||
}
|
||||
System.out.println("current position " + myCurrentPointInStack);
|
||||
*/
|
||||
}
|
||||
|
||||
boolean canRedoPageMove() {
|
||||
|
@ -291,14 +227,7 @@ public class BookTextView extends FBView {
|
|||
}
|
||||
|
||||
void redoPageMove() {
|
||||
gotoPosition((Position)myPositionStack.get(++myCurrentPointInStack));
|
||||
gotoPosition(myPositionStack.get(++myCurrentPointInStack));
|
||||
ZLApplication.Instance().repaintView();
|
||||
|
||||
for (Object p : myPositionStack) {
|
||||
System.out.print(((Position) p).ModelIndex + ","
|
||||
+ ((Position) p).ParagraphIndex + "; ");
|
||||
}
|
||||
System.out.println("current position " + myCurrentPointInStack);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,8 +36,8 @@ import org.geometerplus.zlibrary.text.view.ZLTextView;
|
|||
import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator;
|
||||
|
||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||
import org.geometerplus.fbreader.collection.BookCollection;
|
||||
import org.geometerplus.fbreader.collection.BookDescription;
|
||||
import org.geometerplus.fbreader.library.Library;
|
||||
import org.geometerplus.fbreader.library.Book;
|
||||
|
||||
public final class FBReader extends ZLApplication {
|
||||
static interface ViewMode {
|
||||
|
@ -88,6 +88,7 @@ public final class FBReader extends ZLApplication {
|
|||
addAction(ActionCode.SHOW_PREFERENCES, new PreferencesAction(this));
|
||||
addAction(ActionCode.SHOW_BOOK_INFO, new BookInfoAction(this));
|
||||
addAction(ActionCode.SHOW_CONTENTS, new ShowTOCAction(this));
|
||||
addAction(ActionCode.SHOW_BOOKMARKS, new ShowBookmarksAction(this));
|
||||
|
||||
addAction(ActionCode.SEARCH, new SearchAction(this));
|
||||
addAction(ActionCode.FIND_NEXT, new FindNextAction(this));
|
||||
|
@ -120,14 +121,14 @@ public final class FBReader extends ZLApplication {
|
|||
openFiles(
|
||||
ZLFile.createFileByPath(myArg0),
|
||||
ZLFile.createFileByPath(myBookNameOption.getValue()),
|
||||
BookCollection.Instance().getHelpFile()
|
||||
Library.Instance().getHelpFile()
|
||||
);
|
||||
}
|
||||
|
||||
public void openBook(final BookDescription bookDescription) {
|
||||
public void openBook(final Book book) {
|
||||
ZLDialogManager.Instance().wait("loadingBook", new Runnable() {
|
||||
public void run() {
|
||||
openBookInternal(bookDescription);
|
||||
openBookInternal(book);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -188,9 +189,8 @@ public final class FBReader extends ZLApplication {
|
|||
if (Model != null) {
|
||||
BookModel.Label label = Model.getLabel(id);
|
||||
if ((label != null) && (label.Model != null)) {
|
||||
// if (label.Model == Model.BookTextModel) {
|
||||
if (label.ModelIndex != -1) {
|
||||
BookTextView.gotoParagraphSafe(label.ModelIndex, label.ParagraphIndex);
|
||||
if (label.Model == Model.BookTextModel) {
|
||||
BookTextView.gotoParagraphSafe(label.ParagraphIndex);
|
||||
} else {
|
||||
FootnoteView.setModel(label.Model);
|
||||
setMode(ViewMode.FOOTNOTE);
|
||||
|
@ -206,25 +206,25 @@ public final class FBReader extends ZLApplication {
|
|||
FootnoteView.clearCaches();
|
||||
}
|
||||
|
||||
void openBookInternal(BookDescription description) {
|
||||
void openBookInternal(Book book) {
|
||||
clearTextCaches();
|
||||
|
||||
if (description != null) {
|
||||
if (book != null) {
|
||||
onViewChanged();
|
||||
|
||||
BookTextView.saveState();
|
||||
BookTextView.setModels(null, "");
|
||||
BookTextView.setModel(null, "");
|
||||
|
||||
Model = null;
|
||||
Model = new BookModel(description);
|
||||
final String fileName = description.File.getPath();
|
||||
Model = new BookModel(book);
|
||||
final String fileName = book.File.getPath();
|
||||
myBookNameOption.setValue(fileName);
|
||||
ZLTextHyphenator.Instance().load(description.getLanguage());
|
||||
BookTextView.setModels(Model.getBookTextModels(), fileName);
|
||||
BookTextView.setCaption(description.getTitle());
|
||||
ZLTextHyphenator.Instance().load(book.getLanguage());
|
||||
BookTextView.setModel(Model.BookTextModel, fileName);
|
||||
BookTextView.setCaption(book.getTitle());
|
||||
FootnoteView.setModel(null);
|
||||
FootnoteView.setCaption(description.getTitle());
|
||||
BookCollection.Instance().addBookToRecentList(description);
|
||||
FootnoteView.setCaption(book.getTitle());
|
||||
Library.Instance().addBookToRecentList(book);
|
||||
}
|
||||
repaintView();
|
||||
}
|
||||
|
@ -237,27 +237,27 @@ public final class FBReader extends ZLApplication {
|
|||
public void openFiles(final ZLFile ... files) {
|
||||
ZLDialogManager.Instance().wait("loadingBook", new Runnable() {
|
||||
public void run() {
|
||||
BookDescription description = null;
|
||||
Book book = null;
|
||||
main:
|
||||
for (ZLFile f : files) {
|
||||
if (f == null) {
|
||||
continue;
|
||||
}
|
||||
description = BookDescription.getDescription(f);
|
||||
if (description != null) {
|
||||
book = Book.getBook(f);
|
||||
if (book != null) {
|
||||
break;
|
||||
}
|
||||
if (f.isArchive()) {
|
||||
for (ZLFile child : f.children()) {
|
||||
description = BookDescription.getDescription(child);
|
||||
if (description != null) {
|
||||
book = Book.getBook(child);
|
||||
if (book != null) {
|
||||
break main;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (description != null) {
|
||||
openBookInternal(description);
|
||||
if (book != null) {
|
||||
openBookInternal(book);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
36
src/org/geometerplus/fbreader/fbreader/ShowBookmarks.java
Normal file
36
src/org/geometerplus/fbreader/fbreader/ShowBookmarks.java
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2009 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.fbreader.fbreader;
|
||||
|
||||
import org.geometerplus.android.fbreader.BookmarksActivity;
|
||||
|
||||
import org.geometerplus.zlibrary.ui.android.dialogs.ZLAndroidDialogManager;
|
||||
|
||||
class ShowBookmarksAction extends FBAction {
|
||||
ShowBookmarksAction(FBReader fbreader) {
|
||||
super(fbreader);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
final ZLAndroidDialogManager dialogManager =
|
||||
(ZLAndroidDialogManager)ZLAndroidDialogManager.Instance();
|
||||
dialogManager.runActivity(BookmarksActivity.class);
|
||||
}
|
||||
}
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
package org.geometerplus.fbreader.fbreader;
|
||||
|
||||
import org.geometerplus.fbreader.collection.BookCollection;
|
||||
import org.geometerplus.fbreader.library.Library;
|
||||
|
||||
import org.geometerplus.android.fbreader.LibraryTabActivity;
|
||||
|
||||
|
@ -35,9 +35,9 @@ class ShowLibraryAction extends FBAction {
|
|||
(ZLAndroidDialogManager)ZLAndroidDialogManager.Instance();
|
||||
Runnable action = new Runnable() {
|
||||
public void run() {
|
||||
BookCollection collection = BookCollection.Instance();
|
||||
collection.clear();
|
||||
collection.synchronize();
|
||||
Library library = Library.Instance();
|
||||
library.clear();
|
||||
library.synchronize();
|
||||
// TODO: select current book (author?)
|
||||
/*
|
||||
if (myBookModel != null) {
|
||||
|
|
|
@ -23,20 +23,20 @@ import java.io.*;
|
|||
import java.util.*;
|
||||
|
||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||
import org.geometerplus.fbreader.collection.BookDescription;
|
||||
import org.geometerplus.fbreader.library.Book;
|
||||
import org.geometerplus.zlibrary.core.dialogs.ZLOptionsDialog;
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.language.ZLLanguageDetector;
|
||||
|
||||
public abstract class FormatPlugin {
|
||||
public abstract boolean acceptsFile(ZLFile file);
|
||||
public abstract boolean readDescription(ZLFile file, BookDescription description);
|
||||
public abstract boolean readModel(BookDescription description, BookModel model);
|
||||
public abstract boolean readMetaInfo(Book book);
|
||||
public abstract boolean readModel(BookModel model);
|
||||
|
||||
/*
|
||||
public static void detectEncodingAndLanguage(BookDescription description, InputStream stream) throws IOException {
|
||||
String language = description.getLanguage();
|
||||
String encoding = description.getEncoding();
|
||||
public static void detectEncodingAndLanguage(Book book, InputStream stream) throws IOException {
|
||||
String language = book.getLanguage();
|
||||
String encoding = book.getEncoding();
|
||||
if (encoding.length() == 0 || language.length() == 0) {
|
||||
PluginCollection collection = PluginCollection.instance();
|
||||
if (language.length() == 0) {
|
||||
|
@ -61,36 +61,36 @@ public abstract class FormatPlugin {
|
|||
}
|
||||
}
|
||||
}
|
||||
description.setEncoding(encoding);
|
||||
description.setLanguage(language);
|
||||
book.setEncoding(encoding);
|
||||
book.setLanguage(language);
|
||||
}
|
||||
}
|
||||
//Last working version
|
||||
public static void detectEncodingAndLanguage(BookDescription description, InputStream stream) {
|
||||
String encoding = description.getEncoding();
|
||||
public static void detectEncodingAndLanguage(Book book, InputStream stream) {
|
||||
String encoding = book.getEncoding();
|
||||
if (encoding.length() == 0) {
|
||||
encoding = EncodingDetector.detect(stream, PluginCollection.instance().DefaultLanguageOption.getValue());
|
||||
if (encoding == "unknown") {
|
||||
encoding = "windows-1252";
|
||||
}
|
||||
description.setEncoding(encoding);
|
||||
book.setEncoding(encoding);
|
||||
}
|
||||
|
||||
if (description.getLanguage() == "") {
|
||||
if (book.getLanguage() == "") {
|
||||
if ((encoding.equals("US-ASCII")) ||
|
||||
(encoding.equals("ISO-8859-1"))) {
|
||||
description.setLanguage("en");
|
||||
} else if ((description.getEncoding().equals("KOI8-R")) ||
|
||||
book.setLanguage("en");
|
||||
} else if ((book.getEncoding().equals("KOI8-R")) ||
|
||||
(encoding.equals("windows-1251")) ||
|
||||
(encoding.equals("ISO-8859-5")) ||
|
||||
(encoding.equals("IBM866"))) {
|
||||
description.setLanguage("ru");
|
||||
book.setLanguage("ru");
|
||||
} /*else if (
|
||||
(PluginCollection.instance().DefaultLanguageOption.getValue() == EncodingDetector.Language.CZECH) &&
|
||||
((encoding == "windows-1250") ||
|
||||
(encoding == "ISO-8859-2") ||
|
||||
(encoding == "IBM852"))) {
|
||||
description.setLanguage("cs");
|
||||
book.setLanguage("cs");
|
||||
}*/
|
||||
/*}
|
||||
|
||||
|
|
|
@ -24,10 +24,10 @@ import java.util.*;
|
|||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.xml.*;
|
||||
|
||||
import org.geometerplus.fbreader.collection.BookDescription;
|
||||
import org.geometerplus.fbreader.collection.Tag;
|
||||
import org.geometerplus.fbreader.library.Book;
|
||||
import org.geometerplus.fbreader.library.Tag;
|
||||
|
||||
public class FB2DescriptionReader extends ZLXMLReaderAdapter {
|
||||
public class FB2MetaInfoReader extends ZLXMLReaderAdapter {
|
||||
private final static int READ_NOTHING = 0;
|
||||
private final static int READ_SOMETHING = 1;
|
||||
private final static int READ_TITLE = 2;
|
||||
|
@ -38,29 +38,29 @@ public class FB2DescriptionReader extends ZLXMLReaderAdapter {
|
|||
private final static int READ_LANGUAGE = 7;
|
||||
private final static int READ_GENRE = 8;
|
||||
|
||||
private final BookDescription myDescription;
|
||||
private final Book myBook;
|
||||
private int myReadState = READ_NOTHING;
|
||||
|
||||
private final String[] myAuthorNames = new String[3];
|
||||
private final StringBuilder myBuffer = new StringBuilder();
|
||||
|
||||
public FB2DescriptionReader(BookDescription description) {
|
||||
myDescription = description;
|
||||
myDescription.setTitle(null);
|
||||
myDescription.setLanguage(null);
|
||||
public FB2MetaInfoReader(Book book) {
|
||||
myBook = book;
|
||||
myBook.setTitle(null);
|
||||
myBook.setLanguage(null);
|
||||
}
|
||||
|
||||
public boolean dontCacheAttributeValues() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean readDescription(ZLFile file) {
|
||||
public boolean readMetaInfo() {
|
||||
myReadState = READ_NOTHING;
|
||||
myAuthorNames[0] = "";
|
||||
myAuthorNames[1] = "";
|
||||
myAuthorNames[2] = "";
|
||||
myBuffer.delete(0, myBuffer.length());
|
||||
return readDocument(file);
|
||||
return readDocument(myBook.File);
|
||||
}
|
||||
|
||||
public boolean startElementHandler(String tagName, ZLStringMap attributes) {
|
||||
|
@ -112,7 +112,7 @@ public class FB2DescriptionReader extends ZLXMLReaderAdapter {
|
|||
name.trim();
|
||||
if (name.length() != 0) {
|
||||
String index = attributes.getValue("number");
|
||||
myDescription.setSeriesInfo(name, (index != null) ? Integer.parseInt(index) : 0);
|
||||
myBook.setSeriesInfo(name, (index != null) ? Integer.parseInt(index) : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ public class FB2DescriptionReader extends ZLXMLReaderAdapter {
|
|||
break;
|
||||
case FB2Tag.BOOK_TITLE:
|
||||
if (myReadState == READ_TITLE) {
|
||||
myDescription.setTitle(myBuffer.toString().trim());
|
||||
myBook.setTitle(myBuffer.toString().trim());
|
||||
myReadState = READ_SOMETHING;
|
||||
}
|
||||
break;
|
||||
|
@ -139,10 +139,10 @@ public class FB2DescriptionReader extends ZLXMLReaderAdapter {
|
|||
final ArrayList<Tag> tags = FB2TagManager.humanReadableTags(genre);
|
||||
if (tags != null) {
|
||||
for (Tag t : tags) {
|
||||
myDescription.addTag(t);
|
||||
myBook.addTag(t);
|
||||
}
|
||||
} else {
|
||||
myDescription.addTag(genre);
|
||||
myBook.addTag(genre);
|
||||
}
|
||||
}
|
||||
myReadState = READ_SOMETHING;
|
||||
|
@ -162,7 +162,7 @@ public class FB2DescriptionReader extends ZLXMLReaderAdapter {
|
|||
fullName += ' ';
|
||||
}
|
||||
fullName += myAuthorNames[2];
|
||||
myDescription.addAuthor(fullName, myAuthorNames[2]);
|
||||
myBook.addAuthor(fullName, myAuthorNames[2]);
|
||||
myAuthorNames[0] = "";
|
||||
myAuthorNames[1] = "";
|
||||
myAuthorNames[2] = "";
|
||||
|
@ -171,7 +171,7 @@ public class FB2DescriptionReader extends ZLXMLReaderAdapter {
|
|||
break;
|
||||
case FB2Tag.LANG:
|
||||
if (myReadState == READ_LANGUAGE) {
|
||||
myDescription.setLanguage(myBuffer.toString().trim());
|
||||
myBook.setLanguage(myBuffer.toString().trim());
|
||||
myReadState = READ_SOMETHING;
|
||||
}
|
||||
break;
|
|
@ -20,20 +20,23 @@
|
|||
package org.geometerplus.fbreader.formats.fb2;
|
||||
|
||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||
import org.geometerplus.fbreader.collection.BookDescription;
|
||||
import org.geometerplus.fbreader.library.Book;
|
||||
import org.geometerplus.fbreader.formats.FormatPlugin;
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
|
||||
public class FB2Plugin extends FormatPlugin {
|
||||
@Override
|
||||
public boolean acceptsFile(ZLFile file) {
|
||||
return "fb2".equals(file.getExtension());
|
||||
}
|
||||
|
||||
public boolean readDescription(ZLFile file, BookDescription description) {
|
||||
return new FB2DescriptionReader(description).readDescription(file);
|
||||
@Override
|
||||
public boolean readMetaInfo(Book book) {
|
||||
return new FB2MetaInfoReader(book).readMetaInfo();
|
||||
}
|
||||
|
||||
public boolean readModel(BookDescription description, BookModel model) {
|
||||
return new FB2Reader(model).readBook(description.File);
|
||||
@Override
|
||||
public boolean readModel(BookModel model) {
|
||||
return new FB2Reader(model).readBook();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,10 +53,10 @@ public final class FB2Reader extends BookReader implements ZLXMLReader {
|
|||
super(model);
|
||||
}
|
||||
|
||||
boolean readBook(ZLFile file) {
|
||||
boolean readBook() {
|
||||
Base64EncodedImage.resetCounter();
|
||||
final ZLXMLProcessor processor = ZLXMLProcessorFactory.Instance().createXMLProcessor();
|
||||
return processor.read(this, file);
|
||||
return processor.read(this, Model.Book.File);
|
||||
}
|
||||
|
||||
public void startDocumentHandler() {
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.geometerplus.zlibrary.core.library.ZLibrary;
|
|||
import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile;
|
||||
import org.geometerplus.zlibrary.core.xml.*;
|
||||
|
||||
import org.geometerplus.fbreader.collection.Tag;
|
||||
import org.geometerplus.fbreader.library.Tag;
|
||||
|
||||
abstract class FB2TagManager {
|
||||
private static final HashMap<String,ArrayList<Tag>> ourMap = new HashMap<String,ArrayList<Tag>>();
|
||||
|
|
|
@ -22,25 +22,25 @@ package org.geometerplus.fbreader.formats.html;
|
|||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.xml.*;
|
||||
|
||||
import org.geometerplus.fbreader.collection.BookDescription;
|
||||
import org.geometerplus.fbreader.library.Book;
|
||||
|
||||
public class HtmlDescriptionReader extends ZLXMLReaderAdapter {
|
||||
private final BookDescription myDescription;
|
||||
public class HtmlMetaInfoReader extends ZLXMLReaderAdapter {
|
||||
private final Book myBook;
|
||||
|
||||
private boolean myReadTitle;
|
||||
|
||||
public HtmlDescriptionReader(BookDescription description) {
|
||||
myDescription = description;
|
||||
myDescription.setTitle("");
|
||||
public HtmlMetaInfoReader(Book book) {
|
||||
myBook = book;
|
||||
myBook.setTitle("");
|
||||
}
|
||||
|
||||
public boolean dontCacheAttributeValues() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean readDescription(ZLFile file) {
|
||||
public boolean readMetaInfo() {
|
||||
myReadTitle = false;
|
||||
return readDocument(file);
|
||||
return readDocument(myBook.File);
|
||||
}
|
||||
|
||||
public boolean startElementHandler(String tagName, ZLStringMap attributes) {
|
||||
|
@ -69,7 +69,7 @@ public class HtmlDescriptionReader extends ZLXMLReaderAdapter {
|
|||
// TODO + length -- remove
|
||||
final String text = new String(ch).substring(start, start + length);
|
||||
if (myReadTitle) {
|
||||
myDescription.setTitle(myDescription.getTitle() + text);
|
||||
myBook.setTitle(myBook.getTitle() + text);
|
||||
}
|
||||
}
|
||||
|
|
@ -20,13 +20,10 @@
|
|||
package org.geometerplus.fbreader.formats.html;
|
||||
|
||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||
import org.geometerplus.fbreader.collection.BookDescription;
|
||||
import org.geometerplus.fbreader.library.Book;
|
||||
import org.geometerplus.fbreader.formats.FormatPlugin;
|
||||
import org.geometerplus.fbreader.formats.fb2.FB2DescriptionReader;
|
||||
import org.geometerplus.fbreader.formats.fb2.FB2Reader;
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
|
||||
|
||||
public class HtmlPlugin extends FormatPlugin {
|
||||
private final static String AUTO = "auto";
|
||||
|
||||
|
@ -37,16 +34,16 @@ public class HtmlPlugin extends FormatPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean readDescription(ZLFile file, BookDescription description) {
|
||||
return new HtmlDescriptionReader(description).readDescription(file);
|
||||
public boolean readMetaInfo(Book book) {
|
||||
return new HtmlMetaInfoReader(book).readMetaInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readModel(BookDescription description, BookModel model) {
|
||||
public boolean readModel(BookModel model) {
|
||||
// TODO Auto-generated method stub
|
||||
if (!description.getEncoding().equals(AUTO)) {
|
||||
//new BookDescription.BookInfo(description.FileName).EncodingOption.setValue(AUTO);
|
||||
if (!model.Book.getEncoding().equals(AUTO)) {
|
||||
//new Book.BookInfo(book.FileName).EncodingOption.setValue(AUTO);
|
||||
}
|
||||
return new HtmlReader(model).readBook(description.File);
|
||||
return new HtmlReader(model).readBook();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,17 +56,10 @@ public class HtmlReader extends BookReader implements ZLHtmlReader {
|
|||
super(model);
|
||||
}
|
||||
|
||||
public boolean read() {
|
||||
boolean readBook() {
|
||||
final ZLHtmlProcessor processor = ZLHtmlProcessorFactory.Instance()
|
||||
.createHtmlProcessor();
|
||||
return processor.read(this, Model.Description.File);
|
||||
}
|
||||
|
||||
boolean readBook(ZLFile file) {
|
||||
final ZLHtmlProcessor processor = ZLHtmlProcessorFactory.Instance()
|
||||
.createHtmlProcessor();
|
||||
return processor.read(this, file);
|
||||
// return readDocument(fileName);
|
||||
return processor.read(this, Model.Book.File);
|
||||
}
|
||||
|
||||
public void startDocumentHandler() {
|
||||
|
@ -328,7 +321,7 @@ public class HtmlReader extends BookReader implements ZLHtmlReader {
|
|||
addImageReference(ref, (short)0);
|
||||
String filePath = ref;
|
||||
if (!":\\".equals(ref.substring(1, 3))) {
|
||||
filePath = Model.Description.File.getPath();
|
||||
filePath = Model.Book.File.getPath();
|
||||
filePath = filePath.substring(0, filePath.lastIndexOf('\\') + 1) + ref;
|
||||
}
|
||||
addImage(ref, new ZLFileImage("image/auto", ZLFile.createFileByPath(filePath)));
|
||||
|
|
|
@ -24,11 +24,11 @@ import java.util.*;
|
|||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.xml.*;
|
||||
|
||||
import org.geometerplus.fbreader.collection.BookDescription;
|
||||
import org.geometerplus.fbreader.library.Book;
|
||||
import org.geometerplus.fbreader.constants.XMLNamespace;
|
||||
|
||||
class OEBDescriptionReader extends ZLXMLReaderAdapter implements XMLNamespace {
|
||||
private final BookDescription myDescription;
|
||||
class OEBMetaInfoReader extends ZLXMLReaderAdapter implements XMLNamespace {
|
||||
private final Book myBook;
|
||||
|
||||
private String myDCMetadataTag = "dc-metadata";
|
||||
private String myMetadataTag = "metadata";
|
||||
|
@ -41,13 +41,13 @@ class OEBDescriptionReader extends ZLXMLReaderAdapter implements XMLNamespace {
|
|||
private final ArrayList<String> myAuthorList = new ArrayList<String>();
|
||||
private final ArrayList<String> myAuthorList2 = new ArrayList<String>();
|
||||
|
||||
OEBDescriptionReader(BookDescription description) {
|
||||
myDescription = description;
|
||||
myDescription.setTitle(null);
|
||||
myDescription.setLanguage(null);
|
||||
OEBMetaInfoReader(Book book) {
|
||||
myBook = book;
|
||||
myBook.setTitle(null);
|
||||
myBook.setLanguage(null);
|
||||
}
|
||||
|
||||
boolean readDescription(ZLFile file) {
|
||||
boolean readMetaInfo(ZLFile file) {
|
||||
myReadMetaData = false;
|
||||
myReadState = READ_NONE;
|
||||
|
||||
|
@ -65,7 +65,7 @@ class OEBDescriptionReader extends ZLXMLReaderAdapter implements XMLNamespace {
|
|||
} else {
|
||||
a = a.trim();
|
||||
}
|
||||
myDescription.addAuthor(a);
|
||||
myBook.addAuthor(a);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -155,7 +155,7 @@ class OEBDescriptionReader extends ZLXMLReaderAdapter implements XMLNamespace {
|
|||
if (bufferContent.length() != 0) {
|
||||
switch (myReadState) {
|
||||
case READ_TITLE:
|
||||
myDescription.setTitle(bufferContent);
|
||||
myBook.setTitle(bufferContent);
|
||||
break;
|
||||
case READ_AUTHOR:
|
||||
myAuthorList.add(bufferContent);
|
||||
|
@ -164,7 +164,7 @@ class OEBDescriptionReader extends ZLXMLReaderAdapter implements XMLNamespace {
|
|||
myAuthorList2.add(bufferContent);
|
||||
break;
|
||||
case READ_SUBJECT:
|
||||
myDescription.addTag(bufferContent);
|
||||
myBook.addTag(bufferContent);
|
||||
break;
|
||||
case READ_LANGUAGE:
|
||||
{
|
||||
|
@ -176,7 +176,7 @@ class OEBDescriptionReader extends ZLXMLReaderAdapter implements XMLNamespace {
|
|||
if (index >= 0) {
|
||||
bufferContent = bufferContent.substring(0, index);
|
||||
}
|
||||
myDescription.setLanguage("cz".equals(bufferContent) ? "cs" : bufferContent);
|
||||
myBook.setLanguage("cz".equals(bufferContent) ? "cs" : bufferContent);
|
||||
}
|
||||
break;
|
||||
}
|
|
@ -22,7 +22,7 @@ package org.geometerplus.fbreader.formats.oeb;
|
|||
import java.util.ArrayList;
|
||||
|
||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||
import org.geometerplus.fbreader.collection.BookDescription;
|
||||
import org.geometerplus.fbreader.library.Book;
|
||||
import org.geometerplus.fbreader.formats.FormatPlugin;
|
||||
import org.geometerplus.zlibrary.core.filesystem.*;
|
||||
|
||||
|
@ -45,14 +45,14 @@ public class OEBPlugin extends FormatPlugin {
|
|||
return null;
|
||||
}
|
||||
|
||||
public boolean readDescription(ZLFile file, BookDescription description) {
|
||||
final ZLFile opfFile = getOpfFile(file);
|
||||
return (opfFile != null) ? new OEBDescriptionReader(description).readDescription(opfFile) : false;
|
||||
public boolean readMetaInfo(Book book) {
|
||||
final ZLFile opfFile = getOpfFile(book.File);
|
||||
return (opfFile != null) ? new OEBMetaInfoReader(book).readMetaInfo(opfFile) : false;
|
||||
}
|
||||
|
||||
public boolean readModel(BookDescription description, BookModel model) {
|
||||
description.File.setCached(true);
|
||||
final ZLFile opfFile = getOpfFile(description.File);
|
||||
public boolean readModel(BookModel model) {
|
||||
model.Book.File.setCached(true);
|
||||
final ZLFile opfFile = getOpfFile(model.Book.File);
|
||||
return (opfFile != null) ? new OEBBookReader(model).readBook(opfFile) : false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ public class PluckerBookReader extends BookReader {
|
|||
if (((Integer) ((Pair)list.get(k)).myFirst) != -1) {
|
||||
//addHyperlinkLabel(fromNumber(first) + '#' + fromNumber(second), (Integer)list.get(k));
|
||||
final Pair p = (Pair)list.get(k);
|
||||
addHyperlinkLabel(fromNumber(first) + '#' + fromNumber(second), (Integer) p.mySecond, (Integer) p.myFirst);
|
||||
//addHyperlinkLabel(fromNumber(first) + '#' + fromNumber(second), (Integer) p.mySecond, (Integer) p.myFirst);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ public class PluckerBookReader extends BookReader {
|
|||
processTextRecord(size, pars);
|
||||
if ((flags & 0x1) == 0) {
|
||||
// insertEndOfTextParagraph();
|
||||
setNewTextModel();
|
||||
//setNewTextModel();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -482,8 +482,8 @@ public class PluckerBookReader extends BookReader {
|
|||
myBufferIsEmpty = true;
|
||||
beginParagraph(ZLTextParagraph.Kind.TEXT_PARAGRAPH);
|
||||
if (!myParagraphStored) {
|
||||
final ArrayList models = Model.getBookTextModels();
|
||||
myParagraphVector.add(new Pair(((ZLTextPlainModel) models.get(models.size()-1)/*BookTextModel*/).getParagraphsNumber() - 1, models.size() - 1));
|
||||
//final ArrayList models = Model.getBookTextModels();
|
||||
//myParagraphVector.add(new Pair(((ZLTextPlainModel) models.get(models.size()-1)/*BookTextModel*/).getParagraphsNumber() - 1, models.size() - 1));
|
||||
myParagraphStored = true;
|
||||
}
|
||||
for (Iterator it = myDelayedControls.iterator(); it.hasNext(); ) {
|
||||
|
|
|
@ -22,36 +22,39 @@ package org.geometerplus.fbreader.formats.plucker;
|
|||
import java.io.IOException;
|
||||
|
||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||
import org.geometerplus.fbreader.collection.BookDescription;
|
||||
import org.geometerplus.fbreader.library.Book;
|
||||
import org.geometerplus.fbreader.formats.pdb.PdbPlugin;
|
||||
import org.geometerplus.fbreader.formats.pdb.PdbStream;
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
|
||||
public class PluckerPlugin extends PdbPlugin {
|
||||
@Override
|
||||
public boolean acceptsFile(ZLFile file) {
|
||||
return "DataPlkr".equals(fileType(file));
|
||||
}
|
||||
|
||||
public boolean readDescription(ZLFile file, BookDescription description) {
|
||||
@Override
|
||||
public boolean readMetaInfo(Book book) {
|
||||
try {
|
||||
PdbStream stream = new PluckerTextStream(file);
|
||||
PdbStream stream = new PluckerTextStream(book.File);
|
||||
if (stream.open()) {
|
||||
//detectEncodingAndLanguage(description, stream);
|
||||
//detectEncodingAndLanguage(book, stream);
|
||||
stream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
|
||||
if (description.getEncoding().length() == 0) {
|
||||
if (book.getEncoding().length() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean readModel(BookDescription description, BookModel model) {
|
||||
@Override
|
||||
public boolean readModel(BookModel model) {
|
||||
try {
|
||||
return new PluckerBookReader(description.File, model, description.getEncoding()).readDocument();
|
||||
return new PluckerBookReader(model.Book.File, model, model.Book.getEncoding()).readDocument();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.fbreader.collection;
|
||||
package org.geometerplus.fbreader.library;
|
||||
|
||||
import java.util.*;
|
||||
import org.geometerplus.zlibrary.core.util.*;
|
|
@ -17,14 +17,14 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.fbreader.collection;
|
||||
package org.geometerplus.fbreader.library;
|
||||
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
||||
public class AuthorTree extends CollectionTree {
|
||||
public class AuthorTree extends LibraryTree {
|
||||
private final Author myAuthor;
|
||||
|
||||
AuthorTree(CollectionTree parent, Author author) {
|
||||
AuthorTree(LibraryTree parent, Author author) {
|
||||
super(parent);
|
||||
myAuthor = author;
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.fbreader.collection;
|
||||
package org.geometerplus.fbreader.library;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
@ -26,8 +26,8 @@ import org.geometerplus.zlibrary.core.filesystem.*;
|
|||
|
||||
import org.geometerplus.fbreader.formats.*;
|
||||
|
||||
public class BookDescription {
|
||||
public static BookDescription getDescription(ZLFile bookFile) {
|
||||
public class Book {
|
||||
public static Book getBook(ZLFile bookFile) {
|
||||
if (bookFile == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -37,30 +37,30 @@ public class BookDescription {
|
|||
return null;
|
||||
}
|
||||
|
||||
final BookDescription description = new BookDescription(bookFile, true);
|
||||
final Book book = new Book(bookFile, true);
|
||||
|
||||
FileInfoSet fileInfos = new FileInfoSet();
|
||||
fileInfos.load(physicalFile);
|
||||
if (fileInfos.check(physicalFile) && description.myIsSaved) {
|
||||
return description;
|
||||
if (fileInfos.check(physicalFile) && book.myIsSaved) {
|
||||
return book;
|
||||
}
|
||||
fileInfos.save();
|
||||
|
||||
final FormatPlugin plugin = PluginCollection.instance().getPlugin(bookFile);
|
||||
if ((plugin == null) || !plugin.readDescription(bookFile, description)) {
|
||||
if ((plugin == null) || !plugin.readMetaInfo(book)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String title = description.getTitle();
|
||||
String title = book.getTitle();
|
||||
if ((title == null) || (title.length() == 0)) {
|
||||
description.setTitle(bookFile.getName(true));
|
||||
book.setTitle(bookFile.getName(true));
|
||||
}
|
||||
return description;
|
||||
return book;
|
||||
}
|
||||
|
||||
public final ZLFile File;
|
||||
|
||||
private long myBookId;
|
||||
private long myId;
|
||||
|
||||
private String myEncoding;
|
||||
private String myLanguage;
|
||||
|
@ -71,8 +71,8 @@ public class BookDescription {
|
|||
|
||||
private boolean myIsSaved;
|
||||
|
||||
BookDescription(long bookId, ZLFile file, String title, String encoding, String language) {
|
||||
myBookId = bookId;
|
||||
Book(long id, ZLFile file, String title, String encoding, String language) {
|
||||
myId = id;
|
||||
File = file;
|
||||
myTitle = title;
|
||||
myEncoding = encoding;
|
||||
|
@ -80,19 +80,19 @@ public class BookDescription {
|
|||
myIsSaved = true;
|
||||
}
|
||||
|
||||
BookDescription(ZLFile file, boolean createFromDatabase) {
|
||||
Book(ZLFile file, boolean createFromDatabase) {
|
||||
File = file;
|
||||
if (createFromDatabase) {
|
||||
final BooksDatabase database = BooksDatabase.Instance();
|
||||
myBookId = database.loadBook(this);
|
||||
if (myBookId >= 0) {
|
||||
myAuthors = database.loadAuthors(myBookId);
|
||||
myTags = database.loadTags(myBookId);
|
||||
mySeriesInfo = database.loadSeriesInfo(myBookId);
|
||||
myId = database.loadBook(this);
|
||||
if (myId >= 0) {
|
||||
myAuthors = database.loadAuthors(myId);
|
||||
myTags = database.loadTags(myId);
|
||||
mySeriesInfo = database.loadSeriesInfo(myId);
|
||||
myIsSaved = true;
|
||||
}
|
||||
} else {
|
||||
myBookId = -1;
|
||||
myId = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,8 +150,8 @@ public class BookDescription {
|
|||
addAuthor(new Author(strippedName, strippedKey));
|
||||
}
|
||||
|
||||
public long getBookId() {
|
||||
return myBookId;
|
||||
public long getId() {
|
||||
return myId;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
|
@ -273,22 +273,22 @@ public class BookDescription {
|
|||
final BooksDatabase database = BooksDatabase.Instance();
|
||||
database.executeAsATransaction(new Runnable() {
|
||||
public void run() {
|
||||
if (myBookId >= 0) {
|
||||
database.updateBookInfo(myBookId, myEncoding, myLanguage, myTitle);
|
||||
if (myId >= 0) {
|
||||
database.updateBookInfo(myId, myEncoding, myLanguage, myTitle);
|
||||
} else {
|
||||
myBookId = database.insertBookInfo(File.getPath(), myEncoding, myLanguage, myTitle);
|
||||
myId = database.insertBookInfo(File.getPath(), myEncoding, myLanguage, myTitle);
|
||||
}
|
||||
|
||||
long index = 0;
|
||||
database.deleteAllBookAuthors(myBookId);
|
||||
database.deleteAllBookAuthors(myId);
|
||||
for (Author author : authors()) {
|
||||
database.saveBookAuthorInfo(myBookId, index++, author);
|
||||
database.saveBookAuthorInfo(myId, index++, author);
|
||||
}
|
||||
database.deleteAllBookTags(myBookId);
|
||||
database.deleteAllBookTags(myId);
|
||||
for (Tag tag : tags()) {
|
||||
database.saveBookTagInfo(myBookId, tag);
|
||||
database.saveBookTagInfo(myId, tag);
|
||||
}
|
||||
database.saveBookSeriesInfo(myBookId, mySeriesInfo);
|
||||
database.saveBookSeriesInfo(myId, mySeriesInfo);
|
||||
}
|
||||
});
|
||||
|
|
@ -17,18 +17,18 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.fbreader.collection;
|
||||
package org.geometerplus.fbreader.library;
|
||||
|
||||
public final class BookInSeriesTree extends BookTree {
|
||||
BookInSeriesTree(CollectionTree parent, BookDescription description) {
|
||||
super(parent, description, false);
|
||||
BookInSeriesTree(LibraryTree parent, Book book) {
|
||||
super(parent, book, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(CollectionTree tree) {
|
||||
public int compareTo(LibraryTree tree) {
|
||||
if (tree instanceof BookInSeriesTree) {
|
||||
final long difference =
|
||||
Description.getSeriesInfo().Index - ((BookTree)tree).Description.getSeriesInfo().Index;
|
||||
Book.getSeriesInfo().Index - ((BookTree)tree).Book.getSeriesInfo().Index;
|
||||
if (difference != 0) {
|
||||
return (int)difference;
|
||||
}
|
|
@ -17,20 +17,20 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.fbreader.collection;
|
||||
package org.geometerplus.fbreader.library;
|
||||
|
||||
public class BookTree extends CollectionTree {
|
||||
public final BookDescription Description;
|
||||
public class BookTree extends LibraryTree {
|
||||
public final Book Book;
|
||||
private final boolean myShowAuthors;
|
||||
|
||||
BookTree(CollectionTree parent, BookDescription description, boolean showAuthors) {
|
||||
BookTree(LibraryTree parent, Book book, boolean showAuthors) {
|
||||
super(parent);
|
||||
Description = description;
|
||||
Book = book;
|
||||
myShowAuthors = showAuthors;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return Description.getTitle();
|
||||
return Book.getTitle();
|
||||
}
|
||||
|
||||
private String myAuthorsString;
|
||||
|
@ -41,7 +41,7 @@ public class BookTree extends CollectionTree {
|
|||
if (myAuthorsString == null) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int count = 0;
|
||||
for (Author author : Description.authors()) {
|
||||
for (Author author : Book.authors()) {
|
||||
if (count++ > 0) {
|
||||
builder.append(", ");
|
||||
}
|
90
src/org/geometerplus/fbreader/library/Bookmark.java
Normal file
90
src/org/geometerplus/fbreader/library/Bookmark.java
Normal file
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright (C) 2009 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.fbreader.library;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.geometerplus.zlibrary.text.view.impl.ZLTextPosition;
|
||||
|
||||
public class Bookmark {
|
||||
public final static int CREATION = 0;
|
||||
public final static int MODIFICATION = 1;
|
||||
public final static int ACCESS = 2;
|
||||
|
||||
private String myText;
|
||||
private final Date myCreationDate;
|
||||
private Date myModificationDate;
|
||||
private Date myAccessDate;
|
||||
private int myAccessCount;
|
||||
private final ZLTextPosition myPosition;
|
||||
|
||||
Bookmark(String text, Date creationDate, Date modificationDate, Date accessDate, int accessCount, int paragraphIndex, int wordIndex, int charIndex) {
|
||||
myText = text;
|
||||
myCreationDate = creationDate;
|
||||
myModificationDate = modificationDate;
|
||||
myAccessDate = accessDate;
|
||||
myAccessCount = accessCount;
|
||||
myPosition = new ZLTextPosition(paragraphIndex, wordIndex, charIndex);
|
||||
}
|
||||
|
||||
public Bookmark(String text, ZLTextPosition position) {
|
||||
myText = text;
|
||||
myCreationDate = new Date();
|
||||
myPosition = position;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return myText;
|
||||
}
|
||||
|
||||
public ZLTextPosition getPosition() {
|
||||
return myPosition;
|
||||
}
|
||||
|
||||
public Date getTime(int timeStamp) {
|
||||
switch (timeStamp) {
|
||||
default:
|
||||
case CREATION:
|
||||
return myCreationDate;
|
||||
case MODIFICATION:
|
||||
return myModificationDate;
|
||||
case ACCESS:
|
||||
return myAccessDate;
|
||||
}
|
||||
}
|
||||
|
||||
public int getAccessCount() {
|
||||
return myAccessCount;
|
||||
}
|
||||
|
||||
boolean setText(String text) {
|
||||
if (!text.equals(myText)) {
|
||||
myText = text;
|
||||
myModificationDate = new Date();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void onAccess() {
|
||||
myAccessDate = new Date();
|
||||
++myAccessCount;
|
||||
}
|
||||
}
|
66
src/org/geometerplus/fbreader/library/BookmarkList.java
Normal file
66
src/org/geometerplus/fbreader/library/BookmarkList.java
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (C) 2009 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.fbreader.library;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.geometerplus.zlibrary.text.view.impl.ZLTextPosition;
|
||||
import org.geometerplus.zlibrary.text.view.impl.ZLTextViewImpl;
|
||||
|
||||
public class BookmarkList extends LinkedList<Bookmark> {
|
||||
private final Book myBook;
|
||||
private boolean myIsChanged;
|
||||
|
||||
public BookmarkList(Book book) {
|
||||
myBook = book;
|
||||
BooksDatabase.Instance().listBookmarks(book.getId(), this);
|
||||
}
|
||||
|
||||
public void addNewBookmark(String text, ZLTextPosition position) {
|
||||
add(0, new Bookmark(text, position));
|
||||
myIsChanged = true;
|
||||
}
|
||||
|
||||
public void removeBookmark(int index) {
|
||||
remove(index);
|
||||
myIsChanged = true;
|
||||
}
|
||||
|
||||
public void setBookmarkText(int index, String text) {
|
||||
if (get(index).setText(text)) {
|
||||
myIsChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void gotoBookmark(int index, ZLTextViewImpl view) {
|
||||
myIsChanged = true;
|
||||
final Bookmark bookmark = get(index);
|
||||
bookmark.onAccess();
|
||||
view.gotoPosition(bookmark.getPosition());
|
||||
}
|
||||
|
||||
public void save() {
|
||||
if (!myIsChanged) {
|
||||
return;
|
||||
}
|
||||
BooksDatabase.Instance().saveBookmarks(myBook.getId(), this);
|
||||
myIsChanged = false;
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.fbreader.collection;
|
||||
package org.geometerplus.fbreader.library;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
@ -34,22 +34,22 @@ public abstract class BooksDatabase {
|
|||
ourInstance = this;
|
||||
}
|
||||
|
||||
protected BookDescription createDescription(long bookId, String filePath, String title, String encoding, String language) {
|
||||
return new BookDescription(bookId, ZLFile.createFileByPath(filePath), title, encoding, language);
|
||||
protected Book createBook(long id, String filePath, String title, String encoding, String language) {
|
||||
return new Book(id, ZLFile.createFileByPath(filePath), title, encoding, language);
|
||||
}
|
||||
protected void addAuthor(BookDescription description, Author author) {
|
||||
description.addAuthorWithNoCheck(author);
|
||||
protected void addAuthor(Book book, Author author) {
|
||||
book.addAuthorWithNoCheck(author);
|
||||
}
|
||||
protected void addTag(BookDescription description, Tag tag) {
|
||||
description.addTagWithNoCheck(tag);
|
||||
protected void addTag(Book book, Tag tag) {
|
||||
book.addTagWithNoCheck(tag);
|
||||
}
|
||||
protected void setSeriesInfo(BookDescription description, String series, long index) {
|
||||
description.setSeriesInfoWithNoCheck(series, index);
|
||||
protected void setSeriesInfo(Book book, String series, long index) {
|
||||
book.setSeriesInfoWithNoCheck(series, index);
|
||||
}
|
||||
|
||||
protected abstract Map<String,BookDescription> listBooks();
|
||||
protected abstract Map<String,Book> listBooks();
|
||||
protected abstract void executeAsATransaction(Runnable actions);
|
||||
protected abstract long loadBook(BookDescription description);
|
||||
protected abstract long loadBook(Book book);
|
||||
protected abstract List<Author> loadAuthors(long bookId);
|
||||
protected abstract List<Tag> loadTags(long bookId);
|
||||
protected abstract SeriesInfo loadSeriesInfo(long bookId);
|
||||
|
@ -73,4 +73,11 @@ public abstract class BooksDatabase {
|
|||
|
||||
protected abstract List<Long> listRecentBookIds();
|
||||
protected abstract void saveRecentBookIds(final List<Long> ids);
|
||||
|
||||
protected Bookmark createBookmark(String text, Date creationDate, Date modificationDate, Date accessDate, int accessCounter, int paragraphIndex, int wordIndex, int charIndex) {
|
||||
return new Bookmark(text, creationDate, modificationDate, accessDate, accessCounter, paragraphIndex, wordIndex, charIndex);
|
||||
}
|
||||
|
||||
protected abstract void listBookmarks(long bookId, List<Bookmark> list);
|
||||
protected abstract void saveBookmarks(long bookId, List<Bookmark> list);
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.fbreader.collection;
|
||||
package org.geometerplus.fbreader.library;
|
||||
|
||||
import org.geometerplus.zlibrary.core.tree.ZLTree;
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.fbreader.collection;
|
||||
package org.geometerplus.fbreader.library;
|
||||
|
||||
import java.util.*;
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.fbreader.collection;
|
||||
package org.geometerplus.fbreader.library;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
@ -27,12 +27,12 @@ import org.geometerplus.zlibrary.core.library.ZLibrary;
|
|||
|
||||
import org.geometerplus.fbreader.formats.*;
|
||||
|
||||
public final class BookCollection {
|
||||
private static BookCollection ourInstance;
|
||||
public final class Library {
|
||||
private static Library ourInstance;
|
||||
|
||||
public static BookCollection Instance() {
|
||||
public static Library Instance() {
|
||||
if (ourInstance == null) {
|
||||
ourInstance = new BookCollection();
|
||||
ourInstance = new Library();
|
||||
}
|
||||
return ourInstance;
|
||||
}
|
||||
|
@ -40,23 +40,23 @@ public final class BookCollection {
|
|||
// TODO: this option is platform-dependent
|
||||
private final ZLFile BookDirectory = new ZLPhysicalFile(new File("/sdcard/Books"));
|
||||
|
||||
private final LinkedList<BookDescription> myBookDescriptions = new LinkedList<BookDescription>();
|
||||
private final CollectionTree myCollectionByAuthor = new RootTree();
|
||||
private final CollectionTree myCollectionByTag = new RootTree();
|
||||
private final CollectionTree myRecentBooks = new RootTree();
|
||||
private final CollectionTree mySearchResult = new RootTree();
|
||||
private final LinkedList<Book> myBooks = new LinkedList<Book>();
|
||||
private final LibraryTree myLibraryByAuthor = new RootTree();
|
||||
private final LibraryTree myLibraryByTag = new RootTree();
|
||||
private final LibraryTree myRecentBooks = new RootTree();
|
||||
private final LibraryTree mySearchResult = new RootTree();
|
||||
|
||||
private boolean myDoRebuild = true;
|
||||
|
||||
private BookCollection() {
|
||||
private Library() {
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
myDoRebuild = true;
|
||||
|
||||
myBookDescriptions.clear();
|
||||
myCollectionByAuthor.clear();
|
||||
myCollectionByTag.clear();
|
||||
myBooks.clear();
|
||||
myLibraryByAuthor.clear();
|
||||
myLibraryByTag.clear();
|
||||
myRecentBooks.clear();
|
||||
mySearchResult.clear();
|
||||
}
|
||||
|
@ -72,38 +72,38 @@ public final class BookCollection {
|
|||
return ZLResourceFile.createResourceFile("data/help/MiniHelp.en.fb2");
|
||||
}
|
||||
|
||||
private static BookDescription getDescription(ZLFile bookFile, Map<String,BookDescription> saved, boolean doReadMetaInfo) {
|
||||
BookDescription description = saved.get(bookFile.getPath());
|
||||
if (description == null) {
|
||||
private static Book getBook(ZLFile bookFile, Map<String,Book> saved, boolean doReadMetaInfo) {
|
||||
Book book = saved.get(bookFile.getPath());
|
||||
if (book == null) {
|
||||
doReadMetaInfo = true;
|
||||
description = new BookDescription(bookFile, false);
|
||||
book = new Book(bookFile, false);
|
||||
}
|
||||
|
||||
if (doReadMetaInfo) {
|
||||
final FormatPlugin plugin = PluginCollection.instance().getPlugin(bookFile);
|
||||
if ((plugin == null) || !plugin.readDescription(bookFile, description)) {
|
||||
final FormatPlugin plugin = PluginCollection.instance().getPlugin(book.File);
|
||||
if ((plugin == null) || !plugin.readMetaInfo(book)) {
|
||||
return null;
|
||||
}
|
||||
String title = description.getTitle();
|
||||
String title = book.getTitle();
|
||||
if ((title == null) || (title.length() == 0)) {
|
||||
description.setTitle(bookFile.getName(true));
|
||||
book.setTitle(bookFile.getName(true));
|
||||
}
|
||||
}
|
||||
return description;
|
||||
return book;
|
||||
}
|
||||
|
||||
private void collectBookDescriptions(
|
||||
private void collectBooks(
|
||||
ZLFile file,
|
||||
FileInfoSet fileInfos,
|
||||
Map<String,BookDescription> savedDescriptions,
|
||||
Map<String,Book> savedBooks,
|
||||
boolean doReadMetaInfo
|
||||
) {
|
||||
BookDescription description = getDescription(file, savedDescriptions, doReadMetaInfo);
|
||||
if (description != null) {
|
||||
myBookDescriptions.add(description);
|
||||
Book book = getBook(file, savedBooks, doReadMetaInfo);
|
||||
if (book != null) {
|
||||
myBooks.add(book);
|
||||
} else if (file.isArchive()) {
|
||||
for (ZLFile entry : fileInfos.archiveEntries(file)) {
|
||||
collectBookDescriptions(entry, fileInfos, savedDescriptions, doReadMetaInfo);
|
||||
collectBooks(entry, fileInfos, savedBooks, doReadMetaInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -133,15 +133,15 @@ public final class BookCollection {
|
|||
return fileList;
|
||||
}
|
||||
|
||||
private void collectBookDescriptions() {
|
||||
private void collectBooks() {
|
||||
//android.os.Debug.startMethodTracing("/sdcard/ll0");
|
||||
final List<ZLPhysicalFile> physicalFilesList = collectPhysicalFiles();
|
||||
//android.os.Debug.stopMethodTracing();
|
||||
//System.err.println(physicalFilesList.size() + " files " + System.currentTimeMillis() % 20000);
|
||||
//android.os.Debug.startMethodTracing("/sdcard/ll1");
|
||||
final Map<String,BookDescription> savedDescriptions = BooksDatabase.Instance().listBooks();
|
||||
final Map<String,Book> savedBooks = BooksDatabase.Instance().listBooks();
|
||||
//android.os.Debug.stopMethodTracing();
|
||||
//System.err.println(savedDescriptions.size() + " saved books " + System.currentTimeMillis() % 20000);
|
||||
//System.err.println(savedBooks.size() + " saved books " + System.currentTimeMillis() % 20000);
|
||||
|
||||
//android.os.Debug.startMethodTracing("/sdcard/ll2");
|
||||
FileInfoSet fileInfos = new FileInfoSet();
|
||||
|
@ -151,12 +151,12 @@ public final class BookCollection {
|
|||
|
||||
//android.os.Debug.startMethodTracing("/sdcard/ll3");
|
||||
for (ZLPhysicalFile file : physicalFilesList) {
|
||||
collectBookDescriptions(file, fileInfos, savedDescriptions, !fileInfos.check(file));
|
||||
collectBooks(file, fileInfos, savedBooks, !fileInfos.check(file));
|
||||
file.setCached(false);
|
||||
}
|
||||
myBookDescriptions.add(getDescription(getHelpFile(), savedDescriptions, false));
|
||||
myBooks.add(getBook(getHelpFile(), savedBooks, false));
|
||||
//android.os.Debug.stopMethodTracing();
|
||||
//System.err.println("descriptions have been synchronized " + System.currentTimeMillis() % 20000);
|
||||
//System.err.println("books have been synchronized " + System.currentTimeMillis() % 20000);
|
||||
|
||||
//android.os.Debug.startMethodTracing("/sdcard/ll4");
|
||||
fileInfos.save();
|
||||
|
@ -193,9 +193,9 @@ public final class BookCollection {
|
|||
private TagTree getTagTree(Tag tag, HashMap<Tag,TagTree> tagTreeMap) {
|
||||
TagTree tagTree = tagTreeMap.get(tag);
|
||||
if (tagTree == null) {
|
||||
CollectionTree parent =
|
||||
LibraryTree parent =
|
||||
((tag != null) && (tag.Parent != null)) ?
|
||||
getTagTree(tag.Parent, tagTreeMap) : myCollectionByTag;
|
||||
getTagTree(tag.Parent, tagTreeMap) : myLibraryByTag;
|
||||
tagTree = parent.createTagSubTree(tag);
|
||||
tagTreeMap.put(tag, tagTree);
|
||||
}
|
||||
|
@ -207,25 +207,25 @@ public final class BookCollection {
|
|||
final HashMap<Tag,TagTree> tagTreeMap = new HashMap<Tag,TagTree>();
|
||||
final HashMap<Author,AuthorTree> authorTreeMap = new HashMap<Author,AuthorTree>();
|
||||
final HashMap<AuthorSeriesPair,SeriesTree> seriesTreeMap = new HashMap<AuthorSeriesPair,SeriesTree>();
|
||||
final HashMap<Long,BookDescription> bookById = new HashMap<Long,BookDescription>();
|
||||
final HashMap<Long,Book> bookById = new HashMap<Long,Book>();
|
||||
|
||||
collectBookDescriptions();
|
||||
//System.err.println(myBookDescriptions.size() + " books " + System.currentTimeMillis() % 20000);
|
||||
for (BookDescription description : myBookDescriptions) {
|
||||
bookById.put(description.getBookId(), description);
|
||||
List<Author> authors = description.authors();
|
||||
collectBooks();
|
||||
//System.err.println(myBooks.size() + " books " + System.currentTimeMillis() % 20000);
|
||||
for (Book book : myBooks) {
|
||||
bookById.put(book.getId(), book);
|
||||
List<Author> authors = book.authors();
|
||||
if (authors.isEmpty()) {
|
||||
authors = (List<Author>)ourNullList;
|
||||
}
|
||||
final SeriesInfo seriesInfo = description.getSeriesInfo();
|
||||
final SeriesInfo seriesInfo = book.getSeriesInfo();
|
||||
for (Author a : authors) {
|
||||
AuthorTree authorTree = authorTreeMap.get(a);
|
||||
if (authorTree == null) {
|
||||
authorTree = myCollectionByAuthor.createAuthorSubTree(a);
|
||||
authorTree = myLibraryByAuthor.createAuthorSubTree(a);
|
||||
authorTreeMap.put(a, authorTree);
|
||||
}
|
||||
if (seriesInfo == null) {
|
||||
authorTree.createBookSubTree(description, false);
|
||||
authorTree.createBookSubTree(book, false);
|
||||
} else {
|
||||
final String series = seriesInfo.Name;
|
||||
final AuthorSeriesPair pair = new AuthorSeriesPair(a, series);
|
||||
|
@ -234,31 +234,31 @@ public final class BookCollection {
|
|||
seriesTree = authorTree.createSeriesSubTree(series);
|
||||
seriesTreeMap.put(pair, seriesTree);
|
||||
}
|
||||
seriesTree.createBookInSeriesSubTree(description);
|
||||
seriesTree.createBookInSeriesSubTree(book);
|
||||
}
|
||||
}
|
||||
|
||||
List<Tag> tags = description.tags();
|
||||
List<Tag> tags = book.tags();
|
||||
if (tags.isEmpty()) {
|
||||
tags = (List<Tag>)ourNullList;
|
||||
}
|
||||
for (Tag t : tags) {
|
||||
getTagTree(t, tagTreeMap).createBookSubTree(description, true);
|
||||
getTagTree(t, tagTreeMap).createBookSubTree(book, true);
|
||||
}
|
||||
}
|
||||
|
||||
final BooksDatabase db = BooksDatabase.Instance();
|
||||
for (long id : db.listRecentBookIds()) {
|
||||
BookDescription description = bookById.get(id);
|
||||
if (description != null) {
|
||||
myRecentBooks.createBookSubTree(description, true);
|
||||
Book book = bookById.get(id);
|
||||
if (book != null) {
|
||||
myRecentBooks.createBookSubTree(book, true);
|
||||
}
|
||||
}
|
||||
|
||||
db.executeAsATransaction(new Runnable() {
|
||||
public void run() {
|
||||
for (BookDescription description : myBookDescriptions) {
|
||||
description.save();
|
||||
for (Book book : myBooks) {
|
||||
book.save();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -269,34 +269,34 @@ public final class BookCollection {
|
|||
if (myDoRebuild) {
|
||||
build();
|
||||
|
||||
myCollectionByAuthor.sortAllChildren();
|
||||
myCollectionByTag.sortAllChildren();
|
||||
myLibraryByAuthor.sortAllChildren();
|
||||
myLibraryByTag.sortAllChildren();
|
||||
|
||||
myDoRebuild = false;
|
||||
}
|
||||
}
|
||||
|
||||
public CollectionTree collectionByAuthor() {
|
||||
public LibraryTree byAuthor() {
|
||||
synchronize();
|
||||
return myCollectionByAuthor;
|
||||
return myLibraryByAuthor;
|
||||
}
|
||||
|
||||
public CollectionTree collectionByTag() {
|
||||
public LibraryTree byTag() {
|
||||
synchronize();
|
||||
return myCollectionByTag;
|
||||
return myLibraryByTag;
|
||||
}
|
||||
|
||||
public CollectionTree recentBooks() {
|
||||
public LibraryTree recentBooks() {
|
||||
synchronize();
|
||||
return myRecentBooks;
|
||||
}
|
||||
|
||||
public CollectionTree searchBooks(String pattern) {
|
||||
public LibraryTree searchBooks(String pattern) {
|
||||
synchronize();
|
||||
mySearchResult.clear();
|
||||
if (pattern != null) {
|
||||
pattern = pattern.toLowerCase();
|
||||
for (BookDescription book : myBookDescriptions) {
|
||||
for (Book book : myBooks) {
|
||||
if (book.matches(pattern)) {
|
||||
mySearchResult.createBookSubTree(book, true);
|
||||
}
|
||||
|
@ -306,10 +306,10 @@ public final class BookCollection {
|
|||
return mySearchResult;
|
||||
}
|
||||
|
||||
public void addBookToRecentList(BookDescription description) {
|
||||
public void addBookToRecentList(Book book) {
|
||||
final BooksDatabase db = BooksDatabase.Instance();
|
||||
final List<Long> ids = db.listRecentBookIds();
|
||||
final Long bookId = description.getBookId();
|
||||
final Long bookId = book.getId();
|
||||
ids.remove(bookId);
|
||||
ids.add(0, bookId);
|
||||
if (ids.size() > 12) {
|
|
@ -17,19 +17,19 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.fbreader.collection;
|
||||
package org.geometerplus.fbreader.library;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.geometerplus.zlibrary.core.tree.ZLTree;
|
||||
|
||||
public abstract class CollectionTree extends ZLTree<CollectionTree> implements Comparable<CollectionTree> {
|
||||
protected CollectionTree() {
|
||||
public abstract class LibraryTree extends ZLTree<LibraryTree> implements Comparable<LibraryTree> {
|
||||
protected LibraryTree() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected CollectionTree(CollectionTree parent) {
|
||||
protected LibraryTree(LibraryTree parent) {
|
||||
super(parent);
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ public abstract class CollectionTree extends ZLTree<CollectionTree> implements C
|
|||
return new AuthorTree(this, author);
|
||||
}
|
||||
|
||||
BookTree createBookSubTree(BookDescription book, boolean showAuthors) {
|
||||
BookTree createBookSubTree(Book book, boolean showAuthors) {
|
||||
return new BookTree(this, book, showAuthors);
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ public abstract class CollectionTree extends ZLTree<CollectionTree> implements C
|
|||
if (myChildrenString == null) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int count = 0;
|
||||
for (CollectionTree subtree : subTrees()) {
|
||||
for (LibraryTree subtree : subTrees()) {
|
||||
if (count++ > 0) {
|
||||
builder.append(", ");
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ public abstract class CollectionTree extends ZLTree<CollectionTree> implements C
|
|||
return myChildrenString;
|
||||
}
|
||||
|
||||
public int compareTo(CollectionTree ct) {
|
||||
public int compareTo(LibraryTree ct) {
|
||||
final String key0 = getSortKey();
|
||||
final String key1 = ct.getSortKey();
|
||||
if (key0 == null) {
|
||||
|
@ -83,10 +83,10 @@ public abstract class CollectionTree extends ZLTree<CollectionTree> implements C
|
|||
}
|
||||
|
||||
public final void sortAllChildren() {
|
||||
List<CollectionTree> children = subTrees();
|
||||
List<LibraryTree> children = subTrees();
|
||||
if (!children.isEmpty()) {
|
||||
Collections.sort(children);
|
||||
for (CollectionTree tree : children) {
|
||||
for (LibraryTree tree : children) {
|
||||
tree.sortAllChildren();
|
||||
}
|
||||
}
|
|
@ -17,9 +17,9 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.fbreader.collection;
|
||||
package org.geometerplus.fbreader.library;
|
||||
|
||||
final class RootTree extends CollectionTree {
|
||||
final class RootTree extends LibraryTree {
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.fbreader.collection;
|
||||
package org.geometerplus.fbreader.library;
|
||||
|
||||
public final class SeriesInfo {
|
||||
public final String Name;
|
|
@ -17,12 +17,12 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.fbreader.collection;
|
||||
package org.geometerplus.fbreader.library;
|
||||
|
||||
final class SeriesTree extends CollectionTree {
|
||||
final class SeriesTree extends LibraryTree {
|
||||
private final String mySeries;
|
||||
|
||||
SeriesTree(CollectionTree parent, String series) {
|
||||
SeriesTree(LibraryTree parent, String series) {
|
||||
super(parent);
|
||||
mySeries = series;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ final class SeriesTree extends CollectionTree {
|
|||
return mySeries;
|
||||
}
|
||||
|
||||
BookTree createBookInSeriesSubTree(BookDescription book) {
|
||||
BookTree createBookInSeriesSubTree(Book book) {
|
||||
return new BookInSeriesTree(this, book);
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.fbreader.collection;
|
||||
package org.geometerplus.fbreader.library;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
|
@ -17,14 +17,14 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.fbreader.collection;
|
||||
package org.geometerplus.fbreader.library;
|
||||
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
||||
final class TagTree extends CollectionTree {
|
||||
final class TagTree extends LibraryTree {
|
||||
private final Tag myTag;
|
||||
|
||||
TagTree(CollectionTree parent, Tag tag) {
|
||||
TagTree(LibraryTree parent, Tag tag) {
|
||||
super(parent);
|
||||
myTag = tag;
|
||||
}
|
|
@ -29,7 +29,6 @@ import org.geometerplus.zlibrary.text.view.style.*;
|
|||
|
||||
import org.geometerplus.fbreader.encoding.ZLEncodingCollection;
|
||||
import org.geometerplus.fbreader.encodingOption.*;
|
||||
import org.geometerplus.fbreader.collection.BookCollection;
|
||||
import org.geometerplus.fbreader.fbreader.*;
|
||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||
|
||||
|
|
|
@ -132,7 +132,6 @@ public abstract class ZLApplication {
|
|||
}
|
||||
|
||||
public final void onViewChanged() {
|
||||
System.err.println("onViewChanged");
|
||||
for (ButtonPanel panel : myPanels) {
|
||||
panel.hide();
|
||||
}
|
||||
|
|
|
@ -37,15 +37,7 @@ public abstract class ZLTextView extends ZLView {
|
|||
super(context);
|
||||
}
|
||||
|
||||
public final void setModel(ZLTextModel model) {
|
||||
final ArrayList<ZLTextModel> list = new ArrayList<ZLTextModel>(1);
|
||||
list.add(model);
|
||||
setModels(list, 0);
|
||||
}
|
||||
|
||||
public abstract void setModelIndex(int modelIndex);
|
||||
|
||||
public abstract void setModels(ArrayList<ZLTextModel> model, int current);
|
||||
public abstract void setModel(ZLTextModel model);
|
||||
|
||||
public abstract void scrollPage(boolean forward, int scrollingMode, int value);
|
||||
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2009 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.zlibrary.text.view.impl;
|
||||
|
||||
public final class ZLTextPosition {
|
||||
public int ParagraphIndex;
|
||||
public int WordIndex;
|
||||
public int CharIndex;
|
||||
|
||||
public ZLTextPosition(int paragraphIndex, int wordIndex, int charIndex) {
|
||||
ParagraphIndex = paragraphIndex;
|
||||
WordIndex = wordIndex;
|
||||
CharIndex = charIndex;
|
||||
}
|
||||
|
||||
public ZLTextPosition(ZLTextWordCursor cursor) {
|
||||
set(cursor);
|
||||
}
|
||||
|
||||
public void set(ZLTextWordCursor cursor) {
|
||||
if (!cursor.isNull()) {
|
||||
ParagraphIndex = cursor.getParagraphCursor().Index;
|
||||
WordIndex = cursor.getWordIndex();
|
||||
CharIndex = cursor.getCharIndex();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean equalsToCursor(ZLTextWordCursor cursor) {
|
||||
return
|
||||
(ParagraphIndex == cursor.getParagraphCursor().Index) &&
|
||||
(WordIndex == cursor.getWordIndex()) &&
|
||||
(CharIndex == cursor.getCharIndex());
|
||||
}
|
||||
}
|
|
@ -31,44 +31,8 @@ import org.geometerplus.zlibrary.text.view.style.*;
|
|||
|
||||
public abstract class ZLTextViewImpl extends ZLTextView {
|
||||
private ZLTextModel myModel;
|
||||
protected int myCurrentModelIndex;
|
||||
private ArrayList<ZLTextModel> myModelList;
|
||||
private final ZLTextSelectionModel mySelectionModel;
|
||||
|
||||
protected static class Position {
|
||||
public int ParagraphIndex;
|
||||
public int WordIndex;
|
||||
public int CharIndex;
|
||||
public int ModelIndex;
|
||||
|
||||
public Position(int modelIndex, int paragraphIndex, int wordIndex, int charIndex) {
|
||||
ParagraphIndex = paragraphIndex;
|
||||
WordIndex = wordIndex;
|
||||
CharIndex = charIndex;
|
||||
ModelIndex = modelIndex;
|
||||
}
|
||||
|
||||
public Position(int modelIndex, ZLTextWordCursor cursor) {
|
||||
ModelIndex = modelIndex;
|
||||
set(cursor);
|
||||
}
|
||||
|
||||
public void set(ZLTextWordCursor cursor) {
|
||||
if (!cursor.isNull()) {
|
||||
ParagraphIndex = cursor.getParagraphCursor().Index;
|
||||
WordIndex = cursor.getWordIndex();
|
||||
CharIndex = cursor.getCharIndex();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean equalsToCursor(ZLTextWordCursor cursor) {
|
||||
return
|
||||
(ParagraphIndex == cursor.getParagraphCursor().Index) &&
|
||||
(WordIndex == cursor.getWordIndex()) &&
|
||||
(CharIndex == cursor.getCharIndex());
|
||||
}
|
||||
}
|
||||
|
||||
private interface SizeUnit {
|
||||
int PIXEL_UNIT = 0;
|
||||
int LINE_UNIT = 1;
|
||||
|
@ -95,17 +59,10 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
|||
mySelectionModel = new ZLTextSelectionModel(this);
|
||||
}
|
||||
|
||||
public void setModels(ArrayList<ZLTextModel> models, int current) {
|
||||
myModelList = (models != null) ? models : new ArrayList<ZLTextModel>();
|
||||
myModel = (current >= 0 && current < myModelList.size()) ?
|
||||
(ZLTextModel)myModelList.get(current) : null;
|
||||
myCurrentModelIndex = current;
|
||||
setModelInternal();
|
||||
}
|
||||
|
||||
private void setModelInternal() {
|
||||
public final void setModel(ZLTextModel model) {
|
||||
ZLTextParagraphCursorCache.clear();
|
||||
|
||||
myModel = model;
|
||||
if (myModel != null) {
|
||||
final int paragraphsNumber = myModel.getParagraphsNumber();
|
||||
if (paragraphsNumber > 0) {
|
||||
|
@ -121,24 +78,10 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
|||
}
|
||||
}
|
||||
|
||||
public void setModelIndex(int modelIndex) {
|
||||
if ((modelIndex != myCurrentModelIndex) && (modelIndex >= 0) &&
|
||||
(modelIndex < myModelList.size())) {
|
||||
myModel = (ZLTextModel)myModelList.get(modelIndex);
|
||||
myCurrentModelIndex = modelIndex;
|
||||
setModelInternal();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: visibility
|
||||
public ZLTextModel getModel() {
|
||||
return myModel;
|
||||
}
|
||||
|
||||
protected ArrayList<ZLTextModel> getModelList() {
|
||||
return myModelList;
|
||||
}
|
||||
|
||||
public void highlightParagraph(int paragraphIndex) {
|
||||
myModel.selectParagraph(paragraphIndex);
|
||||
rebuildPaintInfo();
|
||||
|
@ -302,7 +245,7 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
|||
if (myCurrentPage.StartCursor.isNull()) {
|
||||
return;
|
||||
}
|
||||
final Position position = new Position(myCurrentModelIndex, myCurrentPage.StartCursor);
|
||||
final ZLTextPosition position = new ZLTextPosition(myCurrentPage.StartCursor);
|
||||
if ((myCurrentPage.StartCursor.getParagraphCursor().Index != mark.ParagraphIndex) || (myCurrentPage.StartCursor.getPosition().compareTo(mark) > 0)) {
|
||||
doRepaint = true;
|
||||
gotoParagraph(mark.ParagraphIndex, false);
|
||||
|
@ -324,19 +267,17 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
|||
savePosition(position);
|
||||
}
|
||||
*/
|
||||
savePosition(position, myCurrentModelIndex, myCurrentPage.StartCursor);
|
||||
savePosition(position, myCurrentPage.StartCursor);
|
||||
ZLApplication.Instance().repaintView();
|
||||
}
|
||||
}
|
||||
|
||||
protected void savePosition(Position position) {
|
||||
protected void savePosition(ZLTextPosition position) {
|
||||
}
|
||||
|
||||
protected final void savePosition(Position position, int modelIndexToCheck, ZLTextWordCursor cursorToCheck) {
|
||||
// System.out.println("trying to save " + position.ModelIndex + " " + position.ParagraphIndex);
|
||||
if ((position.ModelIndex != modelIndexToCheck) || !position.equalsToCursor(cursorToCheck)) {
|
||||
protected final void savePosition(ZLTextPosition position, ZLTextWordCursor cursorToCheck) {
|
||||
if (!position.equalsToCursor(cursorToCheck)) {
|
||||
savePosition(position);
|
||||
// System.out.println("saved");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1100,8 +1041,8 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
|||
}
|
||||
}
|
||||
|
||||
public final void gotoPosition(Position position) {
|
||||
gotoPosition(position.ModelIndex, position.ParagraphIndex, position.WordIndex, position.CharIndex);
|
||||
public final void gotoPosition(ZLTextPosition position) {
|
||||
gotoPosition(position.ParagraphIndex, position.WordIndex, position.CharIndex);
|
||||
}
|
||||
|
||||
public final void gotoPosition(int paragraphIndex, int wordIndex, int charIndex) {
|
||||
|
@ -1117,11 +1058,6 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
|||
myNextPage.reset();
|
||||
}
|
||||
|
||||
public final void gotoPosition(int modelIndex, int paragraphIndex, int wordIndex, int charIndex) {
|
||||
setModelIndex(modelIndex);
|
||||
gotoPosition(paragraphIndex, wordIndex, charIndex);
|
||||
}
|
||||
|
||||
public void gotoParagraph(int num, boolean last) {
|
||||
if (myModel == null) {
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue