From abf7676ae7d14426167171b5589514a06230dab1 Mon Sep 17 00:00:00 2001 From: tarsin Date: Sat, 22 Apr 2023 13:03:17 +0800 Subject: [PATCH] Kill GalleryCommentsScene voteComment callback --- .../com/hippo/ehviewer/client/EhClient.kt | 10 ---- .../ehviewer/ui/scene/GalleryCommentsScene.kt | 49 ++++++------------- 2 files changed, 15 insertions(+), 44 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 37f510b47..92c2b0aff 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhClient.kt +++ b/app/src/main/java/com/hippo/ehviewer/client/EhClient.kt @@ -95,15 +95,6 @@ object EhClient { params[2] as String?, ) - METHOD_VOTE_COMMENT -> EhEngine.voteComment( - params[0] as Long, - params[1] as String?, - params[2] as Long, - params[3] as String?, - params[4] as Long, - params[5] as Int, - ) - METHOD_IMAGE_SEARCH -> EhEngine.imageSearch( params[0] as File, params[1] as Boolean, @@ -136,7 +127,6 @@ object EhClient { const val METHOD_ADD_FAVORITES_RANGE = 10 const val METHOD_MODIFY_FAVORITES = 11 const val METHOD_GET_TORRENT_LIST = 12 - const val METHOD_VOTE_COMMENT = 15 const val METHOD_IMAGE_SEARCH = 16 const val METHOD_ARCHIVE_LIST = 17 } diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.kt index 735c44a6d..083ccc45d 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryCommentsScene.kt @@ -52,6 +52,7 @@ import androidx.core.text.inSpans import androidx.core.text.set import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsAnimationCompat +import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView @@ -65,6 +66,7 @@ import com.hippo.ehviewer.R import com.hippo.ehviewer.UrlOpener import com.hippo.ehviewer.WindowInsetsAnimationHelper import com.hippo.ehviewer.client.EhClient +import com.hippo.ehviewer.client.EhEngine import com.hippo.ehviewer.client.EhFilter import com.hippo.ehviewer.client.EhRequest import com.hippo.ehviewer.client.EhUrl @@ -92,6 +94,9 @@ import com.hippo.yorozuya.SimpleAnimatorListener import com.hippo.yorozuya.StringUtils import com.hippo.yorozuya.ViewUtils import com.hippo.yorozuya.collect.IntList +import eu.kanade.tachiyomi.util.lang.launchIO +import eu.kanade.tachiyomi.util.lang.withUIContext +import moe.tarsin.coroutines.runSuspendCatching import rikka.core.res.resolveColor import kotlin.math.hypot @@ -362,23 +367,17 @@ class GalleryCommentsScene : BaseToolbarScene(), View.OnClickListener, OnRefresh } private fun voteComment(id: Long, vote: Int) { - val context = context - val activity = mainActivity - if (null == context || null == activity) { - return + val gd = mGalleryDetail ?: return + lifecycleScope.launchIO { + runSuspendCatching { + EhEngine.voteComment(gd.apiUid, gd.apiKey, gd.gid, gd.token, id, vote) + }.onSuccess { result -> + showTip(if (result.expectVote > 0) (if (0 != result.vote) R.string.vote_up_successfully else R.string.cancel_vote_up_successfully) else if (0 != result.vote) R.string.vote_down_successfully else R.string.cancel_vote_down_successfully, LENGTH_SHORT) + withUIContext { onVoteCommentSuccess(result) } + }.onFailure { + showTip(R.string.vote_failed, LENGTH_LONG) + } } - val request = EhRequest() - .setMethod(EhClient.METHOD_VOTE_COMMENT) - .setArgs( - mGalleryDetail!!.apiUid, - mGalleryDetail!!.apiKey, - mGalleryDetail!!.gid, - mGalleryDetail!!.token, - id, - vote, - ) - .setCallback(VoteCommentListener(context)) - request.enqueue(this) } @SuppressLint("InflateParams") @@ -839,24 +838,6 @@ class GalleryCommentsScene : BaseToolbarScene(), View.OnClickListener, OnRefresh override fun onCancel() {} } - private inner class VoteCommentListener(context: Context) : - EhCallback(context) { - override fun onSuccess(result: VoteCommentParser.Result) { - showTip( - if (result.expectVote > 0) (if (0 != result.vote) R.string.vote_up_successfully else R.string.cancel_vote_up_successfully) else if (0 != result.vote) R.string.vote_down_successfully else R.string.cancel_vote_down_successfully, - LENGTH_SHORT, - ) - val scene = this@GalleryCommentsScene - scene.onVoteCommentSuccess(result) - } - - override fun onFailure(e: Exception) { - showTip(R.string.vote_failed, LENGTH_LONG) - } - - override fun onCancel() {} - } - private inner class ActualCommentHolder(inflater: LayoutInflater, parent: ViewGroup?) : CommentHolder(inflater, R.layout.item_gallery_comment, parent) { private val user: TextView = itemView.findViewById(R.id.user)