From 20651f5add5d7bb3a7282ba8b948470662ec600e Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Wed, 1 Feb 2023 13:16:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=90=A7=E9=A1=B5=E9=9D=A2=E9=97=AA?= =?UTF-8?q?=E9=80=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/page/forum/threadlist/ForumThreadListViewModel.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/threadlist/ForumThreadListViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/threadlist/ForumThreadListViewModel.kt index 857a9586..263b839b 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/threadlist/ForumThreadListViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/forum/threadlist/ForumThreadListViewModel.kt @@ -25,6 +25,7 @@ import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.merge import kotlinx.coroutines.flow.onStart import javax.inject.Inject +import kotlin.math.min abstract class ForumThreadListViewModel : BaseViewModel() { @@ -140,12 +141,13 @@ private class ForumThreadListPartialChangeProducer(val type: ForumThreadListType private fun ForumThreadListUiIntent.LoadMore.producePartialChange(): Flow { val flow = if (threadListIds.isNotEmpty()) { + val size = min(threadListIds.size, 30) TiebaApi.getInstance().threadList( forumId, forumName, currentPage, sortType, - threadListIds.subList(0, 30).joinToString(separator = ",") { "$it" } + threadListIds.subList(0, size).joinToString(separator = ",") { "$it" } ).map { response -> if (response.data_ == null) ForumThreadListPartialChange.LoadMore.Failure( NullPointerException("未知错误") @@ -157,7 +159,7 @@ private class ForumThreadListPartialChangeProducer(val type: ForumThreadListType } ForumThreadListPartialChange.LoadMore.Success( threadList = threadList, - threadListIds = threadListIds.drop(30), + threadListIds = threadListIds.drop(size), currentPage = currentPage, hasMore = threadList.isNotEmpty() )