mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 02:09:35 +02:00
Library class is splitted to Library & LibraryUtil
Conflicts: src/org/geometerplus/android/fbreader/library/LibraryActivity.java
This commit is contained in:
parent
f41c1f8b09
commit
ca00b0124a
12 changed files with 89 additions and 69 deletions
|
@ -72,7 +72,7 @@ public class BookInfoActivity extends Activity {
|
||||||
myDontReloadBook = getIntent().getBooleanExtra(FROM_READING_MODE_KEY, false);
|
myDontReloadBook = getIntent().getBooleanExtra(FROM_READING_MODE_KEY, false);
|
||||||
myFile = ZLFile.createFileByPath(path);
|
myFile = ZLFile.createFileByPath(path);
|
||||||
|
|
||||||
myImage = Library.getCover(myFile);
|
myImage = LibraryUtil.getCover(myFile);
|
||||||
|
|
||||||
if (SQLiteBooksDatabase.Instance() == null) {
|
if (SQLiteBooksDatabase.Instance() == null) {
|
||||||
new SQLiteBooksDatabase(this, "LIBRARY");
|
new SQLiteBooksDatabase(this, "LIBRARY");
|
||||||
|
@ -253,7 +253,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 = Library.getAnnotation(book.File);
|
final String annotation = LibraryUtil.getAnnotation(book.File);
|
||||||
if (annotation == null) {
|
if (annotation == null) {
|
||||||
titleView.setVisibility(View.GONE);
|
titleView.setVisibility(View.GONE);
|
||||||
bodyView.setVisibility(View.GONE);
|
bodyView.setVisibility(View.GONE);
|
||||||
|
|
|
@ -178,7 +178,7 @@ public class LibraryActivity extends TreeActivity implements MenuItem.OnMenuItem
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createBookContextMenu(ContextMenu menu, Book book) {
|
private void createBookContextMenu(ContextMenu menu, Book book) {
|
||||||
final ZLResource resource = Library.resource();
|
final ZLResource resource = LibraryUtil.resource();
|
||||||
menu.setHeaderTitle(book.getTitle());
|
menu.setHeaderTitle(book.getTitle());
|
||||||
menu.add(0, OPEN_BOOK_ITEM_ID, 0, resource.getResource("openBook").getValue());
|
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());
|
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) {
|
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);
|
final MenuItem item = menu.add(0, index, Menu.NONE, label);
|
||||||
item.setOnMenuItemClickListener(this);
|
item.setOnMenuItemClickListener(this);
|
||||||
item.setIcon(iconId);
|
item.setIcon(iconId);
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class AuthorTree extends LibraryTree {
|
||||||
return
|
return
|
||||||
Author != null ?
|
Author != null ?
|
||||||
Author.DisplayName :
|
Author.DisplayName :
|
||||||
Library.resource().getResource("unknownAuthor").getValue();
|
LibraryUtil.resource().getResource("unknownAuthor").getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -155,7 +155,7 @@ public class Book {
|
||||||
}
|
}
|
||||||
final String demoPathPrefix = Paths.BooksDirectoryOption().getValue() + java.io.File.separator + "Demos" + java.io.File.separator;
|
final String demoPathPrefix = Paths.BooksDirectoryOption().getValue() + java.io.File.separator + "Demos" + java.io.File.separator;
|
||||||
if (File.getPath().startsWith(demoPathPrefix)) {
|
if (File.getPath().startsWith(demoPathPrefix)) {
|
||||||
final String demoTag = Library.resource().getResource("demo").getValue();
|
final String demoTag = LibraryUtil.resource().getResource("demo").getValue();
|
||||||
setTitle(getTitle() + " (" + demoTag + ")");
|
setTitle(getTitle() + " (" + demoTag + ")");
|
||||||
addTag(demoTag);
|
addTag(demoTag);
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class BookTree extends LibraryTree {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ZLImage createCover() {
|
protected ZLImage createCover() {
|
||||||
return Library.getCover(Book.File);
|
return LibraryUtil.getCover(Book.File);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class FileFirstLevelTree extends FirstLevelTree {
|
||||||
private void addChild(String path, String resourceKey) {
|
private void addChild(String path, String resourceKey) {
|
||||||
final ZLFile file = ZLFile.createFileByPath(path);
|
final ZLFile file = ZLFile.createFileByPath(path);
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
final ZLResource resource = Library.resource().getResource(resourceKey);
|
final ZLResource resource = LibraryUtil.resource().getResource(resourceKey);
|
||||||
new FileTree(
|
new FileTree(
|
||||||
this,
|
this,
|
||||||
file,
|
file,
|
||||||
|
|
|
@ -98,7 +98,7 @@ public class FileTree extends LibraryTree {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ZLImage createCover() {
|
public ZLImage createCover() {
|
||||||
return Library.getCover(myFile);
|
return LibraryUtil.getCover(myFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZLFile getFile() {
|
public ZLFile getFile() {
|
||||||
|
|
|
@ -28,13 +28,13 @@ public class FirstLevelTree extends LibraryTree {
|
||||||
FirstLevelTree(RootTree root, int position, String id) {
|
FirstLevelTree(RootTree root, int position, String id) {
|
||||||
super(root, position);
|
super(root, position);
|
||||||
myId = id;
|
myId = id;
|
||||||
myResource = Library.resource().getResource(myId);
|
myResource = LibraryUtil.resource().getResource(myId);
|
||||||
}
|
}
|
||||||
|
|
||||||
FirstLevelTree(RootTree root, String id) {
|
FirstLevelTree(RootTree root, String id) {
|
||||||
super(root);
|
super(root);
|
||||||
myId = id;
|
myId = id;
|
||||||
myResource = Library.resource().getResource(myId);
|
myResource = LibraryUtil.resource().getResource(myId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -20,16 +20,11 @@
|
||||||
package org.geometerplus.fbreader.library;
|
package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.filesystem.*;
|
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.tree.FBTree;
|
||||||
import org.geometerplus.fbreader.formats.FormatPlugin;
|
|
||||||
import org.geometerplus.fbreader.formats.PluginCollection;
|
|
||||||
import org.geometerplus.fbreader.Paths;
|
import org.geometerplus.fbreader.Paths;
|
||||||
|
|
||||||
public final class Library extends AbstractLibrary {
|
public final class Library extends AbstractLibrary {
|
||||||
|
@ -50,12 +45,8 @@ public final class Library extends AbstractLibrary {
|
||||||
return ourInstance;
|
return ourInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ZLResource resource() {
|
|
||||||
return ZLResource.resource("library");
|
|
||||||
}
|
|
||||||
|
|
||||||
private final List<Book> myBooks = Collections.synchronizedList(new LinkedList<Book>());
|
private final List<Book> myBooks = Collections.synchronizedList(new LinkedList<Book>());
|
||||||
private final RootTree myRootTree = new RootTree(this);
|
private final RootTree myRootTree = new RootTree();
|
||||||
private boolean myDoGroupTitlesByFirstLetter;
|
private boolean myDoGroupTitlesByFirstLetter;
|
||||||
|
|
||||||
private final static int STATUS_LOADING = 1;
|
private final static int STATUS_LOADING = 1;
|
||||||
|
@ -578,42 +569,4 @@ public final class Library extends AbstractLibrary {
|
||||||
book.File.getPhysicalFile().delete();
|
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) {
|
|
||||||
if (file == null) {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getAnnotation(ZLFile file) {
|
|
||||||
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(file);
|
|
||||||
return plugin != null ? plugin.readAnnotation(file) : null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
74
src/org/geometerplus/fbreader/library/LibraryUtil.java
Normal file
74
src/org/geometerplus/fbreader/library/LibraryUtil.java
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2007-2012 Geometer Plus <contact@geometerplus.com>
|
||||||
|
*
|
||||||
|
* 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<String,WeakReference<ZLImage>> ourCoverMap =
|
||||||
|
new HashMap<String,WeakReference<ZLImage>>();
|
||||||
|
private static final WeakReference<ZLImage> NULL_IMAGE = new WeakReference<ZLImage>(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<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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getAnnotation(ZLFile file) {
|
||||||
|
final FormatPlugin plugin = PluginCollection.Instance().getPlugin(file);
|
||||||
|
return plugin != null ? plugin.readAnnotation(file) : null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,19 +20,12 @@
|
||||||
package org.geometerplus.fbreader.library;
|
package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
class RootTree extends LibraryTree {
|
class RootTree extends LibraryTree {
|
||||||
private final Library myLibrary;
|
RootTree() {
|
||||||
|
|
||||||
RootTree(Library library) {
|
|
||||||
myLibrary = library;
|
|
||||||
}
|
|
||||||
|
|
||||||
Library getLibrary() {
|
|
||||||
return myLibrary;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return Library.resource().getValue();
|
return LibraryUtil.resource().getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -34,7 +34,7 @@ public final class TagTree extends LibraryTree {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return Tag != null
|
return Tag != null
|
||||||
? Tag.Name : Library.resource().getResource("booksWithNoTags").getValue();
|
? Tag.Name : LibraryUtil.resource().getResource("booksWithNoTags").getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue