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,8 +672,9 @@ 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 = {
thread {
if (threadTitle.isNotBlank()) { if (threadTitle.isNotBlank()) {
HistoryUtil.saveHistory( HistoryUtil.saveHistory(
History( History(
@ -689,12 +693,9 @@ fun ThreadPage(
savedHistory = true savedHistory = true
} }
} }
if (!savedHistory || lastVisibilityPostId != 0L) {
saveHistory()
} }
onDispose { if (!savedHistory || lastVisibilityPostId != 0L) {
saveHistory() saveHistory()
} }
} }
@ -1119,7 +1120,7 @@ fun ThreadPage(
} }
}, },
hasAgreed = hasThreadAgreed, hasAgreed = hasThreadAgreed,
agreeNum = thread?.get { agree?.diffAgreeNum } ?: 0L, agreeNum = threadAgreeNum,
modifier = Modifier.navigationBarsPadding() modifier = Modifier.navigationBarsPadding()
) )
} }