pref: 历史记录保存

This commit is contained in:
HuanCheng65 2023-07-18 22:19:58 +08:00
parent a5c32056c0
commit e5f4654e3e
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
1 changed files with 24 additions and 23 deletions

View File

@ -62,7 +62,6 @@ import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.material.rememberModalBottomSheetState import androidx.compose.material.rememberModalBottomSheetState
import androidx.compose.material.rememberScaffoldState import androidx.compose.material.rememberScaffoldState
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
@ -156,6 +155,7 @@ import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlin.concurrent.thread
import kotlin.math.max import kotlin.math.max
private fun getDescText( private fun getDescText(
@ -516,6 +516,9 @@ fun ThreadPage(
val hasThreadAgreed = remember(thread) { val hasThreadAgreed = remember(thread) {
thread?.get { agree?.hasAgree == 1 } == true thread?.get { agree?.hasAgree == 1 } == true
} }
val threadAgreeNum = remember(thread) {
thread?.get { agree?.diffAgreeNum } ?: 0L
}
val threadTitle = remember(thread) { val threadTitle = remember(thread) {
thread?.get { title } ?: "" thread?.get { title } ?: ""
} }
@ -669,34 +672,32 @@ fun ThreadPage(
} }
var savedHistory by remember { mutableStateOf(false) } var savedHistory by remember { mutableStateOf(false) }
DisposableEffect(threadId, threadTitle, author, lastVisibilityPostId) { LaunchedEffect(threadId, threadTitle, author, lastVisibilityPostId) {
val saveHistory = { val saveHistory = {
if (threadTitle.isNotBlank()) { thread {
HistoryUtil.saveHistory( if (threadTitle.isNotBlank()) {
History( HistoryUtil.saveHistory(
title = threadTitle, History(
data = threadId.toString(), title = threadTitle,
type = HistoryUtil.TYPE_THREAD, data = threadId.toString(),
extras = ThreadHistoryInfoBean( type = HistoryUtil.TYPE_THREAD,
pid = lastVisibilityPostId.toString(), extras = ThreadHistoryInfoBean(
isSeeLz = seeLz pid = lastVisibilityPostId.toString(),
).toJson(), isSeeLz = seeLz
avatar = StringUtil.getAvatarUrl(author?.get { portrait }), ).toJson(),
username = author?.get { nameShow } avatar = StringUtil.getAvatarUrl(author?.get { portrait }),
), username = author?.get { nameShow }
async = true ),
) async = true
savedHistory = true )
savedHistory = true
}
} }
} }
if (!savedHistory || lastVisibilityPostId != 0L) { if (!savedHistory || lastVisibilityPostId != 0L) {
saveHistory() saveHistory()
} }
onDispose {
saveHistory()
}
} }
val pullRefreshState = rememberPullRefreshState( val pullRefreshState = rememberPullRefreshState(
@ -1119,7 +1120,7 @@ fun ThreadPage(
} }
}, },
hasAgreed = hasThreadAgreed, hasAgreed = hasThreadAgreed,
agreeNum = thread?.get { agree?.diffAgreeNum } ?: 0L, agreeNum = threadAgreeNum,
modifier = Modifier.navigationBarsPadding() modifier = Modifier.navigationBarsPadding()
) )
} }