Kill GalleryCommentsScene RefreshCommentListener
This commit is contained in:
1 parent
13705f9872
commit
c20bc215a8
2 files changed
+18
-40
No files matched your search
@@ -46,10 +46,6 @@ object EhClient {
|
||||
|
||||
suspend fun execute(method: Int, vararg params: Any?): Any? {
|
||||
return when (method) {
|
||||
METHOD_GET_GALLERY_DETAIL -> EhEngine.getGalleryDetail(
|
||||
params[0] as String,
|
||||
)
|
||||
|
||||
METHOD_GET_COMMENT_GALLERY -> EhEngine.commentGallery(
|
||||
params[0] as String?,
|
||||
params[1] as String,
|
||||
@@ -96,7 +92,6 @@ object EhClient {
|
||||
fun onCancel()
|
||||
}
|
||||
|
||||
const val METHOD_GET_GALLERY_DETAIL = 3
|
||||
const val METHOD_GET_COMMENT_GALLERY = 6
|
||||
const val METHOD_GET_FAVORITES = 8
|
||||
const val METHOD_ADD_FAVORITES_RANGE = 10
|
||||
|
||||
@@ -76,7 +76,6 @@ import com.hippo.ehviewer.client.data.GalleryDetail
|
||||
import com.hippo.ehviewer.client.data.ListUrlBuilder
|
||||
import com.hippo.ehviewer.client.parser.VoteCommentParser
|
||||
import com.hippo.ehviewer.dao.Filter
|
||||
import com.hippo.ehviewer.ui.MainActivity
|
||||
import com.hippo.ehviewer.ui.scene.GalleryListScene.Companion.toStartArgs
|
||||
import com.hippo.text.URLImageGetter
|
||||
import com.hippo.util.ExceptionUtils
|
||||
@@ -493,19 +492,27 @@ class GalleryCommentsScene : BaseToolbarScene(), View.OnClickListener, OnRefresh
|
||||
mRefreshingComments = true
|
||||
mShowAllComments = true
|
||||
mAdapter!!.notifyItemChanged(position)
|
||||
val url = galleryDetailUrl
|
||||
if (url != null) {
|
||||
// Request
|
||||
val request = EhRequest()
|
||||
.setMethod(EhClient.METHOD_GET_GALLERY_DETAIL)
|
||||
.setArgs(url)
|
||||
.setCallback(RefreshCommentListener(activity))
|
||||
request.enqueue(this)
|
||||
}
|
||||
galleryDetailUrl?.let { refreshComment(it) }
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun refreshComment(url: String) {
|
||||
lifecycleScope.launchIO {
|
||||
runSuspendCatching {
|
||||
EhEngine.getGalleryDetail(url)
|
||||
}.onSuccess {
|
||||
withUIContext {
|
||||
onRefreshGallerySuccess(it.comments)
|
||||
}
|
||||
}.onFailure {
|
||||
withUIContext {
|
||||
onRefreshGalleryFailure()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateView(animation: Boolean) {
|
||||
if (null == mViewTransition) {
|
||||
return
|
||||
@@ -764,17 +771,8 @@ class GalleryCommentsScene : BaseToolbarScene(), View.OnClickListener, OnRefresh
|
||||
|
||||
override fun onRefresh() {
|
||||
if (!mRefreshingComments && mAdapter != null) {
|
||||
val activity = requireActivity() as MainActivity
|
||||
mRefreshingComments = true
|
||||
val url = galleryDetailUrl
|
||||
if (url != null) {
|
||||
// Request
|
||||
val request = EhRequest()
|
||||
.setMethod(EhClient.METHOD_GET_GALLERY_DETAIL)
|
||||
.setArgs(url)
|
||||
.setCallback(RefreshCommentListener(activity))
|
||||
request.enqueue(this)
|
||||
}
|
||||
galleryDetailUrl?.let { refreshComment(it) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -799,21 +797,6 @@ class GalleryCommentsScene : BaseToolbarScene(), View.OnClickListener, OnRefresh
|
||||
private class ProgressCommentHolder(inflater: LayoutInflater, parent: ViewGroup?) :
|
||||
CommentHolder(inflater, R.layout.item_gallery_comment_progress, parent)
|
||||
|
||||
private inner class RefreshCommentListener(context: Context) :
|
||||
EhCallback<GalleryCommentsScene?, GalleryDetail>(context) {
|
||||
override fun onSuccess(result: GalleryDetail) {
|
||||
val scene = this@GalleryCommentsScene
|
||||
scene.onRefreshGallerySuccess(result.comments)
|
||||
}
|
||||
|
||||
override fun onFailure(e: Exception) {
|
||||
val scene = this@GalleryCommentsScene
|
||||
scene.onRefreshGalleryFailure()
|
||||
}
|
||||
|
||||
override fun onCancel() {}
|
||||
}
|
||||
|
||||
private inner class CommentGalleryListener(context: Context, private val mCommentId: Long) :
|
||||
EhCallback<GalleryCommentsScene?, GalleryCommentList>(context) {
|
||||
override fun onSuccess(result: GalleryCommentList) {
|
||||
|
||||
Reference in new issue
Block a user