From a94d6a66e872667640c2b2283b54f1382cfc6188 Mon Sep 17 00:00:00 2001 From: Sad Ellie Date: Thu, 23 Jun 2022 21:24:50 +0300 Subject: [PATCH] Replaced one bug with another. SecondScreen.kt: Fixed bug when selected chip was set to null after activity recreation. Introduced new bug when selected chip is not saved when changing device configuration. (Will probably fix it, but it's such a rare case and the app has to be released already) --- .../sadellie/unitto/screens/second/SecondScreen.kt | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/sadellie/unitto/screens/second/SecondScreen.kt b/app/src/main/java/com/sadellie/unitto/screens/second/SecondScreen.kt index 4cf2bb6d..413edc18 100644 --- a/app/src/main/java/com/sadellie/unitto/screens/second/SecondScreen.kt +++ b/app/src/main/java/com/sadellie/unitto/screens/second/SecondScreen.kt @@ -28,9 +28,6 @@ import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.rememberTopAppBarScrollState import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.ui.Modifier import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.LocalFocusManager @@ -72,10 +69,6 @@ private fun BasicUnitListScreen( title: String, ) { val uiState = viewModel.uiState - val currentUnitGroup: UnitGroup? by rememberSaveable { - viewModel.setSelectedChip(currentUnit.group) - mutableStateOf(currentUnit.group) - } val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarScrollState()) val focusManager = LocalFocusManager.current val chipsRowLazyListState = rememberLazyListState() @@ -131,10 +124,9 @@ private fun BasicUnitListScreen( /** * Telling viewModel that it needs to update the list */ + viewModel.setSelectedChip(currentUnit.group) viewModel.loadUnitsToShow(noBrokenCurrencies) - currentUnitGroup?.let { - chipsRowLazyListState.animateScrollToItem(ALL_UNIT_GROUPS.indexOf(it)) - } + chipsRowLazyListState.animateScrollToItem(ALL_UNIT_GROUPS.indexOf(currentUnit.group)) } }