Add delay after download to reduce download speed
This commit is contained in:
1 parent
73440b3abb
commit
c111ec85cf
7 files changed
+53
-1
No files matched your search
@@ -257,6 +257,8 @@ public class Settings {
|
||||
private static final boolean DEFAULT_GUIDE_GALLERY = true;
|
||||
private static final String KEY_CLIPBOARD_TEXT_HASH_CODE = "clipboard_text_hash_code";
|
||||
private static final int DEFAULT_CLIPBOARD_TEXT_HASH_CODE = 0;
|
||||
private static final String KEY_DOWNLOAD_DELAY = "download_delay";
|
||||
private static final int DEFAULT_DOWNLOAD_DELAY = 0;
|
||||
private static Context sContext;
|
||||
private static SharedPreferences sSettingsPre;
|
||||
private static EhConfig sEhConfig;
|
||||
@@ -740,6 +742,14 @@ public class Settings {
|
||||
putIntToStr(KEY_MULTI_THREAD_DOWNLOAD, value);
|
||||
}
|
||||
|
||||
public static int getDownloadDelay() {
|
||||
return getIntFromStr(KEY_DOWNLOAD_DELAY, DEFAULT_DOWNLOAD_DELAY);
|
||||
}
|
||||
|
||||
public static void putDownloadDelay(int value) {
|
||||
putIntToStr(KEY_DOWNLOAD_DELAY, value);
|
||||
}
|
||||
|
||||
public static int getPreloadImage() {
|
||||
return getIntFromStr(KEY_PRELOAD_IMAGE, DEFAULT_PRELOAD_IMAGE);
|
||||
}
|
||||
|
||||
@@ -143,6 +143,7 @@ public final class SpiderQueen implements Runnable {
|
||||
private final int mPreloadNumber;
|
||||
private int mReadReference = 0;
|
||||
private int mDownloadReference = 0;
|
||||
private final int mDownloadDelay;
|
||||
// It mQueenThread is null, failed or stopped
|
||||
@Nullable
|
||||
private volatile Thread mQueenThread;
|
||||
@@ -169,6 +170,7 @@ public final class SpiderQueen implements Runnable {
|
||||
mWorkerPoolExecutor = new ThreadPoolExecutor(mWorkerMaxCount, mWorkerMaxCount,
|
||||
0, TimeUnit.SECONDS, new LinkedBlockingDeque<>(),
|
||||
new PriorityThreadFactory(SpiderWorker.class.getSimpleName(), Process.THREAD_PRIORITY_BACKGROUND));
|
||||
mDownloadDelay = Settings.getDownloadDelay();
|
||||
}
|
||||
|
||||
@UiThread
|
||||
@@ -1349,6 +1351,11 @@ public final class SpiderQueen implements Runnable {
|
||||
|
||||
// Download finished
|
||||
updatePageState(index, STATE_FINISHED);
|
||||
try {
|
||||
Thread.sleep(mDownloadDelay);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
Reference in new issue
Block a user