diff --git a/app/src/main/java/com/huanchengfly/tieba/post/activities/ThreadActivity.kt b/app/src/main/java/com/huanchengfly/tieba/post/activities/ThreadActivity.kt index 84886a11..091a73f6 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/activities/ThreadActivity.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/activities/ThreadActivity.kt @@ -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?, update: Boolean) { if (dataBean == null || threadId == null) return val postListItemBean = firstVisibleItem ?: return - TiebaApi.getInstance() - .addStore(threadId!!, postListItemBean.id!!, tbs = dataBean!!.anti?.tbs!!) - .enqueue(object : Callback { - override fun onFailure(call: Call, t: Throwable) { - if (t is TiebaException) { - commonCallback?.onFailure(t.code, t.message) - } else { - commonCallback?.onFailure(-1, t.message) - } + launchIO { + TiebaApi.getInstance() + .addStoreAsync(threadId!!.toLong(), postListItemBean.id!!.toLong()) + .doIfSuccess { + commonCallback?.onSuccess(it) } - - override fun onResponse( - call: Call, - response: Response - ) { - commonCallback?.onSuccess(response.body()!!) + .doIfFailure { + commonCallback?.onFailure(it.getErrorCode(), it.getErrorMessage()) } - - }) + } if (!update) Util.miuiFav( this, getString(R.string.title_miui_fav, dataBean!!.thread?.title), diff --git a/app/src/main/java/com/huanchengfly/tieba/post/api/interfaces/ITiebaApi.kt b/app/src/main/java/com/huanchengfly/tieba/post/api/interfaces/ITiebaApi.kt index c6e4706b..1fc68153 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/api/interfaces/ITiebaApi.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/api/interfaces/ITiebaApi.kt @@ -571,6 +571,19 @@ interface ITiebaApi { tbs: String ): Call + /** + * 添加/更新收藏 + * + * **需登录** + * + * @param threadId 贴子 ID + * @param postId 收藏到的回复 ID + */ + fun addStoreAsync( + threadId: Long, + postId: Long + ): Deferred> + /** * 添加/更新收藏 * diff --git a/app/src/main/java/com/huanchengfly/tieba/post/api/interfaces/impls/MixedTiebaApiImpl.kt b/app/src/main/java/com/huanchengfly/tieba/post/api/interfaces/impls/MixedTiebaApiImpl.kt index 091d8b19..1823a704 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/api/interfaces/impls/MixedTiebaApiImpl.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/api/interfaces/impls/MixedTiebaApiImpl.kt @@ -435,6 +435,17 @@ object MixedTiebaApiImpl : ITiebaApi { tbs ) + override fun addStoreAsync(threadId: Long, postId: Long): Deferred> = + RetrofitTiebaApi.OFFICIAL_TIEBA_API.addStoreAsync( + listOf( + NewCollectDataBean( + threadId.toString(), + postId.toString(), + status = 1 + ) + ).toJson() + ) + override fun addStoreFlow(threadId: Long, postId: Long): Flow = RetrofitTiebaApi.OFFICIAL_TIEBA_API.addStoreFlow( listOf( diff --git a/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interfaces/OfficialTiebaApi.kt b/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interfaces/OfficialTiebaApi.kt index 271fc8d0..02055620 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interfaces/OfficialTiebaApi.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interfaces/OfficialTiebaApi.kt @@ -423,6 +423,20 @@ interface OfficialTiebaApi { @retrofit2.http.Header("client_user_token") client_user_token: String? = user_id, ): Flow + @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> + @POST("/c/c/post/addstore") @FormUrlEncoded @Headers(