mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 00:35:26 +02:00
Refactor setting screens
This commit is contained in:
parent
165fdd38ad
commit
59c151d2a6
@ -82,8 +82,7 @@ private fun SettingsScreen(
|
||||
) { padding ->
|
||||
LazyColumn(contentPadding = padding) {
|
||||
|
||||
// THEME
|
||||
item {
|
||||
item("theme") {
|
||||
UnittoListItem(
|
||||
icon = Icons.Default.Palette,
|
||||
iconDescription = stringResource(R.string.display_settings),
|
||||
@ -93,8 +92,7 @@ private fun SettingsScreen(
|
||||
)
|
||||
}
|
||||
|
||||
// START SCREEN
|
||||
item {
|
||||
item("starting screen") {
|
||||
UnittoListItem(
|
||||
icon = Icons.Default.Home,
|
||||
iconDescription = stringResource(R.string.starting_screen_setting),
|
||||
@ -104,8 +102,7 @@ private fun SettingsScreen(
|
||||
)
|
||||
}
|
||||
|
||||
// FORMATTING
|
||||
item {
|
||||
item("formatting") {
|
||||
UnittoListItem(
|
||||
icon = Icons.Default._123,
|
||||
iconDescription = stringResource(R.string.formatting_setting),
|
||||
@ -115,7 +112,7 @@ private fun SettingsScreen(
|
||||
)
|
||||
}
|
||||
|
||||
item {
|
||||
item("calculator") {
|
||||
UnittoListItem(
|
||||
icon = Icons.Default.Calculate,
|
||||
iconDescription = stringResource(R.string.calculator),
|
||||
@ -125,7 +122,7 @@ private fun SettingsScreen(
|
||||
)
|
||||
}
|
||||
|
||||
item {
|
||||
item("unit converter") {
|
||||
UnittoListItem(
|
||||
icon = Icons.Default.SwapHoriz,
|
||||
iconDescription = stringResource(R.string.unit_converter),
|
||||
@ -135,11 +132,9 @@ private fun SettingsScreen(
|
||||
)
|
||||
}
|
||||
|
||||
// ADDITIONAL GROUP
|
||||
item { Header(stringResource(R.string.additional_settings_group)) }
|
||||
item("additional") { Header(stringResource(R.string.additional_settings_group)) }
|
||||
|
||||
// VIBRATIONS
|
||||
item {
|
||||
item("vibrations") {
|
||||
UnittoListItem(
|
||||
icon = Icons.Default.Vibration,
|
||||
iconDescription = stringResource(R.string.enable_vibrations),
|
||||
@ -153,7 +148,7 @@ private fun SettingsScreen(
|
||||
|
||||
// RATE THIS APP
|
||||
if (BuildConfig.STORE_LINK.isNotEmpty()) {
|
||||
item {
|
||||
item("rate this app") {
|
||||
UnittoListItem(
|
||||
icon = Icons.Default.RateReview,
|
||||
iconDescription = stringResource(R.string.rate_this_app),
|
||||
@ -163,8 +158,7 @@ private fun SettingsScreen(
|
||||
}
|
||||
}
|
||||
|
||||
// More settings
|
||||
item {
|
||||
item("about") {
|
||||
UnittoListItem(
|
||||
icon = Icons.Default.Info,
|
||||
iconDescription = stringResource(R.string.about_unitto),
|
||||
|
@ -41,6 +41,7 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.sadellie.unitto.core.base.BuildConfig
|
||||
@ -49,15 +50,32 @@ import com.sadellie.unitto.core.ui.common.NavigateUpButton
|
||||
import com.sadellie.unitto.core.ui.common.UnittoListItem
|
||||
import com.sadellie.unitto.core.ui.common.UnittoScreenWithLargeTopBar
|
||||
import com.sadellie.unitto.core.ui.openLink
|
||||
import com.sadellie.unitto.data.userprefs.AboutPreferences
|
||||
|
||||
@Composable
|
||||
internal fun AboutScreen(
|
||||
internal fun AboutRoute(
|
||||
viewModel: AboutViewModel = hiltViewModel(),
|
||||
navigateUpAction: () -> Unit,
|
||||
navigateToThirdParty: () -> Unit,
|
||||
) {
|
||||
val mContext = LocalContext.current
|
||||
val prefs = viewModel.prefs.collectAsStateWithLifecycle()
|
||||
|
||||
AboutScreen(
|
||||
prefs = prefs.value,
|
||||
navigateUpAction = navigateUpAction,
|
||||
navigateToThirdParty = navigateToThirdParty,
|
||||
enableToolsExperiment = viewModel::enableToolsExperiment
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AboutScreen(
|
||||
prefs: AboutPreferences,
|
||||
navigateUpAction: () -> Unit,
|
||||
navigateToThirdParty: () -> Unit,
|
||||
enableToolsExperiment: () -> Unit,
|
||||
) {
|
||||
val mContext = LocalContext.current
|
||||
var aboutItemClick: Int by rememberSaveable { mutableIntStateOf(0) }
|
||||
var showDialog: Boolean by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
@ -139,7 +157,7 @@ internal fun AboutScreen(
|
||||
headlineText = stringResource(R.string.app_version_name_setting),
|
||||
supportingText = "${BuildConfig.APP_NAME} (${BuildConfig.APP_CODE})",
|
||||
modifier = Modifier.combinedClickable {
|
||||
if (prefs.value.enableToolsExperiment) {
|
||||
if (prefs.enableToolsExperiment) {
|
||||
Toast.makeText(mContext, "Experiments features are already enabled!", Toast.LENGTH_LONG).show()
|
||||
return@combinedClickable
|
||||
}
|
||||
@ -147,7 +165,7 @@ internal fun AboutScreen(
|
||||
aboutItemClick++
|
||||
if (aboutItemClick < 7) return@combinedClickable
|
||||
|
||||
viewModel.enableToolsExperiment()
|
||||
enableToolsExperiment()
|
||||
Toast.makeText(mContext, "Experimental features enabled!", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
)
|
||||
@ -172,3 +190,14 @@ internal fun AboutScreen(
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun PreviewAboutScreen() {
|
||||
AboutScreen(
|
||||
prefs = AboutPreferences(),
|
||||
navigateUpAction = {},
|
||||
navigateToThirdParty = {},
|
||||
enableToolsExperiment = {}
|
||||
)
|
||||
}
|
||||
|
@ -23,35 +23,60 @@ import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Timer
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.sadellie.unitto.core.base.R
|
||||
import com.sadellie.unitto.core.ui.common.NavigateUpButton
|
||||
import com.sadellie.unitto.core.ui.common.UnittoListItem
|
||||
import com.sadellie.unitto.core.ui.common.UnittoScreenWithLargeTopBar
|
||||
import com.sadellie.unitto.data.userprefs.CalculatorPreferences
|
||||
|
||||
@Composable
|
||||
internal fun CalculatorSettingsScreen(
|
||||
internal fun CalculatorSettingsRoute(
|
||||
viewModel: CalculatorViewModel = hiltViewModel(),
|
||||
navigateUpAction: () -> Unit,
|
||||
) {
|
||||
val prefs = viewModel.prefs.collectAsStateWithLifecycle()
|
||||
|
||||
CalculatorSettingsScreen(
|
||||
prefs = prefs.value,
|
||||
navigateUpAction = navigateUpAction,
|
||||
updatePartialHistoryView = viewModel::updatePartialHistoryView
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CalculatorSettingsScreen(
|
||||
prefs: CalculatorPreferences,
|
||||
navigateUpAction: () -> Unit,
|
||||
updatePartialHistoryView: (Boolean) -> Unit,
|
||||
) {
|
||||
UnittoScreenWithLargeTopBar(
|
||||
title = stringResource(R.string.calculator),
|
||||
navigationIcon = { NavigateUpButton(navigateUpAction) }
|
||||
) { padding ->
|
||||
LazyColumn(contentPadding = padding) {
|
||||
item {
|
||||
item("partial history") {
|
||||
UnittoListItem(
|
||||
headlineText = stringResource(R.string.partial_history_view_setting),
|
||||
icon = Icons.Default.Timer,
|
||||
iconDescription = stringResource(R.string.partial_history_view_setting),
|
||||
supportingText = stringResource(R.string.partial_history_view_setting_support),
|
||||
switchState = prefs.value.partialHistoryView,
|
||||
onSwitchChange = viewModel::updatePartialHistoryView
|
||||
switchState = prefs.partialHistoryView,
|
||||
onSwitchChange = updatePartialHistoryView
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
private fun PreviewCalculatorSettingsScreen() {
|
||||
CalculatorSettingsScreen(
|
||||
prefs = CalculatorPreferences(),
|
||||
navigateUpAction = {},
|
||||
updatePartialHistoryView = {}
|
||||
)
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.sadellie.unitto.core.base.R
|
||||
@ -38,15 +39,34 @@ import com.sadellie.unitto.core.ui.common.NavigateUpButton
|
||||
import com.sadellie.unitto.core.ui.common.UnittoListItem
|
||||
import com.sadellie.unitto.core.ui.common.UnittoScreenWithLargeTopBar
|
||||
import com.sadellie.unitto.data.model.UnitsListSorting
|
||||
import com.sadellie.unitto.data.userprefs.ConverterPreferences
|
||||
import com.sadellie.unitto.feature.settings.components.AlertDialogWithList
|
||||
|
||||
@Composable
|
||||
internal fun ConverterSettingsScreen(
|
||||
internal fun ConverterSettingsRoute(
|
||||
viewModel: ConverterViewModel = hiltViewModel(),
|
||||
navigateUpAction: () -> Unit,
|
||||
navigateToUnitsGroup: () -> Unit,
|
||||
) {
|
||||
val prefs = viewModel.prefs.collectAsStateWithLifecycle()
|
||||
|
||||
ConverterSettingsScreen(
|
||||
prefs = prefs.value,
|
||||
navigateUpAction = navigateUpAction,
|
||||
navigateToUnitsGroup = navigateToUnitsGroup,
|
||||
updateUnitConverterFormatTime = viewModel::updateUnitConverterFormatTime,
|
||||
updateUnitConverterSorting = viewModel::updateUnitConverterSorting
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ConverterSettingsScreen(
|
||||
prefs: ConverterPreferences,
|
||||
navigateUpAction: () -> Unit,
|
||||
navigateToUnitsGroup: () -> Unit,
|
||||
updateUnitConverterFormatTime: (Boolean) -> Unit,
|
||||
updateUnitConverterSorting: (UnitsListSorting) -> Unit,
|
||||
) {
|
||||
var showDialog: Boolean by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
UnittoScreenWithLargeTopBar(
|
||||
@ -54,8 +74,7 @@ internal fun ConverterSettingsScreen(
|
||||
navigationIcon = { NavigateUpButton(navigateUpAction) }
|
||||
) { padding ->
|
||||
LazyColumn(contentPadding = padding) {
|
||||
// UNIT GROUPS
|
||||
item {
|
||||
item("unit group") {
|
||||
UnittoListItem(
|
||||
icon = Icons.AutoMirrored.Filled.Rule,
|
||||
iconDescription = stringResource(R.string.unit_groups_setting),
|
||||
@ -65,8 +84,7 @@ internal fun ConverterSettingsScreen(
|
||||
)
|
||||
}
|
||||
|
||||
// UNITS LIST SORTING
|
||||
item {
|
||||
item("units sorting") {
|
||||
UnittoListItem(
|
||||
icon = Icons.AutoMirrored.Filled.Sort,
|
||||
iconDescription = stringResource(R.string.units_sorting),
|
||||
@ -76,15 +94,14 @@ internal fun ConverterSettingsScreen(
|
||||
)
|
||||
}
|
||||
|
||||
// FORMAT TIME
|
||||
item {
|
||||
item("format time") {
|
||||
UnittoListItem(
|
||||
icon = Icons.Default.Timer,
|
||||
iconDescription = stringResource(R.string.format_time),
|
||||
headlineText = stringResource(R.string.format_time),
|
||||
supportingText = stringResource(R.string.format_time_support),
|
||||
switchState = prefs.value.unitConverterFormatTime,
|
||||
onSwitchChange = viewModel::updateUnitConverterFormatTime
|
||||
switchState = prefs.unitConverterFormatTime,
|
||||
onSwitchChange = updateUnitConverterFormatTime
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -99,9 +116,21 @@ internal fun ConverterSettingsScreen(
|
||||
UnitsListSorting.SCALE_DESC to R.string.sort_by_scale_desc,
|
||||
UnitsListSorting.SCALE_ASC to R.string.sort_by_scale_asc,
|
||||
),
|
||||
selectedItemIndex = prefs.value.unitConverterSorting,
|
||||
selectAction = viewModel::updateUnitConverterSorting,
|
||||
selectedItemIndex = prefs.unitConverterSorting,
|
||||
selectAction = updateUnitConverterSorting,
|
||||
dismissAction = { showDialog = false }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
private fun PreviewConverterSettingsScreen() {
|
||||
ConverterSettingsScreen(
|
||||
prefs = ConverterPreferences(),
|
||||
navigateUpAction = {},
|
||||
navigateToUnitsGroup = {},
|
||||
updateUnitConverterFormatTime = {},
|
||||
updateUnitConverterSorting = {}
|
||||
)
|
||||
}
|
||||
|
@ -26,13 +26,13 @@ import com.sadellie.unitto.core.base.TopLevelDestinations
|
||||
import com.sadellie.unitto.core.ui.unittoComposable
|
||||
import com.sadellie.unitto.core.ui.unittoNavigation
|
||||
import com.sadellie.unitto.feature.settings.SettingsRoute
|
||||
import com.sadellie.unitto.feature.settings.about.AboutScreen
|
||||
import com.sadellie.unitto.feature.settings.calculator.CalculatorSettingsScreen
|
||||
import com.sadellie.unitto.feature.settings.converter.ConverterSettingsScreen
|
||||
import com.sadellie.unitto.feature.settings.about.AboutRoute
|
||||
import com.sadellie.unitto.feature.settings.calculator.CalculatorSettingsRoute
|
||||
import com.sadellie.unitto.feature.settings.converter.ConverterSettingsRoute
|
||||
import com.sadellie.unitto.feature.settings.display.DisplayRoute
|
||||
import com.sadellie.unitto.feature.settings.formatting.FormattingRoute
|
||||
import com.sadellie.unitto.feature.settings.language.LanguageRoute
|
||||
import com.sadellie.unitto.feature.settings.startingscreen.StartingScreenRoute
|
||||
import com.sadellie.unitto.feature.settings.display.DisplayRoute
|
||||
import com.sadellie.unitto.feature.settings.thirdparty.ThirdPartyLicensesScreen
|
||||
import com.sadellie.unitto.feature.settings.unitgroups.UnitGroupsScreen
|
||||
import io.github.sadellie.themmo.ThemmoController
|
||||
@ -102,13 +102,13 @@ fun NavGraphBuilder.settingGraph(
|
||||
}
|
||||
|
||||
unittoComposable(calculatorSettingsRoute) {
|
||||
CalculatorSettingsScreen(
|
||||
CalculatorSettingsRoute(
|
||||
navigateUpAction = navController::navigateUp,
|
||||
)
|
||||
}
|
||||
|
||||
unittoComposable(converterSettingsRoute) {
|
||||
ConverterSettingsScreen(
|
||||
ConverterSettingsRoute(
|
||||
navigateUpAction = navController::navigateUp,
|
||||
navigateToUnitsGroup = { navController.navigate(unitsGroupRoute) }
|
||||
)
|
||||
@ -121,7 +121,7 @@ fun NavGraphBuilder.settingGraph(
|
||||
}
|
||||
|
||||
unittoComposable(aboutRoute) {
|
||||
AboutScreen(
|
||||
AboutRoute(
|
||||
navigateUpAction = navController::navigateUp,
|
||||
navigateToThirdParty = { navController.navigate(thirdPartyRoute) }
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user