Little code clean up

This commit is contained in:
Sad Ellie 2022-08-13 23:57:43 +03:00
parent e0ee67ee9c
commit fb123d697e
12 changed files with 38 additions and 38 deletions

View File

@ -36,7 +36,7 @@ fun NavigateUpButton(onClick: () -> Unit) {
IconButton(onClick = onClick) { IconButton(onClick = onClick) {
Icon( Icon(
Icons.Outlined.ArrowBack, Icons.Outlined.ArrowBack,
contentDescription = stringResource(id = R.string.navigate_up_description) contentDescription = stringResource(R.string.navigate_up_description)
) )
} }
} }

View File

@ -69,7 +69,7 @@ fun MainScreen(
IconButton(onClick = { navControllerAction(SETTINGS_SCREEN) }) { IconButton(onClick = { navControllerAction(SETTINGS_SCREEN) }) {
Icon( Icon(
Icons.Outlined.MoreVert, Icons.Outlined.MoreVert,
contentDescription = stringResource(id = R.string.open_settings_description) contentDescription = stringResource(R.string.open_settings_description)
) )
} }
}, },

View File

@ -68,8 +68,8 @@ fun MyTextField(
val clipboardManager = LocalClipboardManager.current val clipboardManager = LocalClipboardManager.current
val mc = LocalContext.current val mc = LocalContext.current
val textToShow = when { val textToShow = when {
showError -> stringResource(id = R.string.error_label) showError -> stringResource(R.string.error_label)
showLoading -> stringResource(id = R.string.loading_label) showLoading -> stringResource(R.string.loading_label)
else -> Formatter.format(currentText) else -> Formatter.format(currentText)
} }
val copiedText: String = stringResource(R.string.copied, textToShow) val copiedText: String = stringResource(R.string.copied, textToShow)

View File

@ -87,14 +87,14 @@ fun TopScreenPart(
MyTextField( MyTextField(
Modifier.fillMaxWidth(), Modifier.fillMaxWidth(),
inputValue, inputValue,
stringResource(id = if (loadingDatabase) R.string.loading_label else unitFrom.shortName), stringResource(if (loadingDatabase) R.string.loading_label else unitFrom.shortName),
loadingNetwork, loadingNetwork,
networkError networkError
) )
MyTextField( MyTextField(
Modifier.fillMaxWidth(), Modifier.fillMaxWidth(),
outputValue, outputValue,
stringResource(id = if (loadingDatabase) R.string.loading_label else unitTo.shortName), stringResource(if (loadingDatabase) R.string.loading_label else unitTo.shortName),
loadingNetwork, loadingNetwork,
networkError networkError
) )

View File

@ -107,7 +107,7 @@ private fun BasicUnitListScreen(
return@LazyColumn return@LazyColumn
} }
uiState.unitsToShow.forEach { (unitGroup, listOfUnits) -> uiState.unitsToShow.forEach { (unitGroup, listOfUnits) ->
item { Header(text = stringResource(id = unitGroup.res)) } item { Header(text = stringResource(unitGroup.res)) }
items(items = listOfUnits, key = { it.unitId }) { unit -> items(items = listOfUnits, key = { it.unitId }) { unit ->
unitsListItem(unit) { unitsListItem(unit) {
selectAction(it) selectAction(it)

View File

@ -82,12 +82,12 @@ fun ChipsRow(
Icon( Icon(
modifier = Modifier.height(18.dp), modifier = Modifier.height(18.dp),
imageVector = Icons.Default.Check, imageVector = Icons.Default.Check,
contentDescription = stringResource(id = R.string.checked_filter_description) contentDescription = stringResource(R.string.checked_filter_description)
) )
} }
Text( Text(
modifier = Modifier.padding(start = 8.dp), modifier = Modifier.padding(start = 8.dp),
text = stringResource(id = item.res), text = stringResource(item.res),
style = MaterialTheme.typography.labelLarge, style = MaterialTheme.typography.labelLarge,
color = if (isSelected) MaterialTheme.colorScheme.onSecondaryContainer else MaterialTheme.colorScheme.onSurfaceVariant color = if (isSelected) MaterialTheme.colorScheme.onSecondaryContainer else MaterialTheme.colorScheme.onSurfaceVariant
) )
@ -108,7 +108,7 @@ fun ChipsRow(
Icon( Icon(
modifier = Modifier.height(18.dp), modifier = Modifier.height(18.dp),
imageVector = Icons.Default.Settings, imageVector = Icons.Default.Settings,
contentDescription = stringResource(id = R.string.open_settings_description) contentDescription = stringResource(R.string.open_settings_description)
) )
} }
} }

View File

@ -200,7 +200,7 @@ private fun SearchTextField(
innerTextField() innerTextField()
Text( Text(
modifier = Modifier.alpha(0.7f), modifier = Modifier.alpha(0.7f),
text = stringResource(id = R.string.search_bar_placeholder), text = stringResource(R.string.search_bar_placeholder),
style = MaterialTheme.typography.titleLarge, style = MaterialTheme.typography.titleLarge,
color = MaterialTheme.colorScheme.onSurface color = MaterialTheme.colorScheme.onSurface
) )
@ -218,7 +218,7 @@ private fun SearchButton(
IconButton(onClick) { IconButton(onClick) {
Icon( Icon(
Icons.Default.Search, Icons.Default.Search,
contentDescription = stringResource(id = R.string.search_button_description) contentDescription = stringResource(R.string.search_button_description)
) )
} }
} }
@ -237,7 +237,7 @@ private fun FavoritesButton(
) { ) {
Icon( Icon(
if (favoritesOnly) Icons.Filled.Favorite else Icons.Filled.FavoriteBorder, if (favoritesOnly) Icons.Filled.Favorite else Icons.Filled.FavoriteBorder,
contentDescription = stringResource(id = R.string.favorite_button_description) contentDescription = stringResource(R.string.favorite_button_description)
) )
} }
} }

