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="collapseTree" value="Collapse tree"/>
|
||||||
<node name="readText" value="Read book text"/>
|
<node name="readText" value="Read book text"/>
|
||||||
</node>
|
</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="menu">
|
||||||
<node name="preferences-old" value="Settings (old)"/>
|
<node name="preferences-old" value="Settings (old)"/>
|
||||||
<node name="preferences" value="Settings"/>
|
<node name="preferences" value="Settings"/>
|
||||||
|
@ -46,7 +52,7 @@
|
||||||
<node name="rotate" value="Rotate Screen"/>
|
<node name="rotate" value="Rotate Screen"/>
|
||||||
<node name="toggleFullscreen" value="Full Screen"/>
|
<node name="toggleFullscreen" value="Full Screen"/>
|
||||||
</node>
|
</node>
|
||||||
<node name="quit" value="Close"/>
|
<node name="bookmarks" value="Bookmarks"/>
|
||||||
</node>
|
</node>
|
||||||
<node name="dialog">
|
<node name="dialog">
|
||||||
<node name="BookInfo">
|
<node name="BookInfo">
|
||||||
|
|
|
@ -19,6 +19,12 @@
|
||||||
<node name="collapseTree" value="Свернуть ветвь дерева"/>
|
<node name="collapseTree" value="Свернуть ветвь дерева"/>
|
||||||
<node name="readText" value="Читать главу"/>
|
<node name="readText" value="Читать главу"/>
|
||||||
</node>
|
</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="menu">
|
||||||
<node name="preferences" value="Настройки"/>
|
<node name="preferences" value="Настройки"/>
|
||||||
<node name="bookInfo" value="О книге"/>
|
<node name="bookInfo" value="О книге"/>
|
||||||
|
@ -44,6 +50,7 @@
|
||||||
<node name="rotate" value="Повернуть"/>
|
<node name="rotate" value="Повернуть"/>
|
||||||
<node name="toggleFullscreen" value="На весь экран"/>
|
<node name="toggleFullscreen" value="На весь экран"/>
|
||||||
</node>
|
</node>
|
||||||
|
<node name="bookmarks" value="Закладки"/>
|
||||||
</node>
|
</node>
|
||||||
<node name="dialog">
|
<node name="dialog">
|
||||||
<node name="BookInfo">
|
<node name="BookInfo">
|
||||||
|
|
|
@ -26,12 +26,10 @@
|
||||||
<activity android:name="org.geometerplus.android.fbreader.LibraryTabActivity" android:configChanges="orientation|keyboardHidden">
|
<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" />
|
<meta-data android:name="android.app.default_searchable" android:value="org.geometerplus.android.fbreader.BookSearchActivity" />
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name="org.geometerplus.android.fbreader.TOCActivity" android:configChanges="orientation|keyboardHidden">
|
<activity android:name="org.geometerplus.android.fbreader.TOCActivity" android:configChanges="orientation|keyboardHidden" />
|
||||||
</activity>
|
<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.PreferenceActivity" android:configChanges="orientation|keyboardHidden" />
|
||||||
</activity>
|
<activity android:name="org.geometerplus.android.fbreader.preferences.BookInfoActivity" android:configChanges="orientation|keyboardHidden" />
|
||||||
<activity android:name="org.geometerplus.android.fbreader.preferences.BookInfoActivity" android:configChanges="orientation|keyboardHidden">
|
|
||||||
</activity>
|
|
||||||
<activity android:name="org.geometerplus.android.fbreader.BookDownloader" android:theme="@android:style/Theme.Dialog" android:configChanges="orientation|keyboardHidden">
|
<activity android:name="org.geometerplus.android.fbreader.BookDownloader" android:theme="@android:style/Theme.Dialog" android:configChanges="orientation|keyboardHidden">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
|
@ -1,5 +1,12 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<menubar>
|
<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">
|
<submenu id="navigate">
|
||||||
<item id="gotoHome"/>
|
<item id="gotoHome"/>
|
||||||
<item id="gotoSectionStart"/>
|
<item id="gotoSectionStart"/>
|
||||||
|
@ -9,10 +16,4 @@
|
||||||
<item id="undo"/>
|
<item id="undo"/>
|
||||||
<item id="redo"/>
|
<item id="redo"/>
|
||||||
</submenu>
|
</submenu>
|
||||||
<item id="library"/>
|
|
||||||
<item id="toc"/>
|
|
||||||
<item id="search"/>
|
|
||||||
<item id="preferences"/>
|
|
||||||
<item id="preferences-old"/>
|
|
||||||
<item id="bookInfo"/>
|
|
||||||
</menubar>
|
</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 android.app.Activity;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBReader;
|
import org.geometerplus.fbreader.fbreader.FBReader;
|
||||||
import org.geometerplus.fbreader.collection.*;
|
import org.geometerplus.fbreader.library.*;
|
||||||
|
|
||||||
public class BookSearchActivity extends SearchActivity {
|
public class BookSearchActivity extends SearchActivity {
|
||||||
private CollectionTree myTree;
|
private LibraryTree myTree;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void onSuccess() {
|
void onSuccess() {
|
||||||
|
@ -50,7 +50,7 @@ public class BookSearchActivity extends SearchActivity {
|
||||||
boolean runSearch(final String pattern) {
|
boolean runSearch(final String pattern) {
|
||||||
final FBReader fbreader = (FBReader)FBReader.Instance();
|
final FBReader fbreader = (FBReader)FBReader.Instance();
|
||||||
fbreader.BookSearchPatternOption.setValue(pattern);
|
fbreader.BookSearchPatternOption.setValue(pattern);
|
||||||
myTree = BookCollection.Instance().searchBooks(pattern);
|
myTree = Library.Instance().searchBooks(pattern);
|
||||||
return myTree.hasChildren();
|
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.zlibrary.core.resources.ZLResource;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBReader;
|
import org.geometerplus.fbreader.fbreader.FBReader;
|
||||||
import org.geometerplus.fbreader.collection.*;
|
import org.geometerplus.fbreader.library.*;
|
||||||
|
|
||||||
public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuItemClickListener {
|
public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuItemClickListener {
|
||||||
static LibraryTabActivity Instance;
|
static LibraryTabActivity Instance;
|
||||||
|
@ -54,16 +54,16 @@ public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuIt
|
||||||
final TabHost host = getTabHost();
|
final TabHost host = getTabHost();
|
||||||
LayoutInflater.from(this).inflate(R.layout.library, host.getTabContentView(), true);
|
LayoutInflater.from(this).inflate(R.layout.library, host.getTabContentView(), true);
|
||||||
|
|
||||||
new LibraryAdapter(createTab("byAuthor", R.id.by_author), BookCollection.Instance().collectionByAuthor());
|
new LibraryAdapter(createTab("byAuthor", R.id.by_author), Library.Instance().byAuthor());
|
||||||
new LibraryAdapter(createTab("byTag", R.id.by_tag), BookCollection.Instance().collectionByTag());
|
new LibraryAdapter(createTab("byTag", R.id.by_tag), Library.Instance().byTag());
|
||||||
new LibraryAdapter(createTab("recent", R.id.recent), BookCollection.Instance().recentBooks());
|
new LibraryAdapter(createTab("recent", R.id.recent), Library.Instance().recentBooks());
|
||||||
findViewById(R.id.search_results).setVisibility(View.GONE);
|
findViewById(R.id.search_results).setVisibility(View.GONE);
|
||||||
|
|
||||||
host.setCurrentTabByTag(mySelectedTabOption.getValue());
|
host.setCurrentTabByTag(mySelectedTabOption.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
private LibraryAdapter mySearchResultsAdapter;
|
private LibraryAdapter mySearchResultsAdapter;
|
||||||
void showSearchResultsTab(CollectionTree tree) {
|
void showSearchResultsTab(LibraryTree tree) {
|
||||||
if (mySearchResultsAdapter == null) {
|
if (mySearchResultsAdapter == null) {
|
||||||
mySearchResultsAdapter =
|
mySearchResultsAdapter =
|
||||||
new LibraryAdapter(createTab("searchResults", R.id.search_results), tree);
|
new LibraryAdapter(createTab("searchResults", R.id.search_results), tree);
|
||||||
|
@ -88,7 +88,7 @@ public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuIt
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
mySelectedTabOption.setValue(getTabHost().getCurrentTabTag());
|
mySelectedTabOption.setValue(getTabHost().getCurrentTabTag());
|
||||||
Instance = null;
|
Instance = null;
|
||||||
BookCollection.Instance().clear();
|
Library.Instance().clear();
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,17 +124,17 @@ public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuIt
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class LibraryAdapter extends ZLTreeAdapter {
|
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);
|
super(view, tree);
|
||||||
myCollectionTree = tree;
|
myLibraryTree = tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
final View view = (convertView != null) ? convertView :
|
final View view = (convertView != null) ? convertView :
|
||||||
LayoutInflater.from(parent.getContext()).inflate(R.layout.library_tree_item, parent, false);
|
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);
|
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_name)).setText(tree.getName());
|
||||||
((TextView)view.findViewById(R.id.library_tree_item_childrenlist)).setText(tree.getSecondString());
|
((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();
|
finish();
|
||||||
final FBReader fbreader = (FBReader)FBReader.Instance();
|
final FBReader fbreader = (FBReader)FBReader.Instance();
|
||||||
fbreader.openBook(((BookTree)tree).Description);
|
fbreader.openBook(((BookTree)tree).Book);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,10 @@ import android.database.Cursor;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.dialogs.ZLDialogManager;
|
import org.geometerplus.zlibrary.core.dialogs.ZLDialogManager;
|
||||||
import org.geometerplus.zlibrary.core.options.ZLStringOption;
|
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.zlibrary.ui.android.library.ZLAndroidApplication;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.collection.*;
|
import org.geometerplus.fbreader.library.*;
|
||||||
|
|
||||||
final class SQLiteBooksDatabase extends BooksDatabase {
|
final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
private final SQLiteDatabase myDatabase;
|
private final SQLiteDatabase myDatabase;
|
||||||
|
@ -44,7 +45,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
|
|
||||||
private void migrate() {
|
private void migrate() {
|
||||||
final int version = myDatabase.getVersion();
|
final int version = myDatabase.getVersion();
|
||||||
if (version >= 5) {
|
if (version >= 6) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ZLDialogManager.Instance().wait((version == 0) ? "creatingBooksDatabase" : "updatingBooksDatabase", new Runnable() {
|
ZLDialogManager.Instance().wait((version == 0) ? "creatingBooksDatabase" : "updatingBooksDatabase", new Runnable() {
|
||||||
|
@ -64,12 +65,14 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
updateTables4();
|
updateTables4();
|
||||||
case 5:
|
case 5:
|
||||||
updateTables5();
|
updateTables5();
|
||||||
|
case 6:
|
||||||
|
updateTables6();
|
||||||
}
|
}
|
||||||
myDatabase.setTransactionSuccessful();
|
myDatabase.setTransactionSuccessful();
|
||||||
myDatabase.endTransaction();
|
myDatabase.endTransaction();
|
||||||
|
|
||||||
myDatabase.execSQL("VACUUM");
|
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_TABLE = "Books";
|
||||||
private static final String[] BOOKS_COLUMNS = { "book_id", "encoding", "language", "title" };
|
private static final String[] BOOKS_COLUMNS = { "book_id", "encoding", "language", "title" };
|
||||||
private static final String FILE_NAME_CONDITION = "file_name = ?";
|
private static final String FILE_NAME_CONDITION = "file_name = ?";
|
||||||
protected long loadBook(BookDescription description) {
|
protected long loadBook(Book book) {
|
||||||
final Cursor cursor = myDatabase.query(
|
final Cursor cursor = myDatabase.query(
|
||||||
BOOKS_TABLE,
|
BOOKS_TABLE,
|
||||||
BOOKS_COLUMNS,
|
BOOKS_COLUMNS,
|
||||||
FILE_NAME_CONDITION, new String[] { description.File.getPath() },
|
FILE_NAME_CONDITION, new String[] { book.File.getPath() },
|
||||||
null, null, null, null
|
null, null, null, null
|
||||||
);
|
);
|
||||||
long id = -1;
|
long id = -1;
|
||||||
if (cursor.moveToNext()) {
|
if (cursor.moveToNext()) {
|
||||||
id = cursor.getLong(0);
|
id = cursor.getLong(0);
|
||||||
description.setEncoding(cursor.getString(1));
|
book.setEncoding(cursor.getString(1));
|
||||||
description.setLanguage(cursor.getString(2));
|
book.setLanguage(cursor.getString(2));
|
||||||
description.setTitle(cursor.getString(3));
|
book.setTitle(cursor.getString(3));
|
||||||
}
|
}
|
||||||
cursor.close();
|
cursor.close();
|
||||||
return id;
|
return id;
|
||||||
|
@ -135,21 +153,21 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map<String,BookDescription> listBooks() {
|
protected Map<String,Book> listBooks() {
|
||||||
Cursor cursor = myDatabase.rawQuery(
|
Cursor cursor = myDatabase.rawQuery(
|
||||||
"SELECT book_id,file_name,title,encoding,language FROM Books", null
|
"SELECT book_id,file_name,title,encoding,language FROM Books", null
|
||||||
);
|
);
|
||||||
final int count = cursor.getCount();
|
final int count = cursor.getCount();
|
||||||
final HashMap<Long,BookDescription> booksById = new HashMap<Long,BookDescription>(count);
|
final HashMap<Long,Book> booksById = new HashMap<Long,Book>(count);
|
||||||
final HashMap<String,BookDescription> booksByFilename = new HashMap<String,BookDescription>(count);
|
final HashMap<String,Book> booksByFilename = new HashMap<String,Book>(count);
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
final long id = cursor.getLong(0);
|
final long id = cursor.getLong(0);
|
||||||
final String fileName = cursor.getString(1);
|
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)
|
id, fileName, cursor.getString(2), cursor.getString(3), cursor.getString(4)
|
||||||
);
|
);
|
||||||
booksById.put(id, description);
|
booksById.put(id, book);
|
||||||
booksByFilename.put(fileName, description);
|
booksByFilename.put(fileName, book);
|
||||||
}
|
}
|
||||||
cursor.close();
|
cursor.close();
|
||||||
|
|
||||||
|
@ -168,7 +186,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
"SELECT book_id,author_id FROM BookAuthor ORDER BY author_index", null
|
"SELECT book_id,author_id FROM BookAuthor ORDER BY author_index", null
|
||||||
);
|
);
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
BookDescription book = booksById.get(cursor.getLong(0));
|
Book book = booksById.get(cursor.getLong(0));
|
||||||
if (book != null) {
|
if (book != null) {
|
||||||
Author author = authorById.get(cursor.getLong(1));
|
Author author = authorById.get(cursor.getLong(1));
|
||||||
if (author != null) {
|
if (author != null) {
|
||||||
|
@ -180,7 +198,7 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
|
|
||||||
cursor = myDatabase.rawQuery("SELECT book_id,tag_id FROM BookTag", null);
|
cursor = myDatabase.rawQuery("SELECT book_id,tag_id FROM BookTag", null);
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
BookDescription book = booksById.get(cursor.getLong(0));
|
Book book = booksById.get(cursor.getLong(0));
|
||||||
if (book != null) {
|
if (book != null) {
|
||||||
addTag(book, getTagById(cursor.getLong(1)));
|
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
|
"SELECT book_id,series_id,book_index FROM BookSeries", null
|
||||||
);
|
);
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
BookDescription book = booksById.get(cursor.getLong(0));
|
Book book = booksById.get(cursor.getLong(0));
|
||||||
if (book != null) {
|
if (book != null) {
|
||||||
String series = seriesById.get(cursor.getLong(1));
|
String series = seriesById.get(cursor.getLong(1));
|
||||||
if (series != null) {
|
if (series != null) {
|
||||||
|
@ -606,6 +624,41 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
return ids;
|
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() {
|
private void createTables() {
|
||||||
myDatabase.execSQL(
|
myDatabase.execSQL(
|
||||||
"CREATE TABLE Books(" +
|
"CREATE TABLE Books(" +
|
||||||
|
@ -716,5 +769,38 @@ final class SQLiteBooksDatabase extends BooksDatabase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTables5() {
|
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.os.*;
|
||||||
import android.app.*;
|
import android.app.*;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
import org.geometerplus.zlibrary.core.dialogs.ZLDialogManager;
|
import org.geometerplus.zlibrary.core.dialogs.ZLDialogManager;
|
||||||
|
@ -40,21 +41,14 @@ abstract class SearchActivity extends Activity {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
final Handler failureHandler = new Handler() {
|
final Handler failureHandler = new Handler() {
|
||||||
private AlertDialog myAlertDialog;
|
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
switch (message.what) {
|
Toast.makeText(
|
||||||
case 0:
|
getParentActivity(),
|
||||||
onFailure();
|
ZLResource.resource("errorMessage").getResource(
|
||||||
myAlertDialog =
|
getFailureMessageResourceKey()
|
||||||
new AlertDialog.Builder(getParentActivity()).setMessage(
|
).getValue(),
|
||||||
ZLResource.resource("errorMessage").getResource(getFailureMessageResourceKey()).getValue()
|
Toast.LENGTH_SHORT
|
||||||
).create();
|
).show();
|
||||||
myAlertDialog.show();
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
myAlertDialog.dismiss();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ZLDialogManager.Instance().wait(getWaitMessageResourceKey(), new Runnable() {
|
ZLDialogManager.Instance().wait(getWaitMessageResourceKey(), new Runnable() {
|
||||||
|
@ -63,15 +57,6 @@ abstract class SearchActivity extends Activity {
|
||||||
successHandler.sendEmptyMessage(0);
|
successHandler.sendEmptyMessage(0);
|
||||||
} else {
|
} else {
|
||||||
failureHandler.sendEmptyMessage(0);
|
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();
|
final TOCTree.Reference reference = tree.getReference();
|
||||||
if (reference != null) {
|
if (reference != null) {
|
||||||
final FBReader fbreader = (FBReader)ZLApplication.Instance();
|
final FBReader fbreader = (FBReader)ZLApplication.Instance();
|
||||||
fbreader.BookTextView.gotoParagraphSafe(reference.Model, reference.ParagraphIndex);
|
fbreader.BookTextView.gotoParagraphSafe(reference.ParagraphIndex);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,28 +30,28 @@ import org.geometerplus.zlibrary.core.language.ZLLanguageList;
|
||||||
import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator;
|
import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.fbreader.FBReader;
|
import org.geometerplus.fbreader.fbreader.FBReader;
|
||||||
import org.geometerplus.fbreader.collection.BookDescription;
|
import org.geometerplus.fbreader.library.Book;
|
||||||
|
|
||||||
class BookTitlePreference extends ZLStringPreference {
|
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);
|
super(context, rootResource, resourceKey);
|
||||||
myDescription = description;
|
myBook = book;
|
||||||
setValue(description.getTitle());
|
setValue(book.getTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void accept() {
|
public void accept() {
|
||||||
myDescription.setTitle(getValue());
|
myBook.setTitle(getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class LanguagePreference extends ZLStringListPreference {
|
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);
|
super(context, rootResource, resourceKey);
|
||||||
myDescription = description;
|
myBook = book;
|
||||||
final TreeMap<String,String> map = new TreeMap<String,String>();
|
final TreeMap<String,String> map = new TreeMap<String,String>();
|
||||||
for (String code : ZLLanguageList.languageCodes()) {
|
for (String code : ZLLanguageList.languageCodes()) {
|
||||||
map.put(ZLLanguageList.languageName(code), code);
|
map.put(ZLLanguageList.languageName(code), code);
|
||||||
|
@ -68,7 +68,7 @@ class LanguagePreference extends ZLStringListPreference {
|
||||||
codes[size] = "other";
|
codes[size] = "other";
|
||||||
names[size] = ZLLanguageList.languageName(codes[size]);
|
names[size] = ZLLanguageList.languageName(codes[size]);
|
||||||
setLists(codes, names);
|
setLists(codes, names);
|
||||||
String language = myDescription.getLanguage();
|
String language = myBook.getLanguage();
|
||||||
if (language == null) {
|
if (language == null) {
|
||||||
language = "other";
|
language = "other";
|
||||||
}
|
}
|
||||||
|
@ -79,12 +79,12 @@ class LanguagePreference extends ZLStringListPreference {
|
||||||
|
|
||||||
public void accept() {
|
public void accept() {
|
||||||
final String value = getValue();
|
final String value = getValue();
|
||||||
myDescription.setLanguage((value.length() != 0) ? value : null);
|
myBook.setLanguage((value.length() != 0) ? value : null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BookInfoActivity extends ZLPreferenceActivity {
|
public class BookInfoActivity extends ZLPreferenceActivity {
|
||||||
private BookDescription myDescription;
|
private Book myBook;
|
||||||
|
|
||||||
public BookInfoActivity() {
|
public BookInfoActivity() {
|
||||||
super("BookInfo");
|
super("BookInfo");
|
||||||
|
@ -93,17 +93,17 @@ public class BookInfoActivity extends ZLPreferenceActivity {
|
||||||
@Override
|
@Override
|
||||||
protected void init() {
|
protected void init() {
|
||||||
final Category commonCategory = new Category(null);
|
final Category commonCategory = new Category(null);
|
||||||
myDescription = ((FBReader)FBReader.Instance()).Model.Description;
|
myBook = ((FBReader)FBReader.Instance()).Model.Book;
|
||||||
commonCategory.addPreference(new BookTitlePreference(this, commonCategory.getResource(), "title", myDescription));
|
commonCategory.addPreference(new BookTitlePreference(this, commonCategory.getResource(), "title", myBook));
|
||||||
commonCategory.addPreference(new LanguagePreference(this, commonCategory.getResource(), "language", myDescription));
|
commonCategory.addPreference(new LanguagePreference(this, commonCategory.getResource(), "language", myBook));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
if (myDescription.save()) {
|
if (myBook.save()) {
|
||||||
((FBReader)FBReader.Instance()).clearTextCaches();
|
((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.zlibrary.text.model.*;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.collection.BookDescription;
|
import org.geometerplus.fbreader.library.Book;
|
||||||
import org.geometerplus.fbreader.formats.*;
|
import org.geometerplus.fbreader.formats.*;
|
||||||
|
|
||||||
public final class BookModel {
|
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 ZLTextPlainModel BookTextModel = new ZLTextPlainModel(65536, "/sdcard/Books/.FBReader", "cache");
|
||||||
public final TOCTree TOCTree = new TOCTree();
|
public final TOCTree TOCTree = new TOCTree();
|
||||||
|
|
||||||
private final HashMap<String,ZLTextPlainModel> myFootnotes = new HashMap<String,ZLTextPlainModel>();
|
private final HashMap<String,ZLTextPlainModel> myFootnotes = new HashMap<String,ZLTextPlainModel>();
|
||||||
private final HashMap myInternalHyperlinks = new HashMap();
|
private final HashMap myInternalHyperlinks = new HashMap();
|
||||||
private final ArrayList myBookTextModels;
|
|
||||||
|
|
||||||
private final ZLImageMap myImageMap = new ZLImageMap();
|
private final ZLImageMap myImageMap = new ZLImageMap();
|
||||||
|
|
||||||
public class Label {
|
public class Label {
|
||||||
public final int ParagraphIndex;
|
|
||||||
public final ZLTextModel Model;
|
public final ZLTextModel Model;
|
||||||
|
public final int ParagraphIndex;
|
||||||
public final int ModelIndex;
|
|
||||||
|
|
||||||
Label(ZLTextModel model, int paragraphIndex) {
|
Label(ZLTextModel model, int paragraphIndex) {
|
||||||
ParagraphIndex = paragraphIndex;
|
|
||||||
Model = model;
|
Model = model;
|
||||||
ModelIndex = myBookTextModels.indexOf(model);
|
ParagraphIndex = paragraphIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public BookModel(final BookDescription description) {
|
public BookModel(final Book book) {
|
||||||
myBookTextModels = new ArrayList();
|
Book = book;
|
||||||
myBookTextModels.add(BookTextModel);
|
FormatPlugin plugin = PluginCollection.instance().getPlugin(book.File);
|
||||||
Description = description;
|
|
||||||
FormatPlugin plugin = PluginCollection.instance().getPlugin(description.File);
|
|
||||||
if (plugin != null) {
|
if (plugin != null) {
|
||||||
plugin.readModel(description, this);
|
plugin.readModel(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,14 +91,4 @@ public final class BookModel {
|
||||||
void addImage(String id, ZLImage image) {
|
void addImage(String id, ZLImage image) {
|
||||||
myImageMap.put(id, 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);
|
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 UNDO = "undo";
|
||||||
String REDO = "redo";
|
String REDO = "redo";
|
||||||
String SHOW_CONTENTS = "toc";
|
String SHOW_CONTENTS = "toc";
|
||||||
|
String SHOW_BOOKMARKS = "bookmarks";
|
||||||
String SEARCH = "search";
|
String SEARCH = "search";
|
||||||
String FIND_PREVIOUS = "findPrevious";
|
String FIND_PREVIOUS = "findPrevious";
|
||||||
String FIND_NEXT = "findNext";
|
String FIND_NEXT = "findNext";
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class BookTextView extends FBView {
|
||||||
private ZLIntegerOption myWordIndexOption;
|
private ZLIntegerOption myWordIndexOption;
|
||||||
private ZLIntegerOption myCharIndexOption;
|
private ZLIntegerOption myCharIndexOption;
|
||||||
|
|
||||||
private ArrayList myPositionStack = new ArrayList();
|
private ArrayList<ZLTextPosition> myPositionStack = new ArrayList<ZLTextPosition>();
|
||||||
private int myCurrentPointInStack;
|
private int myCurrentPointInStack;
|
||||||
|
|
||||||
private String myFileName;
|
private String myFileName;
|
||||||
|
@ -54,7 +54,9 @@ public class BookTextView extends FBView {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setModels(ArrayList<ZLTextModel> models, String fileName) {
|
public void setModel(ZLTextModel model, String fileName) {
|
||||||
|
super.setModel(model);
|
||||||
|
|
||||||
myFileName = fileName;
|
myFileName = fileName;
|
||||||
|
|
||||||
myPositionStack.clear();
|
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();
|
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();
|
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 ZLIntegerOption option = new ZLIntegerOption(fileName, "", 0);
|
||||||
final int size = models.size();
|
|
||||||
for (int i = 0; i < stackSize; ++i) {
|
for (int i = 0; i < stackSize; ++i) {
|
||||||
// option.changeName(MODEL_PREFIX + i);
|
|
||||||
// final int modelIndex = option.getValue();
|
|
||||||
option.changeName(PARAGRAPH_PREFIX + i);
|
option.changeName(PARAGRAPH_PREFIX + i);
|
||||||
int paragraphIndex = option.getValue();
|
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);
|
option.changeName(WORD_PREFIX + i);
|
||||||
final int wordIndex = option.getValue();
|
final int wordIndex = option.getValue();
|
||||||
option.changeName(CHAR_PREFIX + i);
|
option.changeName(CHAR_PREFIX + i);
|
||||||
final int charIndex = option.getValue();
|
final int charIndex = option.getValue();
|
||||||
myPositionStack.add(new Position(modelIndex, paragraphIndex, wordIndex, charIndex));
|
myPositionStack.add(new ZLTextPosition(paragraphIndex, wordIndex, charIndex));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!myPositionStack.isEmpty()) {
|
if (!myPositionStack.isEmpty()) {
|
||||||
super.setModels(models, ((Position)myPositionStack.get(myCurrentPointInStack)).ModelIndex);
|
gotoPosition(myPositionStack.get(myCurrentPointInStack));
|
||||||
} else {
|
|
||||||
super.setModels(models, 0);
|
|
||||||
}
|
}
|
||||||
if ((getModel() != null) && (!myPositionStack.isEmpty())) {
|
|
||||||
gotoPosition((Position)myPositionStack.get(myCurrentPointInStack));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onPaintInfoPrepared() {
|
protected void onPaintInfoPrepared() {
|
||||||
if (myPositionStack.isEmpty()) {
|
if (myPositionStack.isEmpty()) {
|
||||||
myPositionStack.add(new Position(myCurrentModelIndex, getStartCursor()));
|
myPositionStack.add(new ZLTextPosition(getStartCursor()));
|
||||||
} else {
|
} else {
|
||||||
((Position)myPositionStack.get(myCurrentPointInStack)).set(getStartCursor());
|
myPositionStack.get(myCurrentPointInStack).set(getStartCursor());
|
||||||
((Position)myPositionStack.get(myCurrentPointInStack)).ModelIndex = myCurrentModelIndex;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void scrollToHome() {
|
void scrollToHome() {
|
||||||
final ZLTextWordCursor cursor = getStartCursor();
|
final ZLTextWordCursor cursor = getStartCursor();
|
||||||
if (!cursor.isNull() && cursor.isStartOfParagraph() && cursor.getParagraphCursor().Index == 0
|
if (!cursor.isNull() && cursor.isStartOfParagraph() && cursor.getParagraphCursor().Index == 0) {
|
||||||
&& myCurrentModelIndex == 0) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final int modelIndexToCheck = myCurrentModelIndex;
|
final ZLTextPosition position = new ZLTextPosition(cursor);
|
||||||
setModelIndex(0);
|
|
||||||
final Position position = new Position(modelIndexToCheck, cursor);
|
|
||||||
gotoParagraph(0, false);
|
gotoParagraph(0, false);
|
||||||
gotoPosition(0, 0, 0);
|
gotoPosition(0, 0, 0);
|
||||||
preparePaintInfo();
|
preparePaintInfo();
|
||||||
savePosition(position, 0, getStartCursor());
|
savePosition(position, getStartCursor());
|
||||||
ZLApplication.Instance().repaintView();
|
ZLApplication.Instance().repaintView();
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: remove
|
public void gotoParagraphSafe(int paragraphIndex) {
|
||||||
void gotoParagraphSafe(int paragraphIndex) {
|
|
||||||
// gotoParagraphSafe(paragraphIndex, myCurrentModelIndex);
|
|
||||||
preparePaintInfo();
|
preparePaintInfo();
|
||||||
final ZLTextWordCursor cursor = getStartCursor();
|
final ZLTextWordCursor cursor = getStartCursor();
|
||||||
if (!cursor.isNull()) {
|
if (!cursor.isNull()) {
|
||||||
final Position position = new Position(myCurrentModelIndex, cursor);
|
final ZLTextPosition position = new ZLTextPosition(cursor);
|
||||||
gotoParagraph(paragraphIndex, false);
|
gotoParagraph(paragraphIndex, false);
|
||||||
preparePaintInfo();
|
preparePaintInfo();
|
||||||
savePosition(position, myCurrentModelIndex, getStartCursor());
|
savePosition(position, 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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,12 +163,11 @@ public class BookTextView extends FBView {
|
||||||
return this.myFileName;
|
return this.myFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void savePosition(Position position) {
|
protected void savePosition(ZLTextPosition position) {
|
||||||
if (myPositionStack.isEmpty()) {
|
if (myPositionStack.isEmpty()) {
|
||||||
preparePaintInfo();
|
preparePaintInfo();
|
||||||
}
|
}
|
||||||
Position currentPosition =
|
final ZLTextPosition currentPosition = myPositionStack.get(myCurrentPointInStack);
|
||||||
(Position)myPositionStack.get(myCurrentPointInStack);
|
|
||||||
while (myPositionStack.size() > myCurrentPointInStack) {
|
while (myPositionStack.size() > myCurrentPointInStack) {
|
||||||
myPositionStack.remove(myPositionStack.size() - 1);
|
myPositionStack.remove(myPositionStack.size() - 1);
|
||||||
}
|
}
|
||||||
|
@ -215,14 +177,6 @@ public class BookTextView extends FBView {
|
||||||
myPositionStack.remove(0);
|
myPositionStack.remove(0);
|
||||||
}
|
}
|
||||||
myCurrentPointInStack = myPositionStack.size() - 1;
|
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() {
|
void saveState() {
|
||||||
|
@ -249,24 +203,13 @@ public class BookTextView extends FBView {
|
||||||
|
|
||||||
final ZLIntegerOption option = new ZLIntegerOption(group, "", 0);
|
final ZLIntegerOption option = new ZLIntegerOption(group, "", 0);
|
||||||
for (int i = 0; i < myPositionStack.size(); ++i) {
|
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);
|
option.changeName(PARAGRAPH_PREFIX + i);
|
||||||
int paragraphIndex = position.ParagraphIndex + position.ModelIndex;
|
option.setValue(position.ParagraphIndex);
|
||||||
final ArrayList models = getModelList();
|
|
||||||
for (int j = 0; j < position.ModelIndex; j++) {
|
|
||||||
paragraphIndex += ((ZLTextModel)models.get(j)).getParagraphsNumber();
|
|
||||||
}
|
|
||||||
|
|
||||||
option.setValue(paragraphIndex);
|
|
||||||
|
|
||||||
option.changeName(CHAR_PREFIX + i);
|
option.changeName(CHAR_PREFIX + i);
|
||||||
option.setValue(position.CharIndex);
|
option.setValue(position.CharIndex);
|
||||||
|
|
||||||
option.changeName(WORD_PREFIX + i);
|
option.changeName(WORD_PREFIX + i);
|
||||||
option.setValue(position.WordIndex);
|
option.setValue(position.WordIndex);
|
||||||
|
|
||||||
// option.changeName(MODEL_PREFIX + i);
|
|
||||||
// option.setValue(position.ModelIndex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,15 +218,8 @@ public class BookTextView extends FBView {
|
||||||
}
|
}
|
||||||
|
|
||||||
void undoPageMove() {
|
void undoPageMove() {
|
||||||
gotoPosition((Position)myPositionStack.get(--myCurrentPointInStack));
|
gotoPosition(myPositionStack.get(--myCurrentPointInStack));
|
||||||
ZLApplication.Instance().repaintView();
|
ZLApplication.Instance().repaintView();
|
||||||
/*
|
|
||||||
for (Object p : myPositionStack) {
|
|
||||||
System.out.print(((Position) p).ModelIndex + ","
|
|
||||||
+ ((Position) p).ParagraphIndex + "; ");
|
|
||||||
}
|
|
||||||
System.out.println("current position " + myCurrentPointInStack);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean canRedoPageMove() {
|
boolean canRedoPageMove() {
|
||||||
|
@ -291,14 +227,7 @@ public class BookTextView extends FBView {
|
||||||
}
|
}
|
||||||
|
|
||||||
void redoPageMove() {
|
void redoPageMove() {
|
||||||
gotoPosition((Position)myPositionStack.get(++myCurrentPointInStack));
|
gotoPosition(myPositionStack.get(++myCurrentPointInStack));
|
||||||
ZLApplication.Instance().repaintView();
|
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.zlibrary.text.hyphenation.ZLTextHyphenator;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||||
import org.geometerplus.fbreader.collection.BookCollection;
|
import org.geometerplus.fbreader.library.Library;
|
||||||
import org.geometerplus.fbreader.collection.BookDescription;
|
import org.geometerplus.fbreader.library.Book;
|
||||||
|
|
||||||
public final class FBReader extends ZLApplication {
|
public final class FBReader extends ZLApplication {
|
||||||
static interface ViewMode {
|
static interface ViewMode {
|
||||||
|
@ -88,6 +88,7 @@ public final class FBReader extends ZLApplication {
|
||||||
addAction(ActionCode.SHOW_PREFERENCES, new PreferencesAction(this));
|
addAction(ActionCode.SHOW_PREFERENCES, new PreferencesAction(this));
|
||||||
addAction(ActionCode.SHOW_BOOK_INFO, new BookInfoAction(this));
|
addAction(ActionCode.SHOW_BOOK_INFO, new BookInfoAction(this));
|
||||||
addAction(ActionCode.SHOW_CONTENTS, new ShowTOCAction(this));
|
addAction(ActionCode.SHOW_CONTENTS, new ShowTOCAction(this));
|
||||||
|
addAction(ActionCode.SHOW_BOOKMARKS, new ShowBookmarksAction(this));
|
||||||
|
|
||||||
addAction(ActionCode.SEARCH, new SearchAction(this));
|
addAction(ActionCode.SEARCH, new SearchAction(this));
|
||||||
addAction(ActionCode.FIND_NEXT, new FindNextAction(this));
|
addAction(ActionCode.FIND_NEXT, new FindNextAction(this));
|
||||||
|
@ -120,14 +121,14 @@ public final class FBReader extends ZLApplication {
|
||||||
openFiles(
|
openFiles(
|
||||||
ZLFile.createFileByPath(myArg0),
|
ZLFile.createFileByPath(myArg0),
|
||||||
ZLFile.createFileByPath(myBookNameOption.getValue()),
|
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() {
|
ZLDialogManager.Instance().wait("loadingBook", new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
openBookInternal(bookDescription);
|
openBookInternal(book);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -188,9 +189,8 @@ public final class FBReader extends ZLApplication {
|
||||||
if (Model != null) {
|
if (Model != null) {
|
||||||
BookModel.Label label = Model.getLabel(id);
|
BookModel.Label label = Model.getLabel(id);
|
||||||
if ((label != null) && (label.Model != null)) {
|
if ((label != null) && (label.Model != null)) {
|
||||||
// if (label.Model == Model.BookTextModel) {
|
if (label.Model == Model.BookTextModel) {
|
||||||
if (label.ModelIndex != -1) {
|
BookTextView.gotoParagraphSafe(label.ParagraphIndex);
|
||||||
BookTextView.gotoParagraphSafe(label.ModelIndex, label.ParagraphIndex);
|
|
||||||
} else {
|
} else {
|
||||||
FootnoteView.setModel(label.Model);
|
FootnoteView.setModel(label.Model);
|
||||||
setMode(ViewMode.FOOTNOTE);
|
setMode(ViewMode.FOOTNOTE);
|
||||||
|
@ -206,25 +206,25 @@ public final class FBReader extends ZLApplication {
|
||||||
FootnoteView.clearCaches();
|
FootnoteView.clearCaches();
|
||||||
}
|
}
|
||||||
|
|
||||||
void openBookInternal(BookDescription description) {
|
void openBookInternal(Book book) {
|
||||||
clearTextCaches();
|
clearTextCaches();
|
||||||
|
|
||||||
if (description != null) {
|
if (book != null) {
|
||||||
onViewChanged();
|
onViewChanged();
|
||||||
|
|
||||||
BookTextView.saveState();
|
BookTextView.saveState();
|
||||||
BookTextView.setModels(null, "");
|
BookTextView.setModel(null, "");
|
||||||
|
|
||||||
Model = null;
|
Model = null;
|
||||||
Model = new BookModel(description);
|
Model = new BookModel(book);
|
||||||
final String fileName = description.File.getPath();
|
final String fileName = book.File.getPath();
|
||||||
myBookNameOption.setValue(fileName);
|
myBookNameOption.setValue(fileName);
|
||||||
ZLTextHyphenator.Instance().load(description.getLanguage());
|
ZLTextHyphenator.Instance().load(book.getLanguage());
|
||||||
BookTextView.setModels(Model.getBookTextModels(), fileName);
|
BookTextView.setModel(Model.BookTextModel, fileName);
|
||||||
BookTextView.setCaption(description.getTitle());
|
BookTextView.setCaption(book.getTitle());
|
||||||
FootnoteView.setModel(null);
|
FootnoteView.setModel(null);
|
||||||
FootnoteView.setCaption(description.getTitle());
|
FootnoteView.setCaption(book.getTitle());
|
||||||
BookCollection.Instance().addBookToRecentList(description);
|
Library.Instance().addBookToRecentList(book);
|
||||||
}
|
}
|
||||||
repaintView();
|
repaintView();
|
||||||
}
|
}
|
||||||
|
@ -237,27 +237,27 @@ public final class FBReader extends ZLApplication {
|
||||||
public void openFiles(final ZLFile ... files) {
|
public void openFiles(final ZLFile ... files) {
|
||||||
ZLDialogManager.Instance().wait("loadingBook", new Runnable() {
|
ZLDialogManager.Instance().wait("loadingBook", new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
BookDescription description = null;
|
Book book = null;
|
||||||
main:
|
main:
|
||||||
for (ZLFile f : files) {
|
for (ZLFile f : files) {
|
||||||
if (f == null) {
|
if (f == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
description = BookDescription.getDescription(f);
|
book = Book.getBook(f);
|
||||||
if (description != null) {
|
if (book != null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (f.isArchive()) {
|
if (f.isArchive()) {
|
||||||
for (ZLFile child : f.children()) {
|
for (ZLFile child : f.children()) {
|
||||||
description = BookDescription.getDescription(child);
|
book = Book.getBook(child);
|
||||||
if (description != null) {
|
if (book != null) {
|
||||||
break main;
|
break main;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (description != null) {
|
if (book != null) {
|
||||||
openBookInternal(description);
|
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;
|
package org.geometerplus.fbreader.fbreader;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.collection.BookCollection;
|
import org.geometerplus.fbreader.library.Library;
|
||||||
|
|
||||||
import org.geometerplus.android.fbreader.LibraryTabActivity;
|
import org.geometerplus.android.fbreader.LibraryTabActivity;
|
||||||
|
|
||||||
|
@ -35,9 +35,9 @@ class ShowLibraryAction extends FBAction {
|
||||||
(ZLAndroidDialogManager)ZLAndroidDialogManager.Instance();
|
(ZLAndroidDialogManager)ZLAndroidDialogManager.Instance();
|
||||||
Runnable action = new Runnable() {
|
Runnable action = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
BookCollection collection = BookCollection.Instance();
|
Library library = Library.Instance();
|
||||||
collection.clear();
|
library.clear();
|
||||||
collection.synchronize();
|
library.synchronize();
|
||||||
// TODO: select current book (author?)
|
// TODO: select current book (author?)
|
||||||
/*
|
/*
|
||||||
if (myBookModel != null) {
|
if (myBookModel != null) {
|
||||||
|
|
|
@ -23,20 +23,20 @@ import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
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.dialogs.ZLOptionsDialog;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.language.ZLLanguageDetector;
|
import org.geometerplus.zlibrary.core.language.ZLLanguageDetector;
|
||||||
|
|
||||||
public abstract class FormatPlugin {
|
public abstract class FormatPlugin {
|
||||||
public abstract boolean acceptsFile(ZLFile file);
|
public abstract boolean acceptsFile(ZLFile file);
|
||||||
public abstract boolean readDescription(ZLFile file, BookDescription description);
|
public abstract boolean readMetaInfo(Book book);
|
||||||
public abstract boolean readModel(BookDescription description, BookModel model);
|
public abstract boolean readModel(BookModel model);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public static void detectEncodingAndLanguage(BookDescription description, InputStream stream) throws IOException {
|
public static void detectEncodingAndLanguage(Book book, InputStream stream) throws IOException {
|
||||||
String language = description.getLanguage();
|
String language = book.getLanguage();
|
||||||
String encoding = description.getEncoding();
|
String encoding = book.getEncoding();
|
||||||
if (encoding.length() == 0 || language.length() == 0) {
|
if (encoding.length() == 0 || language.length() == 0) {
|
||||||
PluginCollection collection = PluginCollection.instance();
|
PluginCollection collection = PluginCollection.instance();
|
||||||
if (language.length() == 0) {
|
if (language.length() == 0) {
|
||||||
|
@ -61,36 +61,36 @@ public abstract class FormatPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
description.setEncoding(encoding);
|
book.setEncoding(encoding);
|
||||||
description.setLanguage(language);
|
book.setLanguage(language);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Last working version
|
//Last working version
|
||||||
public static void detectEncodingAndLanguage(BookDescription description, InputStream stream) {
|
public static void detectEncodingAndLanguage(Book book, InputStream stream) {
|
||||||
String encoding = description.getEncoding();
|
String encoding = book.getEncoding();
|
||||||
if (encoding.length() == 0) {
|
if (encoding.length() == 0) {
|
||||||
encoding = EncodingDetector.detect(stream, PluginCollection.instance().DefaultLanguageOption.getValue());
|
encoding = EncodingDetector.detect(stream, PluginCollection.instance().DefaultLanguageOption.getValue());
|
||||||
if (encoding == "unknown") {
|
if (encoding == "unknown") {
|
||||||
encoding = "windows-1252";
|
encoding = "windows-1252";
|
||||||
}
|
}
|
||||||
description.setEncoding(encoding);
|
book.setEncoding(encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (description.getLanguage() == "") {
|
if (book.getLanguage() == "") {
|
||||||
if ((encoding.equals("US-ASCII")) ||
|
if ((encoding.equals("US-ASCII")) ||
|
||||||
(encoding.equals("ISO-8859-1"))) {
|
(encoding.equals("ISO-8859-1"))) {
|
||||||
description.setLanguage("en");
|
book.setLanguage("en");
|
||||||
} else if ((description.getEncoding().equals("KOI8-R")) ||
|
} else if ((book.getEncoding().equals("KOI8-R")) ||
|
||||||
(encoding.equals("windows-1251")) ||
|
(encoding.equals("windows-1251")) ||
|
||||||
(encoding.equals("ISO-8859-5")) ||
|
(encoding.equals("ISO-8859-5")) ||
|
||||||
(encoding.equals("IBM866"))) {
|
(encoding.equals("IBM866"))) {
|
||||||
description.setLanguage("ru");
|
book.setLanguage("ru");
|
||||||
} /*else if (
|
} /*else if (
|
||||||
(PluginCollection.instance().DefaultLanguageOption.getValue() == EncodingDetector.Language.CZECH) &&
|
(PluginCollection.instance().DefaultLanguageOption.getValue() == EncodingDetector.Language.CZECH) &&
|
||||||
((encoding == "windows-1250") ||
|
((encoding == "windows-1250") ||
|
||||||
(encoding == "ISO-8859-2") ||
|
(encoding == "ISO-8859-2") ||
|
||||||
(encoding == "IBM852"))) {
|
(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.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.xml.*;
|
import org.geometerplus.zlibrary.core.xml.*;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.collection.BookDescription;
|
import org.geometerplus.fbreader.library.Book;
|
||||||
import org.geometerplus.fbreader.collection.Tag;
|
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_NOTHING = 0;
|
||||||
private final static int READ_SOMETHING = 1;
|
private final static int READ_SOMETHING = 1;
|
||||||
private final static int READ_TITLE = 2;
|
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_LANGUAGE = 7;
|
||||||
private final static int READ_GENRE = 8;
|
private final static int READ_GENRE = 8;
|
||||||
|
|
||||||
private final BookDescription myDescription;
|
private final Book myBook;
|
||||||
private int myReadState = READ_NOTHING;
|
private int myReadState = READ_NOTHING;
|
||||||
|
|
||||||
private final String[] myAuthorNames = new String[3];
|
private final String[] myAuthorNames = new String[3];
|
||||||
private final StringBuilder myBuffer = new StringBuilder();
|
private final StringBuilder myBuffer = new StringBuilder();
|
||||||
|
|
||||||
public FB2DescriptionReader(BookDescription description) {
|
public FB2MetaInfoReader(Book book) {
|
||||||
myDescription = description;
|
myBook = book;
|
||||||
myDescription.setTitle(null);
|
myBook.setTitle(null);
|
||||||
myDescription.setLanguage(null);
|
myBook.setLanguage(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean dontCacheAttributeValues() {
|
public boolean dontCacheAttributeValues() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean readDescription(ZLFile file) {
|
public boolean readMetaInfo() {
|
||||||
myReadState = READ_NOTHING;
|
myReadState = READ_NOTHING;
|
||||||
myAuthorNames[0] = "";
|
myAuthorNames[0] = "";
|
||||||
myAuthorNames[1] = "";
|
myAuthorNames[1] = "";
|
||||||
myAuthorNames[2] = "";
|
myAuthorNames[2] = "";
|
||||||
myBuffer.delete(0, myBuffer.length());
|
myBuffer.delete(0, myBuffer.length());
|
||||||
return readDocument(file);
|
return readDocument(myBook.File);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean startElementHandler(String tagName, ZLStringMap attributes) {
|
public boolean startElementHandler(String tagName, ZLStringMap attributes) {
|
||||||
|
@ -112,7 +112,7 @@ public class FB2DescriptionReader extends ZLXMLReaderAdapter {
|
||||||
name.trim();
|
name.trim();
|
||||||
if (name.length() != 0) {
|
if (name.length() != 0) {
|
||||||
String index = attributes.getValue("number");
|
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;
|
break;
|
||||||
case FB2Tag.BOOK_TITLE:
|
case FB2Tag.BOOK_TITLE:
|
||||||
if (myReadState == READ_TITLE) {
|
if (myReadState == READ_TITLE) {
|
||||||
myDescription.setTitle(myBuffer.toString().trim());
|
myBook.setTitle(myBuffer.toString().trim());
|
||||||
myReadState = READ_SOMETHING;
|
myReadState = READ_SOMETHING;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -139,10 +139,10 @@ public class FB2DescriptionReader extends ZLXMLReaderAdapter {
|
||||||
final ArrayList<Tag> tags = FB2TagManager.humanReadableTags(genre);
|
final ArrayList<Tag> tags = FB2TagManager.humanReadableTags(genre);
|
||||||
if (tags != null) {
|
if (tags != null) {
|
||||||
for (Tag t : tags) {
|
for (Tag t : tags) {
|
||||||
myDescription.addTag(t);
|
myBook.addTag(t);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
myDescription.addTag(genre);
|
myBook.addTag(genre);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
myReadState = READ_SOMETHING;
|
myReadState = READ_SOMETHING;
|
||||||
|
@ -162,7 +162,7 @@ public class FB2DescriptionReader extends ZLXMLReaderAdapter {
|
||||||
fullName += ' ';
|
fullName += ' ';
|
||||||
}
|
}
|
||||||
fullName += myAuthorNames[2];
|
fullName += myAuthorNames[2];
|
||||||
myDescription.addAuthor(fullName, myAuthorNames[2]);
|
myBook.addAuthor(fullName, myAuthorNames[2]);
|
||||||
myAuthorNames[0] = "";
|
myAuthorNames[0] = "";
|
||||||
myAuthorNames[1] = "";
|
myAuthorNames[1] = "";
|
||||||
myAuthorNames[2] = "";
|
myAuthorNames[2] = "";
|
||||||
|
@ -171,7 +171,7 @@ public class FB2DescriptionReader extends ZLXMLReaderAdapter {
|
||||||
break;
|
break;
|
||||||
case FB2Tag.LANG:
|
case FB2Tag.LANG:
|
||||||
if (myReadState == READ_LANGUAGE) {
|
if (myReadState == READ_LANGUAGE) {
|
||||||
myDescription.setLanguage(myBuffer.toString().trim());
|
myBook.setLanguage(myBuffer.toString().trim());
|
||||||
myReadState = READ_SOMETHING;
|
myReadState = READ_SOMETHING;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
|
@ -20,20 +20,23 @@
|
||||||
package org.geometerplus.fbreader.formats.fb2;
|
package org.geometerplus.fbreader.formats.fb2;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
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.FormatPlugin;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
|
|
||||||
public class FB2Plugin extends FormatPlugin {
|
public class FB2Plugin extends FormatPlugin {
|
||||||
|
@Override
|
||||||
public boolean acceptsFile(ZLFile file) {
|
public boolean acceptsFile(ZLFile file) {
|
||||||
return "fb2".equals(file.getExtension());
|
return "fb2".equals(file.getExtension());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean readDescription(ZLFile file, BookDescription description) {
|
@Override
|
||||||
return new FB2DescriptionReader(description).readDescription(file);
|
public boolean readMetaInfo(Book book) {
|
||||||
|
return new FB2MetaInfoReader(book).readMetaInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean readModel(BookDescription description, BookModel model) {
|
@Override
|
||||||
return new FB2Reader(model).readBook(description.File);
|
public boolean readModel(BookModel model) {
|
||||||
|
return new FB2Reader(model).readBook();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,10 +53,10 @@ public final class FB2Reader extends BookReader implements ZLXMLReader {
|
||||||
super(model);
|
super(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean readBook(ZLFile file) {
|
boolean readBook() {
|
||||||
Base64EncodedImage.resetCounter();
|
Base64EncodedImage.resetCounter();
|
||||||
final ZLXMLProcessor processor = ZLXMLProcessorFactory.Instance().createXMLProcessor();
|
final ZLXMLProcessor processor = ZLXMLProcessorFactory.Instance().createXMLProcessor();
|
||||||
return processor.read(this, file);
|
return processor.read(this, Model.Book.File);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startDocumentHandler() {
|
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.filesystem.ZLResourceFile;
|
||||||
import org.geometerplus.zlibrary.core.xml.*;
|
import org.geometerplus.zlibrary.core.xml.*;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.collection.Tag;
|
import org.geometerplus.fbreader.library.Tag;
|
||||||
|
|
||||||
abstract class FB2TagManager {
|
abstract class FB2TagManager {
|
||||||
private static final HashMap<String,ArrayList<Tag>> ourMap = new HashMap<String,ArrayList<Tag>>();
|
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.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.xml.*;
|
import org.geometerplus.zlibrary.core.xml.*;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.collection.BookDescription;
|
import org.geometerplus.fbreader.library.Book;
|
||||||
|
|
||||||
public class HtmlDescriptionReader extends ZLXMLReaderAdapter {
|
public class HtmlMetaInfoReader extends ZLXMLReaderAdapter {
|
||||||
private final BookDescription myDescription;
|
private final Book myBook;
|
||||||
|
|
||||||
private boolean myReadTitle;
|
private boolean myReadTitle;
|
||||||
|
|
||||||
public HtmlDescriptionReader(BookDescription description) {
|
public HtmlMetaInfoReader(Book book) {
|
||||||
myDescription = description;
|
myBook = book;
|
||||||
myDescription.setTitle("");
|
myBook.setTitle("");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean dontCacheAttributeValues() {
|
public boolean dontCacheAttributeValues() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean readDescription(ZLFile file) {
|
public boolean readMetaInfo() {
|
||||||
myReadTitle = false;
|
myReadTitle = false;
|
||||||
return readDocument(file);
|
return readDocument(myBook.File);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean startElementHandler(String tagName, ZLStringMap attributes) {
|
public boolean startElementHandler(String tagName, ZLStringMap attributes) {
|
||||||
|
@ -69,7 +69,7 @@ public class HtmlDescriptionReader extends ZLXMLReaderAdapter {
|
||||||
// TODO + length -- remove
|
// TODO + length -- remove
|
||||||
final String text = new String(ch).substring(start, start + length);
|
final String text = new String(ch).substring(start, start + length);
|
||||||
if (myReadTitle) {
|
if (myReadTitle) {
|
||||||
myDescription.setTitle(myDescription.getTitle() + text);
|
myBook.setTitle(myBook.getTitle() + text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,13 +20,10 @@
|
||||||
package org.geometerplus.fbreader.formats.html;
|
package org.geometerplus.fbreader.formats.html;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
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.FormatPlugin;
|
||||||
import org.geometerplus.fbreader.formats.fb2.FB2DescriptionReader;
|
|
||||||
import org.geometerplus.fbreader.formats.fb2.FB2Reader;
|
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
|
|
||||||
|
|
||||||
public class HtmlPlugin extends FormatPlugin {
|
public class HtmlPlugin extends FormatPlugin {
|
||||||
private final static String AUTO = "auto";
|
private final static String AUTO = "auto";
|
||||||
|
|
||||||
|
@ -37,16 +34,16 @@ public class HtmlPlugin extends FormatPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean readDescription(ZLFile file, BookDescription description) {
|
public boolean readMetaInfo(Book book) {
|
||||||
return new HtmlDescriptionReader(description).readDescription(file);
|
return new HtmlMetaInfoReader(book).readMetaInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean readModel(BookDescription description, BookModel model) {
|
public boolean readModel(BookModel model) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
if (!description.getEncoding().equals(AUTO)) {
|
if (!model.Book.getEncoding().equals(AUTO)) {
|
||||||
//new BookDescription.BookInfo(description.FileName).EncodingOption.setValue(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);
|
super(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean read() {
|
boolean readBook() {
|
||||||
final ZLHtmlProcessor processor = ZLHtmlProcessorFactory.Instance()
|
final ZLHtmlProcessor processor = ZLHtmlProcessorFactory.Instance()
|
||||||
.createHtmlProcessor();
|
.createHtmlProcessor();
|
||||||
return processor.read(this, Model.Description.File);
|
return processor.read(this, Model.Book.File);
|
||||||
}
|
|
||||||
|
|
||||||
boolean readBook(ZLFile file) {
|
|
||||||
final ZLHtmlProcessor processor = ZLHtmlProcessorFactory.Instance()
|
|
||||||
.createHtmlProcessor();
|
|
||||||
return processor.read(this, file);
|
|
||||||
// return readDocument(fileName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startDocumentHandler() {
|
public void startDocumentHandler() {
|
||||||
|
@ -328,7 +321,7 @@ public class HtmlReader extends BookReader implements ZLHtmlReader {
|
||||||
addImageReference(ref, (short)0);
|
addImageReference(ref, (short)0);
|
||||||
String filePath = ref;
|
String filePath = ref;
|
||||||
if (!":\\".equals(ref.substring(1, 3))) {
|
if (!":\\".equals(ref.substring(1, 3))) {
|
||||||
filePath = Model.Description.File.getPath();
|
filePath = Model.Book.File.getPath();
|
||||||
filePath = filePath.substring(0, filePath.lastIndexOf('\\') + 1) + ref;
|
filePath = filePath.substring(0, filePath.lastIndexOf('\\') + 1) + ref;
|
||||||
}
|
}
|
||||||
addImage(ref, new ZLFileImage("image/auto", ZLFile.createFileByPath(filePath)));
|
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.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.xml.*;
|
import org.geometerplus.zlibrary.core.xml.*;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.collection.BookDescription;
|
import org.geometerplus.fbreader.library.Book;
|
||||||
import org.geometerplus.fbreader.constants.XMLNamespace;
|
import org.geometerplus.fbreader.constants.XMLNamespace;
|
||||||
|
|
||||||
class OEBDescriptionReader extends ZLXMLReaderAdapter implements XMLNamespace {
|
class OEBMetaInfoReader extends ZLXMLReaderAdapter implements XMLNamespace {
|
||||||
private final BookDescription myDescription;
|
private final Book myBook;
|
||||||
|
|
||||||
private String myDCMetadataTag = "dc-metadata";
|
private String myDCMetadataTag = "dc-metadata";
|
||||||
private String myMetadataTag = "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> myAuthorList = new ArrayList<String>();
|
||||||
private final ArrayList<String> myAuthorList2 = new ArrayList<String>();
|
private final ArrayList<String> myAuthorList2 = new ArrayList<String>();
|
||||||
|
|
||||||
OEBDescriptionReader(BookDescription description) {
|
OEBMetaInfoReader(Book book) {
|
||||||
myDescription = description;
|
myBook = book;
|
||||||
myDescription.setTitle(null);
|
myBook.setTitle(null);
|
||||||
myDescription.setLanguage(null);
|
myBook.setLanguage(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean readDescription(ZLFile file) {
|
boolean readMetaInfo(ZLFile file) {
|
||||||
myReadMetaData = false;
|
myReadMetaData = false;
|
||||||
myReadState = READ_NONE;
|
myReadState = READ_NONE;
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ class OEBDescriptionReader extends ZLXMLReaderAdapter implements XMLNamespace {
|
||||||
} else {
|
} else {
|
||||||
a = a.trim();
|
a = a.trim();
|
||||||
}
|
}
|
||||||
myDescription.addAuthor(a);
|
myBook.addAuthor(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -155,7 +155,7 @@ class OEBDescriptionReader extends ZLXMLReaderAdapter implements XMLNamespace {
|
||||||
if (bufferContent.length() != 0) {
|
if (bufferContent.length() != 0) {
|
||||||
switch (myReadState) {
|
switch (myReadState) {
|
||||||
case READ_TITLE:
|
case READ_TITLE:
|
||||||
myDescription.setTitle(bufferContent);
|
myBook.setTitle(bufferContent);
|
||||||
break;
|
break;
|
||||||
case READ_AUTHOR:
|
case READ_AUTHOR:
|
||||||
myAuthorList.add(bufferContent);
|
myAuthorList.add(bufferContent);
|
||||||
|
@ -164,7 +164,7 @@ class OEBDescriptionReader extends ZLXMLReaderAdapter implements XMLNamespace {
|
||||||
myAuthorList2.add(bufferContent);
|
myAuthorList2.add(bufferContent);
|
||||||
break;
|
break;
|
||||||
case READ_SUBJECT:
|
case READ_SUBJECT:
|
||||||
myDescription.addTag(bufferContent);
|
myBook.addTag(bufferContent);
|
||||||
break;
|
break;
|
||||||
case READ_LANGUAGE:
|
case READ_LANGUAGE:
|
||||||
{
|
{
|
||||||
|
@ -176,7 +176,7 @@ class OEBDescriptionReader extends ZLXMLReaderAdapter implements XMLNamespace {
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
bufferContent = bufferContent.substring(0, index);
|
bufferContent = bufferContent.substring(0, index);
|
||||||
}
|
}
|
||||||
myDescription.setLanguage("cz".equals(bufferContent) ? "cs" : bufferContent);
|
myBook.setLanguage("cz".equals(bufferContent) ? "cs" : bufferContent);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
|
@ -22,7 +22,7 @@ package org.geometerplus.fbreader.formats.oeb;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
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.FormatPlugin;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.*;
|
import org.geometerplus.zlibrary.core.filesystem.*;
|
||||||
|
|
||||||
|
@ -45,14 +45,14 @@ public class OEBPlugin extends FormatPlugin {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean readDescription(ZLFile file, BookDescription description) {
|
public boolean readMetaInfo(Book book) {
|
||||||
final ZLFile opfFile = getOpfFile(file);
|
final ZLFile opfFile = getOpfFile(book.File);
|
||||||
return (opfFile != null) ? new OEBDescriptionReader(description).readDescription(opfFile) : false;
|
return (opfFile != null) ? new OEBMetaInfoReader(book).readMetaInfo(opfFile) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean readModel(BookDescription description, BookModel model) {
|
public boolean readModel(BookModel model) {
|
||||||
description.File.setCached(true);
|
model.Book.File.setCached(true);
|
||||||
final ZLFile opfFile = getOpfFile(description.File);
|
final ZLFile opfFile = getOpfFile(model.Book.File);
|
||||||
return (opfFile != null) ? new OEBBookReader(model).readBook(opfFile) : false;
|
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) {
|
if (((Integer) ((Pair)list.get(k)).myFirst) != -1) {
|
||||||
//addHyperlinkLabel(fromNumber(first) + '#' + fromNumber(second), (Integer)list.get(k));
|
//addHyperlinkLabel(fromNumber(first) + '#' + fromNumber(second), (Integer)list.get(k));
|
||||||
final Pair p = (Pair)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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,7 +194,7 @@ public class PluckerBookReader extends BookReader {
|
||||||
processTextRecord(size, pars);
|
processTextRecord(size, pars);
|
||||||
if ((flags & 0x1) == 0) {
|
if ((flags & 0x1) == 0) {
|
||||||
// insertEndOfTextParagraph();
|
// insertEndOfTextParagraph();
|
||||||
setNewTextModel();
|
//setNewTextModel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -482,8 +482,8 @@ public class PluckerBookReader extends BookReader {
|
||||||
myBufferIsEmpty = true;
|
myBufferIsEmpty = true;
|
||||||
beginParagraph(ZLTextParagraph.Kind.TEXT_PARAGRAPH);
|
beginParagraph(ZLTextParagraph.Kind.TEXT_PARAGRAPH);
|
||||||
if (!myParagraphStored) {
|
if (!myParagraphStored) {
|
||||||
final ArrayList models = Model.getBookTextModels();
|
//final ArrayList models = Model.getBookTextModels();
|
||||||
myParagraphVector.add(new Pair(((ZLTextPlainModel) models.get(models.size()-1)/*BookTextModel*/).getParagraphsNumber() - 1, models.size() - 1));
|
//myParagraphVector.add(new Pair(((ZLTextPlainModel) models.get(models.size()-1)/*BookTextModel*/).getParagraphsNumber() - 1, models.size() - 1));
|
||||||
myParagraphStored = true;
|
myParagraphStored = true;
|
||||||
}
|
}
|
||||||
for (Iterator it = myDelayedControls.iterator(); it.hasNext(); ) {
|
for (Iterator it = myDelayedControls.iterator(); it.hasNext(); ) {
|
||||||
|
|
|
@ -22,36 +22,39 @@ package org.geometerplus.fbreader.formats.plucker;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
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.PdbPlugin;
|
||||||
import org.geometerplus.fbreader.formats.pdb.PdbStream;
|
import org.geometerplus.fbreader.formats.pdb.PdbStream;
|
||||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
|
|
||||||
public class PluckerPlugin extends PdbPlugin {
|
public class PluckerPlugin extends PdbPlugin {
|
||||||
|
@Override
|
||||||
public boolean acceptsFile(ZLFile file) {
|
public boolean acceptsFile(ZLFile file) {
|
||||||
return "DataPlkr".equals(fileType(file));
|
return "DataPlkr".equals(fileType(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean readDescription(ZLFile file, BookDescription description) {
|
@Override
|
||||||
|
public boolean readMetaInfo(Book book) {
|
||||||
try {
|
try {
|
||||||
PdbStream stream = new PluckerTextStream(file);
|
PdbStream stream = new PluckerTextStream(book.File);
|
||||||
if (stream.open()) {
|
if (stream.open()) {
|
||||||
//detectEncodingAndLanguage(description, stream);
|
//detectEncodingAndLanguage(book, stream);
|
||||||
stream.close();
|
stream.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (description.getEncoding().length() == 0) {
|
if (book.getEncoding().length() == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean readModel(BookDescription description, BookModel model) {
|
@Override
|
||||||
|
public boolean readModel(BookModel model) {
|
||||||
try {
|
try {
|
||||||
return new PluckerBookReader(description.File, model, description.getEncoding()).readDocument();
|
return new PluckerBookReader(model.Book.File, model, model.Book.getEncoding()).readDocument();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.geometerplus.fbreader.collection;
|
package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import org.geometerplus.zlibrary.core.util.*;
|
import org.geometerplus.zlibrary.core.util.*;
|
|
@ -17,14 +17,14 @@
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.geometerplus.fbreader.collection;
|
package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
|
||||||
public class AuthorTree extends CollectionTree {
|
public class AuthorTree extends LibraryTree {
|
||||||
private final Author myAuthor;
|
private final Author myAuthor;
|
||||||
|
|
||||||
AuthorTree(CollectionTree parent, Author author) {
|
AuthorTree(LibraryTree parent, Author author) {
|
||||||
super(parent);
|
super(parent);
|
||||||
myAuthor = author;
|
myAuthor = author;
|
||||||
}
|
}
|
|
@ -17,7 +17,7 @@
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.geometerplus.fbreader.collection;
|
package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
@ -26,8 +26,8 @@ import org.geometerplus.zlibrary.core.filesystem.*;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.formats.*;
|
import org.geometerplus.fbreader.formats.*;
|
||||||
|
|
||||||
public class BookDescription {
|
public class Book {
|
||||||
public static BookDescription getDescription(ZLFile bookFile) {
|
public static Book getBook(ZLFile bookFile) {
|
||||||
if (bookFile == null) {
|
if (bookFile == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -37,30 +37,30 @@ public class BookDescription {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
final BookDescription description = new BookDescription(bookFile, true);
|
final Book book = new Book(bookFile, true);
|
||||||
|
|
||||||
FileInfoSet fileInfos = new FileInfoSet();
|
FileInfoSet fileInfos = new FileInfoSet();
|
||||||
fileInfos.load(physicalFile);
|
fileInfos.load(physicalFile);
|
||||||
if (fileInfos.check(physicalFile) && description.myIsSaved) {
|
if (fileInfos.check(physicalFile) && book.myIsSaved) {
|
||||||
return description;
|
return book;
|
||||||
}
|
}
|
||||||
fileInfos.save();
|
fileInfos.save();
|
||||||
|
|
||||||
final FormatPlugin plugin = PluginCollection.instance().getPlugin(bookFile);
|
final FormatPlugin plugin = PluginCollection.instance().getPlugin(bookFile);
|
||||||
if ((plugin == null) || !plugin.readDescription(bookFile, description)) {
|
if ((plugin == null) || !plugin.readMetaInfo(book)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String title = description.getTitle();
|
String title = book.getTitle();
|
||||||
if ((title == null) || (title.length() == 0)) {
|
if ((title == null) || (title.length() == 0)) {
|
||||||
description.setTitle(bookFile.getName(true));
|
book.setTitle(bookFile.getName(true));
|
||||||
}
|
}
|
||||||
return description;
|
return book;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final ZLFile File;
|
public final ZLFile File;
|
||||||
|
|
||||||
private long myBookId;
|
private long myId;
|
||||||
|
|
||||||
private String myEncoding;
|
private String myEncoding;
|
||||||
private String myLanguage;
|
private String myLanguage;
|
||||||
|
@ -71,8 +71,8 @@ public class BookDescription {
|
||||||
|
|
||||||
private boolean myIsSaved;
|
private boolean myIsSaved;
|
||||||
|
|
||||||
BookDescription(long bookId, ZLFile file, String title, String encoding, String language) {
|
Book(long id, ZLFile file, String title, String encoding, String language) {
|
||||||
myBookId = bookId;
|
myId = id;
|
||||||
File = file;
|
File = file;
|
||||||
myTitle = title;
|
myTitle = title;
|
||||||
myEncoding = encoding;
|
myEncoding = encoding;
|
||||||
|
@ -80,19 +80,19 @@ public class BookDescription {
|
||||||
myIsSaved = true;
|
myIsSaved = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
BookDescription(ZLFile file, boolean createFromDatabase) {
|
Book(ZLFile file, boolean createFromDatabase) {
|
||||||
File = file;
|
File = file;
|
||||||
if (createFromDatabase) {
|
if (createFromDatabase) {
|
||||||
final BooksDatabase database = BooksDatabase.Instance();
|
final BooksDatabase database = BooksDatabase.Instance();
|
||||||
myBookId = database.loadBook(this);
|
myId = database.loadBook(this);
|
||||||
if (myBookId >= 0) {
|
if (myId >= 0) {
|
||||||
myAuthors = database.loadAuthors(myBookId);
|
myAuthors = database.loadAuthors(myId);
|
||||||
myTags = database.loadTags(myBookId);
|
myTags = database.loadTags(myId);
|
||||||
mySeriesInfo = database.loadSeriesInfo(myBookId);
|
mySeriesInfo = database.loadSeriesInfo(myId);
|
||||||
myIsSaved = true;
|
myIsSaved = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
myBookId = -1;
|
myId = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,8 +150,8 @@ public class BookDescription {
|
||||||
addAuthor(new Author(strippedName, strippedKey));
|
addAuthor(new Author(strippedName, strippedKey));
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getBookId() {
|
public long getId() {
|
||||||
return myBookId;
|
return myId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
|
@ -273,22 +273,22 @@ public class BookDescription {
|
||||||
final BooksDatabase database = BooksDatabase.Instance();
|
final BooksDatabase database = BooksDatabase.Instance();
|
||||||
database.executeAsATransaction(new Runnable() {
|
database.executeAsATransaction(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (myBookId >= 0) {
|
if (myId >= 0) {
|
||||||
database.updateBookInfo(myBookId, myEncoding, myLanguage, myTitle);
|
database.updateBookInfo(myId, myEncoding, myLanguage, myTitle);
|
||||||
} else {
|
} else {
|
||||||
myBookId = database.insertBookInfo(File.getPath(), myEncoding, myLanguage, myTitle);
|
myId = database.insertBookInfo(File.getPath(), myEncoding, myLanguage, myTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
long index = 0;
|
long index = 0;
|
||||||
database.deleteAllBookAuthors(myBookId);
|
database.deleteAllBookAuthors(myId);
|
||||||
for (Author author : authors()) {
|
for (Author author : authors()) {
|
||||||
database.saveBookAuthorInfo(myBookId, index++, author);
|
database.saveBookAuthorInfo(myId, index++, author);
|
||||||
}
|
}
|
||||||
database.deleteAllBookTags(myBookId);
|
database.deleteAllBookTags(myId);
|
||||||
for (Tag tag : tags()) {
|
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.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.geometerplus.fbreader.collection;
|
package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
public final class BookInSeriesTree extends BookTree {
|
public final class BookInSeriesTree extends BookTree {
|
||||||
BookInSeriesTree(CollectionTree parent, BookDescription description) {
|
BookInSeriesTree(LibraryTree parent, Book book) {
|
||||||
super(parent, description, false);
|
super(parent, book, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(CollectionTree tree) {
|
public int compareTo(LibraryTree tree) {
|
||||||
if (tree instanceof BookInSeriesTree) {
|
if (tree instanceof BookInSeriesTree) {
|
||||||
final long difference =
|
final long difference =
|
||||||
Description.getSeriesInfo().Index - ((BookTree)tree).Description.getSeriesInfo().Index;
|
Book.getSeriesInfo().Index - ((BookTree)tree).Book.getSeriesInfo().Index;
|
||||||
if (difference != 0) {
|
if (difference != 0) {
|
||||||
return (int)difference;
|
return (int)difference;
|
||||||
}
|
}
|
|
@ -17,20 +17,20 @@
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.geometerplus.fbreader.collection;
|
package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
public class BookTree extends CollectionTree {
|
public class BookTree extends LibraryTree {
|
||||||
public final BookDescription Description;
|
public final Book Book;
|
||||||
private final boolean myShowAuthors;
|
private final boolean myShowAuthors;
|
||||||
|
|
||||||
BookTree(CollectionTree parent, BookDescription description, boolean showAuthors) {
|
BookTree(LibraryTree parent, Book book, boolean showAuthors) {
|
||||||
super(parent);
|
super(parent);
|
||||||
Description = description;
|
Book = book;
|
||||||
myShowAuthors = showAuthors;
|
myShowAuthors = showAuthors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return Description.getTitle();
|
return Book.getTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String myAuthorsString;
|
private String myAuthorsString;
|
||||||
|
@ -41,7 +41,7 @@ public class BookTree extends CollectionTree {
|
||||||
if (myAuthorsString == null) {
|
if (myAuthorsString == null) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (Author author : Description.authors()) {
|
for (Author author : Book.authors()) {
|
||||||
if (count++ > 0) {
|
if (count++ > 0) {
|
||||||
builder.append(", ");
|
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.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.geometerplus.fbreader.collection;
|
package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
@ -34,22 +34,22 @@ public abstract class BooksDatabase {
|
||||||
ourInstance = this;
|
ourInstance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected BookDescription createDescription(long bookId, String filePath, String title, String encoding, String language) {
|
protected Book createBook(long id, String filePath, String title, String encoding, String language) {
|
||||||
return new BookDescription(bookId, ZLFile.createFileByPath(filePath), title, encoding, language);
|
return new Book(id, ZLFile.createFileByPath(filePath), title, encoding, language);
|
||||||
}
|
}
|
||||||
protected void addAuthor(BookDescription description, Author author) {
|
protected void addAuthor(Book book, Author author) {
|
||||||
description.addAuthorWithNoCheck(author);
|
book.addAuthorWithNoCheck(author);
|
||||||
}
|
}
|
||||||
protected void addTag(BookDescription description, Tag tag) {
|
protected void addTag(Book book, Tag tag) {
|
||||||
description.addTagWithNoCheck(tag);
|
book.addTagWithNoCheck(tag);
|
||||||
}
|
}
|
||||||
protected void setSeriesInfo(BookDescription description, String series, long index) {
|
protected void setSeriesInfo(Book book, String series, long index) {
|
||||||
description.setSeriesInfoWithNoCheck(series, 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 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<Author> loadAuthors(long bookId);
|
||||||
protected abstract List<Tag> loadTags(long bookId);
|
protected abstract List<Tag> loadTags(long bookId);
|
||||||
protected abstract SeriesInfo loadSeriesInfo(long bookId);
|
protected abstract SeriesInfo loadSeriesInfo(long bookId);
|
||||||
|
@ -73,4 +73,11 @@ public abstract class BooksDatabase {
|
||||||
|
|
||||||
protected abstract List<Long> listRecentBookIds();
|
protected abstract List<Long> listRecentBookIds();
|
||||||
protected abstract void saveRecentBookIds(final List<Long> ids);
|
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.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.geometerplus.fbreader.collection;
|
package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.tree.ZLTree;
|
import org.geometerplus.zlibrary.core.tree.ZLTree;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.geometerplus.fbreader.collection;
|
package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.geometerplus.fbreader.collection;
|
package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -27,12 +27,12 @@ import org.geometerplus.zlibrary.core.library.ZLibrary;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.formats.*;
|
import org.geometerplus.fbreader.formats.*;
|
||||||
|
|
||||||
public final class BookCollection {
|
public final class Library {
|
||||||
private static BookCollection ourInstance;
|
private static Library ourInstance;
|
||||||
|
|
||||||
public static BookCollection Instance() {
|
public static Library Instance() {
|
||||||
if (ourInstance == null) {
|
if (ourInstance == null) {
|
||||||
ourInstance = new BookCollection();
|
ourInstance = new Library();
|
||||||
}
|
}
|
||||||
return ourInstance;
|
return ourInstance;
|
||||||
}
|
}
|
||||||
|
@ -40,23 +40,23 @@ public final class BookCollection {
|
||||||
// TODO: this option is platform-dependent
|
// TODO: this option is platform-dependent
|
||||||
private final ZLFile BookDirectory = new ZLPhysicalFile(new File("/sdcard/Books"));
|
private final ZLFile BookDirectory = new ZLPhysicalFile(new File("/sdcard/Books"));
|
||||||
|
|
||||||
private final LinkedList<BookDescription> myBookDescriptions = new LinkedList<BookDescription>();
|
private final LinkedList<Book> myBooks = new LinkedList<Book>();
|
||||||
private final CollectionTree myCollectionByAuthor = new RootTree();
|
private final LibraryTree myLibraryByAuthor = new RootTree();
|
||||||
private final CollectionTree myCollectionByTag = new RootTree();
|
private final LibraryTree myLibraryByTag = new RootTree();
|
||||||
private final CollectionTree myRecentBooks = new RootTree();
|
private final LibraryTree myRecentBooks = new RootTree();
|
||||||
private final CollectionTree mySearchResult = new RootTree();
|
private final LibraryTree mySearchResult = new RootTree();
|
||||||
|
|
||||||
private boolean myDoRebuild = true;
|
private boolean myDoRebuild = true;
|
||||||
|
|
||||||
private BookCollection() {
|
private Library() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
myDoRebuild = true;
|
myDoRebuild = true;
|
||||||
|
|
||||||
myBookDescriptions.clear();
|
myBooks.clear();
|
||||||
myCollectionByAuthor.clear();
|
myLibraryByAuthor.clear();
|
||||||
myCollectionByTag.clear();
|
myLibraryByTag.clear();
|
||||||
myRecentBooks.clear();
|
myRecentBooks.clear();
|
||||||
mySearchResult.clear();
|
mySearchResult.clear();
|
||||||
}
|
}
|
||||||
|
@ -72,38 +72,38 @@ public final class BookCollection {
|
||||||
return ZLResourceFile.createResourceFile("data/help/MiniHelp.en.fb2");
|
return ZLResourceFile.createResourceFile("data/help/MiniHelp.en.fb2");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BookDescription getDescription(ZLFile bookFile, Map<String,BookDescription> saved, boolean doReadMetaInfo) {
|
private static Book getBook(ZLFile bookFile, Map<String,Book> saved, boolean doReadMetaInfo) {
|
||||||
BookDescription description = saved.get(bookFile.getPath());
|
Book book = saved.get(bookFile.getPath());
|
||||||
if (description == null) {
|
if (book == null) {
|
||||||
doReadMetaInfo = true;
|
doReadMetaInfo = true;
|
||||||
description = new BookDescription(bookFile, false);
|
book = new Book(bookFile, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doReadMetaInfo) {
|
if (doReadMetaInfo) {
|
||||||
final FormatPlugin plugin = PluginCollection.instance().getPlugin(bookFile);
|
final FormatPlugin plugin = PluginCollection.instance().getPlugin(book.File);
|
||||||
if ((plugin == null) || !plugin.readDescription(bookFile, description)) {
|
if ((plugin == null) || !plugin.readMetaInfo(book)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String title = description.getTitle();
|
String title = book.getTitle();
|
||||||
if ((title == null) || (title.length() == 0)) {
|
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,
|
ZLFile file,
|
||||||
FileInfoSet fileInfos,
|
FileInfoSet fileInfos,
|
||||||
Map<String,BookDescription> savedDescriptions,
|
Map<String,Book> savedBooks,
|
||||||
boolean doReadMetaInfo
|
boolean doReadMetaInfo
|
||||||
) {
|
) {
|
||||||
BookDescription description = getDescription(file, savedDescriptions, doReadMetaInfo);
|
Book book = getBook(file, savedBooks, doReadMetaInfo);
|
||||||
if (description != null) {
|
if (book != null) {
|
||||||
myBookDescriptions.add(description);
|
myBooks.add(book);
|
||||||
} else if (file.isArchive()) {
|
} else if (file.isArchive()) {
|
||||||
for (ZLFile entry : fileInfos.archiveEntries(file)) {
|
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;
|
return fileList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void collectBookDescriptions() {
|
private void collectBooks() {
|
||||||
//android.os.Debug.startMethodTracing("/sdcard/ll0");
|
//android.os.Debug.startMethodTracing("/sdcard/ll0");
|
||||||
final List<ZLPhysicalFile> physicalFilesList = collectPhysicalFiles();
|
final List<ZLPhysicalFile> physicalFilesList = collectPhysicalFiles();
|
||||||
//android.os.Debug.stopMethodTracing();
|
//android.os.Debug.stopMethodTracing();
|
||||||
//System.err.println(physicalFilesList.size() + " files " + System.currentTimeMillis() % 20000);
|
//System.err.println(physicalFilesList.size() + " files " + System.currentTimeMillis() % 20000);
|
||||||
//android.os.Debug.startMethodTracing("/sdcard/ll1");
|
//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();
|
//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");
|
//android.os.Debug.startMethodTracing("/sdcard/ll2");
|
||||||
FileInfoSet fileInfos = new FileInfoSet();
|
FileInfoSet fileInfos = new FileInfoSet();
|
||||||
|
@ -151,12 +151,12 @@ public final class BookCollection {
|
||||||
|
|
||||||
//android.os.Debug.startMethodTracing("/sdcard/ll3");
|
//android.os.Debug.startMethodTracing("/sdcard/ll3");
|
||||||
for (ZLPhysicalFile file : physicalFilesList) {
|
for (ZLPhysicalFile file : physicalFilesList) {
|
||||||
collectBookDescriptions(file, fileInfos, savedDescriptions, !fileInfos.check(file));
|
collectBooks(file, fileInfos, savedBooks, !fileInfos.check(file));
|
||||||
file.setCached(false);
|
file.setCached(false);
|
||||||
}
|
}
|
||||||
myBookDescriptions.add(getDescription(getHelpFile(), savedDescriptions, false));
|
myBooks.add(getBook(getHelpFile(), savedBooks, false));
|
||||||
//android.os.Debug.stopMethodTracing();
|
//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");
|
//android.os.Debug.startMethodTracing("/sdcard/ll4");
|
||||||
fileInfos.save();
|
fileInfos.save();
|
||||||
|
@ -193,9 +193,9 @@ public final class BookCollection {
|
||||||
private TagTree getTagTree(Tag tag, HashMap<Tag,TagTree> tagTreeMap) {
|
private TagTree getTagTree(Tag tag, HashMap<Tag,TagTree> tagTreeMap) {
|
||||||
TagTree tagTree = tagTreeMap.get(tag);
|
TagTree tagTree = tagTreeMap.get(tag);
|
||||||
if (tagTree == null) {
|
if (tagTree == null) {
|
||||||
CollectionTree parent =
|
LibraryTree parent =
|
||||||
((tag != null) && (tag.Parent != null)) ?
|
((tag != null) && (tag.Parent != null)) ?
|
||||||
getTagTree(tag.Parent, tagTreeMap) : myCollectionByTag;
|
getTagTree(tag.Parent, tagTreeMap) : myLibraryByTag;
|
||||||
tagTree = parent.createTagSubTree(tag);
|
tagTree = parent.createTagSubTree(tag);
|
||||||
tagTreeMap.put(tag, tagTree);
|
tagTreeMap.put(tag, tagTree);
|
||||||
}
|
}
|
||||||
|
@ -207,25 +207,25 @@ public final class BookCollection {
|
||||||
final HashMap<Tag,TagTree> tagTreeMap = new HashMap<Tag,TagTree>();
|
final HashMap<Tag,TagTree> tagTreeMap = new HashMap<Tag,TagTree>();
|
||||||
final HashMap<Author,AuthorTree> authorTreeMap = new HashMap<Author,AuthorTree>();
|
final HashMap<Author,AuthorTree> authorTreeMap = new HashMap<Author,AuthorTree>();
|
||||||
final HashMap<AuthorSeriesPair,SeriesTree> seriesTreeMap = new HashMap<AuthorSeriesPair,SeriesTree>();
|
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();
|
collectBooks();
|
||||||
//System.err.println(myBookDescriptions.size() + " books " + System.currentTimeMillis() % 20000);
|
//System.err.println(myBooks.size() + " books " + System.currentTimeMillis() % 20000);
|
||||||
for (BookDescription description : myBookDescriptions) {
|
for (Book book : myBooks) {
|
||||||
bookById.put(description.getBookId(), description);
|
bookById.put(book.getId(), book);
|
||||||
List<Author> authors = description.authors();
|
List<Author> authors = book.authors();
|
||||||
if (authors.isEmpty()) {
|
if (authors.isEmpty()) {
|
||||||
authors = (List<Author>)ourNullList;
|
authors = (List<Author>)ourNullList;
|
||||||
}
|
}
|
||||||
final SeriesInfo seriesInfo = description.getSeriesInfo();
|
final SeriesInfo seriesInfo = book.getSeriesInfo();
|
||||||
for (Author a : authors) {
|
for (Author a : authors) {
|
||||||
AuthorTree authorTree = authorTreeMap.get(a);
|
AuthorTree authorTree = authorTreeMap.get(a);
|
||||||
if (authorTree == null) {
|
if (authorTree == null) {
|
||||||
authorTree = myCollectionByAuthor.createAuthorSubTree(a);
|
authorTree = myLibraryByAuthor.createAuthorSubTree(a);
|
||||||
authorTreeMap.put(a, authorTree);
|
authorTreeMap.put(a, authorTree);
|
||||||
}
|
}
|
||||||
if (seriesInfo == null) {
|
if (seriesInfo == null) {
|
||||||
authorTree.createBookSubTree(description, false);
|
authorTree.createBookSubTree(book, false);
|
||||||
} else {
|
} else {
|
||||||
final String series = seriesInfo.Name;
|
final String series = seriesInfo.Name;
|
||||||
final AuthorSeriesPair pair = new AuthorSeriesPair(a, series);
|
final AuthorSeriesPair pair = new AuthorSeriesPair(a, series);
|
||||||
|
@ -234,31 +234,31 @@ public final class BookCollection {
|
||||||
seriesTree = authorTree.createSeriesSubTree(series);
|
seriesTree = authorTree.createSeriesSubTree(series);
|
||||||
seriesTreeMap.put(pair, seriesTree);
|
seriesTreeMap.put(pair, seriesTree);
|
||||||
}
|
}
|
||||||
seriesTree.createBookInSeriesSubTree(description);
|
seriesTree.createBookInSeriesSubTree(book);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Tag> tags = description.tags();
|
List<Tag> tags = book.tags();
|
||||||
if (tags.isEmpty()) {
|
if (tags.isEmpty()) {
|
||||||
tags = (List<Tag>)ourNullList;
|
tags = (List<Tag>)ourNullList;
|
||||||
}
|
}
|
||||||
for (Tag t : tags) {
|
for (Tag t : tags) {
|
||||||
getTagTree(t, tagTreeMap).createBookSubTree(description, true);
|
getTagTree(t, tagTreeMap).createBookSubTree(book, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final BooksDatabase db = BooksDatabase.Instance();
|
final BooksDatabase db = BooksDatabase.Instance();
|
||||||
for (long id : db.listRecentBookIds()) {
|
for (long id : db.listRecentBookIds()) {
|
||||||
BookDescription description = bookById.get(id);
|
Book book = bookById.get(id);
|
||||||
if (description != null) {
|
if (book != null) {
|
||||||
myRecentBooks.createBookSubTree(description, true);
|
myRecentBooks.createBookSubTree(book, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
db.executeAsATransaction(new Runnable() {
|
db.executeAsATransaction(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
for (BookDescription description : myBookDescriptions) {
|
for (Book book : myBooks) {
|
||||||
description.save();
|
book.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -269,34 +269,34 @@ public final class BookCollection {
|
||||||
if (myDoRebuild) {
|
if (myDoRebuild) {
|
||||||
build();
|
build();
|
||||||
|
|
||||||
myCollectionByAuthor.sortAllChildren();
|
myLibraryByAuthor.sortAllChildren();
|
||||||
myCollectionByTag.sortAllChildren();
|
myLibraryByTag.sortAllChildren();
|
||||||
|
|
||||||
myDoRebuild = false;
|
myDoRebuild = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CollectionTree collectionByAuthor() {
|
public LibraryTree byAuthor() {
|
||||||
synchronize();
|
synchronize();
|
||||||
return myCollectionByAuthor;
|
return myLibraryByAuthor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CollectionTree collectionByTag() {
|
public LibraryTree byTag() {
|
||||||
synchronize();
|
synchronize();
|
||||||
return myCollectionByTag;
|
return myLibraryByTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CollectionTree recentBooks() {
|
public LibraryTree recentBooks() {
|
||||||
synchronize();
|
synchronize();
|
||||||
return myRecentBooks;
|
return myRecentBooks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CollectionTree searchBooks(String pattern) {
|
public LibraryTree searchBooks(String pattern) {
|
||||||
synchronize();
|
synchronize();
|
||||||
mySearchResult.clear();
|
mySearchResult.clear();
|
||||||
if (pattern != null) {
|
if (pattern != null) {
|
||||||
pattern = pattern.toLowerCase();
|
pattern = pattern.toLowerCase();
|
||||||
for (BookDescription book : myBookDescriptions) {
|
for (Book book : myBooks) {
|
||||||
if (book.matches(pattern)) {
|
if (book.matches(pattern)) {
|
||||||
mySearchResult.createBookSubTree(book, true);
|
mySearchResult.createBookSubTree(book, true);
|
||||||
}
|
}
|
||||||
|
@ -306,10 +306,10 @@ public final class BookCollection {
|
||||||
return mySearchResult;
|
return mySearchResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addBookToRecentList(BookDescription description) {
|
public void addBookToRecentList(Book book) {
|
||||||
final BooksDatabase db = BooksDatabase.Instance();
|
final BooksDatabase db = BooksDatabase.Instance();
|
||||||
final List<Long> ids = db.listRecentBookIds();
|
final List<Long> ids = db.listRecentBookIds();
|
||||||
final Long bookId = description.getBookId();
|
final Long bookId = book.getId();
|
||||||
ids.remove(bookId);
|
ids.remove(bookId);
|
||||||
ids.add(0, bookId);
|
ids.add(0, bookId);
|
||||||
if (ids.size() > 12) {
|
if (ids.size() > 12) {
|
|
@ -17,19 +17,19 @@
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.geometerplus.fbreader.collection;
|
package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.tree.ZLTree;
|
import org.geometerplus.zlibrary.core.tree.ZLTree;
|
||||||
|
|
||||||
public abstract class CollectionTree extends ZLTree<CollectionTree> implements Comparable<CollectionTree> {
|
public abstract class LibraryTree extends ZLTree<LibraryTree> implements Comparable<LibraryTree> {
|
||||||
protected CollectionTree() {
|
protected LibraryTree() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CollectionTree(CollectionTree parent) {
|
protected LibraryTree(LibraryTree parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ public abstract class CollectionTree extends ZLTree<CollectionTree> implements C
|
||||||
return new AuthorTree(this, author);
|
return new AuthorTree(this, author);
|
||||||
}
|
}
|
||||||
|
|
||||||
BookTree createBookSubTree(BookDescription book, boolean showAuthors) {
|
BookTree createBookSubTree(Book book, boolean showAuthors) {
|
||||||
return new BookTree(this, book, showAuthors);
|
return new BookTree(this, book, showAuthors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ public abstract class CollectionTree extends ZLTree<CollectionTree> implements C
|
||||||
if (myChildrenString == null) {
|
if (myChildrenString == null) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (CollectionTree subtree : subTrees()) {
|
for (LibraryTree subtree : subTrees()) {
|
||||||
if (count++ > 0) {
|
if (count++ > 0) {
|
||||||
builder.append(", ");
|
builder.append(", ");
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ public abstract class CollectionTree extends ZLTree<CollectionTree> implements C
|
||||||
return myChildrenString;
|
return myChildrenString;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int compareTo(CollectionTree ct) {
|
public int compareTo(LibraryTree ct) {
|
||||||
final String key0 = getSortKey();
|
final String key0 = getSortKey();
|
||||||
final String key1 = ct.getSortKey();
|
final String key1 = ct.getSortKey();
|
||||||
if (key0 == null) {
|
if (key0 == null) {
|
||||||
|
@ -83,10 +83,10 @@ public abstract class CollectionTree extends ZLTree<CollectionTree> implements C
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void sortAllChildren() {
|
public final void sortAllChildren() {
|
||||||
List<CollectionTree> children = subTrees();
|
List<LibraryTree> children = subTrees();
|
||||||
if (!children.isEmpty()) {
|
if (!children.isEmpty()) {
|
||||||
Collections.sort(children);
|
Collections.sort(children);
|
||||||
for (CollectionTree tree : children) {
|
for (LibraryTree tree : children) {
|
||||||
tree.sortAllChildren();
|
tree.sortAllChildren();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -17,9 +17,9 @@
|
||||||
* 02110-1301, USA.
|
* 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() {
|
public String getName() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
|
@ -17,7 +17,7 @@
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.geometerplus.fbreader.collection;
|
package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
public final class SeriesInfo {
|
public final class SeriesInfo {
|
||||||
public final String Name;
|
public final String Name;
|
|
@ -17,12 +17,12 @@
|
||||||
* 02110-1301, USA.
|
* 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;
|
private final String mySeries;
|
||||||
|
|
||||||
SeriesTree(CollectionTree parent, String series) {
|
SeriesTree(LibraryTree parent, String series) {
|
||||||
super(parent);
|
super(parent);
|
||||||
mySeries = series;
|
mySeries = series;
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ final class SeriesTree extends CollectionTree {
|
||||||
return mySeries;
|
return mySeries;
|
||||||
}
|
}
|
||||||
|
|
||||||
BookTree createBookInSeriesSubTree(BookDescription book) {
|
BookTree createBookInSeriesSubTree(Book book) {
|
||||||
return new BookInSeriesTree(this, book);
|
return new BookInSeriesTree(this, book);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -17,7 +17,7 @@
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.geometerplus.fbreader.collection;
|
package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
|
@ -17,14 +17,14 @@
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.geometerplus.fbreader.collection;
|
package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
|
||||||
final class TagTree extends CollectionTree {
|
final class TagTree extends LibraryTree {
|
||||||
private final Tag myTag;
|
private final Tag myTag;
|
||||||
|
|
||||||
TagTree(CollectionTree parent, Tag tag) {
|
TagTree(LibraryTree parent, Tag tag) {
|
||||||
super(parent);
|
super(parent);
|
||||||
myTag = tag;
|
myTag = tag;
|
||||||
}
|
}
|
|
@ -29,7 +29,6 @@ import org.geometerplus.zlibrary.text.view.style.*;
|
||||||
|
|
||||||
import org.geometerplus.fbreader.encoding.ZLEncodingCollection;
|
import org.geometerplus.fbreader.encoding.ZLEncodingCollection;
|
||||||
import org.geometerplus.fbreader.encodingOption.*;
|
import org.geometerplus.fbreader.encodingOption.*;
|
||||||
import org.geometerplus.fbreader.collection.BookCollection;
|
|
||||||
import org.geometerplus.fbreader.fbreader.*;
|
import org.geometerplus.fbreader.fbreader.*;
|
||||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,6 @@ public abstract class ZLApplication {
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void onViewChanged() {
|
public final void onViewChanged() {
|
||||||
System.err.println("onViewChanged");
|
|
||||||
for (ButtonPanel panel : myPanels) {
|
for (ButtonPanel panel : myPanels) {
|
||||||
panel.hide();
|
panel.hide();
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,15 +37,7 @@ public abstract class ZLTextView extends ZLView {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setModel(ZLTextModel model) {
|
public abstract 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 scrollPage(boolean forward, int scrollingMode, int value);
|
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 {
|
public abstract class ZLTextViewImpl extends ZLTextView {
|
||||||
private ZLTextModel myModel;
|
private ZLTextModel myModel;
|
||||||
protected int myCurrentModelIndex;
|
|
||||||
private ArrayList<ZLTextModel> myModelList;
|
|
||||||
private final ZLTextSelectionModel mySelectionModel;
|
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 {
|
private interface SizeUnit {
|
||||||
int PIXEL_UNIT = 0;
|
int PIXEL_UNIT = 0;
|
||||||
int LINE_UNIT = 1;
|
int LINE_UNIT = 1;
|
||||||
|
@ -95,17 +59,10 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
||||||
mySelectionModel = new ZLTextSelectionModel(this);
|
mySelectionModel = new ZLTextSelectionModel(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setModels(ArrayList<ZLTextModel> models, int current) {
|
public final void setModel(ZLTextModel model) {
|
||||||
myModelList = (models != null) ? models : new ArrayList<ZLTextModel>();
|
|
||||||
myModel = (current >= 0 && current < myModelList.size()) ?
|
|
||||||
(ZLTextModel)myModelList.get(current) : null;
|
|
||||||
myCurrentModelIndex = current;
|
|
||||||
setModelInternal();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setModelInternal() {
|
|
||||||
ZLTextParagraphCursorCache.clear();
|
ZLTextParagraphCursorCache.clear();
|
||||||
|
|
||||||
|
myModel = model;
|
||||||
if (myModel != null) {
|
if (myModel != null) {
|
||||||
final int paragraphsNumber = myModel.getParagraphsNumber();
|
final int paragraphsNumber = myModel.getParagraphsNumber();
|
||||||
if (paragraphsNumber > 0) {
|
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() {
|
public ZLTextModel getModel() {
|
||||||
return myModel;
|
return myModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ArrayList<ZLTextModel> getModelList() {
|
|
||||||
return myModelList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void highlightParagraph(int paragraphIndex) {
|
public void highlightParagraph(int paragraphIndex) {
|
||||||
myModel.selectParagraph(paragraphIndex);
|
myModel.selectParagraph(paragraphIndex);
|
||||||
rebuildPaintInfo();
|
rebuildPaintInfo();
|
||||||
|
@ -302,7 +245,7 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
||||||
if (myCurrentPage.StartCursor.isNull()) {
|
if (myCurrentPage.StartCursor.isNull()) {
|
||||||
return;
|
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)) {
|
if ((myCurrentPage.StartCursor.getParagraphCursor().Index != mark.ParagraphIndex) || (myCurrentPage.StartCursor.getPosition().compareTo(mark) > 0)) {
|
||||||
doRepaint = true;
|
doRepaint = true;
|
||||||
gotoParagraph(mark.ParagraphIndex, false);
|
gotoParagraph(mark.ParagraphIndex, false);
|
||||||
|
@ -324,19 +267,17 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
||||||
savePosition(position);
|
savePosition(position);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
savePosition(position, myCurrentModelIndex, myCurrentPage.StartCursor);
|
savePosition(position, myCurrentPage.StartCursor);
|
||||||
ZLApplication.Instance().repaintView();
|
ZLApplication.Instance().repaintView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void savePosition(Position position) {
|
protected void savePosition(ZLTextPosition position) {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void savePosition(Position position, int modelIndexToCheck, ZLTextWordCursor cursorToCheck) {
|
protected final void savePosition(ZLTextPosition position, ZLTextWordCursor cursorToCheck) {
|
||||||
// System.out.println("trying to save " + position.ModelIndex + " " + position.ParagraphIndex);
|
if (!position.equalsToCursor(cursorToCheck)) {
|
||||||
if ((position.ModelIndex != modelIndexToCheck) || !position.equalsToCursor(cursorToCheck)) {
|
|
||||||
savePosition(position);
|
savePosition(position);
|
||||||
// System.out.println("saved");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1100,8 +1041,8 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void gotoPosition(Position position) {
|
public final void gotoPosition(ZLTextPosition position) {
|
||||||
gotoPosition(position.ModelIndex, position.ParagraphIndex, position.WordIndex, position.CharIndex);
|
gotoPosition(position.ParagraphIndex, position.WordIndex, position.CharIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void gotoPosition(int paragraphIndex, int wordIndex, int charIndex) {
|
public final void gotoPosition(int paragraphIndex, int wordIndex, int charIndex) {
|
||||||
|
@ -1117,11 +1058,6 @@ public abstract class ZLTextViewImpl extends ZLTextView {
|
||||||
myNextPage.reset();
|
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) {
|
public void gotoParagraph(int num, boolean last) {
|
||||||
if (myModel == null) {
|
if (myModel == null) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue