From c4f9ad8718c8721233196fb80759138fdf6df912 Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Thu, 13 Jul 2023 23:14:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=94=B6=E8=97=8F=20SnackBar=20?= =?UTF-8?q?=E4=B8=8D=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/huanchengfly/tieba/post/api/Utils.kt | 6 ++-- .../tieba/post/arch/Extensions.kt | 30 +++++++++++-------- .../tieba/post/repository/PbPageRepository.kt | 6 +++- .../tieba/post/ui/utils/PhotoViewUtils.kt | 7 +++-- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/api/Utils.kt b/app/src/main/java/com/huanchengfly/tieba/post/api/Utils.kt index 8a1ab56c..bb256533 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/api/Utils.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/api/Utils.kt @@ -293,7 +293,7 @@ val Post.contentRenders: ImmutableList get() { val renders = content.renders - renders.map { + return renders.map { if (it is PicContentRender) { val data = getPhotoViewData( this, @@ -305,7 +305,5 @@ val Post.contentRenders: ImmutableList ) if (data != null) it.copy(photoViewData = wrapImmutable(data)) else it } else it - } - - return renders.toImmutableList() + }.toImmutableList() } \ No newline at end of file diff --git a/app/src/main/java/com/huanchengfly/tieba/post/arch/Extensions.kt b/app/src/main/java/com/huanchengfly/tieba/post/arch/Extensions.kt index 8a1ab214..d4fc4e66 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/arch/Extensions.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/arch/Extensions.kt @@ -3,9 +3,12 @@ package com.huanchengfly.tieba.post.arch import android.util.Log import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect +import androidx.compose.runtime.InternalComposeApi import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.State +import androidx.compose.runtime.currentComposer import androidx.compose.runtime.produceState +import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.platform.LocalContext import androidx.hilt.navigation.compose.hiltViewModel @@ -14,6 +17,7 @@ import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.flowWithLifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.viewModelScope +import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.flow.Flow @@ -79,26 +83,26 @@ inline fun Flow.onEvent( } } +@OptIn(InternalComposeApi::class) @Composable inline fun BaseViewModel<*, *, *, *>.onEvent( noinline listener: suspend (Event) -> Unit ) { - val coroutineScope = rememberCoroutineScope() + val applyContext = currentComposer.applyCoroutineContext + val coroutineScope = remember(applyContext) { CoroutineScope(applyContext) } DisposableEffect(key1 = listener, key2 = this) { - with(coroutineScope) { - val job = launch { - uiEventFlow - .filterIsInstance() - .cancellable() - .collect { - launch { - listener(it) - } + val job = coroutineScope.launch { + uiEventFlow + .filterIsInstance() + .cancellable() + .collect { + coroutineScope.launch { + listener(it) } - } - - onDispose { job.cancel() } + } } + + onDispose { job.cancel() } } } diff --git a/app/src/main/java/com/huanchengfly/tieba/post/repository/PbPageRepository.kt b/app/src/main/java/com/huanchengfly/tieba/post/repository/PbPageRepository.kt index 5f369e4a..6dd8123a 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/repository/PbPageRepository.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/repository/PbPageRepository.kt @@ -58,7 +58,11 @@ object PbPageRepository { ) } val firstPost = postList.firstOrNull { it.floor == 1 } - ?: response.data_.first_floor_post?.copy(author = response.data_.thread.author) + ?: response.data_.first_floor_post?.copy( + author = response.data_.thread.author, + from_forum = response.data_.forum, + tid = response.data_.thread.id, + ) response.copy( data_ = response.data_.copy( diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/utils/PhotoViewUtils.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/utils/PhotoViewUtils.kt index dce1bdba..0ff6722d 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/utils/PhotoViewUtils.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/utils/PhotoViewUtils.kt @@ -17,7 +17,8 @@ fun getPhotoViewData( picUrl: String, originUrl: String, showOriginBtn: Boolean, - originSize: Int + originSize: Int, + seeLz: Boolean = false ): PhotoViewData? { if (post.from_forum == null) return null return PhotoViewData( @@ -28,7 +29,8 @@ fun getPhotoViewData( postId = post.id, objType = "pb", picId = picId, - picIndex = 1 + picIndex = 1, + seeLz = seeLz ), picItems = listOf( PicItem( @@ -51,6 +53,7 @@ fun getImmutablePhotoViewData( return wrapImmutable(getPhotoViewData(threadInfo, index)) } + fun getPhotoViewData( threadInfo: ThreadInfo, index: Int