Should never update state by request

This commit is contained in:
tarsin committed 2023-02-14 14:05:58 +08:00
1 parent fe7ad2032b
commit 032563d7a4
2 files changed
+8 -38

No files matched your search

@@ -124,28 +124,14 @@ public class EhPageLoader extends PageLoader2 implements SpiderQueen.OnSpiderLis
@Override
protected void onRequest(int index) {
if (mSpiderQueen != null) {
Object object = mSpiderQueen.request(index);
if (object instanceof Float) {
notifyPagePercent(index, (Float) object);
} else if (object instanceof String error) {
notifyPageFailed(index, error);
} else if (object == null) {
notifyPageWait(index);
}
mSpiderQueen.request(index);
}
}
@Override
protected void onForceRequest(int index) {
if (mSpiderQueen != null) {
Object object = mSpiderQueen.forceRequest(index);
if (object instanceof Float) {
notifyPagePercent(index, (Float) object);
} else if (object instanceof String error) {
notifyPageFailed(index, error);
} else if (object == null) {
notifyPageWait(index);
}
mSpiderQueen.forceRequest(index);
}
}
@@ -356,12 +356,12 @@ public final class SpiderQueen implements Runnable {
}
}
public Object forceRequest(int index) {
return request(index, true);
public void forceRequest(int index) {
request(index, true);
}
public Object request(int index) {
return request(index, false);
public void request(int index) {
request(index, false);
}
private int getPageState(int index) {
@@ -390,14 +390,9 @@ public final class SpiderQueen implements Runnable {
mWorkerScope.updateRAList(pages);
}
/**
* @return String for error<br>
* Float for download percent<br>
* null for wait
*/
private Object request(int index, boolean force) {
private void request(int index, boolean force) {
if (mQueenThread == null) {
return null;
return;
}
// Get page state
@@ -407,20 +402,9 @@ public final class SpiderQueen implements Runnable {
if ((force && (state == STATE_FINISHED || state == STATE_FAILED)) || (state == STATE_FAILED)) {
// Update state to none at once
updatePageState(index, STATE_NONE);
state = STATE_NONE;
}
mWorkerScope.launch(index, force);
Object result;
switch (state) {
case STATE_NONE, STATE_FINISHED -> result = null;
case STATE_DOWNLOADING -> result = mPagePercentMap.get(index);
default -> throw new IllegalStateException("Unexpected value: " + state);
}
return result;
}
public boolean save(int index, @NonNull UniFile file) {