fix: 收藏 SnackBar 不显示
This commit is contained in:
parent
9f6d854572
commit
c4f9ad8718
|
|
@ -293,7 +293,7 @@ val Post.contentRenders: ImmutableList<PbContentRender>
|
||||||
get() {
|
get() {
|
||||||
val renders = content.renders
|
val renders = content.renders
|
||||||
|
|
||||||
renders.map {
|
return renders.map {
|
||||||
if (it is PicContentRender) {
|
if (it is PicContentRender) {
|
||||||
val data = getPhotoViewData(
|
val data = getPhotoViewData(
|
||||||
this,
|
this,
|
||||||
|
|
@ -305,7 +305,5 @@ val Post.contentRenders: ImmutableList<PbContentRender>
|
||||||
)
|
)
|
||||||
if (data != null) it.copy(photoViewData = wrapImmutable(data)) else it
|
if (data != null) it.copy(photoViewData = wrapImmutable(data)) else it
|
||||||
} else it
|
} else it
|
||||||
}
|
}.toImmutableList()
|
||||||
|
|
||||||
return renders.toImmutableList()
|
|
||||||
}
|
}
|
||||||
|
|
@ -3,9 +3,12 @@ package com.huanchengfly.tieba.post.arch
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.DisposableEffect
|
import androidx.compose.runtime.DisposableEffect
|
||||||
|
import androidx.compose.runtime.InternalComposeApi
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.State
|
import androidx.compose.runtime.State
|
||||||
|
import androidx.compose.runtime.currentComposer
|
||||||
import androidx.compose.runtime.produceState
|
import androidx.compose.runtime.produceState
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
|
|
@ -14,6 +17,7 @@ import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.lifecycle.flowWithLifecycle
|
import androidx.lifecycle.flowWithLifecycle
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
@ -79,19 +83,20 @@ inline fun <reified Event : UiEvent> Flow<UiEvent>.onEvent(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(InternalComposeApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
inline fun <reified Event : UiEvent> BaseViewModel<*, *, *, *>.onEvent(
|
inline fun <reified Event : UiEvent> BaseViewModel<*, *, *, *>.onEvent(
|
||||||
noinline listener: suspend (Event) -> Unit
|
noinline listener: suspend (Event) -> Unit
|
||||||
) {
|
) {
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val applyContext = currentComposer.applyCoroutineContext
|
||||||
|
val coroutineScope = remember(applyContext) { CoroutineScope(applyContext) }
|
||||||
DisposableEffect(key1 = listener, key2 = this) {
|
DisposableEffect(key1 = listener, key2 = this) {
|
||||||
with(coroutineScope) {
|
val job = coroutineScope.launch {
|
||||||
val job = launch {
|
|
||||||
uiEventFlow
|
uiEventFlow
|
||||||
.filterIsInstance<Event>()
|
.filterIsInstance<Event>()
|
||||||
.cancellable()
|
.cancellable()
|
||||||
.collect {
|
.collect {
|
||||||
launch {
|
coroutineScope.launch {
|
||||||
listener(it)
|
listener(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -99,7 +104,6 @@ inline fun <reified Event : UiEvent> BaseViewModel<*, *, *, *>.onEvent(
|
||||||
|
|
||||||
onDispose { job.cancel() }
|
onDispose { job.cancel() }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,11 @@ object PbPageRepository {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val firstPost = postList.firstOrNull { it.floor == 1 }
|
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(
|
response.copy(
|
||||||
data_ = response.data_.copy(
|
data_ = response.data_.copy(
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,8 @@ fun getPhotoViewData(
|
||||||
picUrl: String,
|
picUrl: String,
|
||||||
originUrl: String,
|
originUrl: String,
|
||||||
showOriginBtn: Boolean,
|
showOriginBtn: Boolean,
|
||||||
originSize: Int
|
originSize: Int,
|
||||||
|
seeLz: Boolean = false
|
||||||
): PhotoViewData? {
|
): PhotoViewData? {
|
||||||
if (post.from_forum == null) return null
|
if (post.from_forum == null) return null
|
||||||
return PhotoViewData(
|
return PhotoViewData(
|
||||||
|
|
@ -28,7 +29,8 @@ fun getPhotoViewData(
|
||||||
postId = post.id,
|
postId = post.id,
|
||||||
objType = "pb",
|
objType = "pb",
|
||||||
picId = picId,
|
picId = picId,
|
||||||
picIndex = 1
|
picIndex = 1,
|
||||||
|
seeLz = seeLz
|
||||||
),
|
),
|
||||||
picItems = listOf(
|
picItems = listOf(
|
||||||
PicItem(
|
PicItem(
|
||||||
|
|
@ -51,6 +53,7 @@ fun getImmutablePhotoViewData(
|
||||||
return wrapImmutable(getPhotoViewData(threadInfo, index))
|
return wrapImmutable(getPhotoViewData(threadInfo, index))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun getPhotoViewData(
|
fun getPhotoViewData(
|
||||||
threadInfo: ThreadInfo,
|
threadInfo: ThreadInfo,
|
||||||
index: Int
|
index: Int
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue