Kill EhCallback
This commit is contained in:
1 parent
d200dd9cbe
commit
eb5f39def7
3 files changed
+41
-132
No files matched your search
@@ -50,12 +50,6 @@ object EhClient {
|
||||
params[0] as String,
|
||||
)
|
||||
|
||||
METHOD_MODIFY_FAVORITES -> EhEngine.modifyFavorites(
|
||||
params[0] as String,
|
||||
params[1] as LongArray,
|
||||
params[2] as Int,
|
||||
)
|
||||
|
||||
METHOD_GET_TORRENT_LIST -> EhEngine.getTorrentList(
|
||||
params[0] as String,
|
||||
params[1] as Long,
|
||||
@@ -79,7 +73,6 @@ object EhClient {
|
||||
}
|
||||
|
||||
const val METHOD_GET_FAVORITES = 8
|
||||
const val METHOD_MODIFY_FAVORITES = 11
|
||||
const val METHOD_GET_TORRENT_LIST = 12
|
||||
const val METHOD_ARCHIVE_LIST = 17
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 Hippo Seven
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.hippo.ehviewer.ui.scene
|
||||
|
||||
import android.content.Context
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.hippo.ehviewer.EhApplication
|
||||
import com.hippo.ehviewer.client.EhClient
|
||||
import com.hippo.ehviewer.ui.MainActivity
|
||||
|
||||
abstract class EhCallback<E : Fragment?, T>(context: Context) : EhClient.Callback<T> {
|
||||
val application: EhApplication
|
||||
|
||||
init {
|
||||
application = context.applicationContext as EhApplication
|
||||
}
|
||||
|
||||
val content: Context
|
||||
get() {
|
||||
var context: Context? = application.topActivity
|
||||
if (context == null) {
|
||||
context = application
|
||||
}
|
||||
return context
|
||||
}
|
||||
|
||||
fun showTip(@StringRes id: Int, length: Int) {
|
||||
val activity = application.topActivity
|
||||
if (activity is MainActivity) {
|
||||
activity.showTip(id, length)
|
||||
} else {
|
||||
Toast.makeText(
|
||||
application,
|
||||
id,
|
||||
if (length == BaseScene.LENGTH_LONG) Toast.LENGTH_LONG else Toast.LENGTH_SHORT,
|
||||
).show()
|
||||
}
|
||||
}
|
||||
|
||||
fun showTip(tip: String, length: Int) {
|
||||
val activity = application.topActivity
|
||||
if (activity is MainActivity) {
|
||||
activity.showTip(tip, length)
|
||||
} else {
|
||||
Toast.makeText(
|
||||
application,
|
||||
tip,
|
||||
if (length == BaseScene.LENGTH_LONG) Toast.LENGTH_LONG else Toast.LENGTH_SHORT,
|
||||
).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,6 @@ package com.hippo.ehviewer.ui.scene
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.content.res.Resources
|
||||
import android.os.Bundle
|
||||
@@ -53,7 +52,6 @@ import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.WindowInsetsAnimationHelper
|
||||
import com.hippo.ehviewer.client.EhClient
|
||||
import com.hippo.ehviewer.client.EhEngine
|
||||
import com.hippo.ehviewer.client.EhRequest
|
||||
import com.hippo.ehviewer.client.EhUrl
|
||||
import com.hippo.ehviewer.client.data.FavListUrlBuilder
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo
|
||||
@@ -656,7 +654,7 @@ class FavoritesScene :
|
||||
}
|
||||
}
|
||||
|
||||
private fun onGetFavoritesFailure(e: Exception, taskId: Int) {
|
||||
private fun onGetFavoritesFailure(e: Throwable, taskId: Int) {
|
||||
if (mHelper != null && mHelper!!.isCurrentTask(taskId)) {
|
||||
mHelper!!.onGetException(taskId, e)
|
||||
}
|
||||
@@ -694,37 +692,6 @@ class FavoritesScene :
|
||||
}
|
||||
}
|
||||
|
||||
private inner class GetFavoritesListener(
|
||||
context: Context,
|
||||
private val mTaskId: Int, // Local fav is shown now, but operation need be done for cloud fav
|
||||
private val mLocal: Boolean,
|
||||
private val mKeyword: String?,
|
||||
) : EhCallback<FavoritesScene?, FavoritesParser.Result>(context) {
|
||||
override fun onSuccess(result: FavoritesParser.Result) {
|
||||
// Put fav cat
|
||||
Settings.putFavCat(result.catArray)
|
||||
Settings.putFavCount(result.countArray)
|
||||
val scene = this@FavoritesScene
|
||||
if (mLocal) {
|
||||
scene.onGetFavoritesLocal(mKeyword, mTaskId)
|
||||
} else {
|
||||
scene.onGetFavoritesSuccess(result, mTaskId)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(e: Exception) {
|
||||
val scene = this@FavoritesScene
|
||||
if (mLocal) {
|
||||
e.printStackTrace()
|
||||
scene.onGetFavoritesLocal(mKeyword, mTaskId)
|
||||
} else {
|
||||
scene.onGetFavoritesFailure(e, mTaskId)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCancel() {}
|
||||
}
|
||||
|
||||
private inner class FavDrawerAdapter(private val mInflater: LayoutInflater) :
|
||||
RecyclerView.Adapter<FavDrawerHolder>() {
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
@@ -943,18 +910,31 @@ class FavoritesScene :
|
||||
mUrlBuilder!!.build()
|
||||
}
|
||||
mUrlBuilder!!.setIndex(index, true)
|
||||
val request = EhRequest()
|
||||
request.setMethod(EhClient.METHOD_MODIFY_FAVORITES)
|
||||
request.setCallback(
|
||||
GetFavoritesListener(
|
||||
context,
|
||||
taskId,
|
||||
local,
|
||||
mUrlBuilder!!.keyword,
|
||||
),
|
||||
)
|
||||
request.setArgs(url, gidArray, mModifyFavCat)
|
||||
request.enqueue(this@FavoritesScene)
|
||||
lifecycleScope.launchIO {
|
||||
runSuspendCatching {
|
||||
EhEngine.modifyFavorites(url, gidArray, mModifyFavCat)
|
||||
}.onSuccess { result ->
|
||||
// Put fav cat
|
||||
Settings.putFavCat(result.catArray)
|
||||
Settings.putFavCount(result.countArray)
|
||||
withUIContext {
|
||||
if (local) {
|
||||
onGetFavoritesLocal(mUrlBuilder?.keyword, taskId)
|
||||
} else {
|
||||
onGetFavoritesSuccess(result, taskId)
|
||||
}
|
||||
}
|
||||
}.onFailure {
|
||||
it.printStackTrace()
|
||||
withUIContext {
|
||||
if (local) {
|
||||
onGetFavoritesLocal(mUrlBuilder?.keyword, taskId)
|
||||
} else {
|
||||
onGetFavoritesFailure(it, taskId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (mUrlBuilder!!.favCat == FavListUrlBuilder.FAV_CAT_LOCAL) {
|
||||
val keyword = mUrlBuilder!!.keyword
|
||||
@@ -963,18 +943,21 @@ class FavoritesScene :
|
||||
mUrlBuilder!!.setIndex(index, isNext)
|
||||
mUrlBuilder!!.jumpTo = jumpTo
|
||||
val url = mUrlBuilder!!.build()
|
||||
val request = EhRequest()
|
||||
request.setMethod(EhClient.METHOD_GET_FAVORITES)
|
||||
request.setCallback(
|
||||
GetFavoritesListener(
|
||||
context,
|
||||
taskId,
|
||||
false,
|
||||
mUrlBuilder!!.keyword,
|
||||
),
|
||||
)
|
||||
request.setArgs(url)
|
||||
request.enqueue(this@FavoritesScene)
|
||||
lifecycleScope.launchIO {
|
||||
runSuspendCatching {
|
||||
EhEngine.getFavorites(url)
|
||||
}.onSuccess { result ->
|
||||
Settings.putFavCat(result.catArray)
|
||||
Settings.putFavCount(result.countArray)
|
||||
withUIContext {
|
||||
onGetFavoritesSuccess(result, taskId)
|
||||
}
|
||||
}.onFailure {
|
||||
withUIContext {
|
||||
onGetFavoritesFailure(it, taskId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user