mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 18:29:23 +02:00
work in progress
This commit is contained in:
parent
aba621c9de
commit
93e3df976b
11 changed files with 69 additions and 67 deletions
|
@ -38,7 +38,6 @@ import android.widget.TextView;
|
|||
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||
import org.geometerplus.zlibrary.core.image.ZLImageProxy;
|
||||
import org.geometerplus.zlibrary.core.image.ZLLoadableImage;
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
||||
|
@ -49,10 +48,7 @@ import org.geometerplus.zlibrary.ui.android.image.ZLAndroidImageManager;
|
|||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||
import org.geometerplus.fbreader.formats.FormatPlugin;
|
||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||
import org.geometerplus.fbreader.library.Author;
|
||||
import org.geometerplus.fbreader.library.Book;
|
||||
import org.geometerplus.fbreader.library.SeriesInfo;
|
||||
import org.geometerplus.fbreader.library.Tag;
|
||||
import org.geometerplus.fbreader.library.*;
|
||||
|
||||
import org.geometerplus.android.fbreader.preferences.BookInfoActivity;
|
||||
|
||||
|
@ -61,6 +57,7 @@ public class BookStatusActivity extends Activity {
|
|||
|
||||
private final ZLResource myResource = ZLResource.resource("bookInfo");
|
||||
private Book myBook;
|
||||
private ZLImage myImage;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -69,12 +66,15 @@ public class BookStatusActivity extends Activity {
|
|||
new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this)
|
||||
);
|
||||
|
||||
final String path = getIntent().getStringExtra(CURRENT_BOOK_PATH_KEY);
|
||||
final ZLFile file = ZLFile.createFileByPath(path);
|
||||
|
||||
myImage = Library.getCover(file);
|
||||
|
||||
if (SQLiteBooksDatabase.Instance() == null) {
|
||||
new SQLiteBooksDatabase(this, "LIBRARY");
|
||||
}
|
||||
|
||||
final String path = getIntent().getStringExtra(CURRENT_BOOK_PATH_KEY);
|
||||
final ZLFile file = ZLFile.createFileByPath(path);
|
||||
myBook = Book.getByFile(file);
|
||||
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
|
@ -146,21 +146,15 @@ public class BookStatusActivity extends Activity {
|
|||
coverView.setVisibility(View.GONE);
|
||||
coverView.setImageDrawable(null);
|
||||
|
||||
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(book.File);
|
||||
if (plugin == null) {
|
||||
if (myImage == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ZLImage image = plugin.readCover(book);
|
||||
if (image == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (image instanceof ZLLoadableImage) {
|
||||
((ZLLoadableImage)image).synchronize();
|
||||
if (myImage instanceof ZLLoadableImage) {
|
||||
((ZLLoadableImage)myImage).synchronize();
|
||||
}
|
||||
final ZLAndroidImageData data =
|
||||
((ZLAndroidImageManager)ZLAndroidImageManager.Instance()).getImageData(image);
|
||||
((ZLAndroidImageManager)ZLAndroidImageManager.Instance()).getImageData(myImage);
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -268,11 +268,7 @@ public final class FileManager extends BaseActivity {
|
|||
public ZLImage getCover() {
|
||||
if (!myCoverIsInitialized) {
|
||||
myCoverIsInitialized = true;
|
||||
final Book book = getBook();
|
||||
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(myFile);
|
||||
if (book != null && plugin != null) {
|
||||
myCover = plugin.readCover(book);
|
||||
}
|
||||
myCover = Library.getCover(myFile);
|
||||
}
|
||||
return myCover;
|
||||
}
|
||||
|
|
|
@ -24,10 +24,8 @@ import java.util.Set;
|
|||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
//import android.util.StringBuilderPrinter;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
//import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
|
@ -43,9 +41,7 @@ import org.geometerplus.zlibrary.ui.android.image.ZLAndroidImageData;
|
|||
|
||||
import org.geometerplus.fbreader.network.*;
|
||||
|
||||
|
||||
public class NetworkBookInfoActivity extends Activity implements NetworkView.EventListener {
|
||||
|
||||
private NetworkBookItem myBook;
|
||||
|
||||
private final ZLResource myResource = ZLResource.resource("networkBookView");
|
||||
|
@ -79,27 +75,6 @@ public class NetworkBookInfoActivity extends Activity implements NetworkView.Eve
|
|||
setupInfo();
|
||||
setupCover();
|
||||
setupButtons();
|
||||
|
||||
/*LinearLayout layout = (LinearLayout) findViewById(R.id.network_book_cover).getParent();
|
||||
TextView detailsTitle = new TextView(this, null, android.R.attr.listSeparatorTextViewStyle);
|
||||
TextView details = new TextView(this);
|
||||
detailsTitle.setText("Debug Details");
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
StringBuilderPrinter printer = new StringBuilderPrinter(builder);
|
||||
|
||||
printer.println("Id = " + myBook.Id);
|
||||
printer.println("Index = " + myBook.Index);
|
||||
printer.println("Cover = " + myBook.Cover);
|
||||
printer.println("References (" + myBook.myReferences.size() + "):");
|
||||
for (BookReference ref: myBook.myReferences) {
|
||||
printer.println( ref.toString() );
|
||||
}
|
||||
|
||||
details.setText(builder.toString());
|
||||
|
||||
layout.addView(detailsTitle);
|
||||
layout.addView(details);*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -28,7 +28,7 @@ public abstract class FormatPlugin {
|
|||
public abstract boolean acceptsFile(ZLFile file);
|
||||
public abstract boolean readMetaInfo(Book book);
|
||||
public abstract boolean readModel(BookModel model);
|
||||
public abstract ZLImage readCover(Book book);
|
||||
public abstract ZLImage readCover(ZLFile file);
|
||||
|
||||
/*
|
||||
public static void detectEncodingAndLanguage(Book book, InputStream stream) throws IOException {
|
||||
|
|
|
@ -42,7 +42,7 @@ public class FB2Plugin extends FormatPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ZLImage readCover(Book book) {
|
||||
return new FB2CoverReader().readCover(book.File);
|
||||
public ZLImage readCover(ZLFile file) {
|
||||
return new FB2CoverReader().readCover(file);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public class HtmlPlugin extends FormatPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ZLImage readCover(Book book) {
|
||||
public ZLImage readCover(ZLFile file) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,8 +58,8 @@ public class OEBPlugin extends FormatPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ZLImage readCover(Book book) {
|
||||
final ZLFile opfFile = getOpfFile(book.File);
|
||||
public ZLImage readCover(ZLFile file) {
|
||||
final ZLFile opfFile = getOpfFile(file);
|
||||
return (opfFile != null) ? new OEBCoverReader().readCover(opfFile) : null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -133,10 +133,10 @@ public class MobipocketPlugin extends PdbPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ZLImage readCover(Book book) {
|
||||
public ZLImage readCover(ZLFile file) {
|
||||
InputStream stream = null;
|
||||
try {
|
||||
stream = book.File.getInputStream();
|
||||
stream = file.getInputStream();
|
||||
final PdbHeader header = new PdbHeader(stream);
|
||||
PdbUtil.skip(stream, header.Offsets[0] + 16 - header.length());
|
||||
if (PdbUtil.readInt(stream) != 0x4D4F4249) /* "MOBI" */ {
|
||||
|
@ -202,11 +202,10 @@ public class MobipocketPlugin extends PdbPlugin {
|
|||
coverIndex = thumbIndex;
|
||||
}
|
||||
|
||||
final ZLFile file = book.File;
|
||||
final MobipocketStream mpStream = new MobipocketStream(file);
|
||||
|
||||
// TODO: implement
|
||||
/*int index = pbStream.firstImageLocationIndex(file.path());
|
||||
/*final MobipocketStream mpStream = new MobipocketStream(file);
|
||||
|
||||
int index = pbStream.firstImageLocationIndex(file.path());
|
||||
if (index >= 0) {
|
||||
std::pair<int,int> imageLocation = pbStream.imageLocation(pbStream.header(), index + coverIndex);
|
||||
if ((imageLocation.first > 0) && (imageLocation.second > 0)) {
|
||||
|
|
|
@ -57,7 +57,7 @@ public class PluckerPlugin extends PdbPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ZLImage readCover(Book book) {
|
||||
public ZLImage readCover(ZLFile file) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,11 +60,6 @@ public class BookTree extends LibraryTree {
|
|||
|
||||
@Override
|
||||
protected ZLImage createCover() {
|
||||
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(Book.File);
|
||||
if (plugin != null) {
|
||||
return plugin.readCover(Book);
|
||||
}
|
||||
|
||||
return null;
|
||||
return Library.getCover(Book.File);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,10 +21,14 @@ package org.geometerplus.fbreader.library;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
//import java.lang.ref.WeakReference;
|
||||
|
||||
import org.geometerplus.zlibrary.core.filesystem.*;
|
||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||
import org.geometerplus.zlibrary.core.util.ZLMiscUtil;
|
||||
|
||||
import org.geometerplus.fbreader.formats.FormatPlugin;
|
||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||
import org.geometerplus.fbreader.Paths;
|
||||
|
||||
public final class Library {
|
||||
|
@ -425,4 +429,43 @@ public final class Library {
|
|||
book.File.getPhysicalFile().delete();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
private static final HashMap<String,WeakReference<ZLImage>> ourCoverMap =
|
||||
new HashMap<String,WeakReference<ZLImage>>();
|
||||
private static final WeakReference<ZLImage> NULL_IMAGE = new WeakReference<ZLImage>(null);
|
||||
*/
|
||||
|
||||
public static ZLImage getCover(ZLFile file) {
|
||||
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(file);
|
||||
if (plugin != null) {
|
||||
return plugin.readCover(file);
|
||||
}
|
||||
return null;
|
||||
/*
|
||||
synchronized(ourCoverMap) {
|
||||
final String path = file.getPath();
|
||||
final WeakReference<ZLImage> ref = ourCoverMap.get(path);
|
||||
if (ref == NULL_IMAGE) {
|
||||
return null;
|
||||
} else if (ref != null) {
|
||||
final ZLImage image = ref.get();
|
||||
if (image != null) {
|
||||
return image;
|
||||
}
|
||||
}
|
||||
ZLImage image = null;
|
||||
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(file);
|
||||
if (plugin != null) {
|
||||
image = plugin.readCover(file);
|
||||
}
|
||||
if (image == null) {
|
||||
ourCoverMap.put(path, NULL_IMAGE);
|
||||
} else {
|
||||
ourCoverMap.put(path, new WeakReference<ZLImage>(image));
|
||||
}
|
||||
return image;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue