Skip to content

Commit

Permalink
edundant remember
Browse files Browse the repository at this point in the history
  • Loading branch information
Lambada10 committed Oct 25, 2024
1 parent 6964904 commit cedd529
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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)
}
)
Expand All @@ -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)
}
)
Expand Down

0 comments on commit cedd529

Please sign in to comment.