View File

@ -54,24 +54,24 @@ fun SearchPlaceholder(navigateToSettingsActtion: () -> Unit) {
// Big icon in the middle // Big icon in the middle
Icon( Icon(
Icons.Default.SearchOff, Icons.Default.SearchOff,
contentDescription = stringResource(id = R.string.empty_search_result_description), contentDescription = stringResource(R.string.empty_search_result_description),
modifier = Modifier.size(48.dp) modifier = Modifier.size(48.dp)
) )
// Primary text // Primary text
Text( Text(
text = stringResource(id = R.string.search_placeholder), text = stringResource(R.string.search_placeholder),
textAlign = TextAlign.Center, textAlign = TextAlign.Center,
style = MaterialTheme.typography.bodyLarge style = MaterialTheme.typography.bodyLarge
) )
// Secondary text with tips // Secondary text with tips
Text( Text(
text = stringResource(id = R.string.search_placeholder_secondary), text = stringResource(R.string.search_placeholder_secondary),
textAlign = TextAlign.Center, textAlign = TextAlign.Center,
style = MaterialTheme.typography.bodySmall style = MaterialTheme.typography.bodySmall
) )
// Open settings button // Open settings button
ElevatedButton(onClick = navigateToSettingsActtion) { ElevatedButton(onClick = navigateToSettingsActtion) {
Text(text = stringResource(id = R.string.search_placeholder_button_label)) Text(text = stringResource(R.string.search_placeholder_button_label))
} }
} }
} }

View File

