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) {
|
public ItemsLoadingRunnable(ItemsLoadingHandler handler) {
|
||||||
this(handler, 1000, 500);
|
this(handler, 1000, 500);
|
||||||
|
@ -113,9 +107,6 @@ abstract class ItemsLoadingRunnable implements Runnable {
|
||||||
myUpdateTime = now + UpdateInterval;
|
myUpdateTime = now + UpdateInterval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public boolean requestInterrupt() {
|
|
||||||
return isLoadingInterruptRequested() || myItemsNumber >= ItemsLimit;
|
|
||||||
}
|
|
||||||
public boolean confirmInterrupt() {
|
public boolean confirmInterrupt() {
|
||||||
return confirmInterruptLoading() || myItemsNumber >= ItemsLimit;
|
return confirmInterruptLoading() || myItemsNumber >= ItemsLimit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,7 @@ import org.geometerplus.fbreader.network.SearchResult;
|
||||||
|
|
||||||
class SearchItemActions extends NetworkTreeActions {
|
class SearchItemActions extends NetworkTreeActions {
|
||||||
|
|
||||||
public static final int OPEN_RESULTS_ITEM_ID = 0;
|
public static final int RUN_SEARCH_ITEM_ID = 0;
|
||||||
public static final int RUN_SEARCH_ITEM_ID = 2;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,9 +53,8 @@ class SearchItemActions extends NetworkTreeActions {
|
||||||
|
|
||||||
if (!isLoading) {
|
if (!isLoading) {
|
||||||
addMenuItem(menu, RUN_SEARCH_ITEM_ID, "search");
|
addMenuItem(menu, RUN_SEARCH_ITEM_ID, "search");
|
||||||
}
|
} else {
|
||||||
if (isLoading || tree.hasChildren()) {
|
addMenuItem(menu, TREE_NO_ACTION, "stoppingNetworkSearch");
|
||||||
addMenuItem(menu, OPEN_RESULTS_ITEM_ID, "showResults");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,28 +85,10 @@ class SearchItemActions extends NetworkTreeActions {
|
||||||
@Override
|
@Override
|
||||||
public boolean runAction(NetworkBaseActivity activity, NetworkTree tree, int actionCode) {
|
public boolean runAction(NetworkBaseActivity activity, NetworkTree tree, int actionCode) {
|
||||||
switch (actionCode) {
|
switch (actionCode) {
|
||||||
case OPEN_RESULTS_ITEM_ID:
|
|
||||||
doExpandCatalog(activity, (SearchItemTree)tree);
|
|
||||||
return true;
|
|
||||||
case RUN_SEARCH_ITEM_ID:
|
case RUN_SEARCH_ITEM_ID:
|
||||||
activity.onSearchRequested();
|
activity.onSearchRequested();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
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) {
|
public synchronized void onNewItem(NetworkLibraryItem item) {
|
||||||
listener.onNewItem(item);
|
listener.onNewItem(item);
|
||||||
}
|
}
|
||||||
public synchronized boolean requestInterrupt() {
|
|
||||||
return listener.requestInterrupt();
|
|
||||||
}
|
|
||||||
public synchronized boolean confirmInterrupt() {
|
public synchronized boolean confirmInterrupt() {
|
||||||
return listener.confirmInterrupt();
|
return listener.confirmInterrupt();
|
||||||
}
|
}
|
||||||
|
@ -444,6 +441,9 @@ public class NetworkLibrary {
|
||||||
|
|
||||||
requestList.clear();
|
requestList.clear();
|
||||||
|
|
||||||
|
if (listener.confirmInterrupt()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
for (NetworkOperationData data: dataList) {
|
for (NetworkOperationData data: dataList) {
|
||||||
ZLNetworkRequest request = data.resume();
|
ZLNetworkRequest request = data.resume();
|
||||||
if (request != null) {
|
if (request != null) {
|
||||||
|
|
|
@ -28,7 +28,6 @@ public class NetworkOperationData {
|
||||||
void onNewItem(NetworkLibraryItem item);
|
void onNewItem(NetworkLibraryItem item);
|
||||||
|
|
||||||
// return true to confirm interrupt reading; return false to continue reading
|
// return true to confirm interrupt reading; return false to continue reading
|
||||||
boolean requestInterrupt();
|
|
||||||
boolean confirmInterrupt();
|
boolean confirmInterrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -132,19 +132,9 @@ class NetworkOPDSFeedReader implements OPDSFeedReader {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean tryInterrupt() {
|
private boolean tryInterrupt() {
|
||||||
if (myData.Listener.requestInterrupt()) {
|
final int noninterruptableRemainder = 10;
|
||||||
myData.Interrupt = true;
|
return (myItemsToLoad < 0 || myItemsToLoad > noninterruptableRemainder)
|
||||||
|
&& myData.Listener.confirmInterrupt();
|
||||||
final int noninterruptableRemainder = 10;
|
|
||||||
if (myItemsToLoad < 0 || myItemsToLoad > noninterruptableRemainder) {
|
|
||||||
if (myData.Listener.confirmInterrupt()) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
myData.Interrupt = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean processFeedEntry(OPDSEntry entry) {
|
public boolean processFeedEntry(OPDSEntry entry) {
|
||||||
|
|
|
@ -32,17 +32,10 @@ class OPDSCatalogItem extends NetworkCatalogItem {
|
||||||
static class State extends NetworkOperationData {
|
static class State extends NetworkOperationData {
|
||||||
|
|
||||||
public String LastLoadedTitle;
|
public String LastLoadedTitle;
|
||||||
public boolean Interrupt;
|
|
||||||
|
|
||||||
public State(INetworkLink link, OnNewItemListener listener) {
|
public State(INetworkLink link, OnNewItemListener listener) {
|
||||||
super(link, listener);
|
super(link, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clear() {
|
|
||||||
super.clear();
|
|
||||||
Interrupt = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
private State myLoadingState;
|
private State myLoadingState;
|
||||||
|
|
||||||
|
@ -66,16 +59,8 @@ class OPDSCatalogItem extends NetworkCatalogItem {
|
||||||
myLoadingState = null;
|
myLoadingState = null;
|
||||||
return errorMessage;
|
return errorMessage;
|
||||||
}
|
}
|
||||||
if (myLoadingState.Interrupt) {
|
if (listener.confirmInterrupt()) {
|
||||||
if (myLoadingState.LastLoadedTitle == null) {
|
return 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();
|
networkRequest = myLoadingState.resume();
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,6 +85,9 @@ class OPDSLink extends AbstractNetworkLink {
|
||||||
return new ZLNetworkRequest(url) {
|
return new ZLNetworkRequest(url) {
|
||||||
@Override
|
@Override
|
||||||
public String handleStream(URLConnection connection, InputStream inputStream) throws IOException {
|
public String handleStream(URLConnection connection, InputStream inputStream) throws IOException {
|
||||||
|
if (result.Listener.confirmInterrupt()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
new OPDSXMLReader(
|
new OPDSXMLReader(
|
||||||
new NetworkOPDSFeedReader(URL, result)
|
new NetworkOPDSFeedReader(URL, result)
|
||||||
).read(inputStream);
|
).read(inputStream);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue