mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 19:42:17 +02:00
"by series" branch
This commit is contained in:
parent
73b9d5d1e5
commit
d7ded9b2eb
4 changed files with 101 additions and 10 deletions
|
@ -55,6 +55,9 @@
|
|||
<node name="byDate" value="By date">
|
||||
<node name="summary" value="Books sorted by date of purchasing"/>
|
||||
</node>
|
||||
<node name="bySeries" value="By series">
|
||||
<node name="summary" value="Books sorted by series"/>
|
||||
</node>
|
||||
<node name="openCatalog" value="Open catalog"/>
|
||||
<node name="showResults" value="Show results"/>
|
||||
<node name="showBooks" value="Show books"/>
|
||||
|
|
|
@ -22,9 +22,7 @@ package org.geometerplus.fbreader.network;
|
|||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
|
||||
public final class NetworkBookItemComparator implements Comparator<NetworkLibraryItem> {
|
||||
|
||||
public int compare(NetworkLibraryItem item0, NetworkLibraryItem item1) {
|
||||
final boolean item0isABook = item0 instanceof NetworkBookItem;
|
||||
final boolean item1isABook = item1 instanceof NetworkBookItem;
|
||||
|
|
|
@ -361,11 +361,11 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
|
|||
}
|
||||
|
||||
private void loadPurchasedBooksOnSuccess(LitResNetworkRequest purchasedBooksRequest) {
|
||||
LitResXMLReader reader = (LitResXMLReader) purchasedBooksRequest.Reader;
|
||||
LitResXMLReader reader = (LitResXMLReader)purchasedBooksRequest.Reader;
|
||||
myPurchasedBooks.clear();
|
||||
for (NetworkLibraryItem item: reader.Books) {
|
||||
if (item instanceof NetworkBookItem) {
|
||||
NetworkBookItem book = (NetworkBookItem) item;
|
||||
NetworkBookItem book = (NetworkBookItem)item;
|
||||
myPurchasedBooks.put(book.Id, book);
|
||||
}
|
||||
}
|
||||
|
@ -390,7 +390,7 @@ public class LitResAuthenticationManager extends NetworkAuthenticationManager {
|
|||
}
|
||||
|
||||
private void loadAccountOnSuccess(LitResNetworkRequest accountRequest) {
|
||||
LitResPurchaseXMLReader reader = (LitResPurchaseXMLReader) accountRequest.Reader;
|
||||
LitResPurchaseXMLReader reader = (LitResPurchaseXMLReader)accountRequest.Reader;
|
||||
myAccount = BuyBookReference.price(reader.Account, "RUB");
|
||||
}
|
||||
|
||||
|
|
|
@ -26,12 +26,29 @@ import org.geometerplus.zlibrary.core.network.ZLNetworkException;
|
|||
|
||||
import org.geometerplus.fbreader.network.*;
|
||||
|
||||
class SortedCatalogItem extends NetworkCatalogItem {
|
||||
abstract class SortedCatalogItem extends NetworkCatalogItem {
|
||||
private final List<NetworkLibraryItem> myChildren = new LinkedList<NetworkLibraryItem>();
|
||||
|
||||
private SortedCatalogItem(NetworkCatalogItem parent, ZLResource resource, List<NetworkLibraryItem> children) {
|
||||
super(parent.Link, resource.getValue(), resource.getResource("summary").getValue(), "", parent.URLByType);
|
||||
myChildren.addAll(children);
|
||||
for (NetworkLibraryItem child : children) {
|
||||
if (accepts(child)) {
|
||||
myChildren.add(child);
|
||||
}
|
||||
}
|
||||
final Comparator<NetworkLibraryItem> comparator = getComparator();
|
||||
if (comparator != null) {
|
||||
Collections.sort(myChildren, comparator);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return myChildren.isEmpty();
|
||||
}
|
||||
|
||||
protected abstract Comparator<NetworkLibraryItem> getComparator();
|
||||
protected boolean accepts(NetworkLibraryItem item) {
|
||||
return item instanceof NetworkBookItem;
|
||||
}
|
||||
|
||||
public SortedCatalogItem(NetworkCatalogItem parent, String resourceKey, List<NetworkLibraryItem> children) {
|
||||
|
@ -51,6 +68,75 @@ class SortedCatalogItem extends NetworkCatalogItem {
|
|||
}
|
||||
}
|
||||
|
||||
class ByAuthorCatalogItem extends SortedCatalogItem {
|
||||
ByAuthorCatalogItem(NetworkCatalogItem parent, List<NetworkLibraryItem> children) {
|
||||
super(parent, "byAuthor", children);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Comparator<NetworkLibraryItem> getComparator() {
|
||||
return new NetworkBookItemComparator();
|
||||
}
|
||||
}
|
||||
|
||||
class ByTitleCatalogItem extends SortedCatalogItem {
|
||||
ByTitleCatalogItem(NetworkCatalogItem parent, List<NetworkLibraryItem> children) {
|
||||
super(parent, "byTitle", children);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Comparator<NetworkLibraryItem> getComparator() {
|
||||
return new Comparator<NetworkLibraryItem>() {
|
||||
public int compare(NetworkLibraryItem item0, NetworkLibraryItem item1) {
|
||||
return item0.Title.compareTo(item1.Title);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class ByDateCatalogItem extends SortedCatalogItem {
|
||||
ByDateCatalogItem(NetworkCatalogItem parent, List<NetworkLibraryItem> children) {
|
||||
super(parent, "byDate", children);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Comparator<NetworkLibraryItem> getComparator() {
|
||||
return new Comparator<NetworkLibraryItem>() {
|
||||
public int compare(NetworkLibraryItem item0, NetworkLibraryItem item1) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class BySeriesCatalogItem extends SortedCatalogItem {
|
||||
BySeriesCatalogItem(NetworkCatalogItem parent, List<NetworkLibraryItem> children) {
|
||||
super(parent, "bySeries", children);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Comparator<NetworkLibraryItem> getComparator() {
|
||||
return new Comparator<NetworkLibraryItem>() {
|
||||
public int compare(NetworkLibraryItem item0, NetworkLibraryItem item1) {
|
||||
final NetworkBookItem book0 = (NetworkBookItem)item0;
|
||||
final NetworkBookItem book1 = (NetworkBookItem)item1;
|
||||
int diff = book0.SeriesTitle.compareTo(book1.SeriesTitle);
|
||||
if (diff == 0) {
|
||||
diff = book0.IndexInSeries - book1.IndexInSeries;
|
||||
}
|
||||
return diff != 0 ? diff : book0.Title.compareTo(book1.Title);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean accepts(NetworkLibraryItem item) {
|
||||
return
|
||||
item instanceof NetworkBookItem &&
|
||||
((NetworkBookItem)item).SeriesTitle != null;
|
||||
}
|
||||
}
|
||||
|
||||
public class LitResBookshelfItem extends NetworkCatalogItem {
|
||||
private boolean myForceReload;
|
||||
|
||||
|
@ -87,9 +173,13 @@ public class LitResBookshelfItem extends NetworkCatalogItem {
|
|||
listener.onNewItem(Link, item);
|
||||
}
|
||||
} else {
|
||||
listener.onNewItem(Link, new SortedCatalogItem(this, "byDate", children));
|
||||
listener.onNewItem(Link, new SortedCatalogItem(this, "byAuthor", children));
|
||||
listener.onNewItem(Link, new SortedCatalogItem(this, "byTitle", children));
|
||||
listener.onNewItem(Link, new ByDateCatalogItem(this, children));
|
||||
listener.onNewItem(Link, new ByAuthorCatalogItem(this, children));
|
||||
listener.onNewItem(Link, new ByTitleCatalogItem(this, children));
|
||||
final BySeriesCatalogItem bySeries = new BySeriesCatalogItem(this, children);
|
||||
if (!bySeries.isEmpty()) {
|
||||
listener.onNewItem(Link, bySeries);
|
||||
}
|
||||
}
|
||||
listener.commitItems(Link);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue