1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 10:49:24 +02:00

book-by-title library branch has been implemented

This commit is contained in:
Nikolay Pultsin 2011-01-19 20:35:19 +00:00
parent 3ddd824fe7
commit edc931a04f
5 changed files with 90 additions and 0 deletions

View file

@ -203,6 +203,10 @@ abstract class LibraryBaseActivity extends BaseActivity implements MenuItem.OnMe
if (tree instanceof AuthorTree) { if (tree instanceof AuthorTree) {
return mySelectedBook.authors().contains(((AuthorTree)tree).Author); return mySelectedBook.authors().contains(((AuthorTree)tree).Author);
} }
if (tree instanceof TitleTree) {
final String title = mySelectedBook.getTitle();
return tree != null && title.trim().startsWith(((TitleTree)tree).Title);
}
if (tree instanceof SeriesTree) { if (tree instanceof SeriesTree) {
final SeriesInfo info = mySelectedBook.getSeriesInfo(); final SeriesInfo info = mySelectedBook.getSeriesInfo();
final String series = ((SeriesTree)tree).Series; final String series = ((SeriesTree)tree).Series;

View file

@ -80,6 +80,8 @@ public class LibraryTreeActivity extends LibraryBaseActivity {
tree = LibraryInstance.searchResults(); tree = LibraryInstance.searchResults();
} else if (PATH_BY_AUTHOR.equals(path[0])) { } else if (PATH_BY_AUTHOR.equals(path[0])) {
tree = LibraryInstance.byAuthor(); tree = LibraryInstance.byAuthor();
} else if (PATH_BY_TITLE.equals(path[0])) {
tree = LibraryInstance.byTitle();
} else if (PATH_BY_TAG.equals(path[0])) { } else if (PATH_BY_TAG.equals(path[0])) {
tree = LibraryInstance.byTag(); tree = LibraryInstance.byTag();
} else if (PATH_FAVORITES.equals(path[0])) { } else if (PATH_FAVORITES.equals(path[0])) {

View file

@ -39,6 +39,7 @@ public final class Library {
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();
private final LibraryTree myLibraryByTitle = new RootTree();
private final LibraryTree myLibraryByTag = new RootTree(); private final LibraryTree myLibraryByTag = new RootTree();
private final LibraryTree myRecentBooks = new RootTree(); private final LibraryTree myRecentBooks = new RootTree();
private final LibraryTree myFavorites = new RootTree(); private final LibraryTree myFavorites = new RootTree();
@ -270,6 +271,45 @@ public final class Library {
} }
} }
boolean doGroupTitlesByFirstLetter = false;
if (myBooks.size() > 10) {
final HashSet<Character> letterSet = new HashSet<Character>();
for (Book book : myBooks) {
String title = book.getTitle();
if (title != null) {
title = title.trim();
if (!"".equals(title)) {
letterSet.add(title.charAt(0));
}
}
}
doGroupTitlesByFirstLetter = letterSet.size() > myBooks.size() + 4;
}
if (doGroupTitlesByFirstLetter) {
final HashMap<Character,TitleTree> letterTrees = new HashMap<Character,TitleTree>();
for (Book book : myBooks) {
String title = book.getTitle();
if (title == null) {
continue;
}
title = title.trim();
if ("".equals(title)) {
continue;
}
Character c = title.charAt(0);
TitleTree tree = letterTrees.get(c);
if (tree == null) {
tree = myLibraryByTitle.createTitleSubTree(c.toString());
letterTrees.put(c, tree);
}
tree.createBookSubTree(book, true);
}
} else {
for (Book book : myBooks) {
myLibraryByTitle.createBookSubTree(book, true);
}
}
final BooksDatabase db = BooksDatabase.Instance(); final BooksDatabase db = BooksDatabase.Instance();
for (long id : db.loadRecentBookIds()) { for (long id : db.loadRecentBookIds()) {
Book book = bookById.get(id); Book book = bookById.get(id);
@ -287,6 +327,7 @@ public final class Library {
myFavorites.sortAllChildren(); myFavorites.sortAllChildren();
myLibraryByAuthor.sortAllChildren(); myLibraryByAuthor.sortAllChildren();
myLibraryByTitle.sortAllChildren();
myLibraryByTag.sortAllChildren(); myLibraryByTag.sortAllChildren();
db.executeAsATransaction(new Runnable() { db.executeAsATransaction(new Runnable() {
@ -317,6 +358,11 @@ public final class Library {
return myLibraryByAuthor; return myLibraryByAuthor;
} }
public LibraryTree byTitle() {
waitForState(STATE_FULLY_INITIALIZED);
return myLibraryByTitle;
}
public LibraryTree byTag() { public LibraryTree byTag() {
waitForState(STATE_FULLY_INITIALIZED); waitForState(STATE_FULLY_INITIALIZED);
return myLibraryByTag; return myLibraryByTag;

View file

@ -38,6 +38,10 @@ public abstract class LibraryTree extends FBTree {
return new TagTree(this, tag); return new TagTree(this, tag);
} }
TitleTree createTitleSubTree(String title) {
return new TitleTree(this, title);
}
AuthorTree createAuthorSubTree(Author author) { AuthorTree createAuthorSubTree(Author author) {
return new AuthorTree(this, author); return new AuthorTree(this, author);
} }

View file

@ -0,0 +1,34 @@
/*
* Copyright (C) 2009-2011 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;
public final class TitleTree extends LibraryTree {
public final String Title;
TitleTree(LibraryTree parent, String title) {
super(parent);
Title = title;
}
@Override
public String getName() {
return Title;
}
}