@ -84,7 +84,7 @@ private fun BasicUnitListItem(
RoundedCornerShape(24.dp) RoundedCornerShape(24.dp)
), ),
paddingValues = PaddingValues(horizontal = 12.dp, vertical = 8.dp), paddingValues = PaddingValues(horizontal = 12.dp, vertical = 8.dp),
label = stringResource(id = unit.displayName), label = stringResource(unit.displayName),
supportText = shortNameLabel, supportText = shortNameLabel,
trailingItem = { trailingItem = {
AnimatedContent( AnimatedContent(
@ -101,7 +101,7 @@ private fun BasicUnitListItem(
) { ) {
Icon( Icon(
if (unit.isFavorite) Icons.Filled.Favorite else Icons.Filled.FavoriteBorder, if (unit.isFavorite) Icons.Filled.Favorite else Icons.Filled.FavoriteBorder,
contentDescription = stringResource(id = R.string.favorite_button_description) contentDescription = stringResource(R.string.favorite_button_description)
) )
} }
} }
@ -128,7 +128,7 @@ fun UnitListItem(
isSelected = isSelected, isSelected = isSelected,
selectAction = selectAction, selectAction = selectAction,
favoriteAction = favoriteAction, favoriteAction = favoriteAction,
shortNameLabel = stringResource(id = unit.shortName) shortNameLabel = stringResource(unit.shortName)
) )
/** /**
@ -152,5 +152,5 @@ fun UnitListItem(
isSelected = isSelected, isSelected = isSelected,
selectAction = selectAction, selectAction = selectAction,
favoriteAction = favoriteAction, favoriteAction = favoriteAction,
shortNameLabel = "${convertValue(unit)} ${stringResource(id = unit.shortName)}" shortNameLabel = "${convertValue(unit)} ${stringResource(unit.shortName)}"
) )

View File

@ -54,7 +54,7 @@ fun AboutScreen(
val mContext = LocalContext.current val mContext = LocalContext.current
UnittoLargeTopAppBar( UnittoLargeTopAppBar(
title = stringResource(id = R.string.third_party_licenses), title = stringResource(R.string.third_party_licenses),
navigateUpAction = navigateUpAction navigateUpAction = navigateUpAction
) { padding -> ) { padding ->
LazyColumn( LazyColumn(

View File

@ -52,7 +52,7 @@ fun SettingsScreen(
} }
UnittoLargeTopAppBar( UnittoLargeTopAppBar(
title = stringResource(id = R.string.settings_screen), title = stringResource(R.string.settings_screen),
navigateUpAction = navigateUpAction navigateUpAction = navigateUpAction
) { padding -> ) { padding ->
LazyColumn(contentPadding = padding) { LazyColumn(contentPadding = padding) {
@ -63,7 +63,7 @@ fun SettingsScreen(
// THEME // THEME
item { item {
UnittoListItem( UnittoListItem(
label = stringResource(id = R.string.unit_groups_setting), label = stringResource(R.string.unit_groups_setting),
onClick = { navControllerAction(UNIT_GROUPS_SCREEN) } onClick = { navControllerAction(UNIT_GROUPS_SCREEN) }
) )
} }
@ -173,7 +173,7 @@ fun SettingsScreen(
// APP VERSION // APP VERSION
item { item {
UnittoListItem( UnittoListItem(
label = stringResource(id = R.string.app_version_name_setting), label = stringResource(R.string.app_version_name_setting),
supportText = "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})", supportText = "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})",
onClick = {} onClick = {}
) )
@ -192,17 +192,17 @@ fun SettingsScreen(
when (dialogState) { when (dialogState) {
DialogState.PRECISION -> { DialogState.PRECISION -> {
AlertDialogWithList( AlertDialogWithList(
title = stringResource(id = R.string.precision_setting), title = stringResource(R.string.precision_setting),
listItems = PRECISIONS, listItems = PRECISIONS,
selectedItemIndex = viewModel.userPrefs.digitsPrecision, selectedItemIndex = viewModel.userPrefs.digitsPrecision,
selectAction = { viewModel.updatePrecision(it) }, selectAction = { viewModel.updatePrecision(it) },
dismissAction = { resetDialog() }, dismissAction = { resetDialog() },
supportText = stringResource(id = R.string.precision_setting_info) supportText = stringResource(R.string.precision_setting_info)
) )
} }
DialogState.SEPARATOR -> { DialogState.SEPARATOR -> {
AlertDialogWithList( AlertDialogWithList(
title = stringResource(id = R.string.separator_setting), title = stringResource(R.string.separator_setting),
listItems = SEPARATORS, listItems = SEPARATORS,
selectedItemIndex = viewModel.userPrefs.separator, selectedItemIndex = viewModel.userPrefs.separator,
selectAction = { viewModel.updateSeparator(it) }, selectAction = { viewModel.updateSeparator(it) },
@ -211,20 +211,20 @@ fun SettingsScreen(
} }
DialogState.OUTPUT_FORMAT -> { DialogState.OUTPUT_FORMAT -> {
AlertDialogWithList( AlertDialogWithList(
title = stringResource(id = R.string.output_format_setting), title = stringResource(R.string.output_format_setting),
listItems = OUTPUT_FORMAT, listItems = OUTPUT_FORMAT,
selectedItemIndex = viewModel.userPrefs.outputFormat, selectedItemIndex = viewModel.userPrefs.outputFormat,
selectAction = { viewModel.updateOutputFormat(it) }, selectAction = { viewModel.updateOutputFormat(it) },
dismissAction = { resetDialog() }, dismissAction = { resetDialog() },
supportText = stringResource(id = R.string.output_format_setting_info) supportText = stringResource(R.string.output_format_setting_info)
) )
} }
DialogState.CURRENCY_RATE -> { DialogState.CURRENCY_RATE -> {
AlertDialogWithList( AlertDialogWithList(
title = stringResource(id = R.string.currency_rates_note_title), title = stringResource(R.string.currency_rates_note_title),
dismissAction = { resetDialog() }, dismissAction = { resetDialog() },
supportText = stringResource(id = R.string.currency_rates_note_text), supportText = stringResource(R.string.currency_rates_note_text),
dismissButtonLabel = stringResource(id = R.string.ok_label) dismissButtonLabel = stringResource(R.string.ok_label)
) )
} }
// Dismissing alert dialog // Dismissing alert dialog

View File

@ -76,7 +76,7 @@ fun UnitGroupsScreen(
.reorderable(state) .reorderable(state)
) { ) {
item(key = "enabled") { item(key = "enabled") {
Header(text = stringResource(id = R.string.enabled_label)) Header(text = stringResource(R.string.enabled_label))
} }
items(shownUnits.value, { it }) { item -> items(shownUnits.value, { it }) { item ->
@ -97,7 +97,7 @@ fun UnitGroupsScreen(
leadingItem = { leadingItem = {
Icon( Icon(
Icons.Default.RemoveCircle, Icons.Default.RemoveCircle,
stringResource(id = R.string.disable_unit_group_description), stringResource(R.string.disable_unit_group_description),
tint= MaterialTheme.colorScheme.outline, tint= MaterialTheme.colorScheme.outline,
modifier = Modifier.clickable( modifier = Modifier.clickable(
interactionSource = remember { MutableInteractionSource() }, interactionSource = remember { MutableInteractionSource() },
@ -109,7 +109,7 @@ fun UnitGroupsScreen(
trailingItem = { trailingItem = {
Icon( Icon(
Icons.Default.DragIndicator, Icons.Default.DragIndicator,
stringResource(id = R.string.reorder_unit_group_description), stringResource(R.string.reorder_unit_group_description),
tint= MaterialTheme.colorScheme.outline, tint= MaterialTheme.colorScheme.outline,
modifier = Modifier modifier = Modifier
.clickable( .clickable(
@ -126,7 +126,7 @@ fun UnitGroupsScreen(
item(key = "disabled") { item(key = "disabled") {
Header( Header(
text = stringResource(id = R.string.disabled_label), text = stringResource(R.string.disabled_label),
modifier = Modifier.animateItemPlacement() modifier = Modifier.animateItemPlacement()
) )
} }
@ -141,7 +141,7 @@ fun UnitGroupsScreen(
trailingItem = { trailingItem = {
Icon( Icon(
Icons.Default.AddCircleOutline, Icons.Default.AddCircleOutline,
stringResource(id = R.string.enable_unit_group_description), stringResource(R.string.enable_unit_group_description),
tint= MaterialTheme.colorScheme.outline, tint= MaterialTheme.colorScheme.outline,
modifier = Modifier.clickable( modifier = Modifier.clickable(
interactionSource = remember { MutableInteractionSource() }, interactionSource = remember { MutableInteractionSource() },