mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 02:39:23 +02:00
Network tree classes have been added
git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@1061 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
1cddf78fa1
commit
282c132922
10 changed files with 254 additions and 76 deletions
|
@ -33,12 +33,10 @@ public class BookTree extends LibraryTree {
|
|||
return Book.getTitle();
|
||||
}
|
||||
|
||||
private String myAuthorsString;
|
||||
public String getSecondString() {
|
||||
public String getSummary() {
|
||||
if (!myShowAuthors) {
|
||||
return super.getSecondString();
|
||||
}
|
||||
if (myAuthorsString == null) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int count = 0;
|
||||
for (Author author : Book.authors()) {
|
||||
|
@ -50,8 +48,6 @@ public class BookTree extends LibraryTree {
|
|||
break;
|
||||
}
|
||||
}
|
||||
myAuthorsString = builder.toString();
|
||||
}
|
||||
return myAuthorsString;
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,25 +46,6 @@ public abstract class LibraryTree extends FBTree {
|
|||
return new BookTree(this, book, showAuthors);
|
||||
}
|
||||
|
||||
private String myChildrenString;
|
||||
public String getSecondString() {
|
||||
if (myChildrenString == null) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int count = 0;
|
||||
for (FBTree subtree : subTrees()) {
|
||||
if (count++ > 0) {
|
||||
builder.append(", ");
|
||||
}
|
||||
builder.append(subtree.getName());
|
||||
if (count == 5) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
myChildrenString = builder.toString();
|
||||
}
|
||||
return myChildrenString;
|
||||
}
|
||||
|
||||
public boolean removeBook(Book book) {
|
||||
final LinkedList<FBTree> toRemove = new LinkedList<FBTree>();
|
||||
for (FBTree tree : this) {
|
||||
|
@ -79,7 +60,7 @@ public abstract class LibraryTree extends FBTree {
|
|||
parent.removeSelf();
|
||||
}
|
||||
for (; parent != null; parent = parent.Parent) {
|
||||
((LibraryTree)parent).myChildrenString = null;
|
||||
((LibraryTree)parent).invalidateChildren();
|
||||
}
|
||||
}
|
||||
return !toRemove.isEmpty();
|
||||
|
|
|
@ -22,9 +22,9 @@ package org.geometerplus.fbreader.network;
|
|||
import java.util.*;
|
||||
|
||||
|
||||
class NetworkBookItem extends NetworkLibraryItem {
|
||||
public class NetworkBookItem extends NetworkLibraryItem {
|
||||
|
||||
public static class AuthorData {
|
||||
public static class AuthorData implements Comparable<AuthorData> {
|
||||
public final String DisplayName;
|
||||
public final String SortKey;
|
||||
|
||||
|
@ -32,6 +32,29 @@ class NetworkBookItem extends NetworkLibraryItem {
|
|||
DisplayName = displayName;
|
||||
SortKey = sortKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(AuthorData data) {
|
||||
int key = SortKey.compareTo(data.SortKey);
|
||||
if (key != 0) {
|
||||
return key;
|
||||
}
|
||||
return DisplayName.compareTo(data.DisplayName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || !(o instanceof AuthorData)) {
|
||||
return false;
|
||||
}
|
||||
AuthorData data = (AuthorData) o;
|
||||
return SortKey == data.SortKey && DisplayName == data.DisplayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return SortKey.hashCode() + DisplayName.hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
public final int Index;
|
||||
|
|
|
@ -41,28 +41,7 @@ public class NetworkLibrary {
|
|||
private boolean myUpdateChildren = true;
|
||||
|
||||
|
||||
private static class DummyCatalogItem extends NetworkCatalogItem {
|
||||
public DummyCatalogItem(NetworkLink link, String title, String summary) {
|
||||
super(link, title, summary, VisibilityType.ALWAYS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String loadChildren(List<NetworkLibraryItem> children) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public NetworkLibrary() {
|
||||
myLinks.add(new NetworkLink("feedbooks.com") {
|
||||
public NetworkLibraryItem libraryItem() {
|
||||
return new DummyCatalogItem(this, "Feedbooks catalog", "feedbooks online catalog");
|
||||
}
|
||||
});
|
||||
myLinks.add(new NetworkLink("litres.ru") {
|
||||
public NetworkLibraryItem libraryItem() {
|
||||
return new DummyCatalogItem(this, "Litres catalog", "litres online catalog");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public List<NetworkLink> links() {
|
||||
|
|
|
@ -39,22 +39,4 @@ public abstract class NetworkTree extends FBTree {
|
|||
super(parent, position);
|
||||
}
|
||||
|
||||
private String myChildrenString;
|
||||
public String getSecondString() {
|
||||
if (myChildrenString == null) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int count = 0;
|
||||
for (FBTree subtree : subTrees()) {
|
||||
if (count++ > 0) {
|
||||
builder.append(", ");
|
||||
}
|
||||
builder.append(subtree.getName());
|
||||
if (count == 5) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
myChildrenString = builder.toString();
|
||||
}
|
||||
return myChildrenString;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* 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.network.tree;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.geometerplus.fbreader.network.*;
|
||||
|
||||
|
||||
public class NetworkAuthorTree extends NetworkTree {
|
||||
|
||||
public final NetworkBookItem.AuthorData Author;
|
||||
|
||||
|
||||
NetworkAuthorTree(NetworkTree parent, NetworkBookItem.AuthorData author) {
|
||||
super(parent);
|
||||
Author = author;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return Author.DisplayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getSortKey() {
|
||||
return Author.SortKey;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* 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.network.tree;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.geometerplus.fbreader.tree.FBTree;
|
||||
import org.geometerplus.fbreader.network.*;
|
||||
|
||||
|
||||
public class NetworkBookTree extends NetworkTree {
|
||||
|
||||
public final NetworkBookItem Book;
|
||||
|
||||
NetworkBookTree(NetworkTree parent, NetworkBookItem book) {
|
||||
super(parent);
|
||||
Book = book;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return Book.Title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSummary() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int count = 0;
|
||||
for (NetworkBookItem.AuthorData author: Book.Authors) {
|
||||
if (count++ > 0) {
|
||||
builder.append(", ");
|
||||
}
|
||||
builder.append(author.DisplayName);
|
||||
}
|
||||
String authorsString = builder.toString();
|
||||
|
||||
FBTree parent = this.Parent;
|
||||
if (parent.getName().equals(authorsString)) {
|
||||
return "";
|
||||
}
|
||||
return authorsString;
|
||||
}
|
||||
|
||||
}
|
|
@ -45,6 +45,11 @@ public class NetworkCatalogTree extends NetworkTree {
|
|||
return Item.Title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSummary() {
|
||||
return Item.Summary;
|
||||
}
|
||||
|
||||
public void updateChildren() {
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* 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.network.tree;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.geometerplus.fbreader.tree.FBTree;
|
||||
import org.geometerplus.fbreader.network.*;
|
||||
|
||||
|
||||
public class NetworkSeriesTree extends NetworkTree {
|
||||
|
||||
private final String myTitle;
|
||||
private final boolean myShowAuthors;
|
||||
|
||||
NetworkSeriesTree(NetworkTree parent, String seriesTitle, boolean showAuthors) {
|
||||
super(parent);
|
||||
myTitle = seriesTitle;
|
||||
myShowAuthors = showAuthors;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return myTitle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSummary() {
|
||||
if (!myShowAuthors) {
|
||||
return super.getSecondString();
|
||||
}
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int count = 0;
|
||||
|
||||
Set<NetworkBookItem.AuthorData> authorSet = new TreeSet<NetworkBookItem.AuthorData>();
|
||||
for (FBTree tree: this) {
|
||||
if (!(tree instanceof NetworkBookTree)) {
|
||||
continue;
|
||||
}
|
||||
final NetworkBookItem book = (NetworkBookItem) ((NetworkBookTree)tree).Book;
|
||||
|
||||
for (NetworkBookItem.AuthorData author: book.Authors) {
|
||||
if (!authorSet.contains(author)) {
|
||||
authorSet.add(author);
|
||||
if (count++ > 0) {
|
||||
builder.append(", ");
|
||||
}
|
||||
builder.append(author.DisplayName);
|
||||
if (count == 5) {
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -63,4 +63,32 @@ public abstract class FBTree extends ZLTree<FBTree> implements Comparable<FBTree
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String myChildrenString;
|
||||
|
||||
public final void invalidateChildren() {
|
||||
myChildrenString = "";
|
||||
}
|
||||
|
||||
public final String getSecondString() {
|
||||
if (myChildrenString == null) {
|
||||
myChildrenString = getSummary();
|
||||
}
|
||||
return myChildrenString;
|
||||
}
|
||||
|
||||
protected String getSummary() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int count = 0;
|
||||
for (FBTree subtree : subTrees()) {
|
||||
if (count++ > 0) {
|
||||
builder.append(", ");
|
||||
}
|
||||
builder.append(subtree.getName());
|
||||
if (count == 5) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue