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 2ed2a3ef0..1e480882e 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhClient.kt +++ b/app/src/main/java/com/hippo/ehviewer/client/EhClient.kt @@ -15,7 +15,6 @@ */ package com.hippo.ehviewer.client -import com.hippo.ehviewer.EhApplication.Companion.okHttpClient import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.withUIContext import kotlinx.coroutines.CancellationException @@ -47,28 +46,23 @@ object EhClient { suspend fun execute(method: Int, vararg params: Any?): Any? { return when (method) { METHOD_SIGN_IN -> EhEngine.signIn( - mOkHttpClient, params[0] as String, params[1] as String ) METHOD_GET_GALLERY_LIST -> EhEngine.getGalleryList( - mOkHttpClient, params[0] as String ) METHOD_GET_GALLERY_DETAIL -> EhEngine.getGalleryDetail( - mOkHttpClient, params[0] as String? ) METHOD_GET_PREVIEW_SET -> EhEngine.getPreviewSet( - mOkHttpClient, params[0] as String? ) METHOD_GET_RATE_GALLERY -> EhEngine.rateGallery( - mOkHttpClient, params[0] as Long, params[1] as String?, params[2] as Long, @@ -77,26 +71,22 @@ object EhClient { ) METHOD_GET_COMMENT_GALLERY -> EhEngine.commentGallery( - mOkHttpClient, params[0] as String?, params[1] as String, params[2] as String? ) METHOD_GET_GALLERY_TOKEN -> EhEngine.getGalleryToken( - mOkHttpClient, params[0] as Long, params[1] as String?, params[2] as Int ) METHOD_GET_FAVORITES -> EhEngine.getFavorites( - mOkHttpClient, params[0] as String ) METHOD_ADD_FAVORITES -> EhEngine.addFavorites( - mOkHttpClient, params[0] as Long, params[1] as String?, params[2] as Int, @@ -104,29 +94,25 @@ object EhClient { ) METHOD_ADD_FAVORITES_RANGE -> @Suppress("UNCHECKED_CAST") EhEngine.addFavoritesRange( - mOkHttpClient, params[0] as LongArray, params[1] as Array, params[2] as Int ) METHOD_MODIFY_FAVORITES -> EhEngine.modifyFavorites( - mOkHttpClient, params[0] as String, params[1] as LongArray, params[2] as Int ) METHOD_GET_TORRENT_LIST -> EhEngine.getTorrentList( - mOkHttpClient, params[0] as String?, params[1] as Long, params[2] as String? ) - METHOD_GET_PROFILE -> EhEngine.getProfile(mOkHttpClient) + METHOD_GET_PROFILE -> EhEngine.getProfile() METHOD_VOTE_COMMENT -> EhEngine.voteComment( - mOkHttpClient, params[0] as Long, params[1] as String?, params[2] as Long, @@ -136,7 +122,6 @@ object EhClient { ) METHOD_IMAGE_SEARCH -> EhEngine.imageSearch( - mOkHttpClient, params[0] as File, params[1] as Boolean, params[2] as Boolean, @@ -144,14 +129,12 @@ object EhClient { ) METHOD_ARCHIVE_LIST -> EhEngine.getArchiveList( - mOkHttpClient, params[0] as String?, params[1] as Long, params[2] as String? ) METHOD_DOWNLOAD_ARCHIVE -> EhEngine.downloadArchive( - mOkHttpClient, params[0] as Long, params[1] as String?, params[2] as String?, @@ -160,7 +143,6 @@ object EhClient { ) METHOD_VOTE_TAG -> EhEngine.voteTag( - mOkHttpClient, params[0] as Long, params[1] as String?, params[2] as Long, @@ -169,7 +151,7 @@ object EhClient { params[5] as Int ) - METHOD_GET_UCONFIG -> EhEngine.getUConfig(mOkHttpClient) + METHOD_GET_UCONFIG -> EhEngine.getUConfig() else -> throw IllegalStateException("Can't detect method $method") } } @@ -199,5 +181,4 @@ object EhClient { const val METHOD_DOWNLOAD_ARCHIVE = 18 const val METHOD_VOTE_TAG = 19 const val METHOD_GET_UCONFIG = 20 - private val mOkHttpClient = okHttpClient } \ No newline at end of file diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhEngine.kt b/app/src/main/java/com/hippo/ehviewer/client/EhEngine.kt index e58b04307..dd50e5f2d 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhEngine.kt +++ b/app/src/main/java/com/hippo/ehviewer/client/EhEngine.kt @@ -19,6 +19,7 @@ import android.text.TextUtils import android.util.Log import android.util.Pair import com.hippo.ehviewer.AppConfig +import com.hippo.ehviewer.EhApplication import com.hippo.ehviewer.EhApplication.Companion.application import com.hippo.ehviewer.GetText import com.hippo.ehviewer.R @@ -55,7 +56,6 @@ import okhttp3.Headers import okhttp3.MediaType import okhttp3.MediaType.Companion.toMediaType import okhttp3.MultipartBody -import okhttp3.OkHttpClient import okhttp3.RequestBody import okhttp3.RequestBody.Companion.asRequestBody import okhttp3.RequestBody.Companion.toRequestBody @@ -76,6 +76,7 @@ object EhEngine { private const val KOKOMADE_URL = "https://exhentai.org/img/kokomade.jpg" private val MEDIA_TYPE_JPEG: MediaType = "image/jpeg".toMediaType() private var sEhFilter = EhFilter.getInstance() + private val okHttpClient = EhApplication.okHttpClient private fun transformException(code: Int, headers: Headers?, body: String?, e: Throwable?) { // Check sad panda @@ -116,7 +117,7 @@ object EhEngine { } @Throws(Throwable::class) - suspend fun signIn(okHttpClient: OkHttpClient, username: String, password: String): String { + suspend fun signIn(username: String, password: String): String { val referer = "https://forums.e-hentai.org/index.php?act=Login&CODE=00" val builder = FormBody.Builder() .add("referer", referer) @@ -151,7 +152,6 @@ object EhEngine { @Throws(Throwable::class) private suspend fun fillGalleryList( - okHttpClient: OkHttpClient, list: MutableList, url: String, filter: Boolean @@ -188,7 +188,7 @@ object EhEngine { filter && sEhFilter.needTags() && !hasTags || Settings.getShowGalleryPages() && !hasPages || hasRated if (needApi) { - fillGalleryListByApi(okHttpClient, list, url) + fillGalleryListByApi(list, url) } // Filter tag @@ -212,7 +212,7 @@ object EhEngine { } @Throws(Throwable::class) - suspend fun getGalleryList(okHttpClient: OkHttpClient, url: String): GalleryListParser.Result { + suspend fun getGalleryList(url: String): GalleryListParser.Result { val referer = EhUrl.getReferer() Log.d(TAG, url) val request = EhRequestBuilder(url, referer).build() @@ -234,7 +234,7 @@ object EhEngine { transformException(code, headers, body, e) throw e } - fillGalleryList(okHttpClient, result.galleryInfoList, url, true) + fillGalleryList(result.galleryInfoList, url, true) return result } @@ -242,7 +242,6 @@ object EhEngine { @JvmStatic @Throws(Throwable::class) suspend fun fillGalleryListByApi( - okHttpClient: OkHttpClient, galleryInfoList: List, referer: String ): List { @@ -252,7 +251,7 @@ object EhEngine { while (i < size) { requestItems.add(galleryInfoList[i]) if (requestItems.size == MAX_REQUEST_SIZE || i == size - 1) { - doFillGalleryListByApi(okHttpClient, requestItems, referer) + doFillGalleryListByApi(requestItems, referer) requestItems.clear() } i++ @@ -262,7 +261,6 @@ object EhEngine { @Throws(Throwable::class) suspend fun doFillGalleryListByApi( - okHttpClient: OkHttpClient, galleryInfoList: List, referer: String ) { @@ -307,7 +305,7 @@ object EhEngine { } @Throws(Throwable::class) - suspend fun getGalleryDetail(okHttpClient: OkHttpClient, url: String?): GalleryDetail { + suspend fun getGalleryDetail(url: String?): GalleryDetail { val referer = EhUrl.getReferer() Log.d(TAG, url!!) val request = EhRequestBuilder(url, referer).build() @@ -335,7 +333,7 @@ object EhEngine { } @Throws(Throwable::class) - suspend fun getPreviewSet(okHttpClient: OkHttpClient, url: String?): Pair { + suspend fun getPreviewSet(url: String?): Pair { val referer = EhUrl.getReferer() Log.d(TAG, url!!) val request = EhRequestBuilder(url, referer).build() @@ -363,7 +361,6 @@ object EhEngine { @Throws(Throwable::class) suspend fun rateGallery( - okHttpClient: OkHttpClient, apiUid: Long, apiKey: String?, gid: Long, token: String?, rating: Float ): RateGalleryParser.Result { @@ -403,7 +400,6 @@ object EhEngine { @Throws(Throwable::class) suspend fun commentGallery( - okHttpClient: OkHttpClient, url: String?, comment: String, id: String? ): GalleryCommentList { val builder = FormBody.Builder() @@ -444,7 +440,7 @@ object EhEngine { @Throws(Throwable::class) suspend fun getGalleryToken( - okHttpClient: OkHttpClient, gid: Long, + gid: Long, gtoken: String?, page: Int ): String { val json = JSONObject() @@ -482,7 +478,7 @@ object EhEngine { @Throws(Throwable::class) suspend fun getFavorites( - okHttpClient: OkHttpClient, url: String + url: String ): FavoritesParser.Result { val referer = EhUrl.getReferer() Log.d(TAG, url) @@ -505,7 +501,7 @@ object EhEngine { transformException(code, headers, body, e) throw e } - fillGalleryList(okHttpClient, result.galleryInfoList, url, false) + fillGalleryList(result.galleryInfoList, url, false) return result } @@ -515,7 +511,7 @@ object EhEngine { */ @Throws(Throwable::class) suspend fun addFavorites( - okHttpClient: OkHttpClient, gid: Long, + gid: Long, token: String?, dstCat: Int, note: String? ): Void? { val catStr: String = when (dstCat) { @@ -564,14 +560,14 @@ object EhEngine { @Throws(Throwable::class) suspend fun addFavoritesRange( - okHttpClient: OkHttpClient, gidArray: LongArray, + gidArray: LongArray, tokenArray: Array, dstCat: Int ): Void? { AssertUtils.assertEquals(gidArray.size, tokenArray.size) var i = 0 val n = gidArray.size while (i < n) { - addFavorites(okHttpClient, gidArray[i], tokenArray[i], dstCat, null) + addFavorites(gidArray[i], tokenArray[i], dstCat, null) i++ } return null @@ -579,7 +575,7 @@ object EhEngine { @Throws(Throwable::class) suspend fun modifyFavorites( - okHttpClient: OkHttpClient, url: String, + url: String, gidArray: LongArray, dstCat: Int ): FavoritesParser.Result { val catStr: String = when (dstCat) { @@ -623,13 +619,13 @@ object EhEngine { transformException(code, headers, body, e) throw e } - fillGalleryList(okHttpClient, result.galleryInfoList, url, false) + fillGalleryList(result.galleryInfoList, url, false) return result } @Throws(Throwable::class) suspend fun getTorrentList( - okHttpClient: OkHttpClient, url: String?, + url: String?, gid: Long, token: String? ): List { val referer = EhUrl.getGalleryDetailUrl(gid, token) @@ -657,7 +653,7 @@ object EhEngine { @Throws(Throwable::class) suspend fun getArchiveList( - okHttpClient: OkHttpClient, url: String?, + url: String?, gid: Long, token: String? ): ArchiveParser.Result { val referer = EhUrl.getGalleryDetailUrl(gid, token) @@ -685,7 +681,7 @@ object EhEngine { @Throws(Throwable::class) suspend fun downloadArchive( - okHttpClient: OkHttpClient, gid: Long, + gid: Long, token: String?, or: String?, res: String?, isHAtH: Boolean ): String? { if (or.isNullOrEmpty()) { @@ -756,7 +752,6 @@ object EhEngine { @Throws(Throwable::class) private suspend fun getProfileInternal( - okHttpClient: OkHttpClient, url: String, referer: String ): ProfileParser.Result { Log.d(TAG, url) @@ -780,9 +775,7 @@ object EhEngine { } @Throws(Throwable::class) - suspend fun getProfile( - okHttpClient: OkHttpClient - ): ProfileParser.Result { + suspend fun getProfile(): ProfileParser.Result { val url = EhUrl.URL_FORUMS Log.d(TAG, url) val request = EhRequestBuilder(url, null).build() @@ -795,7 +788,7 @@ object EhEngine { code = response.code headers = response.headers body = response.body.string() - return getProfileInternal(okHttpClient, ForumsParser.parse(body), url) + return getProfileInternal(ForumsParser.parse(body), url) } } catch (e: Throwable) { ExceptionUtils.throwIfFatal(e) @@ -805,9 +798,7 @@ object EhEngine { } @Throws(Throwable::class) - suspend fun getUConfig( - okHttpClient: OkHttpClient - ): Void? { + suspend fun getUConfig(): Void? { val url = EhUrl.getUConfigUrl() Log.d(TAG, url) var request = EhRequestBuilder(url, null).build() @@ -852,7 +843,7 @@ object EhEngine { @Throws(Throwable::class) suspend fun voteComment( - okHttpClient: OkHttpClient, apiUid: Long, + apiUid: Long, apiKey: String?, gid: Long, token: String?, commentId: Long, commentVote: Int ): VoteCommentParser.Result { val json = JSONObject() @@ -891,7 +882,7 @@ object EhEngine { @Throws(Throwable::class) suspend fun voteTag( - okHttpClient: OkHttpClient, apiUid: Long, + apiUid: Long, apiKey: String?, gid: Long, token: String?, tags: String?, vote: Int ): VoteTagParser.Result { val json = JSONObject() @@ -933,7 +924,7 @@ object EhEngine { */ @Throws(Throwable::class) suspend fun imageSearch( - okHttpClient: OkHttpClient, image: File, + image: File, uss: Boolean, osc: Boolean, se: Boolean ): GalleryListParser.Result { val builder = MultipartBody.Builder() @@ -992,14 +983,13 @@ object EhEngine { transformException(code, headers, body, e) throw e } - fillGalleryList(okHttpClient, result.galleryInfoList, url, true) + fillGalleryList(result.galleryInfoList, url, true) return result } @JvmStatic @Throws(Throwable::class) fun getGalleryPage( - okHttpClient: OkHttpClient, url: String?, gid: Long, token: String? @@ -1029,7 +1019,6 @@ object EhEngine { @JvmStatic @Throws(Throwable::class) fun getGalleryPageApi( - okHttpClient: OkHttpClient, gid: Long, index: Int, pToken: String?, diff --git a/app/src/main/java/com/hippo/ehviewer/preference/RestoreDownloadPreference.kt b/app/src/main/java/com/hippo/ehviewer/preference/RestoreDownloadPreference.kt index 293179528..cd663f299 100644 --- a/app/src/main/java/com/hippo/ehviewer/preference/RestoreDownloadPreference.kt +++ b/app/src/main/java/com/hippo/ehviewer/preference/RestoreDownloadPreference.kt @@ -20,7 +20,6 @@ import android.content.Context import android.util.AttributeSet import androidx.preference.Preference import com.hippo.ehviewer.EhApplication.Companion.downloadManager -import com.hippo.ehviewer.EhApplication.Companion.okHttpClient import com.hippo.ehviewer.EhDB import com.hippo.ehviewer.R import com.hippo.ehviewer.Settings @@ -35,7 +34,6 @@ import com.hippo.unifile.UniFile import com.hippo.util.ExceptionUtils import com.hippo.yorozuya.IOUtils import kotlinx.coroutines.runBlocking -import okhttp3.OkHttpClient import java.io.IOException import java.io.InputStream import java.util.Collections @@ -49,7 +47,6 @@ class RestoreDownloadPreference constructor( private class RestoreTask(context: Context) : Task(context) { private val mManager: DownloadManager = downloadManager - private val mHttpClient: OkHttpClient = okHttpClient private var restoreDirCount = 0 private fun getRestoreItem(file: UniFile?): RestoreItem? { if (null == file || !file.isDirectory) { @@ -99,7 +96,6 @@ class RestoreDownloadPreference constructor( } else try { runBlocking { fillGalleryListByApi( - mHttpClient, ArrayList(restoreItemList), EhUrl.getReferer() ) diff --git a/app/src/main/java/com/hippo/ehviewer/spider/SpiderQueen.java b/app/src/main/java/com/hippo/ehviewer/spider/SpiderQueen.java index 95b064248..d9c72a3b6 100644 --- a/app/src/main/java/com/hippo/ehviewer/spider/SpiderQueen.java +++ b/app/src/main/java/com/hippo/ehviewer/spider/SpiderQueen.java @@ -1115,7 +1115,7 @@ public final class SpiderQueen implements Runnable { } private GalleryPageParser.Result fetchPageResultFromHtml(int index, String pageUrl) throws Throwable { - GalleryPageParser.Result result = EhEngine.getGalleryPage(mHttpClient, pageUrl, mGalleryInfo.getGid(), mGalleryInfo.getToken()); + GalleryPageParser.Result result = EhEngine.getGalleryPage(pageUrl, mGalleryInfo.getGid(), mGalleryInfo.getToken()); if (StringUtils.endsWith(result.imageUrl, URL_509_SUFFIX_ARRAY)) { // Get 509 // Notify listeners @@ -1127,7 +1127,7 @@ public final class SpiderQueen implements Runnable { } private GalleryPageApiParser.Result fetchPageResultFromApi(long gid, int index, String pToken, String showKey, String previousPToken) throws Throwable { - GalleryPageApiParser.Result result = EhEngine.getGalleryPageApi(mHttpClient, gid, index, pToken, showKey, previousPToken); + GalleryPageApiParser.Result result = EhEngine.getGalleryPageApi(gid, index, pToken, showKey, previousPToken); if (StringUtils.endsWith(result.imageUrl, URL_509_SUFFIX_ARRAY)) { // Get 509 // Notify listeners