From 23009f1da3f4564de7552ecdb43a53c35937a3e0 Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Sat, 22 Jul 2023 08:18:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=A5=BC=E4=B8=AD=E6=A5=BC=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E5=8A=A0=E8=BD=BD=E6=9B=B4=E5=A4=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/ui/page/subposts/SubPostsPage.kt | 8 ++++++-- .../post/ui/page/subposts/SubPostsViewModel.kt | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/subposts/SubPostsPage.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/subposts/SubPostsPage.kt index b94384a1..ec5927ec 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/subposts/SubPostsPage.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/subposts/SubPostsPage.kt @@ -173,9 +173,13 @@ internal fun SubPostsContent( prop1 = SubPostsUiState::currentPage, initial = 1 ) + val totalCount by viewModel.uiState.collectPartialAsState( + prop1 = SubPostsUiState::totalCount, + initial = 0 + ) val hasMore by viewModel.uiState.collectPartialAsState( prop1 = SubPostsUiState::hasMore, - initial = false + initial = true ) val lazyListState = rememberLazyListState() @@ -330,7 +334,7 @@ internal fun SubPostsContent( Text( text = stringResource( id = R.string.title_sub_posts_header, - subPosts.size + totalCount ), style = MaterialTheme.typography.subtitle1 ) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/subposts/SubPostsViewModel.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/subposts/SubPostsViewModel.kt index 5df752d4..5bfc1b23 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/subposts/SubPostsViewModel.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/subposts/SubPostsViewModel.kt @@ -74,9 +74,10 @@ class SubPostsViewModel @Inject constructor() : post.contentRenders, subPosts.wrapImmutable(), subPosts.map { it.content.renders }.toImmutableList(), - page.has_more == 1, + page.current_page < page.total_page, page.current_page, - page.total_page + page.total_page, + page.total_count ) } .onStart { emit(SubPostsPartialChange.Load.Start) } @@ -92,8 +93,10 @@ class SubPostsViewModel @Inject constructor() : SubPostsPartialChange.LoadMore.Success( subPosts.wrapImmutable(), subPosts.map { it.content.renders }.toImmutableList(), - page.has_more == 1, - page.current_page + page.current_page < page.total_page, + page.current_page, + page.total_page, + page.total_count, ) } .onStart { emit(SubPostsPartialChange.LoadMore.Start) } @@ -155,6 +158,7 @@ sealed interface SubPostsPartialChange : PartialChange { hasMore = hasMore, currentPage = currentPage, totalPage = totalPage, + totalCount = totalCount, forum = forum, post = post, postContentRenders = postContentRenders, @@ -177,6 +181,7 @@ sealed interface SubPostsPartialChange : PartialChange { val hasMore: Boolean, val currentPage: Int, val totalPage: Int, + val totalCount: Int, ) : Load() data class Failure(val throwable: Throwable) : Load() @@ -193,6 +198,8 @@ sealed interface SubPostsPartialChange : PartialChange { isLoading = false, hasMore = hasMore, currentPage = currentPage, + totalPage = totalPage, + totalCount = totalCount, subPosts = (oldState.subPosts + subPosts).toImmutableList(), subPostsContentRenders = (oldState.subPostsContentRenders + subPostsContentRenders).toImmutableList(), ) @@ -208,6 +215,8 @@ sealed interface SubPostsPartialChange : PartialChange { val subPostsContentRenders: ImmutableList>, val hasMore: Boolean, val currentPage: Int, + val totalPage: Int, + val totalCount: Int, ) : LoadMore() data class Failure(val throwable: Throwable) : LoadMore() @@ -287,6 +296,7 @@ data class SubPostsUiState( val hasMore: Boolean = true, val currentPage: Int = 1, val totalPage: Int = 1, + val totalCount: Int = 0, val forum: ImmutableHolder? = null, val post: ImmutableHolder? = null,