diff --git a/app/src/main/java/pl/lambada/songsync/ui/screens/home/HomeScreen.kt b/app/src/main/java/pl/lambada/songsync/ui/screens/home/HomeScreen.kt index cbd97de..9a08427 100644 --- a/app/src/main/java/pl/lambada/songsync/ui/screens/home/HomeScreen.kt +++ b/app/src/main/java/pl/lambada/songsync/ui/screens/home/HomeScreen.kt @@ -229,8 +229,7 @@ fun HomeScreenLoaded( if (viewModel.showSort) { SortDialog( - sortBy = viewModel.userSettingsController.sortBy, - sortOrder = viewModel.userSettingsController.sortOrder, + userSettingsController = viewModel.userSettingsController, onDismiss = { viewModel.showSort = false }, onSortOrderChange = { viewModel.userSettingsController.updateSortOrder(it) }, onSortByChange = { viewModel.userSettingsController.updateSortBy(it) } diff --git a/app/src/main/java/pl/lambada/songsync/ui/screens/home/components/SortDialog.kt b/app/src/main/java/pl/lambada/songsync/ui/screens/home/components/SortDialog.kt index 564ac35..fcf05d1 100644 --- a/app/src/main/java/pl/lambada/songsync/ui/screens/home/components/SortDialog.kt +++ b/app/src/main/java/pl/lambada/songsync/ui/screens/home/components/SortDialog.kt @@ -1,8 +1,6 @@ package pl.lambada.songsync.ui.screens.home.components -import androidx.annotation.StringRes import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer @@ -11,7 +9,6 @@ import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.layout.wrapContentWidth import androidx.compose.material3.AlertDialogDefaults import androidx.compose.material3.BasicAlertDialog -import androidx.compose.material3.Button import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.MaterialTheme @@ -20,23 +17,19 @@ import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import pl.lambada.songsync.R +import pl.lambada.songsync.data.remote.UserSettingsController import pl.lambada.songsync.domain.model.SortOrders import pl.lambada.songsync.domain.model.SortValues @OptIn(ExperimentalMaterial3Api::class) @Composable fun SortDialog( - sortBy: SortValues, - sortOrder: SortOrders, + userSettingsController: UserSettingsController, onDismiss: () -> Unit, onSortByChange: (SortValues) -> Unit, onSortOrderChange: (SortOrders) -> Unit @@ -55,9 +48,9 @@ fun SortDialog( style = MaterialTheme.typography.titleLarge, modifier = Modifier.padding(top = 24.dp, start = 24.dp, bottom = 16.dp) ) - SortByRadioGroup(sortBy, onSortByChange) + SortByRadioGroup(userSettingsController, onSortByChange) HorizontalDivider() - SortOrderRadioGroup(sortOrder, onSortOrderChange) + SortOrderRadioGroup(userSettingsController, onSortOrderChange) Row(modifier = Modifier.padding(16.dp)) { Spacer(modifier = Modifier.weight(1f)) TextButton(onDismiss) { @@ -70,22 +63,21 @@ fun SortDialog( } @Composable -fun SortOrderRadioGroup(sortOrder: SortOrders, onSortOrderChange: (SortOrders) -> Unit) { - var selected by remember { mutableStateOf(sortOrder) } +fun SortOrderRadioGroup(userSettingsController: UserSettingsController, onSortOrderChange: (SortOrders) -> Unit) { Column { SortOrders.entries.forEach { Row(verticalAlignment = Alignment.CenterVertically) { RadioButton( - selected = selected == it, + selected = userSettingsController.sortOrder == it, onClick = { - selected = it + userSettingsController.updateSortOrder(it) onSortOrderChange(it) } ) Text( stringResource(it.displayName), modifier = Modifier.clickable { - selected = it + userSettingsController.updateSortOrder(it) onSortOrderChange(it) } ) @@ -95,22 +87,21 @@ fun SortOrderRadioGroup(sortOrder: SortOrders, onSortOrderChange: (SortOrders) - } @Composable -fun SortByRadioGroup(sortBy: SortValues, onSortByChange: (SortValues) -> Unit) { - var selected by remember { mutableStateOf(sortBy) } +fun SortByRadioGroup(userSettingsController: UserSettingsController, onSortByChange: (SortValues) -> Unit) { Column { SortValues.entries.forEach { Row(verticalAlignment = Alignment.CenterVertically) { RadioButton( - selected = selected == it, + selected = userSettingsController.sortBy == it, onClick = { - selected = it + userSettingsController.updateSortBy(it) onSortByChange(it) } ) Text( stringResource(it.displayName), modifier = Modifier.clickable { - selected = it + userSettingsController.updateSortBy(it) onSortByChange(it) } )