fix data saving

This commit is contained in:
1
2025-07-17 11:05:27 +08:00
parent b212ab777a
commit 17b4ffa75d
3 changed files with 7 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ plugins {
alias(libs.plugins.compose.compiler)
id("com.google.gms.google-services")
id("kotlin-parcelize")
kotlin("plugin.serialization") version "2.2.0"
}
android {

View File

@@ -11,10 +11,12 @@ import com.donut.mixfile.activity.video.player.VideoPlayerScreen
import com.donut.mixfile.ui.theme.MainTheme
import com.donut.mixfile.util.cachedMutableOf
import com.donut.mixfile.util.objects.MixActivity
import kotlinx.serialization.Serializable
var playHistory by cachedMutableOf(listOf<VideoHistory>(), "video_player_history_v2")
@Serializable
data class VideoHistory(val time: Long, val hash: String, val episode: Int)
class VideoActivity : MixActivity("video") {

View File

@@ -53,11 +53,13 @@ inline fun <reified T, reified C : Iterable<T>> cachedMutableOf(value: C, key: S
constructCachedMutableValue(
value,
{
kv.encode(key, it.toJsonString())
errorDialog("保存数据失败 key=${key}") {
kv.encode(key, it.toJsonString())
}
},
getter@{
var result = value
catchError {
errorDialog("读取数据失败 key=${key}") {
if (kv.containsKey(key)) {
val json: C = kv.decodeString(key)?.parseJsonObject() ?: value
result = json