From d4ad60515b8e1aebac7462d8b0dbeabef56ec4e9 Mon Sep 17 00:00:00 2001 From: semenvav Date: Tue, 1 Aug 2023 15:42:26 +0300 Subject: [PATCH] use Saver to save to state of expanded map --- .../more/download/DownloadstatsContent.kt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/more/download/DownloadstatsContent.kt b/app/src/main/java/eu/kanade/presentation/more/download/DownloadstatsContent.kt index 33852a183c..d98755b2ba 100644 --- a/app/src/main/java/eu/kanade/presentation/more/download/DownloadstatsContent.kt +++ b/app/src/main/java/eu/kanade/presentation/more/download/DownloadstatsContent.kt @@ -26,6 +26,8 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateMapOf import androidx.compose.runtime.remember +import androidx.compose.runtime.saveable.Saver +import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -235,9 +237,17 @@ fun CategoryList( onSelected: (DownloadStatManga, Boolean, Boolean, Boolean) -> Unit, categoryMap: Map>, ) { - val expanded = remember { - mutableStateMapOf(*categoryMap.keys.toList().map { it to false }.toTypedArray()) - } + val categoryExpandedMapSaver: Saver, *> = Saver( + save = { map -> map.toMap() }, + restore = { map -> mutableStateMapOf(*map.toList().toTypedArray()) }, + ) + + val expanded = rememberSaveable( + saver = categoryExpandedMapSaver, + key = "CategoryExpandedMap", + init = { mutableStateMapOf(*categoryMap.keys.toList().map { it to false }.toTypedArray()) }, + ) + FastScrollLazyColumn(contentPadding = contentPadding) { categoryMap.forEach { (category, items) -> downloadStatGroupUiItem(