mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 02:39:23 +02:00
autosorting for AuthorTree's
This commit is contained in:
parent
05365b01d1
commit
31075d08a0
3 changed files with 19 additions and 13 deletions
|
@ -22,8 +22,12 @@ package org.geometerplus.fbreader.library;
|
|||
public class AuthorTree extends LibraryTree {
|
||||
public final Author Author;
|
||||
|
||||
AuthorTree(LibraryTree parent, Author author) {
|
||||
super(parent);
|
||||
AuthorTree(Author author) {
|
||||
Author = author;
|
||||
}
|
||||
|
||||
AuthorTree(LibraryTree parent, Author author, int position) {
|
||||
super(parent, position);
|
||||
Author = author;
|
||||
}
|
||||
|
||||
|
@ -34,18 +38,19 @@ public class AuthorTree extends LibraryTree {
|
|||
@Override
|
||||
public String getName() {
|
||||
return
|
||||
(Author != null) ?
|
||||
Author != null ?
|
||||
Author.DisplayName :
|
||||
Library.resource().getResource("unknownAuthor").getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getStringId() {
|
||||
return getName();
|
||||
return getName() + ":" + getSortKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSortKey() {
|
||||
return (Author != null) ? Author.SortKey : null;
|
||||
return Author != null ? Author.SortKey : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -271,7 +271,6 @@ public final class Library {
|
|||
|
||||
private void build() {
|
||||
final HashMap<Tag,TagTree> tagTreeMap = new HashMap<Tag,TagTree>();
|
||||
final HashMap<Author,AuthorTree> authorTreeMap = new HashMap<Author,AuthorTree>();
|
||||
final HashMap<AuthorSeriesPair,SeriesTree> seriesTreeMap = new HashMap<AuthorSeriesPair,SeriesTree>();
|
||||
final HashMap<Long,Book> bookById = new HashMap<Long,Book>();
|
||||
|
||||
|
@ -285,11 +284,7 @@ public final class Library {
|
|||
}
|
||||
final SeriesInfo seriesInfo = book.getSeriesInfo();
|
||||
for (Author a : authors) {
|
||||
AuthorTree authorTree = authorTreeMap.get(a);
|
||||
if (authorTree == null) {
|
||||
authorTree = getFirstLevelTree(ROOT_BY_AUTHOR).createAuthorSubTree(a);
|
||||
authorTreeMap.put(a, authorTree);
|
||||
}
|
||||
final AuthorTree authorTree = getFirstLevelTree(ROOT_BY_AUTHOR).getAuthorSubTree(a);
|
||||
if (seriesInfo == null) {
|
||||
authorTree.createBookSubTree(book, false);
|
||||
} else {
|
||||
|
|
|
@ -56,8 +56,14 @@ public abstract class LibraryTree extends FBTree {
|
|||
return new TitleTree(this, title);
|
||||
}
|
||||
|
||||
AuthorTree createAuthorSubTree(Author author) {
|
||||
return new AuthorTree(this, author);
|
||||
AuthorTree getAuthorSubTree(Author author) {
|
||||
final AuthorTree temp = new AuthorTree(author);
|
||||
int position = Collections.binarySearch(subTrees(), temp);
|
||||
if (position >= 0) {
|
||||
return (AuthorTree)subTrees().get(position);
|
||||
} else {
|
||||
return new AuthorTree(this, author, - position - 1);
|
||||
}
|
||||
}
|
||||
|
||||
BookTree createBookSubTree(Book book, boolean showAuthors) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue