mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
NetworkCatalogItem.CatalogListener has been added
git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@1144 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
fd9842c49d
commit
593f51fa17
7 changed files with 51 additions and 66 deletions
|
@ -49,10 +49,6 @@ class NetworkCatalogActions extends NetworkTreeActions {
|
|||
public static final int RELOAD_ITEM_ID = 2;
|
||||
//public static final int DONT_SHOW_ITEM_ID = 3;
|
||||
|
||||
|
||||
private static final LinkedList<NetworkTree> ourProcessingTrees = new LinkedList<NetworkTree>();
|
||||
private static final int ourProcessingNotificationId = (int) System.currentTimeMillis();
|
||||
|
||||
private ZLTreeAdapter myAdapter;
|
||||
|
||||
public NetworkCatalogActions(NetworkLibraryActivity activity, ZLTreeAdapter adapter) {
|
||||
|
@ -147,6 +143,9 @@ class NetworkCatalogActions extends NetworkTreeActions {
|
|||
}
|
||||
|
||||
|
||||
private static final LinkedList<NetworkTree> ourProcessingTrees = new LinkedList<NetworkTree>();
|
||||
private static final int ourProcessingNotificationId = (int) System.currentTimeMillis();
|
||||
|
||||
private void updateProgressNotification(NetworkCatalogTree tree) {
|
||||
final RemoteViews contentView = new RemoteViews(myActivity.getPackageName(), R.layout.download_notification);
|
||||
String title = getTitleValue("downloadingCatalogs");
|
||||
|
|
|
@ -65,7 +65,7 @@ public class NetworkBookItem extends NetworkLibraryItem {
|
|||
}
|
||||
}
|
||||
|
||||
public /*final*/ int Index;
|
||||
public final int Index;
|
||||
public final String Id;
|
||||
public final String Language;
|
||||
public final String Date;
|
||||
|
|
|
@ -78,7 +78,38 @@ public abstract class NetworkCatalogItem extends NetworkLibraryItem {
|
|||
CatalogType = catalogType;
|
||||
}
|
||||
|
||||
public abstract String loadChildren(List<NetworkLibraryItem> children); // returns Error Message
|
||||
public interface CatalogListener {
|
||||
void onNewItem(NetworkLibraryItem item);
|
||||
void onStop();
|
||||
}
|
||||
|
||||
public static class OperationData {
|
||||
public final NetworkLink Link;
|
||||
public final CatalogListener Listener;
|
||||
public String ResumeURI;
|
||||
public int ResumeCount;
|
||||
|
||||
public OperationData(NetworkLink link, CatalogListener listener) {
|
||||
Link = link;
|
||||
Listener = listener;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
ResumeURI = null;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract String loadChildren(CatalogListener listener); // returns Error Message
|
||||
|
||||
public final String loadChildren(final List<NetworkLibraryItem> children) {
|
||||
return loadChildren(new CatalogListener() {
|
||||
public void onNewItem(NetworkLibraryItem item) {
|
||||
children.add(item);
|
||||
}
|
||||
public void onStop() {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Method is called each time this item is displayed to the user.
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Mutable class that serves as a buffer stores network operation results.
|
||||
*/
|
||||
public class NetworkOperationData {
|
||||
|
||||
public final NetworkLink Link;
|
||||
public LinkedList<NetworkLibraryItem> Items = new LinkedList<NetworkLibraryItem>();
|
||||
public String ResumeURI;
|
||||
public int ResumeCount;
|
||||
|
||||
public NetworkOperationData(NetworkLink link) {
|
||||
Link = link;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
Items.clear();
|
||||
ResumeURI = null;
|
||||
}
|
||||
}
|
|
@ -30,10 +30,9 @@ import org.geometerplus.fbreader.network.atom.*;
|
|||
class NetworkOPDSFeedReader implements OPDSFeedReader {
|
||||
|
||||
private final String myBaseURL;
|
||||
private final NetworkOperationData myData;
|
||||
private final NetworkCatalogItem.OperationData myData;
|
||||
|
||||
private int myIndex;
|
||||
private int myOpenSearchStartIndex;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -43,7 +42,7 @@ class NetworkOPDSFeedReader implements OPDSFeedReader {
|
|||
* @param result network results buffer. Must be created using OPDSLink corresponding to the OPDS feed,
|
||||
* that will be read using this instance of the reader.
|
||||
*/
|
||||
NetworkOPDSFeedReader(String baseURL, NetworkOperationData result) {
|
||||
NetworkOPDSFeedReader(String baseURL, NetworkCatalogItem.OperationData result) {
|
||||
myBaseURL = baseURL;
|
||||
myData = result;
|
||||
if (!(result.Link instanceof OPDSLink)) {
|
||||
|
@ -72,19 +71,10 @@ class NetworkOPDSFeedReader implements OPDSFeedReader {
|
|||
myData.ResumeURI = href;
|
||||
}
|
||||
}
|
||||
myOpenSearchStartIndex = feed.OpensearchStartIndex - 1;
|
||||
myIndex = feed.OpensearchStartIndex - 1;
|
||||
}
|
||||
|
||||
public void processFeedEnd() {
|
||||
if (myOpenSearchStartIndex > 0) {
|
||||
for (NetworkLibraryItem item: myData.Items) {
|
||||
if (!(item instanceof NetworkBookItem)) {
|
||||
continue;
|
||||
}
|
||||
NetworkBookItem book = (NetworkBookItem) item;
|
||||
book.Index += myOpenSearchStartIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -145,7 +135,8 @@ class NetworkOPDSFeedReader implements OPDSFeedReader {
|
|||
}
|
||||
if (item != null) {
|
||||
//item.dbgEntry = entry;
|
||||
myData.Items.add(item);
|
||||
//myData.Items.add(item);
|
||||
myData.Listener.onNewItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -264,7 +255,7 @@ class NetworkOPDSFeedReader implements OPDSFeedReader {
|
|||
//entry.rights();
|
||||
|
||||
return new NetworkBookItem(
|
||||
myData.Link,
|
||||
opdsLink,
|
||||
entry.Id.Uri,
|
||||
myIndex++,
|
||||
entry.Title,
|
||||
|
|
|
@ -41,8 +41,8 @@ class OPDSCatalogItem extends NetworkCatalogItem {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String loadChildren(List<NetworkLibraryItem> children) {
|
||||
NetworkOperationData data = new NetworkOperationData(Link);
|
||||
public String loadChildren(CatalogListener listener) {
|
||||
OperationData data = new OperationData(Link, listener);
|
||||
|
||||
String urlString = URLByType.get(URL_CATALOG);
|
||||
if (urlString == null) {
|
||||
|
@ -73,7 +73,6 @@ class OPDSCatalogItem extends NetworkCatalogItem {
|
|||
return null; // return error???
|
||||
}
|
||||
|
||||
children.addAll(data.Items);
|
||||
urlString = data.ResumeURI;
|
||||
data.clear();
|
||||
}
|
||||
|
@ -89,6 +88,8 @@ class OPDSCatalogItem extends NetworkCatalogItem {
|
|||
// return error???
|
||||
return null;
|
||||
}
|
||||
} finally {
|
||||
listener.onStop();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -226,6 +226,11 @@ class OPDSXMLReader extends ZLXMLReaderAdapter {
|
|||
myEntry.readAttributes(attributes);
|
||||
mySummaryTagFound = false;
|
||||
myState = F_ENTRY;
|
||||
// Process feed metadata just before first feed entry
|
||||
if (myFeed != null && myFeed.Id != null) {
|
||||
myFeedReader.processFeedMetadata(myFeed);
|
||||
}
|
||||
myFeed = null;
|
||||
}
|
||||
} else if (tagPrefix == myOpenSearchNamespaceId) {
|
||||
if (tag == OPENSEARCH_TAG_TOTALRESULTS) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue