Kill ProgressScene GetGalleryTokenListener
This commit is contained in:
1 parent
f02cd58a6b
commit
13705f9872
2 files changed
+30
-56
No files matched your search
@@ -56,12 +56,6 @@ object EhClient {
|
||||
params[2] as String?,
|
||||
)
|
||||
|
||||
METHOD_GET_GALLERY_TOKEN -> EhEngine.getGalleryToken(
|
||||
params[0] as Long,
|
||||
params[1] as String?,
|
||||
params[2] as Int,
|
||||
)
|
||||
|
||||
METHOD_GET_FAVORITES -> EhEngine.getFavorites(
|
||||
params[0] as String,
|
||||
)
|
||||
@@ -104,7 +98,6 @@ object EhClient {
|
||||
|
||||
const val METHOD_GET_GALLERY_DETAIL = 3
|
||||
const val METHOD_GET_COMMENT_GALLERY = 6
|
||||
const val METHOD_GET_GALLERY_TOKEN = 7
|
||||
const val METHOD_GET_FAVORITES = 8
|
||||
const val METHOD_ADD_FAVORITES_RANGE = 10
|
||||
const val METHOD_MODIFY_FAVORITES = 11
|
||||
|
||||
@@ -15,20 +15,22 @@
|
||||
*/
|
||||
package com.hippo.ehviewer.ui.scene
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.client.EhClient
|
||||
import com.hippo.ehviewer.client.EhRequest
|
||||
import com.hippo.ehviewer.client.EhEngine
|
||||
import com.hippo.util.ExceptionUtils
|
||||
import com.hippo.view.ViewTransition
|
||||
import com.hippo.yorozuya.ViewUtils
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import eu.kanade.tachiyomi.util.lang.withUIContext
|
||||
import moe.tarsin.coroutines.runSuspendCatching
|
||||
|
||||
/**
|
||||
* Only show a progress with jobs in background
|
||||
@@ -65,15 +67,31 @@ class ProgressScene : BaseScene(), View.OnClickListener {
|
||||
if (mGid == -1L || mPToken == null || mPage == -1) {
|
||||
return false
|
||||
}
|
||||
val request = EhRequest()
|
||||
.setMethod(EhClient.METHOD_GET_GALLERY_TOKEN)
|
||||
.setArgs(mGid, mPToken!!, mPage)
|
||||
.setCallback(
|
||||
GetGalleryTokenListener(
|
||||
context,
|
||||
),
|
||||
)
|
||||
request.enqueue()
|
||||
lifecycleScope.launchIO {
|
||||
runSuspendCatching {
|
||||
EhEngine.getGalleryToken(mGid, mPToken, mPage)
|
||||
}.onSuccess {
|
||||
val arg = Bundle()
|
||||
arg.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GID_TOKEN)
|
||||
arg.putLong(GalleryDetailScene.KEY_GID, mGid)
|
||||
arg.putString(GalleryDetailScene.KEY_TOKEN, it)
|
||||
arg.putInt(GalleryDetailScene.KEY_PAGE, mPage)
|
||||
withUIContext {
|
||||
findNavController().popBackStack()
|
||||
navigate(R.id.galleryDetailScene, arg)
|
||||
}
|
||||
}.onFailure {
|
||||
mValid = false
|
||||
if (null != mViewTransition && null != mTip) {
|
||||
// Show tip
|
||||
mError = ExceptionUtils.getReadableString(it)
|
||||
withUIContext {
|
||||
mViewTransition!!.showView(1)
|
||||
mTip!!.text = mError
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@@ -162,43 +180,6 @@ class ProgressScene : BaseScene(), View.OnClickListener {
|
||||
}
|
||||
}
|
||||
|
||||
private fun onGetGalleryTokenSuccess(result: String) {
|
||||
val arg = Bundle()
|
||||
arg.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GID_TOKEN)
|
||||
arg.putLong(GalleryDetailScene.KEY_GID, mGid)
|
||||
arg.putString(GalleryDetailScene.KEY_TOKEN, result)
|
||||
arg.putInt(GalleryDetailScene.KEY_PAGE, mPage)
|
||||
findNavController().popBackStack()
|
||||
navigate(R.id.galleryDetailScene, arg)
|
||||
}
|
||||
|
||||
private fun onGetGalleryTokenFailure(e: Exception) {
|
||||
mValid = false
|
||||
val context = context
|
||||
if (null != context && null != mViewTransition && null != mTip) {
|
||||
// Show tip
|
||||
mError = ExceptionUtils.getReadableString(e)
|
||||
mViewTransition!!.showView(1)
|
||||
mTip!!.text = mError
|
||||
}
|
||||
}
|
||||
|
||||
private inner class GetGalleryTokenListener(
|
||||
context: Context,
|
||||
) : EhCallback<ProgressScene, String>(context) {
|
||||
override fun onSuccess(result: String) {
|
||||
val scene = this@ProgressScene
|
||||
scene.onGetGalleryTokenSuccess(result)
|
||||
}
|
||||
|
||||
override fun onFailure(e: Exception) {
|
||||
val scene = this@ProgressScene
|
||||
scene.onGetGalleryTokenFailure(e)
|
||||
}
|
||||
|
||||
override fun onCancel() {}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val KEY_ACTION = "action"
|
||||
const val ACTION_GALLERY_TOKEN = "gallery_token"
|
||||
|
||||
Reference in new issue
Block a user