mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
NG Library view: recent books list (very slow at this moment)
ZLAndroidLibrary.createImage() method has gone
This commit is contained in:
parent
1e9396d5c2
commit
c33d802c6d
16 changed files with 189 additions and 67 deletions
|
@ -80,6 +80,9 @@
|
|||
<activity android:name="org.geometerplus.android.fbreader.library.LibraryTopLevelActivity" android:process=":library" android:configChanges="orientation|keyboardHidden">
|
||||
<meta-data android:name="android.app.default_searchable" android:value="org.geometerplus.android.fbreader.BookSearchActivity" />
|
||||
</activity>
|
||||
<activity android:name="org.geometerplus.android.fbreader.library.LibraryRecentActivity" android:process=":library" android:configChanges="orientation|keyboardHidden">
|
||||
<meta-data android:name="android.app.default_searchable" android:value="org.geometerplus.android.fbreader.BookSearchActivity" />
|
||||
</activity>
|
||||
<activity android:name="org.geometerplus.android.fbreader.TOCActivity" android:configChanges="orientation|keyboardHidden" />
|
||||
<activity android:name="org.geometerplus.android.fbreader.BookmarksActivity" android:configChanges="orientation|keyboardHidden">
|
||||
<meta-data android:name="android.app.default_searchable" android:value="org.geometerplus.android.fbreader.BookmarkSearchActivity" />
|
||||
|
|
|
@ -80,6 +80,9 @@
|
|||
<activity android:name="org.geometerplus.android.fbreader.library.LibraryTopLevelActivity" android:process=":library" android:configChanges="orientation|keyboardHidden">
|
||||
<meta-data android:name="android.app.default_searchable" android:value="org.geometerplus.android.fbreader.BookSearchActivity" />
|
||||
</activity>
|
||||
<activity android:name="org.geometerplus.android.fbreader.library.LibraryRecentActivity" android:process=":library" android:configChanges="orientation|keyboardHidden">
|
||||
<meta-data android:name="android.app.default_searchable" android:value="org.geometerplus.android.fbreader.BookSearchActivity" />
|
||||
</activity>
|
||||
<activity android:name="org.geometerplus.android.fbreader.TOCActivity" android:configChanges="orientation|keyboardHidden" />
|
||||
<activity android:name="org.geometerplus.android.fbreader.BookmarksActivity" android:configChanges="orientation|keyboardHidden">
|
||||
<meta-data android:name="android.app.default_searchable" android:value="org.geometerplus.android.fbreader.BookmarkSearchActivity" />
|
||||
|
|
|
@ -98,7 +98,7 @@ public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuIt
|
|||
}
|
||||
};
|
||||
System.err.println("before");
|
||||
action.run();
|
||||
action.run();
|
||||
//AndroidUtil.wait("loadingBookList", action, this);
|
||||
System.err.println("after");
|
||||
|
||||
|
|
|
@ -22,16 +22,23 @@ package org.geometerplus.android.fbreader.library;
|
|||
import java.util.List;
|
||||
|
||||
import android.app.ListActivity;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||
|
||||
import org.geometerplus.zlibrary.ui.android.image.ZLAndroidImageData;
|
||||
import org.geometerplus.zlibrary.ui.android.image.ZLAndroidImageManager;
|
||||
|
||||
import org.geometerplus.fbreader.tree.FBTree;
|
||||
|
||||
import org.geometerplus.zlibrary.ui.android.R;
|
||||
|
||||
import org.geometerplus.android.fbreader.tree.ZLAndroidTree;
|
||||
|
||||
public class LibraryBaseActivity extends ListActivity {
|
||||
protected final ZLResource myResource = ZLResource.resource("libraryView");
|
||||
|
||||
|
@ -42,6 +49,7 @@ public class LibraryBaseActivity extends ListActivity {
|
|||
|
||||
@Override
|
||||
public void onListItemClick(ListView listView, View view, int position, long rowId) {
|
||||
FBTree tree = ((LibraryAdapter)getListAdapter()).getItem(position);
|
||||
}
|
||||
|
||||
protected final class LibraryAdapter extends BaseAdapter {
|
||||
|
@ -90,30 +98,27 @@ public class LibraryBaseActivity extends ListActivity {
|
|||
coverView.getLayoutParams().height = myCoverHeight;
|
||||
coverView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
||||
coverView.requestLayout();
|
||||
coverView.setImageResource(R.drawable.fbreader);
|
||||
//setupCover(coverView, tree, myCoverWidth, myCoverWidth);
|
||||
|
||||
if (tree instanceof ZLAndroidTree) {
|
||||
coverView.setImageResource(((ZLAndroidTree)tree).getCoverResourceId());
|
||||
} else {
|
||||
Bitmap coverBitmap = null;
|
||||
ZLImage cover = tree.getCover();
|
||||
if (cover != null) {
|
||||
final ZLAndroidImageData data =
|
||||
((ZLAndroidImageManager)ZLAndroidImageManager.Instance()).getImageData(cover);
|
||||
if (data != null) {
|
||||
coverBitmap = data.getBitmap(2 * myCoverWidth, 2 * myCoverHeight);
|
||||
}
|
||||
}
|
||||
if (coverBitmap != null) {
|
||||
coverView.setImageBitmap(coverBitmap);
|
||||
} else {
|
||||
coverView.setImageResource(R.drawable.fbreader);
|
||||
}
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
private void setupCover(final ImageView coverView, FBTree tree, int width, int height) {
|
||||
Bitmap coverBitmap = null;
|
||||
ZLImage cover = tree.getCover();
|
||||
if (cover != null) {
|
||||
ZLAndroidImageData data = null;
|
||||
final ZLAndroidImageManager mgr = (ZLAndroidImageManager) ZLAndroidImageManager.Instance();
|
||||
data = mgr.getImageData(cover);
|
||||
if (data != null) {
|
||||
coverBitmap = data.getBitmap(2 * width, 2 * height);
|
||||
}
|
||||
}
|
||||
if (coverBitmap != null) {
|
||||
coverView.setImageBitmap(coverBitmap);
|
||||
} else {
|
||||
coverView.setImageResource(R.drawable.fbreader);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2007-2010 Geometer Plus <contact@geometerplus.com>
|
||||
* Copyright (C) 2010 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -17,24 +17,17 @@
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.zlibrary.ui.android.image;
|
||||
package org.geometerplus.android.fbreader.library;
|
||||
|
||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||
import android.os.Bundle;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.content.res.Resources;
|
||||
import org.geometerplus.fbreader.library.Library;
|
||||
|
||||
public final class ZLAndroidResourceBasedImageData extends ZLAndroidImageData implements ZLImage {
|
||||
private final Resources myResources;
|
||||
private final int myId;
|
||||
public class LibraryRecentActivity extends LibraryBaseActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
public ZLAndroidResourceBasedImageData(Resources resources, int id) {
|
||||
myResources = resources;
|
||||
myId = id;
|
||||
}
|
||||
|
||||
protected Bitmap decodeWithOptions(BitmapFactory.Options options) {
|
||||
return BitmapFactory.decodeResource(myResources, myId, options);
|
||||
setListAdapter(new LibraryAdapter(new Library().recentBooks().subTrees()));
|
||||
}
|
||||
}
|
|
@ -21,31 +21,93 @@ package org.geometerplus.android.fbreader.library;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ListView;
|
||||
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
||||
import org.geometerplus.fbreader.tree.FBTree;
|
||||
|
||||
import org.geometerplus.zlibrary.ui.android.R;
|
||||
|
||||
import org.geometerplus.android.fbreader.SQLiteBooksDatabase;
|
||||
import org.geometerplus.android.fbreader.tree.ZLAndroidTree;
|
||||
|
||||
public class LibraryTopLevelActivity extends LibraryBaseActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
if (SQLiteBooksDatabase.Instance() == null) {
|
||||
new SQLiteBooksDatabase("LIBRARY_NG");
|
||||
}
|
||||
|
||||
final ArrayList<FBTree> items = new ArrayList<FBTree>();
|
||||
items.add(new TopLevelTree(myResource.getResource("searchResults")));
|
||||
items.add(new TopLevelTree(myResource.getResource("recent")));
|
||||
items.add(new TopLevelTree(myResource.getResource("byAuthor")));
|
||||
items.add(new TopLevelTree(myResource.getResource("byTag")));
|
||||
items.add(new TopLevelTree(myResource.getResource("fileTree")));
|
||||
items.add(new TopLevelTree(
|
||||
myResource.getResource("searchResults"),
|
||||
R.drawable.ic_tab_library_results,
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
}
|
||||
}
|
||||
));
|
||||
items.add(new TopLevelTree(
|
||||
myResource.getResource("recent"),
|
||||
R.drawable.ic_tab_library_recent,
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
startActivity(new Intent(
|
||||
LibraryTopLevelActivity.this,
|
||||
LibraryRecentActivity.class
|
||||
));
|
||||
}
|
||||
}
|
||||
));
|
||||
items.add(new TopLevelTree(
|
||||
myResource.getResource("byAuthor"),
|
||||
R.drawable.ic_tab_library_author,
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
}
|
||||
}
|
||||
));
|
||||
items.add(new TopLevelTree(
|
||||
myResource.getResource("byTag"),
|
||||
R.drawable.ic_tab_library_tag,
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
}
|
||||
}
|
||||
));
|
||||
items.add(new TopLevelTree(
|
||||
myResource.getResource("fileTree"),
|
||||
R.drawable.fbreader,
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
}
|
||||
}
|
||||
));
|
||||
setListAdapter(new LibraryAdapter(items));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView listView, View view, int position, long rowId) {
|
||||
TopLevelTree tree = (TopLevelTree)((LibraryAdapter)getListAdapter()).getItem(position);
|
||||
tree.getAction().run();
|
||||
}
|
||||
}
|
||||
|
||||
class TopLevelTree extends FBTree {
|
||||
class TopLevelTree extends FBTree implements ZLAndroidTree {
|
||||
private final ZLResource myResource;
|
||||
private final int myCoverResourceId;
|
||||
private final Runnable myAction;
|
||||
|
||||
public TopLevelTree(ZLResource resource) {
|
||||
public TopLevelTree(ZLResource resource, int coverResourceId, Runnable action) {
|
||||
myResource = resource;
|
||||
myCoverResourceId = coverResourceId;
|
||||
myAction = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,4 +119,12 @@ class TopLevelTree extends FBTree {
|
|||
public String getSummary() {
|
||||
return myResource.getResource("summary").getValue();
|
||||
}
|
||||
|
||||
public int getCoverResourceId() {
|
||||
return myCoverResourceId;
|
||||
}
|
||||
|
||||
public Runnable getAction() {
|
||||
return myAction;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,15 +22,14 @@ package org.geometerplus.android.fbreader.network;
|
|||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
||||
import org.geometerplus.zlibrary.ui.android.library.ZLAndroidLibrary;
|
||||
import org.geometerplus.zlibrary.ui.android.R;
|
||||
|
||||
import org.geometerplus.fbreader.network.NetworkLibraryItem;
|
||||
import org.geometerplus.fbreader.network.NetworkTree;
|
||||
|
||||
import org.geometerplus.android.fbreader.tree.ZLAndroidTree;
|
||||
|
||||
public class AddCustomCatalogItemTree extends NetworkTree {
|
||||
|
||||
public class AddCustomCatalogItemTree extends NetworkTree implements ZLAndroidTree {
|
||||
public AddCustomCatalogItemTree() {
|
||||
super(1);
|
||||
}
|
||||
|
@ -50,8 +49,7 @@ public class AddCustomCatalogItemTree extends NetworkTree {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ZLImage createCover() {
|
||||
return ((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).createImage(R.drawable.ic_list_plus);
|
||||
public int getCoverResourceId() {
|
||||
return R.drawable.ic_list_plus;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ import org.geometerplus.fbreader.network.NetworkTree;
|
|||
import org.geometerplus.fbreader.network.NetworkImage;
|
||||
import org.geometerplus.fbreader.network.tree.NetworkBookTree;
|
||||
|
||||
import org.geometerplus.android.fbreader.tree.ZLAndroidTree;
|
||||
|
||||
abstract class NetworkBaseActivity extends ListActivity
|
||||
implements NetworkView.EventListener, View.OnCreateContextMenuListener {
|
||||
|
@ -113,6 +114,11 @@ abstract class NetworkBaseActivity extends ListActivity
|
|||
private HashSet<String> myAwaitedCovers = new HashSet<String>();
|
||||
|
||||
private void setupCover(final ImageView coverView, NetworkTree tree, int width, int height) {
|
||||
if (tree instanceof ZLAndroidTree) {
|
||||
coverView.setImageResource(((ZLAndroidTree)tree).getCoverResourceId());
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap coverBitmap = null;
|
||||
ZLImage cover = tree.getCover();
|
||||
if (cover != null) {
|
||||
|
|
|
@ -30,10 +30,11 @@ import org.geometerplus.fbreader.tree.FBTree;
|
|||
import org.geometerplus.fbreader.network.*;
|
||||
import org.geometerplus.fbreader.network.tree.NetworkAuthorTree;
|
||||
|
||||
import org.geometerplus.zlibrary.ui.android.library.ZLAndroidLibrary;
|
||||
import org.geometerplus.zlibrary.ui.android.R;
|
||||
|
||||
public class SearchItemTree extends NetworkTree {
|
||||
import org.geometerplus.android.fbreader.tree.ZLAndroidTree;
|
||||
|
||||
public class SearchItemTree extends NetworkTree implements ZLAndroidTree {
|
||||
|
||||
private SearchResult myResult;
|
||||
|
||||
|
@ -51,9 +52,8 @@ public class SearchItemTree extends NetworkTree {
|
|||
return ZLResource.resource("networkView").getResource("searchSummary").getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ZLImage createCover() {
|
||||
return ((ZLAndroidLibrary)ZLAndroidLibrary.Instance()).createImage(R.drawable.ic_list_searchresult);
|
||||
public int getCoverResourceId() {
|
||||
return R.drawable.ic_list_searchresult;
|
||||
}
|
||||
|
||||
public void setSearchResult(SearchResult result) {
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (C) 2010 Geometer Plus <contact@geometerplus.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.geometerplus.android.fbreader.tree;
|
||||
|
||||
public interface ZLAndroidTree {
|
||||
int getCoverResourceId();
|
||||
}
|
|
@ -31,7 +31,7 @@ import org.geometerplus.fbreader.Paths;
|
|||
|
||||
public final class BookModel {
|
||||
public static BookModel createModel(Book book) {
|
||||
FormatPlugin plugin = PluginCollection.instance().getPlugin(book.File);
|
||||
FormatPlugin plugin = PluginCollection.Instance().getPlugin(book.File);
|
||||
if (plugin == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ public class PluginCollection {
|
|||
public ZLStringOption DefaultEncodingOption;
|
||||
public ZLBooleanOption LanguageAutoDetectOption;
|
||||
|
||||
public static PluginCollection instance() {
|
||||
public static PluginCollection Instance() {
|
||||
if (ourInstance == null) {
|
||||
ourInstance = new PluginCollection();
|
||||
ourInstance.myPlugins.add(new FB2Plugin());
|
||||
|
|
|
@ -116,7 +116,7 @@ public class Book {
|
|||
}
|
||||
|
||||
boolean readMetaInfo() {
|
||||
final FormatPlugin plugin = PluginCollection.instance().getPlugin(File);
|
||||
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(File);
|
||||
if ((plugin == null) || !plugin.readMetaInfo(this)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,11 @@
|
|||
|
||||
package org.geometerplus.fbreader.library;
|
||||
|
||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||
|
||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||
import org.geometerplus.fbreader.formats.FormatPlugin;
|
||||
|
||||
public class BookTree extends LibraryTree {
|
||||
public final Book Book;
|
||||
private final boolean myShowAuthors;
|
||||
|
@ -29,10 +34,12 @@ public class BookTree extends LibraryTree {
|
|||
myShowAuthors = showAuthors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return Book.getTitle();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSummary() {
|
||||
if (!myShowAuthors) {
|
||||
return super.getSummary();
|
||||
|
@ -50,4 +57,14 @@ public class BookTree extends LibraryTree {
|
|||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ZLImage createCover() {
|
||||
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(Book.File);
|
||||
if (plugin != null) {
|
||||
return plugin.readCover(Book);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -254,6 +254,7 @@ public final class Library {
|
|||
}
|
||||
|
||||
final BooksDatabase db = BooksDatabase.Instance();
|
||||
myRecentBooks.clear();
|
||||
for (long id : db.loadRecentBookIds()) {
|
||||
Book book = bookById.get(id);
|
||||
if (book != null) {
|
||||
|
@ -293,7 +294,15 @@ public final class Library {
|
|||
}
|
||||
|
||||
public LibraryTree recentBooks() {
|
||||
synchronize();
|
||||
if (!myRecentBooks.hasChildren()) {
|
||||
final BooksDatabase db = BooksDatabase.Instance();
|
||||
for (long id : db.loadRecentBookIds()) {
|
||||
Book book = Book.getById(id);
|
||||
if (book != null) {
|
||||
myRecentBooks.createBookSubTree(book, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return myRecentBooks;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,12 +34,10 @@ import org.geometerplus.zlibrary.core.library.ZLibrary;
|
|||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLResourceFile;
|
||||
import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||
|
||||
import org.geometerplus.zlibrary.ui.android.R;
|
||||
import org.geometerplus.zlibrary.ui.android.view.ZLAndroidWidget;
|
||||
import org.geometerplus.zlibrary.ui.android.dialogs.ZLAndroidDialogManager;
|
||||
import org.geometerplus.zlibrary.ui.android.image.ZLAndroidResourceBasedImageData;
|
||||
|
||||
import org.geometerplus.android.fbreader.network.BookDownloader;
|
||||
import org.geometerplus.android.fbreader.network.BookDownloaderService;
|
||||
|
@ -108,10 +106,6 @@ public final class ZLAndroidLibrary extends ZLibrary {
|
|||
return new AndroidAssetsFile((AndroidAssetsFile)parent, name);
|
||||
}
|
||||
|
||||
public ZLImage createImage(int drawableId) {
|
||||
return new ZLAndroidResourceBasedImageData(myApplication.getResources(), drawableId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersionName() {
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue