From bb833413357235440840ff81ff21df49e00c7191 Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Sun, 23 Jul 2023 20:01:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=98=85=E8=AF=BB=E6=A5=BC=E5=B1=82?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tieba/post/ui/page/thread/ThreadPage.kt | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/thread/ThreadPage.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/thread/ThreadPage.kt index b6562cce..a8507d7f 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/thread/ThreadPage.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/thread/ThreadPage.kt @@ -541,20 +541,18 @@ fun ThreadPage( initialValue = ModalBottomSheetValue.Hidden, skipHalfExpanded = true ) - val getLastVisibilityPost = { - data.firstOrNull { (post) -> - lazyListState.layoutInfo.visibleItemsInfo.lastOrNull { info -> info.key is Long }?.key as Long? == post.get { id } - }?.post ?: firstPost - } val lastVisibilityPost by remember { derivedStateOf { data.firstOrNull { (post) -> - lazyListState.layoutInfo.visibleItemsInfo.lastOrNull { info -> info.key is Long }?.key as Long? == post.get { id } + val lastPostKey = lazyListState.layoutInfo.visibleItemsInfo.lastOrNull { info -> + info.key is String && (info.key as String).startsWith("Post") + }?.key as String? + lastPostKey?.endsWith(post.get { id }.toString()) == true }?.post ?: firstPost } } - val lastVisibilityPostId = remember(lastVisibilityPost) { - lastVisibilityPost?.get { id } ?: 0L + val lastVisibilityPostId by remember { + derivedStateOf { lastVisibilityPost?.get { id } ?: 0L } } val coroutineScope = rememberCoroutineScope() val context = LocalContext.current @@ -630,11 +628,10 @@ fun ThreadPage( dialogState = updateCollectMarkDialogState, onConfirm = { coroutineScope.launch { - val readPostId = getLastVisibilityPost()?.get { id } ?: 0L navigator.navigateUp() - if (readPostId != 0L) { + if (lastVisibilityPostId != 0L) { TiebaApi.getInstance() - .addStoreFlow(threadId, postId) + .addStoreFlow(threadId, lastVisibilityPostId) .catch { context.toastShort( R.string.message_update_collect_mark_failed, @@ -657,7 +654,7 @@ fun ThreadPage( enabled = isCollected && !bottomSheetState.isVisible, currentScreen = ThreadPageDestination ) { - readFloorBeforeBack = getLastVisibilityPost()?.get { floor } ?: 0 + readFloorBeforeBack = lastVisibilityPost?.get { floor } ?: 0 if (readFloorBeforeBack != 0) { updateCollectMarkDialogState.show() } else {