mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
SystemInfo in plugins
This commit is contained in:
parent
8121d5c6f8
commit
cf13daad1c
46 changed files with 210 additions and 157 deletions
|
@ -25,7 +25,7 @@
|
|||
#include "fbreader/src/formats/FormatPlugin.h"
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jobjectArray JNICALL Java_org_geometerplus_fbreader_formats_PluginCollection_nativePlugins(JNIEnv* env, jobject thiz) {
|
||||
JNIEXPORT jobjectArray JNICALL Java_org_geometerplus_fbreader_formats_PluginCollection_nativePlugins(JNIEnv* env, jobject thiz, jobject systemInfo) {
|
||||
const std::vector<shared_ptr<FormatPlugin> > plugins = PluginCollection::Instance().plugins();
|
||||
const std::size_t size = plugins.size();
|
||||
jclass cls = AndroidUtil::Class_NativeFormatPlugin.j();
|
||||
|
@ -34,7 +34,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_geometerplus_fbreader_formats_PluginColl
|
|||
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
jstring fileType = AndroidUtil::createJavaString(env, plugins[i]->supportedFileType());
|
||||
jobject p = AndroidUtil::StaticMethod_NativeFormatPlugin_create->call(fileType);
|
||||
jobject p = AndroidUtil::StaticMethod_NativeFormatPlugin_create->call(systemInfo, fileType);
|
||||
env->SetObjectArrayElement(javaPlugins, i, p);
|
||||
env->DeleteLocalRef(p);
|
||||
env->DeleteLocalRef(fileType);
|
||||
|
|
|
@ -92,7 +92,7 @@ public:
|
|||
private:
|
||||
static PluginCollection *ourInstance;
|
||||
|
||||
jobject myJavaInstance;
|
||||
//jobject myJavaInstance;
|
||||
|
||||
std::vector<shared_ptr<FormatPlugin> > myPlugins;
|
||||
};
|
||||
|
|
|
@ -69,15 +69,15 @@ void PluginCollection::deleteInstance() {
|
|||
}
|
||||
|
||||
PluginCollection::PluginCollection() {
|
||||
JNIEnv *env = AndroidUtil::getEnv();
|
||||
jobject instance = AndroidUtil::StaticMethod_PluginCollection_Instance->call();
|
||||
myJavaInstance = env->NewGlobalRef(instance);
|
||||
env->DeleteLocalRef(instance);
|
||||
//JNIEnv *env = AndroidUtil::getEnv();
|
||||
//jobject instance = AndroidUtil::StaticMethod_PluginCollection_Instance->call();
|
||||
//myJavaInstance = env->NewGlobalRef(instance);
|
||||
//env->DeleteLocalRef(instance);
|
||||
}
|
||||
|
||||
PluginCollection::~PluginCollection() {
|
||||
JNIEnv *env = AndroidUtil::getEnv();
|
||||
env->DeleteGlobalRef(myJavaInstance);
|
||||
//JNIEnv *env = AndroidUtil::getEnv();
|
||||
//env->DeleteGlobalRef(myJavaInstance);
|
||||
}
|
||||
|
||||
shared_ptr<FormatPlugin> PluginCollection::pluginByType(const std::string &fileType) const {
|
||||
|
|
|
@ -75,7 +75,7 @@ shared_ptr<StringMethod> AndroidUtil::Method_ZLibrary_getVersionName;
|
|||
shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_NativeFormatPlugin_create;
|
||||
shared_ptr<StringMethod> AndroidUtil::Method_NativeFormatPlugin_supportedFileType;
|
||||
|
||||
shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_PluginCollection_Instance;
|
||||
//shared_ptr<StaticObjectMethod> AndroidUtil::StaticMethod_PluginCollection_Instance;
|
||||
|
||||
shared_ptr<ObjectMethod> AndroidUtil::Method_Encoding_createConverter;
|
||||
|
||||
|
@ -154,10 +154,10 @@ bool AndroidUtil::init(JavaVM* jvm) {
|
|||
StaticMethod_ZLibrary_Instance = new StaticObjectMethod(Class_ZLibrary, "Instance", Class_ZLibrary, "()");
|
||||
Method_ZLibrary_getVersionName = new StringMethod(Class_ZLibrary, "getVersionName", "()");
|
||||
|
||||
StaticMethod_NativeFormatPlugin_create = new StaticObjectMethod(Class_NativeFormatPlugin, "create", Class_NativeFormatPlugin, "(Ljava/lang/String;)");
|
||||
StaticMethod_NativeFormatPlugin_create = new StaticObjectMethod(Class_NativeFormatPlugin, "create", Class_NativeFormatPlugin, "(Lorg/geometerplus/zlibrary/core/util/SystemInfo;Ljava/lang/String;)");
|
||||
Method_NativeFormatPlugin_supportedFileType = new StringMethod(Class_NativeFormatPlugin, "supportedFileType", "()");
|
||||
|
||||
StaticMethod_PluginCollection_Instance = new StaticObjectMethod(Class_PluginCollection, "Instance", Class_PluginCollection, "()");
|
||||
//StaticMethod_PluginCollection_Instance = new StaticObjectMethod(Class_PluginCollection, "Instance", Class_PluginCollection, "()");
|
||||
|
||||
Method_Encoding_createConverter = new ObjectMethod(Class_Encoding, "createConverter", Class_EncodingConverter, "()");
|
||||
Field_EncodingConverter_Name = new ObjectField(Class_EncodingConverter, "Name", Class_java_lang_String);
|
||||
|
|
|
@ -127,7 +127,7 @@ public:
|
|||
static shared_ptr<StaticObjectMethod> StaticMethod_NativeFormatPlugin_create;
|
||||
static shared_ptr<StringMethod> Method_NativeFormatPlugin_supportedFileType;
|
||||
|
||||
static shared_ptr<StaticObjectMethod> StaticMethod_PluginCollection_Instance;
|
||||
//static shared_ptr<StaticObjectMethod> StaticMethod_PluginCollection_Instance;
|
||||
|
||||
static shared_ptr<ObjectMethod> Method_Encoding_createConverter;
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ import org.geometerplus.fbreader.bookmodel.BookModel;
|
|||
import org.geometerplus.fbreader.fbreader.*;
|
||||
import org.geometerplus.fbreader.fbreader.options.CancelMenuHelper;
|
||||
import org.geometerplus.fbreader.formats.ExternalFormatPlugin;
|
||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||
import org.geometerplus.fbreader.tips.TipsManager;
|
||||
|
||||
import org.geometerplus.android.fbreader.api.*;
|
||||
|
@ -350,7 +351,10 @@ public final class FBReader extends FBReaderMainActivity implements ZLApplicatio
|
|||
if (!collection.sameBook(b, myFBReaderApp.ExternalBook)) {
|
||||
try {
|
||||
final ExternalFormatPlugin plugin =
|
||||
(ExternalFormatPlugin)BookUtil.getPlugin(myFBReaderApp.ExternalBook);
|
||||
(ExternalFormatPlugin)BookUtil.getPlugin(
|
||||
PluginCollection.Instance(Paths.systemInfo(this)),
|
||||
myFBReaderApp.ExternalBook
|
||||
);
|
||||
startActivity(PluginUtil.createIntent(plugin, FBReaderIntents.Action.PLUGIN_KILL));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.geometerplus.zlibrary.core.util.MimeType;
|
|||
import org.geometerplus.zlibrary.core.util.SliceInputStream;
|
||||
import org.geometerplus.zlibrary.ui.android.image.ZLBitmapImage;
|
||||
|
||||
import org.geometerplus.fbreader.Paths;
|
||||
import org.geometerplus.fbreader.book.CoverUtil;
|
||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||
import org.geometerplus.fbreader.formats.PluginImage;
|
||||
|
@ -60,7 +61,7 @@ public class DataServer extends NanoHTTPD {
|
|||
try {
|
||||
final ZLImage image = CoverUtil.getCover(
|
||||
DataUtil.fileFromEncodedPath(uri.substring(7)),
|
||||
PluginCollection.Instance()
|
||||
PluginCollection.Instance(Paths.systemInfo(myService))
|
||||
);
|
||||
if (image instanceof ZLFileImageProxy) {
|
||||
final ZLFileImageProxy proxy = (ZLFileImageProxy)image;
|
||||
|
|
|
@ -93,13 +93,16 @@ public class BookInfoActivity extends Activity implements IBookCollection.Listen
|
|||
|
||||
OrientationUtil.setOrientation(this, getIntent());
|
||||
|
||||
final PluginCollection pluginCollection =
|
||||
PluginCollection.Instance(Paths.systemInfo(this));
|
||||
|
||||
if (myBook != null) {
|
||||
// we force language & encoding detection
|
||||
BookUtil.getEncoding(myBook);
|
||||
BookUtil.getEncoding(myBook, pluginCollection);
|
||||
|
||||
setupCover(myBook);
|
||||
setupBookInfo(myBook);
|
||||
setupAnnotation(myBook);
|
||||
setupAnnotation(myBook, pluginCollection);
|
||||
setupFileInfo(myBook);
|
||||
}
|
||||
|
||||
|
@ -123,7 +126,7 @@ public class BookInfoActivity extends Activity implements IBookCollection.Listen
|
|||
setupButton(R.id.book_info_button_reload, "reloadInfo", new View.OnClickListener() {
|
||||
public void onClick(View view) {
|
||||
if (myBook != null) {
|
||||
BookUtil.reloadInfoFromFile(myBook);
|
||||
BookUtil.reloadInfoFromFile(myBook, pluginCollection);
|
||||
setupBookInfo(myBook);
|
||||
myDontReloadBook = false;
|
||||
myCollection.bindToService(BookInfoActivity.this, new Runnable() {
|
||||
|
@ -189,7 +192,7 @@ public class BookInfoActivity extends Activity implements IBookCollection.Listen
|
|||
coverView.setVisibility(View.GONE);
|
||||
coverView.setImageDrawable(null);
|
||||
|
||||
final ZLImage image = CoverUtil.getCover(book, PluginCollection.Instance());
|
||||
final ZLImage image = CoverUtil.getCover(book, PluginCollection.Instance(Paths.systemInfo(this)));
|
||||
|
||||
if (image == null) {
|
||||
return;
|
||||
|
@ -276,10 +279,10 @@ public class BookInfoActivity extends Activity implements IBookCollection.Listen
|
|||
setupInfoPair(R.id.book_language, "language", new Language(language).Name);
|
||||
}
|
||||
|
||||
private void setupAnnotation(Book book) {
|
||||
private void setupAnnotation(Book book, PluginCollection pluginCollection) {
|
||||
final TextView titleView = (TextView)findViewById(R.id.book_info_annotation_title);
|
||||
final TextView bodyView = (TextView)findViewById(R.id.book_info_annotation_body);
|
||||
final String annotation = BookUtil.getAnnotation(book);
|
||||
final String annotation = BookUtil.getAnnotation(book, pluginCollection);
|
||||
if (annotation == null) {
|
||||
titleView.setVisibility(View.GONE);
|
||||
bodyView.setVisibility(View.GONE);
|
||||
|
|
|
@ -35,7 +35,9 @@ import org.geometerplus.zlibrary.core.resources.ZLResource;
|
|||
|
||||
import org.geometerplus.zlibrary.ui.android.R;
|
||||
|
||||
import org.geometerplus.fbreader.Paths;
|
||||
import org.geometerplus.fbreader.book.*;
|
||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||
import org.geometerplus.fbreader.library.*;
|
||||
import org.geometerplus.fbreader.tree.FBTree;
|
||||
|
||||
|
@ -68,7 +70,7 @@ public class LibraryActivity extends TreeActivity<LibraryTree> implements MenuIt
|
|||
myCollection.bindToService(this, new Runnable() {
|
||||
public void run() {
|
||||
setProgressBarIndeterminateVisibility(!myCollection.status().IsComplete);
|
||||
myRootTree = new RootTree(myCollection);
|
||||
myRootTree = new RootTree(myCollection, PluginCollection.Instance(Paths.systemInfo(LibraryActivity.this)));
|
||||
myCollection.addListener(LibraryActivity.this);
|
||||
init(getIntent());
|
||||
}
|
||||
|
|
|
@ -100,7 +100,9 @@ public class LibraryService extends Service {
|
|||
|
||||
LibraryImplementation(BooksDatabase db) {
|
||||
myDatabase = db;
|
||||
myCollection = new BookCollection(myDatabase, Paths.bookPath());
|
||||
myCollection = new BookCollection(
|
||||
Paths.systemInfo(LibraryService.this), myDatabase, Paths.bookPath()
|
||||
);
|
||||
reset(true);
|
||||
}
|
||||
|
||||
|
@ -124,7 +126,9 @@ public class LibraryService extends Service {
|
|||
deactivate();
|
||||
myFileObservers.clear();
|
||||
|
||||
myCollection = new BookCollection(myDatabase, bookDirectories);
|
||||
myCollection = new BookCollection(
|
||||
Paths.systemInfo(LibraryService.this), myDatabase, bookDirectories
|
||||
);
|
||||
for (String dir : bookDirectories) {
|
||||
final Observer observer = new Observer(dir, myCollection);
|
||||
observer.startWatching();
|
||||
|
@ -293,7 +297,7 @@ public class LibraryService extends Service {
|
|||
|
||||
@Override
|
||||
public String getDescription(String book) {
|
||||
return BookUtil.getAnnotation(SerializerUtil.deserializeBook(book, myCollection));
|
||||
return BookUtil.getAnnotation(SerializerUtil.deserializeBook(book, myCollection), myCollection.PluginCollection);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,9 +31,9 @@ import org.geometerplus.zlibrary.core.resources.ZLResource;
|
|||
|
||||
import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator;
|
||||
|
||||
import org.geometerplus.fbreader.Paths;
|
||||
import org.geometerplus.fbreader.book.*;
|
||||
import org.geometerplus.fbreader.formats.BookReadingException;
|
||||
import org.geometerplus.fbreader.formats.FormatPlugin;
|
||||
import org.geometerplus.fbreader.formats.*;
|
||||
|
||||
import org.geometerplus.android.fbreader.api.FBReaderIntents;
|
||||
import org.geometerplus.android.fbreader.libraryService.BookCollectionShadow;
|
||||
|
@ -89,15 +89,17 @@ class BookLanguagePreference extends LanguagePreference {
|
|||
}
|
||||
|
||||
class EncodingPreference extends ZLStringListPreference {
|
||||
private final PluginCollection myPluginCollection;
|
||||
private final Book myBook;
|
||||
|
||||
EncodingPreference(Context context, ZLResource resource, Book book) {
|
||||
super(context, resource);
|
||||
myBook = book;
|
||||
myPluginCollection = PluginCollection.Instance(Paths.systemInfo(context));
|
||||
|
||||
final FormatPlugin plugin;
|
||||
try {
|
||||
plugin = BookUtil.getPlugin(book);
|
||||
plugin = BookUtil.getPlugin(myPluginCollection, book);
|
||||
} catch (BookReadingException e) {
|
||||
return;
|
||||
}
|
||||
|
@ -123,7 +125,7 @@ class EncodingPreference extends ZLStringListPreference {
|
|||
setInitialValue(codes[0]);
|
||||
setEnabled(false);
|
||||
} else {
|
||||
final String bookEncoding = BookUtil.getEncoding(book);
|
||||
final String bookEncoding = BookUtil.getEncoding(book, myPluginCollection);
|
||||
if (bookEncoding != null) {
|
||||
setInitialValue(bookEncoding.toLowerCase());
|
||||
}
|
||||
|
@ -135,7 +137,7 @@ class EncodingPreference extends ZLStringListPreference {
|
|||
super.onDialogClosed(result);
|
||||
if (result) {
|
||||
final String value = getValue();
|
||||
if (!value.equalsIgnoreCase(BookUtil.getEncoding(myBook))) {
|
||||
if (!value.equalsIgnoreCase(BookUtil.getEncoding(myBook, myPluginCollection))) {
|
||||
myBook.setEncoding(value);
|
||||
((EditBookInfoActivity)getContext()).saveBook();
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.*;
|
|||
import org.geometerplus.zlibrary.core.filesystem.*;
|
||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||
import org.geometerplus.zlibrary.core.util.MiscUtil;
|
||||
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||
|
||||
import org.geometerplus.zlibrary.text.view.ZLTextFixedPosition;
|
||||
import org.geometerplus.zlibrary.text.view.ZLTextPosition;
|
||||
|
@ -34,6 +35,8 @@ import org.geometerplus.fbreader.formats.*;
|
|||
public class BookCollection extends AbstractBookCollection<DbBook> {
|
||||
private static final String ZERO_HASH = String.format("%040d", 0);
|
||||
|
||||
private final SystemInfo mySystemInfo;
|
||||
public final PluginCollection PluginCollection;
|
||||
private final BooksDatabase myDatabase;
|
||||
public final List<String> BookDirectories;
|
||||
private Set<String> myActiveFormats;
|
||||
|
@ -51,7 +54,9 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
|||
private final Map<Integer,HighlightingStyle> myStyles =
|
||||
Collections.synchronizedMap(new TreeMap<Integer,HighlightingStyle>());
|
||||
|
||||
public BookCollection(BooksDatabase db, List<String> bookDirectories) {
|
||||
public BookCollection(SystemInfo systemInfo, BooksDatabase db, List<String> bookDirectories) {
|
||||
mySystemInfo = systemInfo;
|
||||
PluginCollection = org.geometerplus.fbreader.formats.PluginCollection.Instance(systemInfo);
|
||||
myDatabase = db;
|
||||
BookDirectories = Collections.unmodifiableList(new ArrayList<String>(bookDirectories));
|
||||
|
||||
|
@ -74,7 +79,7 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
|||
return null;
|
||||
}
|
||||
|
||||
return getBookByFile(bookFile, PluginCollection.Instance().getPlugin(bookFile));
|
||||
return getBookByFile(bookFile, PluginCollection.getPlugin(bookFile));
|
||||
}
|
||||
|
||||
private DbBook getBookByFile(ZLFile bookFile, final FormatPlugin plugin) {
|
||||
|
@ -110,7 +115,7 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
|||
|
||||
book = myDatabase.loadBookByFile(fileInfos.getId(bookFile), bookFile);
|
||||
if (book != null) {
|
||||
book.loadLists(myDatabase);
|
||||
book.loadLists(myDatabase, PluginCollection);
|
||||
}
|
||||
|
||||
if (book != null && fileInfos.check(physicalFile, physicalFile != bookFile)) {
|
||||
|
@ -143,7 +148,7 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
|||
if (book == null || book.File == null || !book.File.exists() || !isBookFormatActive(book)) {
|
||||
return null;
|
||||
}
|
||||
book.loadLists(myDatabase);
|
||||
book.loadLists(myDatabase, PluginCollection);
|
||||
|
||||
final ZLFile bookFile = book.File;
|
||||
final ZLPhysicalFile physicalFile = bookFile.getPhysicalFile();
|
||||
|
@ -165,7 +170,7 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
|||
fileInfos.save();
|
||||
|
||||
try {
|
||||
BookUtil.readMetainfo(book);
|
||||
BookUtil.readMetainfo(book, PluginCollection);
|
||||
// loaded from db
|
||||
addBook(book, false);
|
||||
return book;
|
||||
|
@ -560,7 +565,7 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
|||
}
|
||||
if (!fileInfos.check(file, true)) {
|
||||
try {
|
||||
BookUtil.readMetainfo(book);
|
||||
BookUtil.readMetainfo(book, PluginCollection);
|
||||
saveBook(book);
|
||||
} catch (BookReadingException e) {
|
||||
doAdd = false;
|
||||
|
@ -659,7 +664,7 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
|||
return;
|
||||
}
|
||||
|
||||
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(file);
|
||||
final FormatPlugin plugin = PluginCollection.getPlugin(file);
|
||||
if (plugin != null && !isFormatActive(plugin)) {
|
||||
return;
|
||||
}
|
||||
|
@ -668,7 +673,7 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
|||
final DbBook book = orphanedBooksByFileId.get(fileId);
|
||||
if (book != null) {
|
||||
if (doReadMetaInfo) {
|
||||
BookUtil.readMetainfo(book);
|
||||
BookUtil.readMetainfo(book, PluginCollection);
|
||||
}
|
||||
newBooks.add(book);
|
||||
return;
|
||||
|
@ -834,7 +839,7 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
|||
}
|
||||
|
||||
public List<FormatDescriptor> formats() {
|
||||
final List<FormatPlugin> plugins = PluginCollection.Instance().plugins();
|
||||
final List<FormatPlugin> plugins = PluginCollection.plugins();
|
||||
final List<FormatDescriptor> descriptors = new ArrayList<FormatDescriptor>(plugins.size());
|
||||
for (FormatPlugin p : plugins) {
|
||||
final FormatDescriptor d = new FormatDescriptor();
|
||||
|
@ -863,7 +868,7 @@ public class BookCollection extends AbstractBookCollection<DbBook> {
|
|||
|
||||
private boolean isBookFormatActive(DbBook book) {
|
||||
try {
|
||||
return isFormatActive(BookUtil.getPlugin(book));
|
||||
return isFormatActive(BookUtil.getPlugin(PluginCollection, book));
|
||||
} catch (BookReadingException e) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -28,9 +28,9 @@ import org.geometerplus.zlibrary.text.view.ZLTextPosition;
|
|||
import org.geometerplus.fbreader.formats.BookReadingException;
|
||||
|
||||
class BookMergeHelper {
|
||||
private final IBookCollection myCollection;
|
||||
private final BookCollection myCollection;
|
||||
|
||||
BookMergeHelper(IBookCollection collection) {
|
||||
BookMergeHelper(BookCollection collection) {
|
||||
myCollection = collection;
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ class BookMergeHelper {
|
|||
}
|
||||
final DbBook vanilla;
|
||||
try {
|
||||
vanilla = new DbBook(base.File, BookUtil.getPlugin(base));
|
||||
vanilla = new DbBook(base.File, BookUtil.getPlugin(myCollection.PluginCollection, base));
|
||||
} catch (BookReadingException e) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -30,9 +30,9 @@ import org.geometerplus.zlibrary.core.filesystem.*;
|
|||
import org.geometerplus.fbreader.formats.*;
|
||||
|
||||
public abstract class BookUtil {
|
||||
public static String getAnnotation(AbstractBook book) {
|
||||
public static String getAnnotation(AbstractBook book, PluginCollection pluginCollection) {
|
||||
try {
|
||||
return getPlugin(book).readAnnotation(fileByBook(book));
|
||||
return getPlugin(pluginCollection, book).readAnnotation(fileByBook(book));
|
||||
} catch (BookReadingException e) {
|
||||
return null;
|
||||
}
|
||||
|
@ -97,19 +97,19 @@ public abstract class BookUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static FormatPlugin getPlugin(AbstractBook book) throws BookReadingException {
|
||||
public static FormatPlugin getPlugin(PluginCollection pluginCollection, AbstractBook book) throws BookReadingException {
|
||||
final ZLFile file = fileByBook(book);
|
||||
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(file);
|
||||
final FormatPlugin plugin = pluginCollection.getPlugin(file);
|
||||
if (plugin == null) {
|
||||
throw new BookReadingException("pluginNotFound", file);
|
||||
}
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public static String getEncoding(AbstractBook book) {
|
||||
public static String getEncoding(AbstractBook book, PluginCollection pluginCollection) {
|
||||
if (book.getEncodingNoDetection() == null) {
|
||||
try {
|
||||
BookUtil.getPlugin(book).detectLanguageAndEncoding(book);
|
||||
BookUtil.getPlugin(pluginCollection, book).detectLanguageAndEncoding(book);
|
||||
} catch (BookReadingException e) {
|
||||
}
|
||||
if (book.getEncodingNoDetection() == null) {
|
||||
|
@ -119,16 +119,16 @@ public abstract class BookUtil {
|
|||
return book.getEncodingNoDetection();
|
||||
}
|
||||
|
||||
public static void reloadInfoFromFile(AbstractBook book) {
|
||||
public static void reloadInfoFromFile(AbstractBook book, PluginCollection pluginCollection) {
|
||||
try {
|
||||
readMetainfo(book);
|
||||
readMetainfo(book, pluginCollection);
|
||||
} catch (BookReadingException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
static void readMetainfo(AbstractBook book) throws BookReadingException {
|
||||
readMetainfo(book, getPlugin(book));
|
||||
static void readMetainfo(AbstractBook book, PluginCollection pluginCollection) throws BookReadingException {
|
||||
readMetainfo(book, getPlugin(pluginCollection, book));
|
||||
}
|
||||
|
||||
static void readMetainfo(AbstractBook book, FormatPlugin plugin) throws BookReadingException {
|
||||
|
|
|
@ -24,8 +24,7 @@ import java.util.*;
|
|||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.util.MiscUtil;
|
||||
|
||||
import org.geometerplus.fbreader.formats.BookReadingException;
|
||||
import org.geometerplus.fbreader.formats.FormatPlugin;
|
||||
import org.geometerplus.fbreader.formats.*;
|
||||
|
||||
public final class DbBook extends AbstractBook {
|
||||
public final ZLFile File;
|
||||
|
@ -51,7 +50,7 @@ public final class DbBook extends AbstractBook {
|
|||
return File.getPath();
|
||||
}
|
||||
|
||||
void loadLists(BooksDatabase database) {
|
||||
void loadLists(BooksDatabase database, PluginCollection pluginCollection) {
|
||||
myAuthors = database.listAuthors(myId);
|
||||
myTags = database.listTags(myId);
|
||||
myLabels = database.listLabels(myId);
|
||||
|
@ -62,7 +61,7 @@ public final class DbBook extends AbstractBook {
|
|||
myIsSaved = true;
|
||||
if (myUids == null || myUids.isEmpty()) {
|
||||
try {
|
||||
BookUtil.getPlugin(this).readUids(this);
|
||||
BookUtil.getPlugin(pluginCollection, this).readUids(this);
|
||||
save(database, false);
|
||||
} catch (BookReadingException e) {
|
||||
}
|
||||
|
|
|
@ -30,12 +30,10 @@ import org.geometerplus.fbreader.book.BookUtil;
|
|||
import org.geometerplus.fbreader.formats.*;
|
||||
|
||||
public final class BookModel {
|
||||
public static BookModel createModel(Book book, String cacheDir) throws BookReadingException {
|
||||
final FormatPlugin plugin = BookUtil.getPlugin(book);
|
||||
|
||||
public static BookModel createModel(Book book, FormatPlugin plugin) throws BookReadingException {
|
||||
if (plugin instanceof BuiltinFormatPlugin) {
|
||||
final BookModel model = new BookModel(book);
|
||||
((BuiltinFormatPlugin)plugin).readModel(model, cacheDir);
|
||||
((BuiltinFormatPlugin)plugin).readModel(model);
|
||||
return model;
|
||||
}
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ public final class FBReaderApp extends ZLApplication {
|
|||
|
||||
public FBReaderApp(SystemInfo systemInfo, final IBookCollection<Book> collection) {
|
||||
super(systemInfo);
|
||||
System.err.println("systemInfo 0 = " + systemInfo);
|
||||
|
||||
Collection = collection;
|
||||
|
||||
|
@ -313,7 +314,7 @@ public final class FBReaderApp extends ZLApplication {
|
|||
}
|
||||
}
|
||||
|
||||
private synchronized void openBookInternal(Book book, Bookmark bookmark, boolean force) {
|
||||
private synchronized void openBookInternal(final Book book, Bookmark bookmark, boolean force) {
|
||||
if (!force && Model != null && Collection.sameBook(book, Model.Book)) {
|
||||
if (bookmark != null) {
|
||||
gotoBookmark(bookmark, false);
|
||||
|
@ -332,9 +333,11 @@ public final class FBReaderApp extends ZLApplication {
|
|||
System.gc();
|
||||
System.gc();
|
||||
|
||||
System.err.println("systemInfo 1 = " + SystemInfo);
|
||||
final PluginCollection pluginCollection = PluginCollection.Instance(SystemInfo);
|
||||
FormatPlugin plugin = null;
|
||||
try {
|
||||
plugin = BookUtil.getPlugin(book);
|
||||
plugin = BookUtil.getPlugin(pluginCollection, book);
|
||||
} catch (BookReadingException e) {
|
||||
// ignore
|
||||
}
|
||||
|
@ -355,7 +358,8 @@ public final class FBReaderApp extends ZLApplication {
|
|||
}
|
||||
|
||||
try {
|
||||
Model = BookModel.createModel(book, SystemInfo.tempDirectory());
|
||||
System.err.println("systemInfo 2 = " + SystemInfo);
|
||||
Model = BookModel.createModel(book, plugin);
|
||||
Collection.saveBook(book);
|
||||
ZLTextHyphenator.Instance().load(book.getLanguage());
|
||||
BookTextView.setModel(Model.getTextModel());
|
||||
|
@ -385,16 +389,12 @@ public final class FBReaderApp extends ZLApplication {
|
|||
getViewWidget().reset();
|
||||
getViewWidget().repaint();
|
||||
|
||||
try {
|
||||
for (FileEncryptionInfo info : BookUtil.getPlugin(book).readEncryptionInfos(book)) {
|
||||
for (FileEncryptionInfo info : plugin.readEncryptionInfos(book)) {
|
||||
if (info != null && !EncryptionMethod.isSupported(info.Method)) {
|
||||
showErrorMessage("unsupportedEncryptionMethod", book.getPath());
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (BookReadingException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
private List<Bookmark> invisibleBookmarks() {
|
||||
|
|
|
@ -19,12 +19,14 @@
|
|||
|
||||
package org.geometerplus.fbreader.formats;
|
||||
|
||||
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||
|
||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||
|
||||
public abstract class BuiltinFormatPlugin extends FormatPlugin {
|
||||
protected BuiltinFormatPlugin(String fileType) {
|
||||
super(fileType);
|
||||
protected BuiltinFormatPlugin(SystemInfo systemInfo, String fileType) {
|
||||
super(systemInfo, fileType);
|
||||
}
|
||||
|
||||
public abstract void readModel(BookModel model, String cacheDir) throws BookReadingException;
|
||||
public abstract void readModel(BookModel model) throws BookReadingException;
|
||||
}
|
||||
|
|
|
@ -19,11 +19,13 @@
|
|||
|
||||
package org.geometerplus.fbreader.formats;
|
||||
|
||||
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||
|
||||
import org.geometerplus.fbreader.book.AbstractBook;
|
||||
|
||||
public class ComicBookPlugin extends ExternalFormatPlugin {
|
||||
public ComicBookPlugin() {
|
||||
super("CBZ");
|
||||
public ComicBookPlugin(SystemInfo systemInfo) {
|
||||
super(systemInfo, "CBZ");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,11 +19,13 @@
|
|||
|
||||
package org.geometerplus.fbreader.formats;
|
||||
|
||||
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||
|
||||
import org.geometerplus.fbreader.book.AbstractBook;
|
||||
|
||||
public class DjVuPlugin extends ExternalFormatPlugin {
|
||||
public DjVuPlugin() {
|
||||
super("DjVu");
|
||||
public DjVuPlugin(SystemInfo systemInfo) {
|
||||
super(systemInfo, "DjVu");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -21,13 +21,14 @@ package org.geometerplus.fbreader.formats;
|
|||
|
||||
import org.geometerplus.zlibrary.core.encodings.AutoEncodingCollection;
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||
|
||||
import org.geometerplus.fbreader.book.AbstractBook;
|
||||
import org.geometerplus.fbreader.book.BookUtil;
|
||||
|
||||
public abstract class ExternalFormatPlugin extends FormatPlugin {
|
||||
protected ExternalFormatPlugin(String fileType) {
|
||||
super(fileType);
|
||||
protected ExternalFormatPlugin(SystemInfo systemInfo, String fileType) {
|
||||
super(systemInfo, fileType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,13 +27,16 @@ import org.geometerplus.zlibrary.core.encodings.EncodingCollection;
|
|||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||
|
||||
import org.geometerplus.fbreader.book.AbstractBook;
|
||||
|
||||
public abstract class FormatPlugin {
|
||||
protected final SystemInfo SystemInfo;
|
||||
private final String myFileType;
|
||||
|
||||
protected FormatPlugin(String fileType) {
|
||||
protected FormatPlugin(SystemInfo systemInfo, String fileType) {
|
||||
SystemInfo = systemInfo;
|
||||
myFileType = fileType;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.geometerplus.zlibrary.core.encodings.EncodingCollection;
|
|||
import org.geometerplus.zlibrary.core.encodings.JavaEncodingCollection;
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.image.*;
|
||||
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||
import org.geometerplus.zlibrary.text.model.CachedCharStorageException;
|
||||
|
||||
import org.geometerplus.fbreader.book.AbstractBook;
|
||||
|
@ -37,18 +38,18 @@ import org.geometerplus.fbreader.formats.oeb.OEBNativePlugin;
|
|||
public class NativeFormatPlugin extends BuiltinFormatPlugin {
|
||||
private static final Object ourNativeLock = new Object();
|
||||
|
||||
public static NativeFormatPlugin create(String fileType) {
|
||||
public static NativeFormatPlugin create(SystemInfo systemInfo, String fileType) {
|
||||
if ("fb2".equals(fileType)) {
|
||||
return new FB2NativePlugin();
|
||||
return new FB2NativePlugin(systemInfo);
|
||||
} else if ("ePub".equals(fileType)) {
|
||||
return new OEBNativePlugin();
|
||||
return new OEBNativePlugin(systemInfo);
|
||||
} else {
|
||||
return new NativeFormatPlugin(fileType);
|
||||
return new NativeFormatPlugin(systemInfo, fileType);
|
||||
}
|
||||
}
|
||||
|
||||
protected NativeFormatPlugin(String fileType) {
|
||||
super(fileType);
|
||||
protected NativeFormatPlugin(SystemInfo systemInfo, String fileType) {
|
||||
super(systemInfo, fileType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -103,10 +104,10 @@ public class NativeFormatPlugin extends BuiltinFormatPlugin {
|
|||
private native void detectLanguageAndEncodingNative(AbstractBook book);
|
||||
|
||||
@Override
|
||||
synchronized public void readModel(BookModel model, String cacheDir) throws BookReadingException {
|
||||
synchronized public void readModel(BookModel model) throws BookReadingException {
|
||||
final int code;
|
||||
synchronized (ourNativeLock) {
|
||||
code = readModelNative(model, cacheDir);
|
||||
code = readModelNative(model, SystemInfo.tempDirectory());
|
||||
}
|
||||
switch (code) {
|
||||
case 0:
|
||||
|
|
|
@ -23,12 +23,14 @@ import org.pdfparse.model.PDFDocInfo;
|
|||
import org.pdfparse.model.PDFDocument;
|
||||
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||
|
||||
import org.geometerplus.fbreader.book.AbstractBook;
|
||||
import org.geometerplus.fbreader.book.BookUtil;
|
||||
|
||||
public class PDFPlugin extends ExternalFormatPlugin {
|
||||
public PDFPlugin() {
|
||||
super("PDF");
|
||||
public PDFPlugin(SystemInfo systemInfo) {
|
||||
super(systemInfo, "PDF");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,6 +25,7 @@ import android.os.Build;
|
|||
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.filetypes.*;
|
||||
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||
|
||||
public class PluginCollection implements IFormatPluginCollection {
|
||||
static {
|
||||
|
@ -38,20 +39,20 @@ public class PluginCollection implements IFormatPluginCollection {
|
|||
private final List<ExternalFormatPlugin> myExternalPlugins =
|
||||
new LinkedList<ExternalFormatPlugin>();
|
||||
|
||||
public static PluginCollection Instance() {
|
||||
public static PluginCollection Instance(SystemInfo systemInfo) {
|
||||
if (ourInstance == null) {
|
||||
createInstance();
|
||||
createInstance(systemInfo);
|
||||
}
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
private static synchronized void createInstance() {
|
||||
private static synchronized void createInstance(SystemInfo systemInfo) {
|
||||
if (ourInstance == null) {
|
||||
ourInstance = new PluginCollection();
|
||||
ourInstance = new PluginCollection(systemInfo);
|
||||
|
||||
// This code cannot be moved to constructor
|
||||
// because nativePlugins() is a native method
|
||||
for (NativeFormatPlugin p : ourInstance.nativePlugins()) {
|
||||
for (NativeFormatPlugin p : ourInstance.nativePlugins(systemInfo)) {
|
||||
ourInstance.myBuiltinPlugins.add(p);
|
||||
System.err.println("native plugin: " + p);
|
||||
}
|
||||
|
@ -64,11 +65,11 @@ public class PluginCollection implements IFormatPluginCollection {
|
|||
}
|
||||
}
|
||||
|
||||
private PluginCollection() {
|
||||
private PluginCollection(SystemInfo systemInfo) {
|
||||
if (Build.VERSION.SDK_INT >= 8) {
|
||||
myExternalPlugins.add(new DjVuPlugin());
|
||||
myExternalPlugins.add(new PDFPlugin());
|
||||
myExternalPlugins.add(new ComicBookPlugin());
|
||||
myExternalPlugins.add(new DjVuPlugin(systemInfo));
|
||||
myExternalPlugins.add(new PDFPlugin(systemInfo));
|
||||
myExternalPlugins.add(new ComicBookPlugin(systemInfo));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,7 +116,7 @@ public class PluginCollection implements IFormatPluginCollection {
|
|||
return all;
|
||||
}
|
||||
|
||||
private native NativeFormatPlugin[] nativePlugins();
|
||||
private native NativeFormatPlugin[] nativePlugins(SystemInfo systemInfo);
|
||||
private native void free();
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
|
|
|
@ -25,8 +25,8 @@ import java.util.List;
|
|||
|
||||
import org.geometerplus.zlibrary.core.encodings.EncodingCollection;
|
||||
import org.geometerplus.zlibrary.core.encodings.AutoEncodingCollection;
|
||||
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||
|
||||
import org.geometerplus.fbreader.book.AbstractBook;
|
||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||
|
@ -34,13 +34,15 @@ import org.geometerplus.fbreader.formats.BookReadingException;
|
|||
import org.geometerplus.fbreader.formats.NativeFormatPlugin;
|
||||
|
||||
public class FB2NativePlugin extends NativeFormatPlugin {
|
||||
public FB2NativePlugin() {
|
||||
super("fb2");
|
||||
public FB2NativePlugin(SystemInfo systemInfo) {
|
||||
super(systemInfo, "fb2");
|
||||
System.err.println("systemInfo fbc " + systemInfo);
|
||||
new Exception("systemInfo fbc2").printStackTrace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readModel(BookModel model, String cacheDir) throws BookReadingException {
|
||||
super.readModel(model, cacheDir);
|
||||
public void readModel(BookModel model) throws BookReadingException {
|
||||
super.readModel(model);
|
||||
model.setLabelResolver(new BookModel.LabelResolver() {
|
||||
public List<String> getCandidates(String id) {
|
||||
final List<String> candidates = new ArrayList<String>();
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.List;
|
|||
import org.geometerplus.zlibrary.core.encodings.EncodingCollection;
|
||||
import org.geometerplus.zlibrary.core.encodings.AutoEncodingCollection;
|
||||
import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||
import org.geometerplus.zlibrary.core.util.SystemInfo;
|
||||
|
||||
import org.geometerplus.fbreader.book.AbstractBook;
|
||||
import org.geometerplus.fbreader.book.BookUtil;
|
||||
|
@ -33,16 +34,16 @@ import org.geometerplus.fbreader.formats.BookReadingException;
|
|||
import org.geometerplus.fbreader.formats.NativeFormatPlugin;
|
||||
|
||||
public class OEBNativePlugin extends NativeFormatPlugin {
|
||||
public OEBNativePlugin() {
|
||||
super("ePub");
|
||||
public OEBNativePlugin(SystemInfo systemInfo) {
|
||||
super(systemInfo, "ePub");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readModel(BookModel model, String cacheDir) throws BookReadingException {
|
||||
public void readModel(BookModel model) throws BookReadingException {
|
||||
final ZLFile file = BookUtil.fileByBook(model.Book);
|
||||
file.setCached(true);
|
||||
try {
|
||||
super.readModel(model, cacheDir);
|
||||
super.readModel(model);
|
||||
model.setLabelResolver(new BookModel.LabelResolver() {
|
||||
public List<String> getCandidates(String id) {
|
||||
final int index = id.indexOf("#");
|
||||
|
|
|
@ -67,7 +67,7 @@ public class AuthorListTree extends FirstLevelTree {
|
|||
}
|
||||
|
||||
private boolean createAuthorSubtree(Author author) {
|
||||
final AuthorTree temp = new AuthorTree(Collection, author);
|
||||
final AuthorTree temp = new AuthorTree(Collection, PluginCollection, author);
|
||||
int position = Collections.binarySearch(subtrees(), temp);
|
||||
if (position >= 0) {
|
||||
return false;
|
||||
|
|
|
@ -22,12 +22,13 @@ package org.geometerplus.fbreader.library;
|
|||
import java.util.Collections;
|
||||
|
||||
import org.geometerplus.fbreader.book.*;
|
||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||
|
||||
public class AuthorTree extends FilteredTree {
|
||||
public final Author Author;
|
||||
|
||||
AuthorTree(IBookCollection collection, Author author) {
|
||||
super(collection, new Filter.ByAuthor(author));
|
||||
AuthorTree(IBookCollection collection, PluginCollection pluginCollection, Author author) {
|
||||
super(collection, pluginCollection, new Filter.ByAuthor(author));
|
||||
Author = author;
|
||||
}
|
||||
|
||||
|
@ -61,7 +62,7 @@ public class AuthorTree extends FilteredTree {
|
|||
}
|
||||
|
||||
private SeriesTree getSeriesSubtree(Series series) {
|
||||
final SeriesTree temp = new SeriesTree(Collection, series, Author);
|
||||
final SeriesTree temp = new SeriesTree(Collection, PluginCollection, series, Author);
|
||||
int position = Collections.binarySearch(subtrees(), temp);
|
||||
if (position >= 0) {
|
||||
return (SeriesTree)subtrees().get(position);
|
||||
|
@ -77,7 +78,7 @@ public class AuthorTree extends FilteredTree {
|
|||
return getSeriesSubtree(seriesInfo.Series).createSubtree(book);
|
||||
}
|
||||
|
||||
final BookTree temp = new BookTree(Collection, book);
|
||||
final BookTree temp = new BookTree(Collection, PluginCollection, book);
|
||||
int position = Collections.binarySearch(subtrees(), temp);
|
||||
if (position >= 0) {
|
||||
return false;
|
||||
|
|
|
@ -23,11 +23,12 @@ import java.math.BigDecimal;
|
|||
|
||||
import org.geometerplus.fbreader.book.Book;
|
||||
import org.geometerplus.fbreader.book.IBookCollection;
|
||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||
import org.geometerplus.fbreader.tree.FBTree;
|
||||
|
||||
public final class BookInSeriesTree extends BookTree {
|
||||
BookInSeriesTree(IBookCollection collection, Book book) {
|
||||
super(collection, book);
|
||||
BookInSeriesTree(IBookCollection collection, PluginCollection pluginCollection, Book book) {
|
||||
super(collection, pluginCollection, book);
|
||||
}
|
||||
|
||||
BookInSeriesTree(LibraryTree parent, Book book, int position) {
|
||||
|
|
|
@ -28,8 +28,8 @@ import org.geometerplus.fbreader.tree.FBTree;
|
|||
public class BookTree extends LibraryTree {
|
||||
public final Book Book;
|
||||
|
||||
BookTree(IBookCollection<Book> collection, Book book) {
|
||||
super(collection);
|
||||
BookTree(IBookCollection<Book> collection, PluginCollection pluginCollection, Book book) {
|
||||
super(collection, pluginCollection);
|
||||
Book = book;
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ public class BookTree extends LibraryTree {
|
|||
|
||||
@Override
|
||||
protected ZLImage createCover() {
|
||||
return CoverUtil.getCover(Book, PluginCollection.Instance());
|
||||
return CoverUtil.getCover(Book, PluginCollection);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,10 +20,11 @@
|
|||
package org.geometerplus.fbreader.library;
|
||||
|
||||
import org.geometerplus.fbreader.book.*;
|
||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||
|
||||
public class BookWithAuthorsTree extends BookTree {
|
||||
BookWithAuthorsTree(IBookCollection collection, Book book) {
|
||||
super(collection, book);
|
||||
BookWithAuthorsTree(IBookCollection collection, PluginCollection pluginCollection, Book book) {
|
||||
super(collection, pluginCollection, book);
|
||||
}
|
||||
|
||||
BookWithAuthorsTree(LibraryTree parent, Book book) {
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
|||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||
|
||||
import org.geometerplus.fbreader.book.*;
|
||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||
import org.geometerplus.fbreader.tree.FBTree;
|
||||
|
||||
public class FileTree extends LibraryTree {
|
||||
|
@ -86,7 +85,7 @@ public class FileTree extends LibraryTree {
|
|||
|
||||
@Override
|
||||
public ZLImage createCover() {
|
||||
return CoverUtil.getCover(getBook(), PluginCollection.Instance());
|
||||
return CoverUtil.getCover(getBook(), PluginCollection);
|
||||
}
|
||||
|
||||
public ZLFile getFile() {
|
||||
|
|
|
@ -24,12 +24,13 @@ import java.util.List;
|
|||
import org.geometerplus.zlibrary.core.util.MiscUtil;
|
||||
|
||||
import org.geometerplus.fbreader.book.*;
|
||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||
|
||||
abstract class FilteredTree extends LibraryTree {
|
||||
private final Filter myFilter;
|
||||
|
||||
FilteredTree(IBookCollection collection, Filter filter) {
|
||||
super(collection);
|
||||
FilteredTree(IBookCollection collection, PluginCollection pluginCollection, Filter filter) {
|
||||
super(collection, pluginCollection);
|
||||
myFilter = filter;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.*;
|
|||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
||||
import org.geometerplus.fbreader.book.*;
|
||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||
import org.geometerplus.fbreader.tree.FBTree;
|
||||
|
||||
public abstract class LibraryTree extends FBTree {
|
||||
|
@ -32,6 +33,7 @@ public abstract class LibraryTree extends FBTree {
|
|||
}
|
||||
|
||||
public final IBookCollection<Book> Collection;
|
||||
public final PluginCollection PluginCollection;
|
||||
|
||||
static final String ROOT_EXTERNAL_VIEW = "bookshelfView";
|
||||
static final String ROOT_FOUND = "found";
|
||||
|
@ -44,19 +46,22 @@ public abstract class LibraryTree extends FBTree {
|
|||
static final String ROOT_SYNC = "sync";
|
||||
static final String ROOT_FILE = "fileTree";
|
||||
|
||||
protected LibraryTree(IBookCollection collection) {
|
||||
protected LibraryTree(IBookCollection collection, PluginCollection pluginCollection) {
|
||||
super();
|
||||
Collection = collection;
|
||||
PluginCollection = pluginCollection;
|
||||
}
|
||||
|
||||
protected LibraryTree(LibraryTree parent) {
|
||||
super(parent);
|
||||
Collection = parent.Collection;
|
||||
PluginCollection = parent.PluginCollection;
|
||||
}
|
||||
|
||||
protected LibraryTree(LibraryTree parent, int position) {
|
||||
super(parent, position);
|
||||
Collection = parent.Collection;
|
||||
PluginCollection = parent.PluginCollection;
|
||||
}
|
||||
|
||||
public Book getBook() {
|
||||
|
@ -72,7 +77,7 @@ public abstract class LibraryTree extends FBTree {
|
|||
}
|
||||
|
||||
boolean createTagSubtree(Tag tag) {
|
||||
final TagTree temp = new TagTree(Collection, tag);
|
||||
final TagTree temp = new TagTree(Collection, PluginCollection, tag);
|
||||
int position = Collections.binarySearch(subtrees(), temp);
|
||||
if (position >= 0) {
|
||||
return false;
|
||||
|
@ -83,7 +88,7 @@ public abstract class LibraryTree extends FBTree {
|
|||
}
|
||||
|
||||
boolean createBookWithAuthorsSubtree(Book book) {
|
||||
final BookWithAuthorsTree temp = new BookWithAuthorsTree(Collection, book);
|
||||
final BookWithAuthorsTree temp = new BookWithAuthorsTree(Collection, PluginCollection, book);
|
||||
int position = Collections.binarySearch(subtrees(), temp);
|
||||
if (position >= 0) {
|
||||
return false;
|
||||
|
|
|
@ -23,11 +23,12 @@ import java.util.List;
|
|||
|
||||
import org.geometerplus.fbreader.book.IBookCollection;
|
||||
import org.geometerplus.fbreader.fbreader.options.SyncOptions;
|
||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||
import org.geometerplus.fbreader.tree.FBTree;
|
||||
|
||||
public class RootTree extends LibraryTree {
|
||||
public RootTree(IBookCollection collection) {
|
||||
super(collection);
|
||||
public RootTree(IBookCollection collection, PluginCollection pluginCollection) {
|
||||
super(collection, pluginCollection);
|
||||
|
||||
//new ExternalViewTree(this);
|
||||
new FavoritesTree(this);
|
||||
|
|
|
@ -72,7 +72,7 @@ public class SeriesListTree extends FirstLevelTree {
|
|||
private boolean createSeriesSubtree(String seriesTitle) {
|
||||
// TODO: pass series as parameter
|
||||
final Series series = new Series(seriesTitle);
|
||||
final SeriesTree temp = new SeriesTree(Collection, series, null);
|
||||
final SeriesTree temp = new SeriesTree(Collection, PluginCollection, series, null);
|
||||
int position = Collections.binarySearch(subtrees(), temp);
|
||||
if (position >= 0) {
|
||||
return false;
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.geometerplus.fbreader.library;
|
|||
import java.util.Collections;
|
||||
|
||||
import org.geometerplus.fbreader.book.*;
|
||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||
|
||||
public final class SeriesTree extends FilteredTree {
|
||||
public final Series Series;
|
||||
|
@ -31,8 +32,8 @@ public final class SeriesTree extends FilteredTree {
|
|||
return author != null ? new Filter.And(f, new Filter.ByAuthor(author)) : f;
|
||||
}
|
||||
|
||||
SeriesTree(IBookCollection collection, Series series, Author author) {
|
||||
super(collection, filter(series, author));
|
||||
SeriesTree(IBookCollection collection, PluginCollection pluginCollection, Series series, Author author) {
|
||||
super(collection, pluginCollection, filter(series, author));
|
||||
Series = series;
|
||||
}
|
||||
|
||||
|
@ -58,7 +59,7 @@ public final class SeriesTree extends FilteredTree {
|
|||
|
||||
@Override
|
||||
protected boolean createSubtree(Book book) {
|
||||
final BookInSeriesTree temp = new BookInSeriesTree(Collection, book);
|
||||
final BookInSeriesTree temp = new BookInSeriesTree(Collection, PluginCollection, book);
|
||||
int position = Collections.binarySearch(subtrees(), temp);
|
||||
if (position >= 0) {
|
||||
return false;
|
||||
|
|
|
@ -22,12 +22,13 @@ package org.geometerplus.fbreader.library;
|
|||
import java.util.List;
|
||||
|
||||
import org.geometerplus.fbreader.book.*;
|
||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||
|
||||
public final class TagTree extends FilteredTree {
|
||||
public final Tag Tag;
|
||||
|
||||
TagTree(IBookCollection collection, Tag tag) {
|
||||
super(collection, new Filter.ByTag(tag));
|
||||
TagTree(IBookCollection collection, PluginCollection pluginCollection, Tag tag) {
|
||||
super(collection, pluginCollection, new Filter.ByTag(tag));
|
||||
Tag = tag;
|
||||
}
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ public class TitleListTree extends FirstLevelTree {
|
|||
if (prefix == null) {
|
||||
return false;
|
||||
}
|
||||
final TitleTree temp = new TitleTree(Collection, prefix);
|
||||
final TitleTree temp = new TitleTree(Collection, PluginCollection, prefix);
|
||||
int position = Collections.binarySearch(subtrees(), temp);
|
||||
if (position >= 0) {
|
||||
return false;
|
||||
|
|
|
@ -20,12 +20,13 @@
|
|||
package org.geometerplus.fbreader.library;
|
||||
|
||||
import org.geometerplus.fbreader.book.*;
|
||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||
|
||||
public final class TitleTree extends FilteredTree {
|
||||
public final String Prefix;
|
||||
|
||||
TitleTree(IBookCollection collection, String prefix) {
|
||||
super(collection, new Filter.ByTitlePrefix(prefix));
|
||||
TitleTree(IBookCollection collection, PluginCollection pluginCollection, String prefix) {
|
||||
super(collection, pluginCollection, new Filter.ByTitlePrefix(prefix));
|
||||
Prefix = prefix;
|
||||
}
|
||||
|
||||
|
|
|
@ -132,11 +132,17 @@ public class OPDSBookItem extends NetworkBookItem implements OPDSConstants {
|
|||
}
|
||||
}
|
||||
if (MimeType.TEXT_HTML.equals(mime)) {
|
||||
collectReferences(urls, opdsLink, href,
|
||||
UrlInfo.Type.BookBuyInBrowser, price, true);
|
||||
collectReferences(
|
||||
networkLink.Library,
|
||||
urls, opdsLink, href,
|
||||
UrlInfo.Type.BookBuyInBrowser, price, true
|
||||
);
|
||||
} else {
|
||||
collectReferences(urls, opdsLink, href,
|
||||
UrlInfo.Type.BookBuy, price, false);
|
||||
collectReferences(
|
||||
networkLink.Library,
|
||||
urls, opdsLink, href,
|
||||
UrlInfo.Type.BookBuy, price, false
|
||||
);
|
||||
}
|
||||
} else if (referenceType == UrlInfo.Type.Related) {
|
||||
urls.addInfo(new RelatedUrlInfo(referenceType, link.getTitle(), href, mime));
|
||||
|
@ -145,7 +151,7 @@ public class OPDSBookItem extends NetworkBookItem implements OPDSConstants {
|
|||
} else if (referenceType == UrlInfo.Type.TOC) {
|
||||
urls.addInfo(new UrlInfo(referenceType, href, mime));
|
||||
} else if (referenceType != null) {
|
||||
if (BookUrlInfo.isMimeSupported(mime)) {
|
||||
if (BookUrlInfo.isMimeSupported(mime, networkLink.Library.SystemInfo)) {
|
||||
urls.addInfo(new BookUrlInfo(referenceType, href, mime));
|
||||
}
|
||||
}
|
||||
|
@ -176,6 +182,7 @@ public class OPDSBookItem extends NetworkBookItem implements OPDSConstants {
|
|||
}
|
||||
|
||||
private static void collectReferences(
|
||||
NetworkLibrary library,
|
||||
UrlInfoCollection<UrlInfo> urls,
|
||||
OPDSLink opdsLink,
|
||||
String href,
|
||||
|
@ -186,7 +193,7 @@ public class OPDSBookItem extends NetworkBookItem implements OPDSConstants {
|
|||
boolean added = false;
|
||||
for (String f : opdsLink.Formats) {
|
||||
final MimeType mime = MimeType.get(f);
|
||||
if (BookUrlInfo.isMimeSupported(mime)) {
|
||||
if (BookUrlInfo.isMimeSupported(mime, library.SystemInfo)) {
|
||||
urls.addInfo(new BookBuyUrlInfo(type, href, mime, price));
|
||||
added = true;
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ public class OPDSCustomNetworkLink extends OPDSNetworkLink implements ICustomNet
|
|||
@Override
|
||||
public void handleStream(InputStream inputStream, int length) throws IOException, ZLNetworkException {
|
||||
final OPDSCatalogInfoHandler info = new OPDSCatalogInfoHandler(getURL(), OPDSCustomNetworkLink.this, opensearchDescriptionURLs);
|
||||
new OPDSXMLReader(myLibrary, info, false).read(inputStream);
|
||||
new OPDSXMLReader(Library, info, false).read(inputStream);
|
||||
|
||||
if (!info.FeedStarted) {
|
||||
throw ZLNetworkException.forCode(NetworkException.ERROR_NOT_AN_OPDS);
|
||||
|
|
|
@ -124,7 +124,7 @@ class OPDSFeedHandler extends AbstractOPDSFeedHandler implements OPDSConstants {
|
|||
if (rel == null && MimeType.APP_ATOM_XML.weakEquals(mime)) {
|
||||
return ZLNetworkUtil.url(myBaseURL, link.getHref());
|
||||
}
|
||||
if (!BookUrlInfo.isMimeSupported(mime)) {
|
||||
if (!BookUrlInfo.isMimeSupported(mime, opdsLink.Library.SystemInfo)) {
|
||||
continue;
|
||||
}
|
||||
if (rel != null
|
||||
|
@ -176,7 +176,7 @@ class OPDSFeedHandler extends AbstractOPDSFeedHandler implements OPDSConstants {
|
|||
final MimeType mime = MimeType.get(link.getType());
|
||||
final String rel = opdsLink.relation(link.getRel(), mime);
|
||||
if (rel == null
|
||||
? (BookUrlInfo.isMimeSupported(mime))
|
||||
? (BookUrlInfo.isMimeSupported(mime, opdsLink.Library.SystemInfo))
|
||||
: (rel.equals(REL_RELATED)
|
||||
|| rel.startsWith(REL_ACQUISITION_PREFIX)
|
||||
|| rel.startsWith(REL_FBREADER_ACQUISITION_PREFIX))) {
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.geometerplus.fbreader.network.urlInfo.*;
|
|||
import org.geometerplus.fbreader.network.tree.NetworkItemsLoader;
|
||||
|
||||
public abstract class OPDSNetworkLink extends AbstractNetworkLink {
|
||||
protected final NetworkLibrary myLibrary;
|
||||
protected final NetworkLibrary Library;
|
||||
|
||||
private TreeMap<RelationAlias,String> myRelationAliases;
|
||||
|
||||
|
@ -46,7 +46,7 @@ public abstract class OPDSNetworkLink extends AbstractNetworkLink {
|
|||
OPDSNetworkLink(NetworkLibrary library, int id, String title, String summary, String language,
|
||||
UrlInfoCollection<UrlInfoWithDate> infos) {
|
||||
super(id, title, summary, language, infos);
|
||||
myLibrary = library;
|
||||
Library = library;
|
||||
}
|
||||
|
||||
final void setRelationAliases(Map<RelationAlias,String> relationAliases) {
|
||||
|
@ -202,7 +202,7 @@ public abstract class OPDSNetworkLink extends AbstractNetworkLink {
|
|||
public BasketItem getBasketItem() {
|
||||
final String url = getUrl(UrlInfo.Type.ListBooks);
|
||||
if (url != null && myBasketItem == null) {
|
||||
myBasketItem = new OPDSBasketItem(myLibrary, this);
|
||||
myBasketItem = new OPDSBasketItem(Library, this);
|
||||
}
|
||||
return myBasketItem;
|
||||
}
|
||||
|
|
|
@ -26,8 +26,7 @@ import android.net.Uri;
|
|||
|
||||
import org.geometerplus.zlibrary.core.filetypes.FileType;
|
||||
import org.geometerplus.zlibrary.core.filetypes.FileTypeCollection;
|
||||
import org.geometerplus.zlibrary.core.util.MimeType;
|
||||
import org.geometerplus.zlibrary.core.util.MiscUtil;
|
||||
import org.geometerplus.zlibrary.core.util.*;
|
||||
|
||||
import org.geometerplus.fbreader.Paths;
|
||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
||||
|
@ -43,7 +42,7 @@ public class BookUrlInfo extends UrlInfo {
|
|||
|
||||
private static final String TOESCAPE = "<>:\"|?*\\";
|
||||
|
||||
public static boolean isMimeSupported(MimeType mime) {
|
||||
public static boolean isMimeSupported(MimeType mime, SystemInfo systemInfo) {
|
||||
if (mime == null) {
|
||||
return false;
|
||||
}
|
||||
|
@ -51,7 +50,7 @@ public class BookUrlInfo extends UrlInfo {
|
|||
if (type == null) {
|
||||
return false;
|
||||
}
|
||||
return PluginCollection.Instance().getPlugin(type) != null;
|
||||
return PluginCollection.Instance(systemInfo).getPlugin(type) != null;
|
||||
}
|
||||
|
||||
private static int mimePriority(MimeType mime) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue