mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 19:42:17 +02:00
AuthorListTree
This commit is contained in:
parent
5f9822ba5f
commit
e4912a2beb
4 changed files with 117 additions and 1 deletions
|
@ -20,6 +20,8 @@
|
|||
package org.geometerplus.fbreader.book;
|
||||
|
||||
public final class Author implements Comparable<Author> {
|
||||
public static final Author NULL = new Author("", "");
|
||||
|
||||
public final String DisplayName;
|
||||
public final String SortKey;
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.geometerplus.zlibrary.core.image.ZLImage;
|
|||
import org.geometerplus.zlibrary.text.view.ZLTextPosition;
|
||||
|
||||
import org.geometerplus.fbreader.Paths;
|
||||
import org.geometerplus.fbreader.book.*;
|
||||
import org.geometerplus.fbreader.bookmodel.BookReadingException;
|
||||
import org.geometerplus.fbreader.formats.*;
|
||||
import org.geometerplus.fbreader.library.Library;
|
||||
|
@ -141,6 +140,18 @@ public class Book {
|
|||
readMetaInfo(plugin);
|
||||
}
|
||||
|
||||
public void updateFrom(Book book) {
|
||||
if (myId != book.myId) {
|
||||
return;
|
||||
}
|
||||
myTitle = book.myTitle;
|
||||
myEncoding = book.myEncoding;
|
||||
myLanguage = book.myLanguage;
|
||||
myAuthors = book.myAuthors != null ? new ArrayList<Author>(book.myAuthors) : null;
|
||||
myTags = book.myTags != null ? new ArrayList<Tag>(book.myTags) : null;
|
||||
mySeriesInfo = book.mySeriesInfo;
|
||||
}
|
||||
|
||||
public void reloadInfoFromFile() {
|
||||
try {
|
||||
readMetaInfo();
|
||||
|
|
79
src/org/geometerplus/fbreader/library/AuthorListTree.java
Normal file
79
src/org/geometerplus/fbreader/library/AuthorListTree.java
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (C) 2009-2013 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;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.geometerplus.fbreader.book.*;
|
||||
|
||||
public class AuthorListTree extends FirstLevelTree {
|
||||
AuthorListTree(RootTree root) {
|
||||
super(root, ROOT_BY_AUTHOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Status getOpeningStatus() {
|
||||
return Status.ALWAYS_RELOAD_BEFORE_OPENING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void waitForOpening() {
|
||||
clear();
|
||||
for (Author a : Collection.authors()) {
|
||||
createAuthorSubTree(a);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBookEvent(BookEvent event, Book book) {
|
||||
switch (event) {
|
||||
default:
|
||||
case Added:
|
||||
{
|
||||
final List<Author> bookAuthors = book.authors();
|
||||
boolean changed = false;
|
||||
if (bookAuthors.isEmpty()) {
|
||||
changed &= createAuthorSubTree(Author.NULL);
|
||||
} else for (Author a : Collection.authors()) {
|
||||
changed &= createAuthorSubTree(a);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
case Removed:
|
||||
// TODO: implement
|
||||
return false;
|
||||
case Updated:
|
||||
// TODO: implement
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean createAuthorSubTree(Author author) {
|
||||
final AuthorTree temp = new AuthorTree(Collection, author);
|
||||
int position = Collections.binarySearch(subTrees(), temp);
|
||||
if (position >= 0) {
|
||||
return false;
|
||||
} else {
|
||||
new AuthorTree(this, author, - position - 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -142,6 +142,30 @@ public abstract class LibraryTree extends FBTree {
|
|||
return !toRemove.isEmpty();
|
||||
}
|
||||
|
||||
public boolean onBookEvent(BookEvent event, Book book) {
|
||||
switch (event) {
|
||||
default:
|
||||
case Added:
|
||||
return false;
|
||||
case Removed:
|
||||
return removeBook(book, true);
|
||||
case Updated:
|
||||
{
|
||||
boolean changed = false;
|
||||
for (FBTree tree : this) {
|
||||
if (tree instanceof BookTree) {
|
||||
final Book b = ((BookTree)tree).Book;
|
||||
if (b.equals(book)) {
|
||||
b.updateFrom(book);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(FBTree tree) {
|
||||
final int cmp = super.compareTo(tree);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue