From e0797cd519e875bd97f8b811bedf6a350ef800e0 Mon Sep 17 00:00:00 2001 From: tarsin Date: Sat, 22 Apr 2023 16:03:53 +0800 Subject: [PATCH] Kill EhClient usage in GalleryDetailScene --- .../com/hippo/ehviewer/client/EhClient.kt | 14 --- .../ehviewer/ui/scene/GalleryDetailScene.kt | 99 +++++++------------ 2 files changed, 38 insertions(+), 75 deletions(-) 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 c0c5683ad..fcf896fb2 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhClient.kt +++ b/app/src/main/java/com/hippo/ehviewer/client/EhClient.kt @@ -50,18 +50,6 @@ object EhClient { params[0] as String, ) - METHOD_GET_TORRENT_LIST -> EhEngine.getTorrentList( - params[0] as String, - params[1] as Long, - params[2] as String?, - ) - - METHOD_ARCHIVE_LIST -> EhEngine.getArchiveList( - params[0] as String, - params[1] as Long, - params[2] as String?, - ) - else -> throw IllegalStateException("Can't detect method $method") } } @@ -73,6 +61,4 @@ object EhClient { } const val METHOD_GET_FAVORITES = 8 - const val METHOD_GET_TORRENT_LIST = 12 - const val METHOD_ARCHIVE_LIST = 17 } diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt index 046310b57..b9adabb92 100755 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryDetailScene.kt @@ -123,7 +123,6 @@ import com.hippo.ehviewer.EhDB import com.hippo.ehviewer.R import com.hippo.ehviewer.Settings import com.hippo.ehviewer.UrlOpener -import com.hippo.ehviewer.client.EhClient import com.hippo.ehviewer.client.EhCookieStore import com.hippo.ehviewer.client.EhEngine import com.hippo.ehviewer.client.EhFilter @@ -1565,8 +1564,7 @@ class GalleryDetailScene : BaseScene(), DownloadInfoListener { private inner class ArchiveListDialogHelper : AdapterView.OnItemClickListener, - DialogInterface.OnDismissListener, - EhClient.Callback { + DialogInterface.OnDismissListener { private var mProgressView: CircularProgressIndicator? = null private var mErrorText: TextView? = null private var mListView: ListView? = null @@ -1583,10 +1581,25 @@ class GalleryDetailScene : BaseScene(), DownloadInfoListener { if (mArchiveList == null) { mErrorText!!.visibility = View.GONE mListView!!.visibility = View.GONE - mRequest = EhRequest().setMethod(EhClient.METHOD_ARCHIVE_LIST) - .setArgs(url!!, mGid, mToken) - .setCallback(this) - mRequest!!.enqueue(this@GalleryDetailScene) + lifecycleScope.launchIO { + runSuspendCatching { + EhEngine.getArchiveList(url!!, mGid, mToken) + }.onSuccess { result -> + mArchiveFormParamOr = result.paramOr + mArchiveList = result.archiveList + mCurrentFunds = result.funds + withUIContext { + bind(result.archiveList, result.funds) + } + }.onFailure { + withUIContext { + mProgressView?.visibility = View.GONE + mErrorText?.visibility = View.VISIBLE + mListView?.visibility = View.GONE + mErrorText?.text = ExceptionUtils.getReadableString(it) + } + } + } } else { bind(mArchiveList, mCurrentFunds) } @@ -1694,37 +1707,11 @@ class GalleryDetailScene : BaseScene(), DownloadInfoListener { mErrorText = null mListView = null } - - override fun onSuccess(result: ArchiveParser.Result) { - if (mRequest != null) { - mRequest = null - mArchiveFormParamOr = result.paramOr - mArchiveList = result.archiveList - mCurrentFunds = result.funds - bind(result.archiveList, result.funds) - } - } - - override fun onFailure(e: Exception) { - mRequest = null - val context = context - if (null != context && null != mProgressView && null != mErrorText && null != mListView) { - mProgressView!!.visibility = View.GONE - mErrorText!!.visibility = View.VISIBLE - mListView!!.visibility = View.GONE - mErrorText!!.text = ExceptionUtils.getReadableString(e) - } - } - - override fun onCancel() { - mRequest = null - } } private inner class TorrentListDialogHelper : AdapterView.OnItemClickListener, - DialogInterface.OnDismissListener, - EhClient.Callback> { + DialogInterface.OnDismissListener { private var mProgressView: CircularProgressIndicator? = null private var mErrorText: TextView? = null private var mListView: ListView? = null @@ -1741,10 +1728,23 @@ class GalleryDetailScene : BaseScene(), DownloadInfoListener { if (mTorrentList == null) { mErrorText!!.visibility = View.GONE mListView!!.visibility = View.GONE - mRequest = EhRequest().setMethod(EhClient.METHOD_GET_TORRENT_LIST) - .setArgs(url!!, mGid, mToken) - .setCallback(this) - mRequest!!.enqueue(this@GalleryDetailScene) + lifecycleScope.launchIO { + runSuspendCatching { + EhEngine.getTorrentList(url!!, mGid, mToken) + }.onSuccess { + mTorrentList = it + withUIContext { + bind(it) + } + }.onFailure { + withUIContext { + mProgressView?.visibility = View.GONE + mErrorText?.visibility = View.VISIBLE + mListView?.visibility = View.GONE + mErrorText?.text = ExceptionUtils.getReadableString(it) + } + } + } } else { bind(mTorrentList) } @@ -1810,29 +1810,6 @@ class GalleryDetailScene : BaseScene(), DownloadInfoListener { mErrorText = null mListView = null } - - override fun onSuccess(result: List) { - if (mRequest != null) { - mRequest = null - mTorrentList = result - bind(result) - } - } - - override fun onFailure(e: Exception) { - mRequest = null - val context = context - if (null != context && null != mProgressView && null != mErrorText && null != mListView) { - mProgressView!!.visibility = View.GONE - mErrorText!!.visibility = View.VISIBLE - mListView!!.visibility = View.GONE - mErrorText!!.text = ExceptionUtils.getReadableString(e) - } - } - - override fun onCancel() { - mRequest = null - } } private inner class RateDialogHelper : OnUserRateListener, DialogInterface.OnClickListener {