fix: 收藏 SnackBar 不显示

This commit is contained in:
HuanCheng65 2023-07-13 23:14:16 +08:00
parent 9f6d854572
commit c4f9ad8718
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
4 changed files with 29 additions and 20 deletions

View File

@ -293,7 +293,7 @@ val Post.contentRenders: ImmutableList<PbContentRender>
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<PbContentRender>
)
if (data != null) it.copy(photoViewData = wrapImmutable(data)) else it
} else it
}
return renders.toImmutableList()
}.toImmutableList()
}

View File

@ -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,19 +83,20 @@ inline fun <reified Event : UiEvent> Flow<UiEvent>.onEvent(
}
}
@OptIn(InternalComposeApi::class)
@Composable
inline fun <reified Event : UiEvent> 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 {
val job = coroutineScope.launch {
uiEventFlow
.filterIsInstance<Event>()
.cancellable()
.collect {
launch {
coroutineScope.launch {
listener(it)
}
}
@ -99,7 +104,6 @@ inline fun <reified Event : UiEvent> BaseViewModel<*, *, *, *>.onEvent(
onDispose { job.cancel() }
}
}
}
@Composable

View File

@ -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(

View File

@ -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