mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-05 10:49:24 +02:00
Catalog loading changes
git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@1614 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
c363a06058
commit
06b2ffc2bc
7 changed files with 14 additions and 66 deletions
|
@ -72,12 +72,6 @@ abstract class ItemsLoadingRunnable implements Runnable {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean isLoadingInterruptRequested() {
|
||||
synchronized (myInterruptLock) {
|
||||
return myInterruptRequested;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public ItemsLoadingRunnable(ItemsLoadingHandler handler) {
|
||||
this(handler, 1000, 500);
|
||||
|
@ -113,9 +107,6 @@ abstract class ItemsLoadingRunnable implements Runnable {
|
|||
myUpdateTime = now + UpdateInterval;
|
||||
}
|
||||
}
|
||||
public boolean requestInterrupt() {
|
||||
return isLoadingInterruptRequested() || myItemsNumber >= ItemsLimit;
|
||||
}
|
||||
public boolean confirmInterrupt() {
|
||||
return confirmInterruptLoading() || myItemsNumber >= ItemsLimit;
|
||||
}
|
||||
|
|
|
@ -28,8 +28,7 @@ import org.geometerplus.fbreader.network.SearchResult;
|
|||
|
||||
class SearchItemActions extends NetworkTreeActions {
|
||||
|
||||
public static final int OPEN_RESULTS_ITEM_ID = 0;
|
||||
public static final int RUN_SEARCH_ITEM_ID = 2;
|
||||
public static final int RUN_SEARCH_ITEM_ID = 0;
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -54,9 +53,8 @@ class SearchItemActions extends NetworkTreeActions {
|
|||
|
||||
if (!isLoading) {
|
||||
addMenuItem(menu, RUN_SEARCH_ITEM_ID, "search");
|
||||
}
|
||||
if (isLoading || tree.hasChildren()) {
|
||||
addMenuItem(menu, OPEN_RESULTS_ITEM_ID, "showResults");
|
||||
} else {
|
||||
addMenuItem(menu, TREE_NO_ACTION, "stoppingNetworkSearch");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,28 +85,10 @@ class SearchItemActions extends NetworkTreeActions {
|
|||
@Override
|
||||
public boolean runAction(NetworkBaseActivity activity, NetworkTree tree, int actionCode) {
|
||||
switch (actionCode) {
|
||||
case OPEN_RESULTS_ITEM_ID:
|
||||
doExpandCatalog(activity, (SearchItemTree)tree);
|
||||
return true;
|
||||
case RUN_SEARCH_ITEM_ID:
|
||||
activity.onSearchRequested();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void doExpandCatalog(final NetworkBaseActivity activity, final SearchItemTree tree) {
|
||||
if (!NetworkView.Instance().isInitialized()) {
|
||||
return;
|
||||
}
|
||||
NetworkView.Instance().tryResumeLoading(activity, tree, NetworkSearchActivity.SEARCH_RUNNABLE_KEY, new Runnable() {
|
||||
public void run() {
|
||||
final boolean isLoading = NetworkView.Instance().containsItemsLoadingRunnable(NetworkSearchActivity.SEARCH_RUNNABLE_KEY);
|
||||
if (isLoading || tree.hasChildren()) {
|
||||
NetworkView.Instance().openTree(activity, tree, NetworkSearchActivity.SEARCH_RUNNABLE_KEY);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -414,9 +414,6 @@ public class NetworkLibrary {
|
|||
public synchronized void onNewItem(NetworkLibraryItem item) {
|
||||
listener.onNewItem(item);
|
||||
}
|
||||
public synchronized boolean requestInterrupt() {
|
||||
return listener.requestInterrupt();
|
||||
}
|
||||
public synchronized boolean confirmInterrupt() {
|
||||
return listener.confirmInterrupt();
|
||||
}
|
||||
|
@ -444,6 +441,9 @@ public class NetworkLibrary {
|
|||
|
||||
requestList.clear();
|
||||
|
||||
if (listener.confirmInterrupt()) {
|
||||
return null;
|
||||
}
|
||||
for (NetworkOperationData data: dataList) {
|
||||
ZLNetworkRequest request = data.resume();
|
||||
if (request != null) {
|
||||
|
|
|
@ -28,7 +28,6 @@ public class NetworkOperationData {
|
|||
void onNewItem(NetworkLibraryItem item);
|
||||
|
||||
// return true to confirm interrupt reading; return false to continue reading
|
||||
boolean requestInterrupt();
|
||||
boolean confirmInterrupt();
|
||||
}
|
||||
|
||||
|
|
|
@ -132,19 +132,9 @@ class NetworkOPDSFeedReader implements OPDSFeedReader {
|
|||
}
|
||||
|
||||
private boolean tryInterrupt() {
|
||||
if (myData.Listener.requestInterrupt()) {
|
||||
myData.Interrupt = true;
|
||||
|
||||
final int noninterruptableRemainder = 10;
|
||||
if (myItemsToLoad < 0 || myItemsToLoad > noninterruptableRemainder) {
|
||||
if (myData.Listener.confirmInterrupt()) {
|
||||
return true;
|
||||
} else {
|
||||
myData.Interrupt = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return (myItemsToLoad < 0 || myItemsToLoad > noninterruptableRemainder)
|
||||
&& myData.Listener.confirmInterrupt();
|
||||
}
|
||||
|
||||
public boolean processFeedEntry(OPDSEntry entry) {
|
||||
|
|
|
@ -32,17 +32,10 @@ class OPDSCatalogItem extends NetworkCatalogItem {
|
|||
static class State extends NetworkOperationData {
|
||||
|
||||
public String LastLoadedTitle;
|
||||
public boolean Interrupt;
|
||||
|
||||
public State(INetworkLink link, OnNewItemListener listener) {
|
||||
super(link, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
super.clear();
|
||||
Interrupt = false;
|
||||
}
|
||||
}
|
||||
private State myLoadingState;
|
||||
|
||||
|
@ -66,17 +59,9 @@ class OPDSCatalogItem extends NetworkCatalogItem {
|
|||
myLoadingState = null;
|
||||
return errorMessage;
|
||||
}
|
||||
if (myLoadingState.Interrupt) {
|
||||
if (myLoadingState.LastLoadedTitle == null) {
|
||||
// In this case Catalog loading was not interrupted, and
|
||||
// we must confirm interruption here.
|
||||
if (listener.confirmInterrupt()) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
networkRequest = myLoadingState.resume();
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -85,6 +85,9 @@ class OPDSLink extends AbstractNetworkLink {
|
|||
return new ZLNetworkRequest(url) {
|
||||
@Override
|
||||
public String handleStream(URLConnection connection, InputStream inputStream) throws IOException {
|
||||
if (result.Listener.confirmInterrupt()) {
|
||||
return null;
|
||||
}
|
||||
new OPDSXMLReader(
|
||||
new NetworkOPDSFeedReader(URL, result)
|
||||
).read(inputStream);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue