Minor cleanup
This commit is contained in:
1 parent
e5ce3450e8
commit
1073ed6c24
3 files changed
+14
-27
No files matched your search
@@ -183,11 +183,7 @@ public class EhPageLoader extends PageLoader2 implements SpiderQueen.OnSpiderLis
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageSuccess(int index, int finished, int downloaded, int total) {
|
||||
if (mSpiderQueen != null) {
|
||||
mSpiderQueen.request(index);
|
||||
}
|
||||
}
|
||||
public void onPageSuccess(int index, int finished, int downloaded, int total) {}
|
||||
|
||||
@Override
|
||||
public void onPageFailure(int index, String error, int finished, int downloaded, int total) {
|
||||
|
||||
@@ -357,11 +357,11 @@ public final class SpiderQueen implements Runnable {
|
||||
}
|
||||
|
||||
public Object forceRequest(int index) {
|
||||
return request(index, true, true);
|
||||
return request(index, true);
|
||||
}
|
||||
|
||||
public Object request(int index) {
|
||||
return request(index, true, false);
|
||||
return request(index, false);
|
||||
}
|
||||
|
||||
private int getPageState(int index) {
|
||||
@@ -395,7 +395,7 @@ public final class SpiderQueen implements Runnable {
|
||||
* Float for download percent<br>
|
||||
* null for wait
|
||||
*/
|
||||
private Object request(int index, boolean ignoreError, boolean force) {
|
||||
private Object request(int index, boolean force) {
|
||||
if (mQueenThread == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -404,8 +404,7 @@ public final class SpiderQueen implements Runnable {
|
||||
int state = getPageState(index);
|
||||
|
||||
// Fix state for force
|
||||
if ((force && (state == STATE_FINISHED || state == STATE_FAILED)) ||
|
||||
(ignoreError && state == STATE_FAILED)) {
|
||||
if ((force && (state == STATE_FINISHED || state == STATE_FAILED)) || (state == STATE_FAILED)) {
|
||||
// Update state to none at once
|
||||
updatePageState(index, STATE_NONE);
|
||||
state = STATE_NONE;
|
||||
@@ -418,13 +417,6 @@ public final class SpiderQueen implements Runnable {
|
||||
switch (state) {
|
||||
case STATE_NONE, STATE_FINISHED -> result = null;
|
||||
case STATE_DOWNLOADING -> result = mPagePercentMap.get(index);
|
||||
case STATE_FAILED -> {
|
||||
String error = mPageErrorMap.get(index);
|
||||
if (error == null) {
|
||||
error = GetText.getString(R.string.error_unknown);
|
||||
}
|
||||
result = error;
|
||||
}
|
||||
default -> throw new IllegalStateException("Unexpected value: " + state);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,21 +73,15 @@ class SpiderQueenWorker(private val queen: SpiderQueen) : CoroutineScope {
|
||||
}.toSet().forEach { mJobMap.remove(it) }
|
||||
list.forEach {
|
||||
if (mJobMap[it]?.isActive != true)
|
||||
launch(it, false, downloadOnly = true)
|
||||
doLaunchDownloadJob(it, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun launch(index: Int, force: Boolean = false, downloadOnly: Boolean = false) {
|
||||
check(index in 0 until size)
|
||||
private fun doLaunchDownloadJob(index: Int, force: Boolean) {
|
||||
val state = queen.mPageStateArray[index]
|
||||
if (!force && state == STATE_FINISHED) {
|
||||
decoder.launch(index)
|
||||
return
|
||||
}
|
||||
|
||||
if (!downloadOnly) synchronized(mJobMap) {
|
||||
if (!force && state == STATE_FINISHED) return
|
||||
synchronized(mJobMap) {
|
||||
val currentJob = mJobMap[index]
|
||||
if (force) currentJob?.cancel()
|
||||
if (currentJob?.isActive != true) {
|
||||
@@ -98,7 +92,12 @@ class SpiderQueenWorker(private val queen: SpiderQueen) : CoroutineScope {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun launch(index: Int, force: Boolean = false) {
|
||||
check(index in 0 until size)
|
||||
if (!isDownloadMode) doLaunchDownloadJob(index, force)
|
||||
decoder.launch(index)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user