Auto close response to avoid resource leak
This commit is contained in:
1 parent
a677d95d34
commit
3d256a402f
4 files changed
+119
-173
No files matched your search
@@ -164,12 +164,13 @@ class EhApplication : SceneApplication() {
|
||||
val request = EhRequestBuilder(EhUrl.HOST_E + "news.php", referer).build()
|
||||
val call = okHttpClient.newCall(request)
|
||||
try {
|
||||
val response = call.execute()
|
||||
val responseBody = response.body
|
||||
val body = responseBody.string()
|
||||
val html = EventPaneParser.parse(body)
|
||||
if (html != null) {
|
||||
showEventPane(html)
|
||||
call.execute().use { response ->
|
||||
val responseBody = response.body
|
||||
val body = responseBody.string()
|
||||
val html = EventPaneParser.parse(body)
|
||||
if (html != null) {
|
||||
showEventPane(html)
|
||||
}
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
e.printStackTrace()
|
||||
@@ -180,7 +181,7 @@ class EhApplication : SceneApplication() {
|
||||
|
||||
fun showEventPane(html: String) {
|
||||
if (Settings.getHideHvEvents() && html.contains("You have encountered a monster!")) {
|
||||
return;
|
||||
return
|
||||
}
|
||||
val activity = topActivity
|
||||
activity?.runOnUiThread {
|
||||
@@ -272,7 +273,7 @@ class EhApplication : SceneApplication() {
|
||||
val ehCookieStore by lazy { EhCookieStore(application) }
|
||||
|
||||
@JvmStatic
|
||||
val ehClient by lazy { EhClient(application) }
|
||||
val ehClient by lazy { EhClient() }
|
||||
|
||||
@JvmStatic
|
||||
val ehProxySelector by lazy { EhProxySelector() }
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.hippo.ehviewer.client;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
@@ -57,16 +56,16 @@ public class EhClient {
|
||||
public static final int METHOD_VOTE_TAG = 19;
|
||||
|
||||
private final ThreadPoolExecutor mRequestThreadPool;
|
||||
private final OkHttpClient mOkHttpClient;
|
||||
private static final OkHttpClient mOkHttpClient = EhApplication.getOkHttpClient();
|
||||
|
||||
public EhClient(Context context) {
|
||||
public EhClient() {
|
||||
mRequestThreadPool = IoThreadPoolExecutor.getInstance();
|
||||
mOkHttpClient = EhApplication.getOkHttpClient();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void execute(EhRequest request) {
|
||||
if (!request.isCancelled()) {
|
||||
Task task = new Task(request.getMethod(), request.getCallback(), request.getEhConfig());
|
||||
Task task = new Task(request.getMethod(), request.getCallback());
|
||||
task.executeOnExecutor(mRequestThreadPool, request.getArgs());
|
||||
request.task = task;
|
||||
} else {
|
||||
@@ -83,18 +82,17 @@ public class EhClient {
|
||||
void onCancel();
|
||||
}
|
||||
|
||||
public class Task extends AsyncTask<Object, Void, Object> {
|
||||
@SuppressWarnings("deprecation")
|
||||
public static class Task extends AsyncTask<Object, Void, Object> {
|
||||
|
||||
private final int mMethod;
|
||||
private final AtomicReference<Call> mCall = new AtomicReference<>();
|
||||
private final AtomicBoolean mStop = new AtomicBoolean();
|
||||
private Callback mCallback;
|
||||
private EhConfig mEhConfig;
|
||||
private Callback<Object> mCallback;
|
||||
|
||||
public Task(int method, Callback callback, EhConfig ehConfig) {
|
||||
public Task(int method, Callback<Object> callback) {
|
||||
mMethod = method;
|
||||
mCallback = callback;
|
||||
mEhConfig = ehConfig;
|
||||
}
|
||||
|
||||
// Called in Job thread
|
||||
@@ -107,10 +105,6 @@ public class EhClient {
|
||||
}
|
||||
}
|
||||
|
||||
public EhConfig getEhConfig() {
|
||||
return mEhConfig;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (!mStop.get()) {
|
||||
mStop.lazySet(true);
|
||||
@@ -133,7 +127,6 @@ public class EhClient {
|
||||
|
||||
// Clear
|
||||
mCallback = null;
|
||||
mEhConfig = null;
|
||||
mCall.lazySet(null);
|
||||
}
|
||||
}
|
||||
@@ -141,53 +134,50 @@ public class EhClient {
|
||||
@Override
|
||||
protected Object doInBackground(Object... params) {
|
||||
try {
|
||||
switch (mMethod) {
|
||||
case METHOD_SIGN_IN:
|
||||
return EhEngine.signIn(this, mOkHttpClient, (String) params[0], (String) params[1]);
|
||||
case METHOD_GET_GALLERY_LIST:
|
||||
return EhEngine.getGalleryList(this, mOkHttpClient, (String) params[0]);
|
||||
case METHOD_GET_GALLERY_DETAIL:
|
||||
return EhEngine.getGalleryDetail(this, mOkHttpClient, (String) params[0]);
|
||||
case METHOD_GET_PREVIEW_SET:
|
||||
return EhEngine.getPreviewSet(this, mOkHttpClient, (String) params[0]);
|
||||
case METHOD_GET_RATE_GALLERY:
|
||||
return EhEngine.rateGallery(this, mOkHttpClient, (Long) params[0], (String) params[1], (Long) params[2], (String) params[3], (Float) params[4]);
|
||||
case METHOD_GET_COMMENT_GALLERY:
|
||||
return EhEngine.commentGallery(this, mOkHttpClient, (String) params[0], (String) params[1], (String) params[2]);
|
||||
case METHOD_GET_GALLERY_TOKEN:
|
||||
return EhEngine.getGalleryToken(this, mOkHttpClient, (Long) params[0], (String) params[1], (Integer) params[2]);
|
||||
case METHOD_GET_FAVORITES:
|
||||
return EhEngine.getFavorites(this, mOkHttpClient, (String) params[0], (Boolean) params[1]);
|
||||
case METHOD_ADD_FAVORITES:
|
||||
return EhEngine.addFavorites(this, mOkHttpClient, (Long) params[0], (String) params[1], (Integer) params[2], (String) params[3]);
|
||||
case METHOD_ADD_FAVORITES_RANGE:
|
||||
return EhEngine.addFavoritesRange(this, mOkHttpClient, (long[]) params[0], (String[]) params[1], (Integer) params[2]);
|
||||
case METHOD_MODIFY_FAVORITES:
|
||||
return EhEngine.modifyFavorites(this, mOkHttpClient, (String) params[0], (long[]) params[1], (Integer) params[2], (Boolean) params[3]);
|
||||
case METHOD_GET_TORRENT_LIST:
|
||||
return EhEngine.getTorrentList(this, mOkHttpClient, (String) params[0], (Long) params[1], (String) params[2]);
|
||||
case METHOD_GET_PROFILE:
|
||||
return EhEngine.getProfile(this, mOkHttpClient);
|
||||
case METHOD_VOTE_COMMENT:
|
||||
return EhEngine.voteComment(this, mOkHttpClient, (Long) params[0], (String) params[1], (Long) params[2], (String) params[3], (Long) params[4], (Integer) params[5]);
|
||||
case METHOD_IMAGE_SEARCH:
|
||||
return EhEngine.imageSearch(this, mOkHttpClient, (File) params[0], (Boolean) params[1], (Boolean) params[2], (Boolean) params[3]);
|
||||
case METHOD_ARCHIVE_LIST:
|
||||
return EhEngine.getArchiveList(this, mOkHttpClient, (String) params[0], (Long) params[1], (String) params[2]);
|
||||
case METHOD_DOWNLOAD_ARCHIVE:
|
||||
return EhEngine.downloadArchive(this, mOkHttpClient, (Long) params[0], (String) params[1], (String) params[2], (String) params[3]);
|
||||
case METHOD_VOTE_TAG:
|
||||
return EhEngine.voteTag(this, mOkHttpClient, (Long) params[0], (String) params[1], (Long) params[2], (String) params[3], (String) params[4], (Integer) params[5]);
|
||||
default:
|
||||
return new IllegalStateException("Can't detect method " + mMethod);
|
||||
}
|
||||
return switch (mMethod) {
|
||||
case METHOD_SIGN_IN ->
|
||||
EhEngine.signIn(this, mOkHttpClient, (String) params[0], (String) params[1]);
|
||||
case METHOD_GET_GALLERY_LIST ->
|
||||
EhEngine.getGalleryList(this, mOkHttpClient, (String) params[0]);
|
||||
case METHOD_GET_GALLERY_DETAIL ->
|
||||
EhEngine.getGalleryDetail(this, mOkHttpClient, (String) params[0]);
|
||||
case METHOD_GET_PREVIEW_SET ->
|
||||
EhEngine.getPreviewSet(this, mOkHttpClient, (String) params[0]);
|
||||
case METHOD_GET_RATE_GALLERY ->
|
||||
EhEngine.rateGallery(this, mOkHttpClient, (Long) params[0], (String) params[1], (Long) params[2], (String) params[3], (Float) params[4]);
|
||||
case METHOD_GET_COMMENT_GALLERY ->
|
||||
EhEngine.commentGallery(this, mOkHttpClient, (String) params[0], (String) params[1], (String) params[2]);
|
||||
case METHOD_GET_GALLERY_TOKEN ->
|
||||
EhEngine.getGalleryToken(this, mOkHttpClient, (Long) params[0], (String) params[1], (Integer) params[2]);
|
||||
case METHOD_GET_FAVORITES ->
|
||||
EhEngine.getFavorites(this, mOkHttpClient, (String) params[0]);
|
||||
case METHOD_ADD_FAVORITES ->
|
||||
EhEngine.addFavorites(this, mOkHttpClient, (Long) params[0], (String) params[1], (Integer) params[2], (String) params[3]);
|
||||
case METHOD_ADD_FAVORITES_RANGE ->
|
||||
EhEngine.addFavoritesRange(this, mOkHttpClient, (long[]) params[0], (String[]) params[1], (Integer) params[2]);
|
||||
case METHOD_MODIFY_FAVORITES ->
|
||||
EhEngine.modifyFavorites(this, mOkHttpClient, (String) params[0], (long[]) params[1], (Integer) params[2]);
|
||||
case METHOD_GET_TORRENT_LIST ->
|
||||
EhEngine.getTorrentList(this, mOkHttpClient, (String) params[0], (Long) params[1], (String) params[2]);
|
||||
case METHOD_GET_PROFILE -> EhEngine.getProfile(this, mOkHttpClient);
|
||||
case METHOD_VOTE_COMMENT ->
|
||||
EhEngine.voteComment(this, mOkHttpClient, (Long) params[0], (String) params[1], (Long) params[2], (String) params[3], (Long) params[4], (Integer) params[5]);
|
||||
case METHOD_IMAGE_SEARCH ->
|
||||
EhEngine.imageSearch(this, mOkHttpClient, (File) params[0], (Boolean) params[1], (Boolean) params[2], (Boolean) params[3]);
|
||||
case METHOD_ARCHIVE_LIST ->
|
||||
EhEngine.getArchiveList(this, mOkHttpClient, (String) params[0], (Long) params[1], (String) params[2]);
|
||||
case METHOD_DOWNLOAD_ARCHIVE ->
|
||||
EhEngine.downloadArchive(this, mOkHttpClient, (Long) params[0], (String) params[1], (String) params[2], (String) params[3]);
|
||||
case METHOD_VOTE_TAG ->
|
||||
EhEngine.voteTag(this, mOkHttpClient, (Long) params[0], (String) params[1], (Long) params[2], (String) params[3], (String) params[4], (Integer) params[5]);
|
||||
default -> new IllegalStateException("Can't detect method " + mMethod);
|
||||
};
|
||||
} catch (Throwable e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void onPostExecute(Object result) {
|
||||
if (mCallback != null) {
|
||||
@@ -205,7 +195,6 @@ public class EhClient {
|
||||
|
||||
// Clear
|
||||
mCallback = null;
|
||||
mEhConfig = null;
|
||||
mCall.lazySet(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,8 +185,7 @@ public class EhEngine {
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
@@ -263,8 +262,7 @@ public class EhEngine {
|
||||
Headers headers = null;
|
||||
GalleryListParser.Result result;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
@@ -326,8 +324,7 @@ public class EhEngine {
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
@@ -354,8 +351,7 @@ public class EhEngine {
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
@@ -387,8 +383,7 @@ public class EhEngine {
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
@@ -429,8 +424,7 @@ public class EhEngine {
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
@@ -466,8 +460,7 @@ public class EhEngine {
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
@@ -510,8 +503,7 @@ public class EhEngine {
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
@@ -524,7 +516,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static FavoritesParser.Result getFavorites(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url, boolean callApi) throws Throwable {
|
||||
String url) throws Throwable {
|
||||
String referer = EhUrl.getReferer();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, referer).build();
|
||||
@@ -539,8 +531,7 @@ public class EhEngine {
|
||||
Headers headers = null;
|
||||
FavoritesParser.Result result;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
@@ -592,8 +583,7 @@ public class EhEngine {
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
@@ -617,7 +607,7 @@ public class EhEngine {
|
||||
}
|
||||
|
||||
public static FavoritesParser.Result modifyFavorites(@Nullable EhClient.Task task, OkHttpClient okHttpClient,
|
||||
String url, long[] gidArray, int dstCat, boolean callApi) throws Throwable {
|
||||
String url, long[] gidArray, int dstCat) throws Throwable {
|
||||
String catStr;
|
||||
if (dstCat == -1) {
|
||||
catStr = "delete";
|
||||
@@ -648,8 +638,7 @@ public class EhEngine {
|
||||
Headers headers = null;
|
||||
FavoritesParser.Result result;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
@@ -681,8 +670,7 @@ public class EhEngine {
|
||||
Headers headers = null;
|
||||
Pair<String, String>[] result;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
@@ -712,8 +700,7 @@ public class EhEngine {
|
||||
Headers headers = null;
|
||||
Pair<String, Pair<String, String>[]> result;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
@@ -754,8 +741,7 @@ public class EhEngine {
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
@@ -788,8 +774,7 @@ public class EhEngine {
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
@@ -816,8 +801,7 @@ public class EhEngine {
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
@@ -857,8 +841,7 @@ public class EhEngine {
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
@@ -898,8 +881,7 @@ public class EhEngine {
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
@@ -962,8 +944,7 @@ public class EhEngine {
|
||||
Headers headers = null;
|
||||
GalleryListParser.Result result;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
|
||||
Log.d(TAG, "" + response.request().url());
|
||||
|
||||
@@ -997,8 +978,7 @@ public class EhEngine {
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
@@ -1039,8 +1019,7 @@ public class EhEngine {
|
||||
String body = null;
|
||||
Headers headers = null;
|
||||
int code = -1;
|
||||
try {
|
||||
Response response = call.execute();
|
||||
try (Response response = call.execute()) {
|
||||
code = response.code();
|
||||
headers = response.headers();
|
||||
body = response.body().string();
|
||||
|
||||
@@ -157,7 +157,7 @@ public final class SpiderQueen implements Runnable {
|
||||
// For download, when it go to mPageStateArray.size(), done
|
||||
private volatile int mDownloadPage = -1;
|
||||
|
||||
private SpiderQueen(EhApplication application, @NonNull GalleryInfo galleryInfo) {
|
||||
private SpiderQueen(@NonNull GalleryInfo galleryInfo) {
|
||||
mHttpClient = EhApplication.getOkHttpClient();
|
||||
mSpiderInfoCache = EhApplication.getSpiderInfoCache();
|
||||
mGalleryInfo = galleryInfo;
|
||||
@@ -183,8 +183,8 @@ public final class SpiderQueen implements Runnable {
|
||||
|
||||
SpiderQueen queen = sQueenMap.get(galleryInfo.gid);
|
||||
if (queen == null) {
|
||||
EhApplication application = (EhApplication) context.getApplicationContext();
|
||||
queen = new SpiderQueen(application, galleryInfo);
|
||||
context.getApplicationContext();
|
||||
queen = new SpiderQueen(galleryInfo);
|
||||
sQueenMap.put(galleryInfo.gid, queen);
|
||||
// Set mode
|
||||
queen.setMode(mode);
|
||||
@@ -358,12 +358,8 @@ public final class SpiderQueen implements Runnable {
|
||||
|
||||
private void setMode(@Mode int mode) {
|
||||
switch (mode) {
|
||||
case MODE_READ:
|
||||
mReadReference++;
|
||||
break;
|
||||
case MODE_DOWNLOAD:
|
||||
mDownloadReference++;
|
||||
break;
|
||||
case MODE_READ -> mReadReference++;
|
||||
case MODE_DOWNLOAD -> mDownloadReference++;
|
||||
}
|
||||
|
||||
if (mDownloadReference > 1) {
|
||||
@@ -375,12 +371,8 @@ public final class SpiderQueen implements Runnable {
|
||||
|
||||
private void clearMode(@Mode int mode) {
|
||||
switch (mode) {
|
||||
case MODE_READ:
|
||||
mReadReference--;
|
||||
break;
|
||||
case MODE_DOWNLOAD:
|
||||
mDownloadReference--;
|
||||
break;
|
||||
case MODE_READ -> mReadReference--;
|
||||
case MODE_DOWNLOAD -> mDownloadReference--;
|
||||
}
|
||||
|
||||
if (mReadReference < 0 || mDownloadReference < 0) {
|
||||
@@ -523,21 +515,16 @@ public final class SpiderQueen implements Runnable {
|
||||
Object result;
|
||||
|
||||
switch (state) {
|
||||
default:
|
||||
case STATE_NONE:
|
||||
result = null;
|
||||
break;
|
||||
case STATE_DOWNLOADING:
|
||||
result = mPagePercentMap.get(index);
|
||||
break;
|
||||
case STATE_FAILED:
|
||||
case STATE_NONE -> 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;
|
||||
break;
|
||||
case STATE_FINISHED:
|
||||
}
|
||||
case STATE_FINISHED -> {
|
||||
synchronized (mDecodeRequestQueue) {
|
||||
if (!contain(mDecodeIndexArray, index) && !mDecodeRequestQueue.contains(index)) {
|
||||
mDecodeRequestQueue.add(index);
|
||||
@@ -545,7 +532,8 @@ public final class SpiderQueen implements Runnable {
|
||||
}
|
||||
}
|
||||
result = null;
|
||||
break;
|
||||
}
|
||||
default -> throw new IllegalStateException("Unexpected value: " + state);
|
||||
}
|
||||
|
||||
tryToEnsureWorkers();
|
||||
@@ -645,7 +633,6 @@ public final class SpiderQueen implements Runnable {
|
||||
return null;
|
||||
}
|
||||
|
||||
OutputStream os = null;
|
||||
try {
|
||||
pipe.obtain();
|
||||
|
||||
@@ -661,7 +648,6 @@ public final class SpiderQueen implements Runnable {
|
||||
} finally {
|
||||
pipe.close();
|
||||
pipe.release();
|
||||
IOUtils.closeQuietly(os);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -751,14 +737,13 @@ public final class SpiderQueen implements Runnable {
|
||||
}
|
||||
|
||||
private SpiderInfo readSpiderInfoFromInternet() {
|
||||
try {
|
||||
SpiderInfo spiderInfo = new SpiderInfo();
|
||||
spiderInfo.gid = mGalleryInfo.gid;
|
||||
spiderInfo.token = mGalleryInfo.token;
|
||||
SpiderInfo spiderInfo = new SpiderInfo();
|
||||
spiderInfo.gid = mGalleryInfo.gid;
|
||||
spiderInfo.token = mGalleryInfo.token;
|
||||
|
||||
Request request = new EhRequestBuilder(EhUrl.getGalleryDetailUrl(
|
||||
mGalleryInfo.gid, mGalleryInfo.token, 0, false), EhUrl.getReferer()).build();
|
||||
Response response = mHttpClient.newCall(request).execute();
|
||||
Request request = new EhRequestBuilder(EhUrl.getGalleryDetailUrl(
|
||||
mGalleryInfo.gid, mGalleryInfo.token, 0, false), EhUrl.getReferer()).build();
|
||||
try (Response response = mHttpClient.newCall(request).execute()) {
|
||||
String body = response.body().string();
|
||||
|
||||
spiderInfo.pages = GalleryDetailParser.parsePages(body);
|
||||
@@ -777,15 +762,14 @@ public final class SpiderQueen implements Runnable {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
String url = EhUrl.getGalleryMultiPageViewerUrl(
|
||||
mGalleryInfo.gid, mGalleryInfo.token);
|
||||
if (DEBUG_PTOKEN) {
|
||||
Log.d(TAG, "getPTokenFromMultiPageViewer index " + index + ", url " + url);
|
||||
}
|
||||
String referer = EhUrl.getReferer();
|
||||
Request request = new EhRequestBuilder(url, referer).build();
|
||||
Response response = mHttpClient.newCall(request).execute();
|
||||
String url = EhUrl.getGalleryMultiPageViewerUrl(
|
||||
mGalleryInfo.gid, mGalleryInfo.token);
|
||||
if (DEBUG_PTOKEN) {
|
||||
Log.d(TAG, "getPTokenFromMultiPageViewer index " + index + ", url " + url);
|
||||
}
|
||||
String referer = EhUrl.getReferer();
|
||||
Request request = new EhRequestBuilder(url, referer).build();
|
||||
try (Response response = mHttpClient.newCall(request).execute()) {
|
||||
String body = response.body().string();
|
||||
|
||||
ArrayList<String> list = GalleryMultiPageViewerPTokenParser.parse(body);
|
||||
@@ -824,16 +808,15 @@ public final class SpiderQueen implements Runnable {
|
||||
previewIndex = Math.min(previewIndex, spiderInfo.previewPages - 1);
|
||||
}
|
||||
|
||||
try {
|
||||
String url = EhUrl.getGalleryDetailUrl(
|
||||
mGalleryInfo.gid, mGalleryInfo.token, previewIndex, false);
|
||||
String referer = EhUrl.getReferer();
|
||||
if (DEBUG_PTOKEN) {
|
||||
Log.d(TAG, "index " + index + ", previewIndex " + previewIndex +
|
||||
", previewPerPage " + spiderInfo.previewPerPage + ", url " + url);
|
||||
}
|
||||
Request request = new EhRequestBuilder(url, referer).build();
|
||||
Response response = mHttpClient.newCall(request).execute();
|
||||
String url = EhUrl.getGalleryDetailUrl(
|
||||
mGalleryInfo.gid, mGalleryInfo.token, previewIndex, false);
|
||||
String referer = EhUrl.getReferer();
|
||||
if (DEBUG_PTOKEN) {
|
||||
Log.d(TAG, "index " + index + ", previewIndex " + previewIndex +
|
||||
", previewPerPage " + spiderInfo.previewPerPage + ", url " + url);
|
||||
}
|
||||
Request request = new EhRequestBuilder(url, referer).build();
|
||||
try (Response response = mHttpClient.newCall(request).execute()) {
|
||||
String body = response.body().string();
|
||||
readPreviews(body, previewIndex, spiderInfo);
|
||||
|
||||
@@ -858,7 +841,7 @@ public final class SpiderQueen implements Runnable {
|
||||
UniFile file = downloadDir.createFile(SPIDER_INFO_FILENAME);
|
||||
try {
|
||||
spiderInfo.write(file.openOutputStream());
|
||||
} catch (Throwable e) {
|
||||
} catch (IOException e) {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
// Ignore
|
||||
}
|
||||
@@ -1150,7 +1133,7 @@ public final class SpiderQueen implements Runnable {
|
||||
}
|
||||
|
||||
// false for stop
|
||||
private boolean downloadImage(long gid, int index, String pToken, String previousPToken, boolean force) {
|
||||
private boolean downloadImage(long gid, int index, String pToken, String previousPToken) {
|
||||
String skipHathKey = null;
|
||||
List<String> skipHathKeys = new ArrayList<>(5);
|
||||
String originImageUrl = null;
|
||||
@@ -1284,12 +1267,6 @@ public final class SpiderQueen implements Runnable {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (responseBody == null) {
|
||||
error = "Empty response body";
|
||||
forceHtml = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get extension
|
||||
String extension = null;
|
||||
MediaType mediaType = responseBody.contentType();
|
||||
@@ -1575,7 +1552,7 @@ public final class SpiderQueen implements Runnable {
|
||||
}
|
||||
|
||||
// Get image url
|
||||
return downloadImage(mGid, index, pToken, previousPToken, force);
|
||||
return downloadImage(mGid, index, pToken, previousPToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1596,7 +1573,7 @@ public final class SpiderQueen implements Runnable {
|
||||
Log.e(TAG, "WTF, mWorkerCount < 0, not thread safe or something wrong");
|
||||
mWorkerCount = 0;
|
||||
}
|
||||
finish = mWorkerCount <= 0;
|
||||
finish = mWorkerCount == 0;
|
||||
}
|
||||
|
||||
if (finish) {
|
||||
|
||||
Reference in new issue
Block a user