Skip to content

Commit

Permalink
fix: home tab preference doesn't update immediately (closes you-apps#360
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Bnyro committed Aug 10, 2024
1 parent 1e2123f commit 7dbfbc3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ fun SettingsScreen(
timerModel: TimerModel
) {
val scrollState = rememberScrollState()
val context = LocalContext.current
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(
rememberTopAppBarState()
)
Expand Down Expand Up @@ -115,18 +114,13 @@ fun SettingsScreen(
color = MaterialTheme.colorScheme.surfaceVariant
)
SettingsCategory(title = stringResource(R.string.behavior))
val selectedStartTab = homeRoutes.first {
it.route == Preferences.instance.getString(
Preferences.startTabKey,
HomeRoutes.Alarm.route
)
}
ButtonGroupPref(
title = stringResource(R.string.start_tab),
options = homeRoutes.map { stringResource(it.stringRes) },
values = homeRoutes,
currentValue = selectedStartTab
currentValue = settingsModel.homeTab
) {
settingsModel.homeTab = it
Preferences.edit { putString(Preferences.startTabKey, it.route) }
}
SwitchPref(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import com.bnyro.clock.R
import com.bnyro.clock.navigation.HomeRoutes
import com.bnyro.clock.navigation.homeRoutes
import com.bnyro.clock.util.Preferences
import com.bnyro.clock.util.catpucchinLatte

Expand Down Expand Up @@ -40,4 +42,13 @@ class SettingsModel : ViewModel() {
catpucchinLatte.first()
)
)

var homeTab by mutableStateOf(
homeRoutes.first {
it.route == Preferences.instance.getString(
Preferences.startTabKey,
HomeRoutes.Alarm.route
)
}
)
}

0 comments on commit 7dbfbc3

Please sign in to comment.