1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-06 03:50:19 +02:00

Library has no static instance since this moment

This commit is contained in:
Nikolay Pultsin 2010-10-14 13:04:42 +01:00
parent fa4ca04dc1
commit 017cdb852c
4 changed files with 13 additions and 18 deletions

View file

@ -50,7 +50,7 @@ public class BookSearchActivity extends SearchActivity {
boolean runSearch(final String pattern) { boolean runSearch(final String pattern) {
final FBReader fbreader = (FBReader)FBReader.Instance(); final FBReader fbreader = (FBReader)FBReader.Instance();
fbreader.BookSearchPatternOption.setValue(pattern); fbreader.BookSearchPatternOption.setValue(pattern);
myTree = Library.Instance().searchBooks(pattern); myTree = LibraryTabActivity.Instance.library().searchBooks(pattern);
return myTree.hasChildren(); return myTree.hasChildren();
} }

View file

@ -45,6 +45,10 @@ public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuIt
private Library myLibrary; private Library myLibrary;
Library library() {
return myLibrary;
}
private ListView createTab(String tag, int viewId, int iconId) { private ListView createTab(String tag, int viewId, int iconId) {
final TabHost host = getTabHost(); final TabHost host = getTabHost();
final String label = myResource.getResource(tag).getValue(); final String label = myResource.getResource(tag).getValue();
@ -71,7 +75,7 @@ public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuIt
Thread.setDefaultUncaughtExceptionHandler(new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this)); Thread.setDefaultUncaughtExceptionHandler(new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this));
if (myLibrary == null) { if (myLibrary == null) {
myLibrary = Library.Instance(); myLibrary = new Library();
} }
myLibrary.clear(); myLibrary.clear();
myLibrary.synchronize(); myLibrary.synchronize();

View file

@ -116,10 +116,10 @@ public final class FBReader extends ZLApplication {
public void run() { public void run() {
Book book = createBookForFile(ZLFile.createFileByPath(myArg0)); Book book = createBookForFile(ZLFile.createFileByPath(myArg0));
if (book == null) { if (book == null) {
book = Library.Instance().getRecentBook(); book = Library.getRecentBook();
} }
if ((book == null) || !book.File.exists()) { if ((book == null) || !book.File.exists()) {
book = Book.getByFile(Library.Instance().getHelpFile()); book = Book.getByFile(Library.getHelpFile());
} }
openBookInternal(book, null); openBookInternal(book, null);
} }
@ -205,7 +205,7 @@ public final class FBReader extends ZLApplication {
} else { } else {
gotoBookmark(bookmark); gotoBookmark(bookmark);
} }
Library.Instance().addBookToRecentList(book); Library.addBookToRecentList(book);
} }
} }
repaintView(); repaintView();

View file

@ -28,15 +28,6 @@ import org.geometerplus.zlibrary.core.util.ZLMiscUtil;
import org.geometerplus.fbreader.Paths; import org.geometerplus.fbreader.Paths;
public final class Library { public final class Library {
private static Library ourInstance;
public static Library Instance() {
if (ourInstance == null) {
ourInstance = new Library();
}
return ourInstance;
}
private final LinkedList<Book> myBooks = new LinkedList<Book>(); private final LinkedList<Book> myBooks = new LinkedList<Book>();
private final HashSet<Book> myExternalBooks = new HashSet<Book>(); private final HashSet<Book> myExternalBooks = new HashSet<Book>();
private final LibraryTree myLibraryByAuthor = new RootTree(); private final LibraryTree myLibraryByAuthor = new RootTree();
@ -46,7 +37,7 @@ public final class Library {
private boolean myDoRebuild = true; private boolean myDoRebuild = true;
private Library() { public Library() {
} }
public void clear() { public void clear() {
@ -60,7 +51,7 @@ public final class Library {
mySearchResult.clear(); mySearchResult.clear();
} }
public ZLResourceFile getHelpFile() { public static ZLResourceFile getHelpFile() {
final ZLResourceFile file = ZLResourceFile.createResourceFile( final ZLResourceFile file = ZLResourceFile.createResourceFile(
"data/help/MiniHelp." + Locale.getDefault().getLanguage() + ".fb2" "data/help/MiniHelp." + Locale.getDefault().getLanguage() + ".fb2"
); );
@ -318,7 +309,7 @@ public final class Library {
return myRecentBooks; return myRecentBooks;
} }
public Book getRecentBook() { public static Book getRecentBook() {
List<Long> recentIds = BooksDatabase.Instance().listRecentBookIds(); List<Long> recentIds = BooksDatabase.Instance().listRecentBookIds();
return (recentIds.size() > 0) ? Book.getById(recentIds.get(0)) : null; return (recentIds.size() > 0) ? Book.getById(recentIds.get(0)) : null;
} }
@ -338,7 +329,7 @@ public final class Library {
return mySearchResult; return mySearchResult;
} }
public void addBookToRecentList(Book book) { public static void addBookToRecentList(Book book) {
final BooksDatabase db = BooksDatabase.Instance(); final BooksDatabase db = BooksDatabase.Instance();
final List<Long> ids = db.listRecentBookIds(); final List<Long> ids = db.listRecentBookIds();
final Long bookId = book.getId(); final Long bookId = book.getId();