diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhClient.kt b/app/src/main/java/com/hippo/ehviewer/client/EhClient.kt index 2ef036e10..0ca7721ee 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhClient.kt +++ b/app/src/main/java/com/hippo/ehviewer/client/EhClient.kt @@ -16,9 +16,9 @@ package com.hippo.ehviewer.client import com.hippo.ehviewer.EhApplication.Companion.okHttpClient -import com.hippo.ehviewer.client.exception.CancelledException import eu.kanade.tachiyomi.util.lang.launchUI import eu.kanade.tachiyomi.util.lang.withUIContext +import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.Dispatchers @@ -183,9 +183,10 @@ class EhClient { } withUIContext { callback?.onSuccess(result) } } catch (e: Exception) { + if (e is CancellationException) + throw e // Don't catch coroutine CancellationException e.printStackTrace() - if (e !is CancelledException) - withUIContext { callback?.onFailure(e) } + withUIContext { callback?.onFailure(e) } } request.task = null request.callback = null @@ -212,15 +213,9 @@ class EhClient { private val mStop get() = !(job?.isActive ?: false) - // Called in Job thread - @Throws(CancelledException::class) fun setCall(call: Call?) { - if (mStop) { - // Stopped Job thread - throw CancelledException() - } else { - mCall.lazySet(call) - } + if (mStop) call?.cancel() + else mCall.lazySet(call) } fun stop() { diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java b/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java index 5760de2be..fd39799c8 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java +++ b/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java @@ -31,7 +31,6 @@ import com.hippo.ehviewer.client.data.GalleryCommentList; import com.hippo.ehviewer.client.data.GalleryDetail; import com.hippo.ehviewer.client.data.GalleryInfo; import com.hippo.ehviewer.client.data.PreviewSet; -import com.hippo.ehviewer.client.exception.CancelledException; import com.hippo.ehviewer.client.exception.EhException; import com.hippo.ehviewer.client.exception.ParseException; import com.hippo.ehviewer.client.parser.ArchiveParser; @@ -64,6 +63,7 @@ import org.jsoup.select.Elements; import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.CancellationException; import okhttp3.Call; import okhttp3.FormBody; @@ -94,7 +94,7 @@ public class EhEngine { private static void doThrowException(Call call, int code, @Nullable Headers headers, @Nullable String body, Throwable e) throws Throwable { if (call.isCanceled()) { - throw new CancelledException(); + throw new CancellationException("Call cancelled!"); } // Check sad panda diff --git a/app/src/main/java/com/hippo/ehviewer/client/exception/CancelledException.java b/app/src/main/java/com/hippo/ehviewer/client/exception/CancelledException.java deleted file mode 100644 index 62283ec24..000000000 --- a/app/src/main/java/com/hippo/ehviewer/client/exception/CancelledException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2016 Hippo Seven - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.hippo.ehviewer.client.exception; - -public class CancelledException extends Exception { - - public CancelledException() { - super("CANCELED"); - } -}