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)
This commit is contained in:
Sad Ellie 2022-06-23 21:24:50 +03:00
parent 6ec1e1dfb0
commit a94d6a66e8

View File

@ -28,9 +28,6 @@ import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.rememberTopAppBarScrollState import androidx.compose.material3.rememberTopAppBarScrollState
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect 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.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.platform.LocalFocusManager
@ -72,10 +69,6 @@ private fun BasicUnitListScreen(
title: String, title: String,
) { ) {
val uiState = viewModel.uiState val uiState = viewModel.uiState
val currentUnitGroup: UnitGroup? by rememberSaveable {
viewModel.setSelectedChip(currentUnit.group)
mutableStateOf(currentUnit.group)
}
val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarScrollState()) val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarScrollState())
val focusManager = LocalFocusManager.current val focusManager = LocalFocusManager.current
val chipsRowLazyListState = rememberLazyListState() val chipsRowLazyListState = rememberLazyListState()
@ -131,10 +124,9 @@ private fun BasicUnitListScreen(
/** /**
* Telling viewModel that it needs to update the list * Telling viewModel that it needs to update the list
*/ */
viewModel.setSelectedChip(currentUnit.group)
viewModel.loadUnitsToShow(noBrokenCurrencies) viewModel.loadUnitsToShow(noBrokenCurrencies)
currentUnitGroup?.let { chipsRowLazyListState.animateScrollToItem(ALL_UNIT_GROUPS.indexOf(currentUnit.group))
chipsRowLazyListState.animateScrollToItem(ALL_UNIT_GROUPS.indexOf(it))
}
} }
} }