mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
new FBTree class has been added
git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@1059 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
5c1ea34fd2
commit
30e9f8dae0
4 changed files with 77 additions and 38 deletions
|
@ -35,6 +35,7 @@ import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
import org.geometerplus.fbreader.fbreader.FBReader;
|
import org.geometerplus.fbreader.fbreader.FBReader;
|
||||||
import org.geometerplus.fbreader.bookmodel.BookModel;
|
import org.geometerplus.fbreader.bookmodel.BookModel;
|
||||||
import org.geometerplus.fbreader.library.*;
|
import org.geometerplus.fbreader.library.*;
|
||||||
|
import org.geometerplus.fbreader.tree.FBTree;
|
||||||
|
|
||||||
public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuItemClickListener {
|
public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuItemClickListener {
|
||||||
static LibraryTabActivity Instance;
|
static LibraryTabActivity Instance;
|
||||||
|
@ -184,7 +185,7 @@ public class LibraryTabActivity extends TabActivity implements MenuItem.OnMenuIt
|
||||||
if (myCurrentBook == null) {
|
if (myCurrentBook == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (LibraryTree tree : myLibraryTree) {
|
for (FBTree tree : myLibraryTree) {
|
||||||
if ((tree instanceof BookTree) && ((BookTree)tree).Book.equals(myCurrentBook)) {
|
if ((tree instanceof BookTree) && ((BookTree)tree).Book.equals(myCurrentBook)) {
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,13 +19,15 @@
|
||||||
|
|
||||||
package org.geometerplus.fbreader.library;
|
package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
|
import org.geometerplus.fbreader.tree.FBTree;
|
||||||
|
|
||||||
public final class BookInSeriesTree extends BookTree {
|
public final class BookInSeriesTree extends BookTree {
|
||||||
BookInSeriesTree(LibraryTree parent, Book book) {
|
BookInSeriesTree(LibraryTree parent, Book book) {
|
||||||
super(parent, book, false);
|
super(parent, book, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(LibraryTree tree) {
|
public int compareTo(FBTree tree) {
|
||||||
if (tree instanceof BookInSeriesTree) {
|
if (tree instanceof BookInSeriesTree) {
|
||||||
final long difference =
|
final long difference =
|
||||||
Book.getSeriesInfo().Index - ((BookTree)tree).Book.getSeriesInfo().Index;
|
Book.getSeriesInfo().Index - ((BookTree)tree).Book.getSeriesInfo().Index;
|
||||||
|
|
|
@ -21,9 +21,11 @@ package org.geometerplus.fbreader.library;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.tree.ZLTree;
|
//import org.geometerplus.zlibrary.core.tree.ZLTree;
|
||||||
|
|
||||||
public abstract class LibraryTree extends ZLTree<LibraryTree> implements Comparable<LibraryTree> {
|
import org.geometerplus.fbreader.tree.FBTree;
|
||||||
|
|
||||||
|
public abstract class LibraryTree extends FBTree {
|
||||||
protected LibraryTree() {
|
protected LibraryTree() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
@ -44,18 +46,12 @@ public abstract class LibraryTree extends ZLTree<LibraryTree> implements Compara
|
||||||
return new BookTree(this, book, showAuthors);
|
return new BookTree(this, book, showAuthors);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String getName();
|
|
||||||
|
|
||||||
protected String getSortKey() {
|
|
||||||
return getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String myChildrenString;
|
private String myChildrenString;
|
||||||
public String getSecondString() {
|
public String getSecondString() {
|
||||||
if (myChildrenString == null) {
|
if (myChildrenString == null) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for (LibraryTree subtree : subTrees()) {
|
for (FBTree subtree : subTrees()) {
|
||||||
if (count++ > 0) {
|
if (count++ > 0) {
|
||||||
builder.append(", ");
|
builder.append(", ");
|
||||||
}
|
}
|
||||||
|
@ -69,43 +65,21 @@ public abstract class LibraryTree extends ZLTree<LibraryTree> implements Compara
|
||||||
return myChildrenString;
|
return myChildrenString;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int compareTo(LibraryTree ct) {
|
|
||||||
final String key0 = getSortKey();
|
|
||||||
final String key1 = ct.getSortKey();
|
|
||||||
if (key0 == null) {
|
|
||||||
return (key1 == null) ? 0 : -1;
|
|
||||||
}
|
|
||||||
if (key1 == null) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return key0.toLowerCase().compareTo(key1.toLowerCase());
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void sortAllChildren() {
|
|
||||||
List<LibraryTree> children = subTrees();
|
|
||||||
if (!children.isEmpty()) {
|
|
||||||
Collections.sort(children);
|
|
||||||
for (LibraryTree tree : children) {
|
|
||||||
tree.sortAllChildren();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean removeBook(Book book) {
|
public boolean removeBook(Book book) {
|
||||||
final LinkedList<LibraryTree> toRemove = new LinkedList<LibraryTree>();
|
final LinkedList<FBTree> toRemove = new LinkedList<FBTree>();
|
||||||
for (LibraryTree tree : this) {
|
for (FBTree tree : this) {
|
||||||
if ((tree instanceof BookTree) && ((BookTree)tree).Book.equals(book)) {
|
if ((tree instanceof BookTree) && ((BookTree)tree).Book.equals(book)) {
|
||||||
toRemove.add(tree);
|
toRemove.add(tree);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (LibraryTree tree : toRemove) {
|
for (FBTree tree : toRemove) {
|
||||||
tree.removeSelf();
|
tree.removeSelf();
|
||||||
LibraryTree parent = tree.Parent;
|
FBTree parent = tree.Parent;
|
||||||
for (; (parent != null) && !parent.hasChildren(); parent = parent.Parent) {
|
for (; (parent != null) && !parent.hasChildren(); parent = parent.Parent) {
|
||||||
parent.removeSelf();
|
parent.removeSelf();
|
||||||
}
|
}
|
||||||
for (; parent != null; parent = parent.Parent) {
|
for (; parent != null; parent = parent.Parent) {
|
||||||
parent.myChildrenString = null;
|
((LibraryTree)parent).myChildrenString = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return !toRemove.isEmpty();
|
return !toRemove.isEmpty();
|
||||||
|
|
62
src/org/geometerplus/fbreader/tree/FBTree.java
Normal file
62
src/org/geometerplus/fbreader/tree/FBTree.java
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2010 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.tree;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
import org.geometerplus.zlibrary.core.tree.ZLTree;
|
||||||
|
|
||||||
|
public abstract class FBTree extends ZLTree<FBTree> implements Comparable<FBTree> {
|
||||||
|
protected FBTree() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected FBTree(FBTree parent) {
|
||||||
|
super(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract String getName();
|
||||||
|
|
||||||
|
protected String getSortKey() {
|
||||||
|
return getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compareTo(FBTree ct) {
|
||||||
|
final String key0 = getSortKey();
|
||||||
|
final String key1 = ct.getSortKey();
|
||||||
|
if (key0 == null) {
|
||||||
|
return (key1 == null) ? 0 : -1;
|
||||||
|
}
|
||||||
|
if (key1 == null) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return key0.toLowerCase().compareTo(key1.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void sortAllChildren() {
|
||||||
|
List<FBTree> children = subTrees();
|
||||||
|
if (!children.isEmpty()) {
|
||||||
|
Collections.sort(children);
|
||||||
|
for (FBTree tree : children) {
|
||||||
|
tree.sortAllChildren();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue