File tree Expand file tree Collapse file tree 2 files changed +13
-7
lines changed
app/src/main/java/me/brisson/algorithm_visualizer/ui/screens/sorting Expand file tree Collapse file tree 2 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import androidx.compose.material3.IconButton
16
16
import androidx.compose.material3.MaterialTheme
17
17
import androidx.compose.material3.Text
18
18
import androidx.compose.runtime.Composable
19
+ import androidx.compose.runtime.DisposableEffect
19
20
import androidx.compose.runtime.LaunchedEffect
20
21
import androidx.compose.runtime.getValue
21
22
import androidx.compose.ui.Alignment
@@ -46,6 +47,10 @@ fun SortingRoute(
46
47
viewModel.updateInfoButtonAvailability()
47
48
}
48
49
50
+ DisposableEffect (Unit ) {
51
+ onDispose { viewModel.resetAllValues() }
52
+ }
53
+
49
54
SortingScreen (
50
55
modifier = modifier,
51
56
uiState = uiState,
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ class SortingViewModel(savedStateHandle: SavedStateHandle) : ViewModel() {
26
26
private val _sortingClassName : String =
27
27
checkNotNull(savedStateHandle[AppNavigationArgs .SORT_ALGORITHM_CLASS_NAME ])
28
28
29
- private val sortClass: Sort ? = Sort .instantiateClass(_sortingClassName )
29
+ private var sortClass: Sort ? = Sort .instantiateClass(_sortingClassName )
30
30
31
31
private val _uiState = MutableStateFlow (SortingUIState ())
32
32
val uiState: StateFlow <SortingUIState > = _uiState .asStateFlow()
@@ -69,12 +69,13 @@ class SortingViewModel(savedStateHandle: SavedStateHandle) : ViewModel() {
69
69
_uiState .update { it.copy(infoMdResId = enumAlgorithm?.mdResId) }
70
70
}
71
71
72
- // fun getAlgorithmMdResId(): Int {
73
- // val enumAlgorithm = enumValues<SortingAlgorithms>().find {
74
- // it.algorithmClass.algorithmName == sortClass?.algorithmName
75
- // }
76
- // return enumAlgorithm?.mdResId ?: -1
77
- // }
72
+ fun resetAllValues () {
73
+ sortClass = Sort .instantiateClass(_sortingClassName )
74
+ chartStateList = emptyList()
75
+ messageLogList = emptyList()
76
+
77
+ _uiState .value = SortingUIState ()
78
+ }
78
79
79
80
fun onEvent (event : SortingEvents ) {
80
81
when (event) {
You can’t perform that action at this time.
0 commit comments