Add multi-thread-download setting and preload-image setting
This commit is contained in:
1 parent
60351a5f1c
commit
b6a6863f6c
8 files changed
+96
-6
No files matched your search
@@ -362,6 +362,28 @@ public class Settings {
|
||||
putString(KEY_DEFAULT_DOWNLOAD_LABEL, value);
|
||||
}
|
||||
|
||||
private static final String KEY_MULTI_THREAD_DOWNLOAD = "download_thread";
|
||||
private static final int DEFAULT_MULTI_THREAD_DOWNLOAD = 3;
|
||||
|
||||
public static int getMultiThreadDownload() {
|
||||
return getIntFromStr(KEY_MULTI_THREAD_DOWNLOAD, DEFAULT_MULTI_THREAD_DOWNLOAD);
|
||||
}
|
||||
|
||||
public static void putMultiThreadDownload(int value) {
|
||||
putIntToStr(KEY_MULTI_THREAD_DOWNLOAD, value);
|
||||
}
|
||||
|
||||
private static final String KEY_PRELOAD_IMAGE = "preload_image";
|
||||
private static final int DEFAULT_PRELOAD_IMAGE = 5;
|
||||
|
||||
public static int getPreloadImage() {
|
||||
return getIntFromStr(KEY_PRELOAD_IMAGE, DEFAULT_PRELOAD_IMAGE);
|
||||
}
|
||||
|
||||
public static void putPreloadImage(int value) {
|
||||
putIntToStr(KEY_PRELOAD_IMAGE, value);
|
||||
}
|
||||
|
||||
/********************
|
||||
****** Favorites
|
||||
********************/
|
||||
|
||||
@@ -100,9 +100,6 @@ public class SpiderQueen implements Runnable {
|
||||
public static final int STATE_FINISHED = 2;
|
||||
public static final int STATE_FAILED = 3;
|
||||
|
||||
private static final int NUMBER_SPIDER_WORKER = 3;
|
||||
private static final int NUMBER_PRELOAD = 5;
|
||||
|
||||
public static final String SPIDER_INFO_FILENAME = ".ehviewer";
|
||||
|
||||
private static final String[] URL_509_SUFFIX_ARRAY = {
|
||||
@@ -169,11 +166,17 @@ public class SpiderQueen implements Runnable {
|
||||
|
||||
private final List<OnSpiderListener> mSpiderListeners = new ArrayList<>();
|
||||
|
||||
private final int mSpiderWorkerNumber;
|
||||
private final int mPreloadNumber;
|
||||
|
||||
private SpiderQueen(EhApplication application, @NonNull GalleryInfo galleryInfo) {
|
||||
mHttpClient = EhApplication.getOkHttpClient(application);
|
||||
mSpiderInfoCache = EhApplication.getSpiderInfoCache(application);
|
||||
mGalleryInfo = galleryInfo;
|
||||
mSpiderDen = new SpiderDen(mGalleryInfo);
|
||||
|
||||
mSpiderWorkerNumber = Settings.getMultiThreadDownload();
|
||||
mPreloadNumber = Settings.getPreloadImage();
|
||||
}
|
||||
|
||||
public void addOnSpiderListener(OnSpiderListener listener) {
|
||||
@@ -494,7 +497,7 @@ public class SpiderQueen implements Runnable {
|
||||
} else {
|
||||
size = Integer.MAX_VALUE;
|
||||
}
|
||||
for (int i = index + 1, n = index + i + NUMBER_PRELOAD; i < n && i < size; i++) {
|
||||
for (int i = index + 1, n = index + i + mPreloadNumber; i < n && i < size; i++) {
|
||||
if (STATE_NONE == getPageState(i)) {
|
||||
mRequestPageQueue2.add(i);
|
||||
}
|
||||
@@ -538,7 +541,7 @@ public class SpiderQueen implements Runnable {
|
||||
private void ensureWorkers() {
|
||||
synchronized (mWorkerLock) {
|
||||
if (mWorkers == null) {
|
||||
mWorkers = new Thread[NUMBER_SPIDER_WORKER];
|
||||
mWorkers = new Thread[mSpiderWorkerNumber];
|
||||
}
|
||||
|
||||
for (int i = 0, n = mWorkers.length; i < n; i++) {
|
||||
|
||||
Reference in new issue
Block a user