mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 17:59:33 +02:00
Book.getPlugin() method
This commit is contained in:
parent
4506c5a8b7
commit
cf849068bd
5 changed files with 65 additions and 53 deletions
|
@ -261,7 +261,7 @@ public class BookInfoActivity extends Activity {
|
|||
private void setupAnnotation(Book book) {
|
||||
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 = LibraryUtil.getAnnotation(book.File);
|
||||
final String annotation = LibraryUtil.getAnnotation(book);
|
||||
if (annotation == null) {
|
||||
titleView.setVisibility(View.GONE);
|
||||
bodyView.setVisibility(View.GONE);
|
||||
|
|
|
@ -32,7 +32,8 @@ import org.geometerplus.zlibrary.core.resources.ZLResource;
|
|||
import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator;
|
||||
|
||||
import org.geometerplus.fbreader.library.Book;
|
||||
import org.geometerplus.fbreader.formats.*;
|
||||
import org.geometerplus.fbreader.formats.FormatPlugin;
|
||||
import org.geometerplus.fbreader.bookmodel.BookReadingException;
|
||||
|
||||
import org.geometerplus.android.fbreader.FBReader;
|
||||
import org.geometerplus.android.fbreader.library.BookInfoActivity;
|
||||
|
@ -97,8 +98,13 @@ class EncodingPreference extends ZLStringListPreference {
|
|||
super(context, rootResource, resourceKey);
|
||||
myBook = book;
|
||||
|
||||
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(book.File);
|
||||
if (plugin != null) {
|
||||
final FormatPlugin plugin;
|
||||
try {
|
||||
plugin = book.getPlugin();
|
||||
} catch (BookReadingException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Encoding> encodings =
|
||||
new ArrayList<Encoding>(plugin.supportedEncodings().encodings());
|
||||
Collections.sort(encodings, new Comparator<Encoding>() {
|
||||
|
@ -126,7 +132,6 @@ class EncodingPreference extends ZLStringListPreference {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDialogClosed(boolean result) {
|
||||
|
|
|
@ -24,14 +24,11 @@ import java.util.List;
|
|||
import org.geometerplus.zlibrary.text.model.*;
|
||||
|
||||
import org.geometerplus.fbreader.library.Book;
|
||||
import org.geometerplus.fbreader.formats.*;
|
||||
import org.geometerplus.fbreader.formats.FormatPlugin;
|
||||
|
||||
public abstract class BookModel {
|
||||
public static BookModel createModel(Book book) throws BookReadingException {
|
||||
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(book.File);
|
||||
if (plugin == null) {
|
||||
throw new BookReadingException("pluginNotFound", book.File);
|
||||
}
|
||||
final FormatPlugin plugin = book.getPlugin();
|
||||
|
||||
System.err.println("using plugin: " + plugin.supportedFileType() + "/" + plugin.type());
|
||||
|
||||
|
|
|
@ -153,7 +153,19 @@ public class Book {
|
|||
myIsSaved = true;
|
||||
}
|
||||
|
||||
public FormatPlugin getPlugin() throws BookReadingException {
|
||||
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(File);
|
||||
if (plugin == null) {
|
||||
throw new BookReadingException("pluginNotFound", File);
|
||||
}
|
||||
return plugin;
|
||||
}
|
||||
|
||||
void readMetaInfo() throws BookReadingException {
|
||||
readMetaInfo(getPlugin());
|
||||
}
|
||||
|
||||
private void readMetaInfo(FormatPlugin plugin) throws BookReadingException {
|
||||
myEncoding = null;
|
||||
myLanguage = null;
|
||||
myTitle = null;
|
||||
|
@ -163,10 +175,6 @@ public class Book {
|
|||
|
||||
myIsSaved = false;
|
||||
|
||||
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(File);
|
||||
if (plugin == null) {
|
||||
throw new BookReadingException("pluginNotFound", File);
|
||||
}
|
||||
plugin.readMetaInfo(this);
|
||||
|
||||
if (myTitle == null || myTitle.length() == 0) {
|
||||
|
@ -295,17 +303,14 @@ public class Book {
|
|||
|
||||
public String getEncoding() {
|
||||
if (myEncoding == null) {
|
||||
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(File);
|
||||
if (plugin != null) {
|
||||
try {
|
||||
plugin.detectLanguageAndEncoding(this);
|
||||
getPlugin().detectLanguageAndEncoding(this);
|
||||
} catch (BookReadingException e) {
|
||||
}
|
||||
if (myEncoding == null) {
|
||||
setEncoding("utf-8");
|
||||
}
|
||||
}
|
||||
}
|
||||
return myEncoding;
|
||||
}
|
||||
|
||||
|
@ -500,9 +505,10 @@ public class Book {
|
|||
}
|
||||
}
|
||||
ZLImage image = null;
|
||||
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(File);
|
||||
if (plugin != null) {
|
||||
image = plugin.readCover(File);
|
||||
try {
|
||||
image = getPlugin().readCover(File);
|
||||
} catch (BookReadingException e) {
|
||||
// ignore
|
||||
}
|
||||
myCover = image != null ? new WeakReference<ZLImage>(image) : NULL_IMAGE;
|
||||
return image;
|
||||
|
|
|
@ -23,7 +23,8 @@ import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
|||
import org.geometerplus.zlibrary.core.image.ZLImage;
|
||||
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||
|
||||
import org.geometerplus.fbreader.formats.*;
|
||||
import org.geometerplus.fbreader.formats.FormatPlugin;
|
||||
import org.geometerplus.fbreader.bookmodel.BookReadingException;
|
||||
|
||||
public abstract class LibraryUtil {
|
||||
public static ZLResource resource() {
|
||||
|
@ -34,8 +35,11 @@ public abstract class LibraryUtil {
|
|||
return book != null ? book.getCover() : null;
|
||||
}
|
||||
|
||||
public static String getAnnotation(ZLFile file) {
|
||||
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(file);
|
||||
return plugin != null ? plugin.readAnnotation(file) : null;
|
||||
public static String getAnnotation(Book book) {
|
||||
try {
|
||||
return book.getPlugin().readAnnotation(book.File);
|
||||
} catch (BookReadingException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue