From 877d1e4aa397365602ac23fae341ac57237b9457 Mon Sep 17 00:00:00 2001 From: HuanCheng65 <609486518@qq.com> Date: Fri, 3 Dec 2021 20:37:35 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20Dev=206=20=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tieba/post/api/interfaces/ITiebaApi.kt | 15 +++++++++ .../api/interfaces/impls/MixedTiebaApiImpl.kt | 13 ++++++++ .../api/retrofit/interfaces/MiniTiebaApi.kt | 17 ++++++++++ .../tieba/post/fragments/ForumFragment.kt | 32 +++++++++---------- application.properties | 4 +-- 5 files changed, 62 insertions(+), 19 deletions(-) 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 7d794994..7e475017 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 @@ -80,6 +80,21 @@ interface ITiebaApi { goodClassifyId: String? = null ): Call + /** + * 吧页面(异步) + * + * @param forumName 吧名 + * @param page 分页页码(从 1 开始) + * @param sortType 排序类型 [com.huanchengfly.tieba.api.ForumSortType] + * @param goodClassifyId 精品贴分类 ID + */ + fun forumPageAsync( + forumName: String, + page: Int = 1, + sortType: ForumSortType = ForumSortType.REPLY_TIME, + goodClassifyId: String? = null + ): 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 ac5bf79b..13da2afc 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 @@ -50,6 +50,19 @@ object MixedTiebaApiImpl : ITiebaApi { ): Call = RetrofitTiebaApi.MINI_TIEBA_API.forumPage(forumName, page, sortType.value, goodClassifyId) + override fun forumPageAsync( + forumName: String, + page: Int, + sortType: ForumSortType, + goodClassifyId: String? + ): Deferred> = + RetrofitTiebaApi.MINI_TIEBA_API.forumPageAsync( + forumName, + page, + sortType.value, + goodClassifyId + ) + override fun floor( threadId: String, page: Int, postId: String?, subPostId: String? ): Call = diff --git a/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interfaces/MiniTiebaApi.kt b/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interfaces/MiniTiebaApi.kt index 6583410a..1d2851b3 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interfaces/MiniTiebaApi.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interfaces/MiniTiebaApi.kt @@ -115,6 +115,23 @@ interface MiniTiebaApi { @Field("scr_w") scr_w: String = getScreenWidth().toString() ): Call + @POST("/c/f/frs/page") + @FormUrlEncoded + fun forumPageAsync( + @Field("kw") forumName: String, + @Field("pn") page: Int = 1, + @Field("sort_type") sort_type: Int, + @Field("cid") goodClassifyId: String? = null, + @Field("is_good") is_good: String? = if (TextUtils.isEmpty(goodClassifyId)) null else "1", + @Field("q_type") q_type: String = "2", + @Field("st_type") st_type: String = "tb_forumlist", + @Field("with_group") with_group: String = "0", + @Field("rn") rn: String = "20", + @Field("scr_dip") scr_dip: String = ScreenInfo.DENSITY.toString(), + @Field("scr_h") scr_h: String = getScreenHeight().toString(), + @Field("scr_w") scr_w: String = getScreenWidth().toString() + ): Deferred> + @POST("/c/f/pb/floor") @FormUrlEncoded fun floor( diff --git a/app/src/main/java/com/huanchengfly/tieba/post/fragments/ForumFragment.kt b/app/src/main/java/com/huanchengfly/tieba/post/fragments/ForumFragment.kt index 91207a8a..0229b36e 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/fragments/ForumFragment.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/fragments/ForumFragment.kt @@ -18,6 +18,8 @@ import com.huanchengfly.tieba.post.api.ForumSortType import com.huanchengfly.tieba.post.api.ForumSortType.Companion.valueOf import com.huanchengfly.tieba.post.api.TiebaApi import com.huanchengfly.tieba.post.api.models.ForumPageBean +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.components.dividers.ForumDivider import com.huanchengfly.tieba.post.interfaces.OnSwitchListener @@ -172,25 +174,21 @@ class ForumFragment : BaseFragment(), Refreshable, OnSwitchListener, ScrollTopab } private fun loadMore() { - TiebaApi.getInstance().forumPage(forumName!!, page + 1, sortType, classifyId) - .enqueue(object : Callback { - override fun onFailure(call: Call, t: Throwable) { + launchIO { + TiebaApi.getInstance() + .forumPageAsync(forumName!!, page + 1, sortType, classifyId) + .doIfSuccess { + page += 1 + mRefreshLayout.finishLoadMore() + mDataBean = it + pageSize = it.page?.pageSize?.toInt() ?: 0 + forumAdapter.addData(it) + mRefreshLayout.setNoMoreData(it.page?.hasMore == "0") + } + .doIfFailure { mRefreshLayout.finishLoadMore(false) } - - override fun onResponse( - call: Call, - response: Response - ) { - page += 1 - val forumPageBean = response.body()!! - mRefreshLayout.finishLoadMore() - mDataBean = forumPageBean - pageSize = forumPageBean.page?.pageSize?.toInt()!! - forumAdapter.addData(forumPageBean) - mRefreshLayout.setNoMoreData(mDataBean!!.page?.hasMore == "0") - } - }) + } } fun refresh() { diff --git a/application.properties b/application.properties index 4aa88e46..d63e24fa 100644 --- a/application.properties +++ b/application.properties @@ -1,5 +1,5 @@ -versionCode=38300 +versionCode=39006 versionName=4.0.0 isPerRelease=true preReleaseName=dev -preReleaseVer=5 \ No newline at end of file +preReleaseVer=6 \ No newline at end of file