From 45cc6acd9fc7bf6d0bfc895106d232aca5e0699d Mon Sep 17 00:00:00 2001 From: tarsin Date: Sat, 22 Apr 2023 12:52:41 +0800 Subject: [PATCH] Kill GalleryDetailScene rateGallery callback --- .../com/hippo/ehviewer/client/EhClient.kt | 9 --- .../ehviewer/ui/scene/GalleryDetailScene.kt | 63 +++++-------------- 2 files changed, 17 insertions(+), 55 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 b2d4d0df8..37f510b47 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhClient.kt +++ b/app/src/main/java/com/hippo/ehviewer/client/EhClient.kt @@ -59,14 +59,6 @@ object EhClient { params[0] as String, ) - METHOD_GET_RATE_GALLERY -> EhEngine.rateGallery( - params[0] as Long, - params[1] as String?, - params[2] as Long, - params[3] as String?, - params[4] as Float, - ) - METHOD_GET_COMMENT_GALLERY -> EhEngine.commentGallery( params[0] as String?, params[1] as String, @@ -138,7 +130,6 @@ object EhClient { const val METHOD_GET_GALLERY_LIST = 1 const val METHOD_GET_GALLERY_DETAIL = 3 const val METHOD_GET_PREVIEW_LIST = 4 - const val METHOD_GET_RATE_GALLERY = 5 const val METHOD_GET_COMMENT_GALLERY = 6 const val METHOD_GET_GALLERY_TOKEN = 7 const val METHOD_GET_FAVORITES = 8 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 1f90aa5da..9d6d9268c 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 @@ -143,7 +143,6 @@ import com.hippo.ehviewer.client.getPreviewThumbKey import com.hippo.ehviewer.client.parser.ArchiveParser import com.hippo.ehviewer.client.parser.HomeParser import com.hippo.ehviewer.client.parser.ParserUtils -import com.hippo.ehviewer.client.parser.RateGalleryParser import com.hippo.ehviewer.client.parser.TorrentParser import com.hippo.ehviewer.coil.imageRequest import com.hippo.ehviewer.dao.DownloadInfo @@ -1528,15 +1527,6 @@ class GalleryDetailScene : BaseScene(), DownloadInfoListener { override fun onRenameLabel(from: String, to: String) {} override fun onUpdateLabels() {} - private fun onRateGallerySuccess(result: RateGalleryParser.Result) { - composeBindingGD?.apply { - rating = result.rating - ratingCount = result.ratingCount - } - composeBindingGD = composeBindingGD - ratingText = getAllRatingText(result.rating, result.ratingCount) - } - private fun onModifyFavoritesSuccess(addOrRemove: Boolean) { if (composeBindingGD != null) { composeBindingGD!!.isFavorited = !addOrRemove && composeBindingGD!!.favoriteName != null @@ -1572,23 +1562,6 @@ class GalleryDetailScene : BaseScene(), DownloadInfoListener { } } - private inner class RateGalleryListener( - context: Context, - ) : EhCallback(context) { - override fun onSuccess(result: RateGalleryParser.Result) { - showTip(R.string.rate_successfully, LENGTH_SHORT) - val scene = this@GalleryDetailScene - scene.onRateGallerySuccess(result) - } - - override fun onFailure(e: Exception) { - e.printStackTrace() - showTip(R.string.rate_failed, LENGTH_LONG) - } - - override fun onCancel() {} - } - private inner class ArchiveListDialogHelper : AdapterView.OnItemClickListener, DialogInterface.OnDismissListener, @@ -1879,26 +1852,24 @@ class GalleryDetailScene : BaseScene(), DownloadInfoListener { } override fun onClick(dialog: DialogInterface, which: Int) { - val context = context - val activity = mainActivity - if (null == context || null == activity || which != DialogInterface.BUTTON_POSITIVE || null == composeBindingGD || null == mRatingBar) { - return + if (which != DialogInterface.BUTTON_POSITIVE) return + val gd = composeBindingGD ?: return + val r = mRatingBar?.rating ?: return + lifecycleScope.launchIO { + runSuspendCatching { + EhEngine.rateGallery(gd.apiUid, gd.apiKey, gd.gid, gd.token, r) + }.onSuccess { result -> + showTip(R.string.rate_successfully, LENGTH_SHORT) + composeBindingGD = composeBindingGD?.apply { + rating = result.rating + ratingCount = result.ratingCount + } + ratingText = getAllRatingText(result.rating, result.ratingCount) + }.onFailure { + it.printStackTrace() + showTip(R.string.rate_failed, LENGTH_LONG) + } } - val request = EhRequest() - .setMethod(EhClient.METHOD_GET_RATE_GALLERY) - .setArgs( - composeBindingGD!!.apiUid, - composeBindingGD!!.apiKey!!, - composeBindingGD!!.gid, - composeBindingGD!!.token!!, - mRatingBar!!.rating, - ) - .setCallback( - RateGalleryListener( - context, - ), - ) - request.enqueue(this@GalleryDetailScene) } }