1
0
Fork 0
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:
Nikolay Pultsin 2011-07-17 14:16:24 +01:00
parent 05365b01d1
commit 31075d08a0
3 changed files with 19 additions and 13 deletions

View file

@ -22,8 +22,12 @@ package org.geometerplus.fbreader.library;
public class AuthorTree extends LibraryTree { public class AuthorTree extends LibraryTree {
public final Author Author; public final Author Author;
AuthorTree(LibraryTree parent, Author author) { AuthorTree(Author author) {
super(parent); Author = author;
}
AuthorTree(LibraryTree parent, Author author, int position) {
super(parent, position);
Author = author; Author = author;
} }
@ -34,18 +38,19 @@ public class AuthorTree extends LibraryTree {
@Override @Override
public String getName() { public String getName() {
return return
(Author != null) ? Author != null ?
Author.DisplayName : Author.DisplayName :
Library.resource().getResource("unknownAuthor").getValue(); Library.resource().getResource("unknownAuthor").getValue();
} }
@Override @Override
protected String getStringId() { protected String getStringId() {
return getName(); return getName() + ":" + getSortKey();
} }
@Override
protected String getSortKey() { protected String getSortKey() {
return (Author != null) ? Author.SortKey : null; return Author != null ? Author.SortKey : null;
} }
@Override @Override

View file

@ -271,7 +271,6 @@ public final class Library {
private void build() { private void build() {
final HashMap<Tag,TagTree> tagTreeMap = new HashMap<Tag,TagTree>(); 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<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>();
@ -285,11 +284,7 @@ public final class Library {
} }
final SeriesInfo seriesInfo = book.getSeriesInfo(); final SeriesInfo seriesInfo = book.getSeriesInfo();
for (Author a : authors) { for (Author a : authors) {
AuthorTree authorTree = authorTreeMap.get(a); final AuthorTree authorTree = getFirstLevelTree(ROOT_BY_AUTHOR).getAuthorSubTree(a);
if (authorTree == null) {
authorTree = getFirstLevelTree(ROOT_BY_AUTHOR).createAuthorSubTree(a);
authorTreeMap.put(a, authorTree);
}
if (seriesInfo == null) { if (seriesInfo == null) {
authorTree.createBookSubTree(book, false); authorTree.createBookSubTree(book, false);
} else { } else {

View file

@ -56,8 +56,14 @@ public abstract class LibraryTree extends FBTree {
return new TitleTree(this, title); return new TitleTree(this, title);
} }
AuthorTree createAuthorSubTree(Author author) { AuthorTree getAuthorSubTree(Author author) {
return new AuthorTree(this, 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) { BookTree createBookSubTree(Book book, boolean showAuthors) {