diff --git a/src/org/geometerplus/android/fbreader/library/BookInfoActivity.java b/src/org/geometerplus/android/fbreader/library/BookInfoActivity.java index de51880c0..a9f9bbb76 100644 --- a/src/org/geometerplus/android/fbreader/library/BookInfoActivity.java +++ b/src/org/geometerplus/android/fbreader/library/BookInfoActivity.java @@ -72,7 +72,7 @@ public class BookInfoActivity extends Activity { myDontReloadBook = getIntent().getBooleanExtra(FROM_READING_MODE_KEY, false); myFile = ZLFile.createFileByPath(path); - myImage = Library.getCover(myFile); + myImage = LibraryUtil.getCover(myFile); if (SQLiteBooksDatabase.Instance() == null) { new SQLiteBooksDatabase(this, "LIBRARY"); @@ -253,7 +253,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 = Library.getAnnotation(book.File); + final String annotation = LibraryUtil.getAnnotation(book.File); if (annotation == null) { titleView.setVisibility(View.GONE); bodyView.setVisibility(View.GONE); diff --git a/src/org/geometerplus/android/fbreader/library/LibraryActivity.java b/src/org/geometerplus/android/fbreader/library/LibraryActivity.java index bdb64d333..bde55dac2 100644 --- a/src/org/geometerplus/android/fbreader/library/LibraryActivity.java +++ b/src/org/geometerplus/android/fbreader/library/LibraryActivity.java @@ -178,7 +178,7 @@ public class LibraryActivity extends TreeActivity implements MenuItem.OnMenuItem } private void createBookContextMenu(ContextMenu menu, Book book) { - final ZLResource resource = Library.resource(); + final ZLResource resource = LibraryUtil.resource(); menu.setHeaderTitle(book.getTitle()); menu.add(0, OPEN_BOOK_ITEM_ID, 0, resource.getResource("openBook").getValue()); menu.add(0, SHOW_BOOK_INFO_ITEM_ID, 0, resource.getResource("showBookInfo").getValue()); @@ -245,7 +245,7 @@ public class LibraryActivity extends TreeActivity implements MenuItem.OnMenuItem } private MenuItem addMenuItem(Menu menu, int index, String resourceKey, int iconId) { - final String label = Library.resource().getResource("menu").getResource(resourceKey).getValue(); + final String label = LibraryUtil.resource().getResource("menu").getResource(resourceKey).getValue(); final MenuItem item = menu.add(0, index, Menu.NONE, label); item.setOnMenuItemClickListener(this); item.setIcon(iconId); diff --git a/src/org/geometerplus/fbreader/library/AuthorTree.java b/src/org/geometerplus/fbreader/library/AuthorTree.java index a46eea3fc..d6d9618f4 100644 --- a/src/org/geometerplus/fbreader/library/AuthorTree.java +++ b/src/org/geometerplus/fbreader/library/AuthorTree.java @@ -36,7 +36,7 @@ public class AuthorTree extends LibraryTree { return Author != null ? Author.DisplayName : - Library.resource().getResource("unknownAuthor").getValue(); + LibraryUtil.resource().getResource("unknownAuthor").getValue(); } @Override diff --git a/src/org/geometerplus/fbreader/library/Book.java b/src/org/geometerplus/fbreader/library/Book.java index fd76f5c76..13070ba23 100644 --- a/src/org/geometerplus/fbreader/library/Book.java +++ b/src/org/geometerplus/fbreader/library/Book.java @@ -155,7 +155,7 @@ public class Book { } final String demoPathPrefix = Paths.BooksDirectoryOption().getValue() + java.io.File.separator + "Demos" + java.io.File.separator; if (File.getPath().startsWith(demoPathPrefix)) { - final String demoTag = Library.resource().getResource("demo").getValue(); + final String demoTag = LibraryUtil.resource().getResource("demo").getValue(); setTitle(getTitle() + " (" + demoTag + ")"); addTag(demoTag); } diff --git a/src/org/geometerplus/fbreader/library/BookTree.java b/src/org/geometerplus/fbreader/library/BookTree.java index ffa9aa8cb..a213291cc 100644 --- a/src/org/geometerplus/fbreader/library/BookTree.java +++ b/src/org/geometerplus/fbreader/library/BookTree.java @@ -78,7 +78,7 @@ public class BookTree extends LibraryTree { @Override protected ZLImage createCover() { - return Library.getCover(Book.File); + return LibraryUtil.getCover(Book.File); } @Override diff --git a/src/org/geometerplus/fbreader/library/FileFirstLevelTree.java b/src/org/geometerplus/fbreader/library/FileFirstLevelTree.java index 2092140cc..970a7f94b 100644 --- a/src/org/geometerplus/fbreader/library/FileFirstLevelTree.java +++ b/src/org/geometerplus/fbreader/library/FileFirstLevelTree.java @@ -35,7 +35,7 @@ public class FileFirstLevelTree extends FirstLevelTree { private void addChild(String path, String resourceKey) { final ZLFile file = ZLFile.createFileByPath(path); if (file != null) { - final ZLResource resource = Library.resource().getResource(resourceKey); + final ZLResource resource = LibraryUtil.resource().getResource(resourceKey); new FileTree( this, file, diff --git a/src/org/geometerplus/fbreader/library/FileTree.java b/src/org/geometerplus/fbreader/library/FileTree.java index 25f053c23..8281b0b35 100644 --- a/src/org/geometerplus/fbreader/library/FileTree.java +++ b/src/org/geometerplus/fbreader/library/FileTree.java @@ -98,7 +98,7 @@ public class FileTree extends LibraryTree { @Override public ZLImage createCover() { - return Library.getCover(myFile); + return LibraryUtil.getCover(myFile); } public ZLFile getFile() { diff --git a/src/org/geometerplus/fbreader/library/FirstLevelTree.java b/src/org/geometerplus/fbreader/library/FirstLevelTree.java index 585af4eaf..681770455 100644 --- a/src/org/geometerplus/fbreader/library/FirstLevelTree.java +++ b/src/org/geometerplus/fbreader/library/FirstLevelTree.java @@ -28,13 +28,13 @@ public class FirstLevelTree extends LibraryTree { FirstLevelTree(RootTree root, int position, String id) { super(root, position); myId = id; - myResource = Library.resource().getResource(myId); + myResource = LibraryUtil.resource().getResource(myId); } FirstLevelTree(RootTree root, String id) { super(root); myId = id; - myResource = Library.resource().getResource(myId); + myResource = LibraryUtil.resource().getResource(myId); } @Override diff --git a/src/org/geometerplus/fbreader/library/Library.java b/src/org/geometerplus/fbreader/library/Library.java index 0d20c8e79..8c624925c 100644 --- a/src/org/geometerplus/fbreader/library/Library.java +++ b/src/org/geometerplus/fbreader/library/Library.java @@ -20,16 +20,11 @@ package org.geometerplus.fbreader.library; import java.io.File; -import java.lang.ref.WeakReference; import java.util.*; import org.geometerplus.zlibrary.core.filesystem.*; -import org.geometerplus.zlibrary.core.image.ZLImage; -import org.geometerplus.zlibrary.core.resources.ZLResource; import org.geometerplus.fbreader.tree.FBTree; -import org.geometerplus.fbreader.formats.FormatPlugin; -import org.geometerplus.fbreader.formats.PluginCollection; import org.geometerplus.fbreader.Paths; public final class Library extends AbstractLibrary { @@ -50,12 +45,8 @@ public final class Library extends AbstractLibrary { return ourInstance; } - public static ZLResource resource() { - return ZLResource.resource("library"); - } - private final List myBooks = Collections.synchronizedList(new LinkedList()); - private final RootTree myRootTree = new RootTree(this); + private final RootTree myRootTree = new RootTree(); private boolean myDoGroupTitlesByFirstLetter; private final static int STATUS_LOADING = 1; @@ -578,42 +569,4 @@ public final class Library extends AbstractLibrary { book.File.getPhysicalFile().delete(); } } - - private static final HashMap> ourCoverMap = - new HashMap>(); - private static final WeakReference NULL_IMAGE = new WeakReference(null); - - public static ZLImage getCover(ZLFile file) { - if (file == null) { - return null; - } - synchronized (ourCoverMap) { - final String path = file.getPath(); - final WeakReference 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(image)); - } - return image; - } - } - - public static String getAnnotation(ZLFile file) { - final FormatPlugin plugin = PluginCollection.Instance().getPlugin(file); - return plugin != null ? plugin.readAnnotation(file) : null; - } } diff --git a/src/org/geometerplus/fbreader/library/LibraryUtil.java b/src/org/geometerplus/fbreader/library/LibraryUtil.java new file mode 100644 index 000000000..c037581d1 --- /dev/null +++ b/src/org/geometerplus/fbreader/library/LibraryUtil.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2007-2012 Geometer Plus + * + * 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.fbreader.library; + +import java.lang.ref.WeakReference; +import java.util.HashMap; + +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.FormatPlugin; +import org.geometerplus.fbreader.formats.PluginCollection; + +public abstract class LibraryUtil { + private static final HashMap> ourCoverMap = + new HashMap>(); + private static final WeakReference NULL_IMAGE = new WeakReference(null); + + public static ZLResource resource() { + return ZLResource.resource("library"); + } + + public static ZLImage getCover(ZLFile file) { + if (file == null) { + return null; + } + synchronized (ourCoverMap) { + final String path = file.getPath(); + final WeakReference 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(image)); + } + return image; + } + } + + public static String getAnnotation(ZLFile file) { + final FormatPlugin plugin = PluginCollection.Instance().getPlugin(file); + return plugin != null ? plugin.readAnnotation(file) : null; + } +} diff --git a/src/org/geometerplus/fbreader/library/RootTree.java b/src/org/geometerplus/fbreader/library/RootTree.java index d524e5b39..193acf1cc 100644 --- a/src/org/geometerplus/fbreader/library/RootTree.java +++ b/src/org/geometerplus/fbreader/library/RootTree.java @@ -20,19 +20,12 @@ package org.geometerplus.fbreader.library; class RootTree extends LibraryTree { - private final Library myLibrary; - - RootTree(Library library) { - myLibrary = library; - } - - Library getLibrary() { - return myLibrary; + RootTree() { } @Override public String getName() { - return Library.resource().getValue(); + return LibraryUtil.resource().getValue(); } @Override diff --git a/src/org/geometerplus/fbreader/library/TagTree.java b/src/org/geometerplus/fbreader/library/TagTree.java index 158ce27c7..87c27437a 100644 --- a/src/org/geometerplus/fbreader/library/TagTree.java +++ b/src/org/geometerplus/fbreader/library/TagTree.java @@ -34,7 +34,7 @@ public final class TagTree extends LibraryTree { @Override public String getName() { return Tag != null - ? Tag.Name : Library.resource().getResource("booksWithNoTags").getValue(); + ? Tag.Name : LibraryUtil.resource().getResource("booksWithNoTags").getValue(); } @Override