Kill GalleryDetailScene rateGallery callback

This commit is contained in:
tarsin committed 2023-04-22 12:52:41 +08:00
1 parent 32038531e1
commit 45cc6acd9f
2 files changed
+17 -55

No files matched your search

@@ -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
@@ -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<GalleryDetailScene?, RateGalleryParser.Result>(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)
}
}