mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
library auto-sorting
This commit is contained in:
parent
31075d08a0
commit
f79aaeb132
10 changed files with 97 additions and 60 deletions
|
@ -63,7 +63,7 @@
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name="org.geometerplus.android.fbreader.CancelActivity" android:theme="@android:style/Theme.Dialog" android:configChanges="orientation|keyboardHidden"/>
|
<activity android:name="org.geometerplus.android.fbreader.CancelActivity" android:theme="@android:style/Theme.Dialog" android:configChanges="orientation|keyboardHidden"/>
|
||||||
<activity android:name="org.geometerplus.android.fbreader.image.ImageViewActivity" android:process=":imageView" android:configChanges="orientation|keyboardHidden"/>
|
<activity android:name="org.geometerplus.android.fbreader.image.ImageViewActivity" android:process=":imageView" android:configChanges="orientation|keyboardHidden"/>
|
||||||
<activity android:name="org.geometerplus.android.fbreader.BookInfoActivity" android:configChanges="orientation|keyboardHidden" android:process=":library"/>
|
<activity android:name="org.geometerplus.android.fbreader.library.BookInfoActivity" android:configChanges="orientation|keyboardHidden" android:process=":library"/>
|
||||||
<service android:name="org.geometerplus.android.fbreader.library.InitializationService" android:process=":library" />
|
<service android:name="org.geometerplus.android.fbreader.library.InitializationService" android:process=":library" />
|
||||||
<receiver android:name="org.geometerplus.android.fbreader.library.KillerCallback" android:process=":library" />
|
<receiver android:name="org.geometerplus.android.fbreader.library.KillerCallback" android:process=":library" />
|
||||||
<activity android:name="org.geometerplus.android.fbreader.library.LibraryActivity" android:launchMode="singleTask" android:process=":library" android:configChanges="orientation|keyboardHidden">
|
<activity android:name="org.geometerplus.android.fbreader.library.LibraryActivity" android:launchMode="singleTask" android:process=":library" android:configChanges="orientation|keyboardHidden">
|
||||||
|
|
|
@ -63,7 +63,7 @@
|
||||||
</activity>
|
</activity>
|
||||||
<activity android:name="org.geometerplus.android.fbreader.CancelActivity" android:theme="@android:style/Theme.Dialog" android:configChanges="orientation|keyboardHidden"/>
|
<activity android:name="org.geometerplus.android.fbreader.CancelActivity" android:theme="@android:style/Theme.Dialog" android:configChanges="orientation|keyboardHidden"/>
|
||||||
<activity android:name="org.geometerplus.android.fbreader.image.ImageViewActivity" android:process=":imageView" android:configChanges="orientation|keyboardHidden"/>
|
<activity android:name="org.geometerplus.android.fbreader.image.ImageViewActivity" android:process=":imageView" android:configChanges="orientation|keyboardHidden"/>
|
||||||
<activity android:name="org.geometerplus.android.fbreader.BookInfoActivity" android:configChanges="orientation|keyboardHidden" android:process=":library"/>
|
<activity android:name="org.geometerplus.android.fbreader.library.BookInfoActivity" android:configChanges="orientation|keyboardHidden" android:process=":library"/>
|
||||||
<service android:name="org.geometerplus.android.fbreader.library.InitializationService" android:process=":library" />
|
<service android:name="org.geometerplus.android.fbreader.library.InitializationService" android:process=":library" />
|
||||||
<receiver android:name="org.geometerplus.android.fbreader.library.KillerCallback" android:process=":library" />
|
<receiver android:name="org.geometerplus.android.fbreader.library.KillerCallback" android:process=":library" />
|
||||||
<activity android:name="org.geometerplus.android.fbreader.library.LibraryActivity" android:launchMode="singleTask" android:process=":library" android:configChanges="orientation|keyboardHidden">
|
<activity android:name="org.geometerplus.android.fbreader.library.LibraryActivity" android:launchMode="singleTask" android:process=":library" android:configChanges="orientation|keyboardHidden">
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
package org.geometerplus.fbreader.library;
|
package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
public class AuthorTree extends LibraryTree {
|
public class AuthorTree extends LibraryTree {
|
||||||
public final Author Author;
|
public final Author Author;
|
||||||
|
|
||||||
|
@ -31,8 +33,14 @@ public class AuthorTree extends LibraryTree {
|
||||||
Author = author;
|
Author = author;
|
||||||
}
|
}
|
||||||
|
|
||||||
SeriesTree createSeriesSubTree(String series) {
|
SeriesTree getSeriesSubTree(String series) {
|
||||||
return new SeriesTree(this, series);
|
final SeriesTree temp = new SeriesTree(series);
|
||||||
|
int position = Collections.binarySearch(subTrees(), temp);
|
||||||
|
if (position >= 0) {
|
||||||
|
return (SeriesTree)subTrees().get(position);
|
||||||
|
} else {
|
||||||
|
return new SeriesTree(this, series, - position - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,8 +22,12 @@ package org.geometerplus.fbreader.library;
|
||||||
import org.geometerplus.fbreader.tree.FBTree;
|
import org.geometerplus.fbreader.tree.FBTree;
|
||||||
|
|
||||||
public final class BookInSeriesTree extends BookTree {
|
public final class BookInSeriesTree extends BookTree {
|
||||||
BookInSeriesTree(LibraryTree parent, Book book) {
|
BookInSeriesTree(Book book) {
|
||||||
super(parent, book, false);
|
super(book, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
BookInSeriesTree(LibraryTree parent, Book book, int position) {
|
||||||
|
super(parent, book, false, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -25,12 +25,23 @@ public class BookTree extends LibraryTree {
|
||||||
public final Book Book;
|
public final Book Book;
|
||||||
private final boolean myShowAuthors;
|
private final boolean myShowAuthors;
|
||||||
|
|
||||||
|
BookTree(Book book, boolean showAuthors) {
|
||||||
|
Book = book;
|
||||||
|
myShowAuthors = showAuthors;
|
||||||
|
}
|
||||||
|
|
||||||
BookTree(LibraryTree parent, Book book, boolean showAuthors) {
|
BookTree(LibraryTree parent, Book book, boolean showAuthors) {
|
||||||
super(parent);
|
super(parent);
|
||||||
Book = book;
|
Book = book;
|
||||||
myShowAuthors = showAuthors;
|
myShowAuthors = showAuthors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BookTree(LibraryTree parent, Book book, boolean showAuthors, int position) {
|
||||||
|
super(parent, position);
|
||||||
|
Book = book;
|
||||||
|
myShowAuthors = showAuthors;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return Book.getTitle();
|
return Book.getTitle();
|
||||||
|
|
|
@ -257,21 +257,15 @@ public final class Library {
|
||||||
myNullList.add(null);
|
myNullList.add(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TagTree getTagTree(Tag tag, HashMap<Tag,TagTree> tagTreeMap) {
|
private LibraryTree getTagTree(Tag tag) {
|
||||||
TagTree tagTree = tagTreeMap.get(tag);
|
if (tag == null || tag.Parent == null) {
|
||||||
if (tagTree == null) {
|
return getFirstLevelTree(ROOT_BY_TAG).getTagSubTree(tag);
|
||||||
LibraryTree parent =
|
} else {
|
||||||
((tag != null) && (tag.Parent != null)) ?
|
return getTagTree(tag.Parent).getTagSubTree(tag);
|
||||||
getTagTree(tag.Parent, tagTreeMap) : getFirstLevelTree(ROOT_BY_TAG);
|
|
||||||
tagTree = parent.createTagSubTree(tag);
|
|
||||||
tagTreeMap.put(tag, tagTree);
|
|
||||||
}
|
}
|
||||||
return tagTree;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void build() {
|
private void build() {
|
||||||
final HashMap<Tag,TagTree> tagTreeMap = new HashMap<Tag,TagTree>();
|
|
||||||
final HashMap<AuthorSeriesPair,SeriesTree> seriesTreeMap = new HashMap<AuthorSeriesPair,SeriesTree>();
|
|
||||||
final HashMap<Long,Book> bookById = new HashMap<Long,Book>();
|
final HashMap<Long,Book> bookById = new HashMap<Long,Book>();
|
||||||
|
|
||||||
collectBooks();
|
collectBooks();
|
||||||
|
@ -286,16 +280,12 @@ public final class Library {
|
||||||
for (Author a : authors) {
|
for (Author a : authors) {
|
||||||
final AuthorTree authorTree = getFirstLevelTree(ROOT_BY_AUTHOR).getAuthorSubTree(a);
|
final AuthorTree authorTree = getFirstLevelTree(ROOT_BY_AUTHOR).getAuthorSubTree(a);
|
||||||
if (seriesInfo == null) {
|
if (seriesInfo == null) {
|
||||||
authorTree.createBookSubTree(book, false);
|
authorTree.getBookSubTree(book, false);
|
||||||
} else {
|
} else {
|
||||||
final String series = seriesInfo.Name;
|
final String series = seriesInfo.Name;
|
||||||
final AuthorSeriesPair pair = new AuthorSeriesPair(a, series);
|
final AuthorSeriesPair pair = new AuthorSeriesPair(a, series);
|
||||||
SeriesTree seriesTree = seriesTreeMap.get(pair);
|
final SeriesTree seriesTree = authorTree.getSeriesSubTree(series);
|
||||||
if (seriesTree == null) {
|
seriesTree.getBookInSeriesSubTree(book);
|
||||||
seriesTree = authorTree.createSeriesSubTree(series);
|
|
||||||
seriesTreeMap.put(pair, seriesTree);
|
|
||||||
}
|
|
||||||
seriesTree.createBookInSeriesSubTree(book);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,7 +294,7 @@ public final class Library {
|
||||||
tags = (List<Tag>)myNullList;
|
tags = (List<Tag>)myNullList;
|
||||||
}
|
}
|
||||||
for (Tag t : tags) {
|
for (Tag t : tags) {
|
||||||
getTagTree(t, tagTreeMap).createBookSubTree(book, true);
|
getTagTree(t).getBookSubTree(book, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,7 +313,6 @@ public final class Library {
|
||||||
doGroupTitlesByFirstLetter = myBooks.size() > letterSet.size() * 5 / 4;
|
doGroupTitlesByFirstLetter = myBooks.size() > letterSet.size() * 5 / 4;
|
||||||
}
|
}
|
||||||
if (doGroupTitlesByFirstLetter) {
|
if (doGroupTitlesByFirstLetter) {
|
||||||
final HashMap<Character,TitleTree> letterTrees = new HashMap<Character,TitleTree>();
|
|
||||||
for (Book book : myBooks) {
|
for (Book book : myBooks) {
|
||||||
String title = book.getTitle();
|
String title = book.getTitle();
|
||||||
if (title == null) {
|
if (title == null) {
|
||||||
|
@ -334,16 +323,12 @@ public final class Library {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Character c = title.charAt(0);
|
Character c = title.charAt(0);
|
||||||
TitleTree tree = letterTrees.get(c);
|
final TitleTree tree = getFirstLevelTree(ROOT_BY_TITLE).getTitleSubTree(c.toString());
|
||||||
if (tree == null) {
|
tree.getBookSubTree(book, true);
|
||||||
tree = getFirstLevelTree(ROOT_BY_TITLE).createTitleSubTree(c.toString());
|
|
||||||
letterTrees.put(c, tree);
|
|
||||||
}
|
|
||||||
tree.createBookSubTree(book, true);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (Book book : myBooks) {
|
for (Book book : myBooks) {
|
||||||
getFirstLevelTree(ROOT_BY_TITLE).createBookSubTree(book, true);
|
getFirstLevelTree(ROOT_BY_TITLE).getBookSubTree(book, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,22 +336,17 @@ public final class Library {
|
||||||
for (long id : db.loadRecentBookIds()) {
|
for (long id : db.loadRecentBookIds()) {
|
||||||
Book book = bookById.get(id);
|
Book book = bookById.get(id);
|
||||||
if (book != null) {
|
if (book != null) {
|
||||||
getFirstLevelTree(ROOT_RECENT).createBookSubTree(book, true);
|
new BookTree(getFirstLevelTree(ROOT_RECENT), book, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (long id : db.loadFavoritesIds()) {
|
for (long id : db.loadFavoritesIds()) {
|
||||||
Book book = bookById.get(id);
|
Book book = bookById.get(id);
|
||||||
if (book != null) {
|
if (book != null) {
|
||||||
getFirstLevelTree(ROOT_FAVORITES).createBookSubTree(book, true);
|
getFirstLevelTree(ROOT_FAVORITES).getBookSubTree(book, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getFirstLevelTree(ROOT_FAVORITES).sortAllChildren();
|
|
||||||
getFirstLevelTree(ROOT_BY_AUTHOR).sortAllChildren();
|
|
||||||
getFirstLevelTree(ROOT_BY_TITLE).sortAllChildren();
|
|
||||||
getFirstLevelTree(ROOT_BY_TAG).sortAllChildren();
|
|
||||||
|
|
||||||
db.executeAsATransaction(new Runnable() {
|
db.executeAsATransaction(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
for (Book book : myBooks) {
|
for (Book book : myBooks) {
|
||||||
|
@ -418,12 +398,9 @@ public final class Library {
|
||||||
if (newSearchResults == null) {
|
if (newSearchResults == null) {
|
||||||
newSearchResults = createNewSearchResults(pattern);
|
newSearchResults = createNewSearchResults(pattern);
|
||||||
}
|
}
|
||||||
newSearchResults.createBookSubTree(book, true);
|
newSearchResults.getBookSubTree(book, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (newSearchResults != null) {
|
|
||||||
newSearchResults.sortAllChildren();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return newSearchResults;
|
return newSearchResults;
|
||||||
}
|
}
|
||||||
|
@ -460,8 +437,7 @@ public final class Library {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final LibraryTree rootFavorites = getFirstLevelTree(ROOT_FAVORITES);
|
final LibraryTree rootFavorites = getFirstLevelTree(ROOT_FAVORITES);
|
||||||
rootFavorites.createBookSubTree(book, true);
|
rootFavorites.getBookSubTree(book, true);
|
||||||
rootFavorites.sortAllChildren();
|
|
||||||
BooksDatabase.Instance().addToFavorites(book.getId());
|
BooksDatabase.Instance().addToFavorites(book.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,12 +48,24 @@ public abstract class LibraryTree extends FBTree {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
TagTree createTagSubTree(Tag tag) {
|
TagTree getTagSubTree(Tag tag) {
|
||||||
return new TagTree(this, tag);
|
final TagTree temp = new TagTree(tag);
|
||||||
|
int position = Collections.binarySearch(subTrees(), temp);
|
||||||
|
if (position >= 0) {
|
||||||
|
return (TagTree)subTrees().get(position);
|
||||||
|
} else {
|
||||||
|
return new TagTree(this, tag, - position - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TitleTree createTitleSubTree(String title) {
|
TitleTree getTitleSubTree(String title) {
|
||||||
return new TitleTree(this, title);
|
final TitleTree temp = new TitleTree(title);
|
||||||
|
int position = Collections.binarySearch(subTrees(), temp);
|
||||||
|
if (position >= 0) {
|
||||||
|
return (TitleTree)subTrees().get(position);
|
||||||
|
} else {
|
||||||
|
return new TitleTree(this, title, - position - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AuthorTree getAuthorSubTree(Author author) {
|
AuthorTree getAuthorSubTree(Author author) {
|
||||||
|
@ -66,8 +78,14 @@ public abstract class LibraryTree extends FBTree {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BookTree createBookSubTree(Book book, boolean showAuthors) {
|
BookTree getBookSubTree(Book book, boolean showAuthors) {
|
||||||
return new BookTree(this, book, showAuthors);
|
final BookTree temp = new BookTree(book, showAuthors);
|
||||||
|
int position = Collections.binarySearch(subTrees(), temp);
|
||||||
|
if (position >= 0) {
|
||||||
|
return (BookTree)subTrees().get(position);
|
||||||
|
} else {
|
||||||
|
return new BookTree(this, book, showAuthors, - position - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeBook(Book book) {
|
public boolean removeBook(Book book) {
|
||||||
|
|
|
@ -19,11 +19,17 @@
|
||||||
|
|
||||||
package org.geometerplus.fbreader.library;
|
package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
public final class SeriesTree extends LibraryTree {
|
public final class SeriesTree extends LibraryTree {
|
||||||
public final String Series;
|
public final String Series;
|
||||||
|
|
||||||
SeriesTree(LibraryTree parent, String series) {
|
SeriesTree(String series) {
|
||||||
super(parent);
|
Series = series;
|
||||||
|
}
|
||||||
|
|
||||||
|
SeriesTree(LibraryTree parent, String series, int position) {
|
||||||
|
super(parent, position);
|
||||||
Series = series;
|
Series = series;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,8 +43,14 @@ public final class SeriesTree extends LibraryTree {
|
||||||
return getName();
|
return getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
BookTree createBookInSeriesSubTree(Book book) {
|
BookTree getBookInSeriesSubTree(Book book) {
|
||||||
return new BookInSeriesTree(this, book);
|
final BookInSeriesTree temp = new BookInSeriesTree(book);
|
||||||
|
int position = Collections.binarySearch(subTrees(), temp);
|
||||||
|
if (position >= 0) {
|
||||||
|
return (BookInSeriesTree)subTrees().get(position);
|
||||||
|
} else {
|
||||||
|
return new BookInSeriesTree(this, book, - position - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -22,8 +22,12 @@ package org.geometerplus.fbreader.library;
|
||||||
public final class TagTree extends LibraryTree {
|
public final class TagTree extends LibraryTree {
|
||||||
public final Tag Tag;
|
public final Tag Tag;
|
||||||
|
|
||||||
TagTree(LibraryTree parent, Tag tag) {
|
TagTree(Tag tag) {
|
||||||
super(parent);
|
Tag = tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
TagTree(LibraryTree parent, Tag tag, int position) {
|
||||||
|
super(parent, position);
|
||||||
Tag = tag;
|
Tag = tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,12 @@ package org.geometerplus.fbreader.library;
|
||||||
public final class TitleTree extends LibraryTree {
|
public final class TitleTree extends LibraryTree {
|
||||||
public final String Title;
|
public final String Title;
|
||||||
|
|
||||||
TitleTree(LibraryTree parent, String title) {
|
TitleTree(String title) {
|
||||||
super(parent);
|
Title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
TitleTree(LibraryTree parent, String title, int position) {
|
||||||
|
super(parent, position);
|
||||||
Title = title;
|
Title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue