refactor: 移除无用代码

This commit is contained in:
HuanCheng65 2022-08-07 16:57:35 +08:00
parent 00c52645ef
commit 26733cf6c3
No known key found for this signature in database
GPG Key ID: E9031EF91A805148
4 changed files with 11 additions and 24 deletions

View File

@ -31,7 +31,7 @@ import com.huanchengfly.tieba.post.adapters.ThreadHeaderAdapter
import com.huanchengfly.tieba.post.adapters.ThreadMainPostAdapter
import com.huanchengfly.tieba.post.adapters.ThreadReplyAdapter
import com.huanchengfly.tieba.post.api.TiebaApi
import com.huanchengfly.tieba.post.api.interfaces.CommonAPICallback
import com.huanchengfly.tieba.post.api.interfaces.CommonCallback
import com.huanchengfly.tieba.post.api.models.AgreeBean
import com.huanchengfly.tieba.post.api.models.CommonResponse
import com.huanchengfly.tieba.post.api.models.ThreadContentBean
@ -616,7 +616,7 @@ class ThreadActivity : BaseActivity(), View.OnClickListener, IThreadMenuFragment
}
}
private fun collect(commonAPICallback: CommonAPICallback<CommonResponse>?, update: Boolean) {
private fun collect(commonCallback: CommonCallback<CommonResponse>?, update: Boolean) {
if (dataBean == null || threadId == null) return
val postListItemBean = firstVisibleItem ?: return
TiebaApi.getInstance()
@ -624,9 +624,9 @@ class ThreadActivity : BaseActivity(), View.OnClickListener, IThreadMenuFragment
.enqueue(object : Callback<CommonResponse> {
override fun onFailure(call: Call<CommonResponse>, t: Throwable) {
if (t is TiebaException) {
commonAPICallback?.onFailure(t.code, t.message)
commonCallback?.onFailure(t.code, t.message)
} else {
commonAPICallback?.onFailure(-1, t.message)
commonCallback?.onFailure(-1, t.message)
}
}
@ -634,7 +634,7 @@ class ThreadActivity : BaseActivity(), View.OnClickListener, IThreadMenuFragment
call: Call<CommonResponse>,
response: Response<CommonResponse>
) {
commonAPICallback?.onSuccess(response.body()!!)
commonCallback?.onSuccess(response.body()!!)
}
})
@ -686,7 +686,7 @@ class ThreadActivity : BaseActivity(), View.OnClickListener, IThreadMenuFragment
DialogUtil.build(this)
.setMessage(R.string.message_update_store_floor)
.setPositiveButton(R.string.button_yes) { dialog: DialogInterface, _ ->
collect(object : CommonAPICallback<CommonResponse> {
collect(object : CommonCallback<CommonResponse> {
override fun onSuccess(data: CommonResponse) {
Toast.makeText(
this@ThreadActivity,
@ -994,7 +994,7 @@ class ThreadActivity : BaseActivity(), View.OnClickListener, IThreadMenuFragment
})
} else {
collect(object : CommonAPICallback<CommonResponse> {
collect(object : CommonCallback<CommonResponse> {
override fun onSuccess(data: CommonResponse) {
Toast.makeText(
this@ThreadActivity,

View File

@ -1,7 +0,0 @@
package com.huanchengfly.tieba.post.api.interfaces;
public interface CommonAPICallback<T> {
void onSuccess(T data);
void onFailure(int code, String error);
}

View File

@ -4,10 +4,10 @@ import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
interface ApiResult<Data> {
class Success<Data>(val data: Data) : ApiResult<Data>
sealed interface ApiResult<Data> {
data class Success<Data>(val data: Data) : ApiResult<Data>
class Failure<Data>(val error: Throwable) : ApiResult<Data>
data class Failure<Data>(val error: Throwable) : ApiResult<Data>
}
val ApiResult<*>.isSuccessful: Boolean

View File

@ -20,13 +20,7 @@ private class KeyEventManager<V : View> : View.OnKeyListener {
}
fun <V : View> V.bindKeyEvent(keyCode: Int, action: (V) -> Unit) {
val keyEventManager: KeyEventManager<V>
if (onKeyListener !is KeyEventManager<*>) {
keyEventManager = KeyEventManager()
setOnKeyListener(keyEventManager)
} else {
keyEventManager = onKeyListener as KeyEventManager<V>
}
val keyEventManager = getKeyEventManager()
keyEventManager.bindKeyEvent(keyCode, action)
}