Add delay after download to reduce download speed

This commit is contained in:
Epix authored and NekoInverter committed 2020-07-20 20:15:31 +08:00
1 parent 73440b3abb
commit c111ec85cf
7 files changed
+53 -1

No files matched your search

+1 -1
View File
@@ -27,7 +27,7 @@ android {
applicationId "com.hippo.ehviewer"
minSdkVersion 21
targetSdkVersion 30
versionCode 107
versionCode 108
versionName "1.7.6"
resConfigs "zh", "zh-rCN", "zh-rHK", "zh-rTW",
"es", "ja", "ko", "fr", "de", "th"
@@ -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();
@@ -716,4 +716,6 @@
<string name="download_filter">过滤</string>
<string name="download_all">全部</string>
<string name="download_start_all_reversed">全部开始(倒序)</string>
<string name="settings_download_download_delay">下载延时</string>
<string name="settings_download_download_delay_summary">每次下载延时 %s 毫秒</string>
</resources>
+22
View File
@@ -115,6 +115,28 @@
<item>7</item>
</string-array>
<string-array name="download_delay_entries" translatable="false">
<item>0</item>
<item>500</item>
<item>1000</item>
<item>1500</item>
<item>2000</item>
<item>3000</item>
<item>10000</item>
<item>20000</item>
</string-array>
<string-array name="download_delay_entry_values" translatable="false">
<item>0</item>
<item>500</item>
<item>1000</item>
<item>1500</item>
<item>2000</item>
<item>3000</item>
<item>10000</item>
<item>20000</item>
</string-array>
<string-array name="preload_image_entries" translatable="false">
<item>3</item>
<item>5</item>
+2
View File
@@ -554,6 +554,8 @@
<string name="settings_download_media_scan_summary_off">Most gallery apps will ignore pictures in the download path</string>
<string name="settings_download_multi_thread_download">Multi-threaded download</string>
<string name="settings_download_multi_thread_download_summary">Up to %s images</string>
<string name="settings_download_download_delay">Download delay</string>
<string name="settings_download_download_delay_summary">Delay %s ms per download</string>
<string name="settings_download_preload_image">Preload image</string>
<string name="settings_download_preload_image_summary">Preload next %s image</string>
<string name="settings_download_image_resolution">Image resolution</string>
@@ -39,6 +39,15 @@
app:entryValues="@array/multi_thread_download_entry_values"
app:iconSpaceReserved="false" />
<SimpleMenuPreference
android:key="download_delay"
android:title="@string/settings_download_download_delay"
android:summary="@string/settings_download_download_delay_summary"
app:entries="@array/download_delay_entries"
app:entryValues="@array/download_delay_entry_values"
android:defaultValue="0"
app:iconSpaceReserved="false" />
<SimpleMenuPreference
android:defaultValue="5"
android:key="preload_image"