fix: 收藏未知错误
This commit is contained in:
parent
2edc0f249b
commit
d0ad2a6a02
|
|
@ -39,6 +39,7 @@ import com.huanchengfly.tieba.post.api.models.ThreadContentBean.PostListItemBean
|
|||
import com.huanchengfly.tieba.post.api.retrofit.doIfFailure
|
||||
import com.huanchengfly.tieba.post.api.retrofit.doIfSuccess
|
||||
import com.huanchengfly.tieba.post.api.retrofit.exception.TiebaException
|
||||
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorCode
|
||||
import com.huanchengfly.tieba.post.api.retrofit.exception.getErrorMessage
|
||||
import com.huanchengfly.tieba.post.components.FillVirtualLayoutManager
|
||||
import com.huanchengfly.tieba.post.components.dialogs.EditTextDialog
|
||||
|
|
@ -613,25 +614,16 @@ class ThreadActivity : BaseActivity(), View.OnClickListener, IThreadMenuFragment
|
|||
private fun collect(commonCallback: CommonCallback<CommonResponse>?, update: Boolean) {
|
||||
if (dataBean == null || threadId == null) return
|
||||
val postListItemBean = firstVisibleItem ?: return
|
||||
launchIO {
|
||||
TiebaApi.getInstance()
|
||||
.addStore(threadId!!, postListItemBean.id!!, tbs = dataBean!!.anti?.tbs!!)
|
||||
.enqueue(object : Callback<CommonResponse> {
|
||||
override fun onFailure(call: Call<CommonResponse>, t: Throwable) {
|
||||
if (t is TiebaException) {
|
||||
commonCallback?.onFailure(t.code, t.message)
|
||||
} else {
|
||||
commonCallback?.onFailure(-1, t.message)
|
||||
.addStoreAsync(threadId!!.toLong(), postListItemBean.id!!.toLong())
|
||||
.doIfSuccess {
|
||||
commonCallback?.onSuccess(it)
|
||||
}
|
||||
.doIfFailure {
|
||||
commonCallback?.onFailure(it.getErrorCode(), it.getErrorMessage())
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResponse(
|
||||
call: Call<CommonResponse>,
|
||||
response: Response<CommonResponse>
|
||||
) {
|
||||
commonCallback?.onSuccess(response.body()!!)
|
||||
}
|
||||
|
||||
})
|
||||
if (!update) Util.miuiFav(
|
||||
this,
|
||||
getString(R.string.title_miui_fav, dataBean!!.thread?.title),
|
||||
|
|
|
|||
|
|
@ -571,6 +571,19 @@ interface ITiebaApi {
|
|||
tbs: String
|
||||
): Call<CommonResponse>
|
||||
|
||||
/**
|
||||
* 添加/更新收藏
|
||||
*
|
||||
* **需登录**
|
||||
*
|
||||
* @param threadId 贴子 ID
|
||||
* @param postId 收藏到的回复 ID
|
||||
*/
|
||||
fun addStoreAsync(
|
||||
threadId: Long,
|
||||
postId: Long
|
||||
): Deferred<ApiResult<CommonResponse>>
|
||||
|
||||
/**
|
||||
* 添加/更新收藏
|
||||
*
|
||||
|
|
|
|||
|
|
@ -435,6 +435,17 @@ object MixedTiebaApiImpl : ITiebaApi {
|
|||
tbs
|
||||
)
|
||||
|
||||
override fun addStoreAsync(threadId: Long, postId: Long): Deferred<ApiResult<CommonResponse>> =
|
||||
RetrofitTiebaApi.OFFICIAL_TIEBA_API.addStoreAsync(
|
||||
listOf(
|
||||
NewCollectDataBean(
|
||||
threadId.toString(),
|
||||
postId.toString(),
|
||||
status = 1
|
||||
)
|
||||
).toJson()
|
||||
)
|
||||
|
||||
override fun addStoreFlow(threadId: Long, postId: Long): Flow<CommonResponse> =
|
||||
RetrofitTiebaApi.OFFICIAL_TIEBA_API.addStoreFlow(
|
||||
listOf(
|
||||
|
|
|
|||
|
|
@ -423,6 +423,20 @@ interface OfficialTiebaApi {
|
|||
@retrofit2.http.Header("client_user_token") client_user_token: String? = user_id,
|
||||
): Flow<CommonResponse>
|
||||
|
||||
@POST("/c/c/post/addstore")
|
||||
@FormUrlEncoded
|
||||
@Headers(
|
||||
"${Header.FORCE_LOGIN}: ${Header.FORCE_LOGIN_TRUE}",
|
||||
"${Header.COOKIE}: ka=open",
|
||||
"${Header.DROP_HEADERS}: ${Header.CHARSET},${Header.CLIENT_TYPE}",
|
||||
"${Header.NO_COMMON_PARAMS}: ${Param.OAID}",
|
||||
)
|
||||
fun addStoreAsync(
|
||||
@Field("data") data: String,
|
||||
@Field("stoken") stoken: String = AccountUtil.getSToken()!!,
|
||||
@retrofit2.http.Header("client_user_token") client_user_token: String? = AccountUtil.getUid(),
|
||||
): Deferred<ApiResult<CommonResponse>>
|
||||
|
||||
@POST("/c/c/post/addstore")
|
||||
@FormUrlEncoded
|
||||
@Headers(
|
||||
|
|
|
|||
Loading…
Reference in New Issue