1
0
Fork 0
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:
Nikolay Pultsin 2012-04-13 19:02:26 +02:00
parent 4506c5a8b7
commit cf849068bd
5 changed files with 65 additions and 53 deletions

View file

@ -261,7 +261,7 @@ public class BookInfoActivity extends Activity {
private void setupAnnotation(Book book) { private void setupAnnotation(Book book) {
final TextView titleView = (TextView)findViewById(R.id.book_info_annotation_title); final TextView titleView = (TextView)findViewById(R.id.book_info_annotation_title);
final TextView bodyView = (TextView)findViewById(R.id.book_info_annotation_body); 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) { if (annotation == null) {
titleView.setVisibility(View.GONE); titleView.setVisibility(View.GONE);
bodyView.setVisibility(View.GONE); bodyView.setVisibility(View.GONE);

View file

@ -32,7 +32,8 @@ import org.geometerplus.zlibrary.core.resources.ZLResource;
import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator; import org.geometerplus.zlibrary.text.hyphenation.ZLTextHyphenator;
import org.geometerplus.fbreader.library.Book; 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.FBReader;
import org.geometerplus.android.fbreader.library.BookInfoActivity; import org.geometerplus.android.fbreader.library.BookInfoActivity;
@ -97,8 +98,13 @@ class EncodingPreference extends ZLStringListPreference {
super(context, rootResource, resourceKey); super(context, rootResource, resourceKey);
myBook = book; myBook = book;
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(book.File); final FormatPlugin plugin;
if (plugin != null) { try {
plugin = book.getPlugin();
} catch (BookReadingException e) {
return;
}
final List<Encoding> encodings = final List<Encoding> encodings =
new ArrayList<Encoding>(plugin.supportedEncodings().encodings()); new ArrayList<Encoding>(plugin.supportedEncodings().encodings());
Collections.sort(encodings, new Comparator<Encoding>() { Collections.sort(encodings, new Comparator<Encoding>() {
@ -126,7 +132,6 @@ class EncodingPreference extends ZLStringListPreference {
} }
} }
} }
}
@Override @Override
protected void onDialogClosed(boolean result) { protected void onDialogClosed(boolean result) {

View file

@ -24,14 +24,11 @@ import java.util.List;
import org.geometerplus.zlibrary.text.model.*; import org.geometerplus.zlibrary.text.model.*;
import org.geometerplus.fbreader.library.Book; import org.geometerplus.fbreader.library.Book;
import org.geometerplus.fbreader.formats.*; import org.geometerplus.fbreader.formats.FormatPlugin;
public abstract class BookModel { public abstract class BookModel {
public static BookModel createModel(Book book) throws BookReadingException { public static BookModel createModel(Book book) throws BookReadingException {
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(book.File); final FormatPlugin plugin = book.getPlugin();
if (plugin == null) {
throw new BookReadingException("pluginNotFound", book.File);
}
System.err.println("using plugin: " + plugin.supportedFileType() + "/" + plugin.type()); System.err.println("using plugin: " + plugin.supportedFileType() + "/" + plugin.type());

View file

@ -153,7 +153,19 @@ public class Book {
myIsSaved = true; 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 { void readMetaInfo() throws BookReadingException {
readMetaInfo(getPlugin());
}
private void readMetaInfo(FormatPlugin plugin) throws BookReadingException {
myEncoding = null; myEncoding = null;
myLanguage = null; myLanguage = null;
myTitle = null; myTitle = null;
@ -163,10 +175,6 @@ public class Book {
myIsSaved = false; myIsSaved = false;
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(File);
if (plugin == null) {
throw new BookReadingException("pluginNotFound", File);
}
plugin.readMetaInfo(this); plugin.readMetaInfo(this);
if (myTitle == null || myTitle.length() == 0) { if (myTitle == null || myTitle.length() == 0) {
@ -295,17 +303,14 @@ public class Book {
public String getEncoding() { public String getEncoding() {
if (myEncoding == null) { if (myEncoding == null) {
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(File);
if (plugin != null) {
try { try {
plugin.detectLanguageAndEncoding(this); getPlugin().detectLanguageAndEncoding(this);
} catch (BookReadingException e) { } catch (BookReadingException e) {
} }
if (myEncoding == null) { if (myEncoding == null) {
setEncoding("utf-8"); setEncoding("utf-8");
} }
} }
}
return myEncoding; return myEncoding;
} }
@ -500,9 +505,10 @@ public class Book {
} }
} }
ZLImage image = null; ZLImage image = null;
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(File); try {
if (plugin != null) { image = getPlugin().readCover(File);
image = plugin.readCover(File); } catch (BookReadingException e) {
// ignore
} }
myCover = image != null ? new WeakReference<ZLImage>(image) : NULL_IMAGE; myCover = image != null ? new WeakReference<ZLImage>(image) : NULL_IMAGE;
return image; return image;

View file

@ -23,7 +23,8 @@ import org.geometerplus.zlibrary.core.filesystem.ZLFile;
import org.geometerplus.zlibrary.core.image.ZLImage; import org.geometerplus.zlibrary.core.image.ZLImage;
import org.geometerplus.zlibrary.core.resources.ZLResource; 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 abstract class LibraryUtil {
public static ZLResource resource() { public static ZLResource resource() {
@ -34,8 +35,11 @@ public abstract class LibraryUtil {
return book != null ? book.getCover() : null; return book != null ? book.getCover() : null;
} }
public static String getAnnotation(ZLFile file) { public static String getAnnotation(Book book) {
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(file); try {
return plugin != null ? plugin.readAnnotation(file) : null; return book.getPlugin().readAnnotation(book.File);
} catch (BookReadingException e) {
return null;
}
} }
} }