Skip to content

Commit

Permalink
🔥 Remove ClockFormatEnum
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Colman Lopes <[email protected]>
  • Loading branch information
LeoColman committed Dec 28, 2024
1 parent c9b790b commit c913401
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.intPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import br.com.colman.petals.utils.datetime.ClockFormatEnum
import br.com.colman.petals.R.string.hours_12
import br.com.colman.petals.R.string.hours_24
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.runBlocking
Expand Down Expand Up @@ -34,6 +35,8 @@ private val TimeFormats = listOf(
"KK:mm:ss a"
)

private val ClockFormats = listOf(hours_12, hours_24)

class SettingsRepository(
private val datastore: DataStore<Preferences>
) {
Expand All @@ -43,7 +46,7 @@ class SettingsRepository(
val dateFormat = datastore.data.map { it[DateFormat] ?: dateFormatList.first() }
val timeFormatList = TimeFormats
val timeFormat = datastore.data.map { it[TimeFormat] ?: timeFormatList.first() }
val clockFormatList = ClockFormatEnum.entries.toList()
val clockFormatList = ClockFormats
val is24HoursFormat = datastore.data.map { it[Is24HoursFormat] ?: false }
val decimalPrecisionList = listOf(0, 1, 2, 3)
val decimalPrecision = datastore.data.map { it[DecimalPrecision] ?: decimalPrecisionList[2] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.core.os.LocaleListCompat
import br.com.colman.petals.settings.view.listitem.ClockListItem
import br.com.colman.petals.settings.view.listitem.CurrencyListItem
Expand Down Expand Up @@ -50,7 +51,13 @@ fun SettingsView(settingsRepository: SettingsRepository) {
RepositoryListItem()
DateListItem(currentDateFormat, settingsRepository.dateFormatList, settingsRepository::setDateFormat)
TimeListItem(currentTimeFormat, settingsRepository.timeFormatList, settingsRepository::setTimeFormat)
ClockListItem(is24HoursFormat, settingsRepository.clockFormatList, settingsRepository::setIs24HoursFormat)
ClockListItem(
is24HoursFormat,
settingsRepository.clockFormatList.map {
stringResource(it)
},
settingsRepository::setIs24HoursFormat
)
PrecisionListItem(
currentDecimalPrecision,
settingsRepository.decimalPrecisionList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import br.com.colman.petals.R
import br.com.colman.petals.R.string.clock_format_label
import br.com.colman.petals.R.string.hours_12
import br.com.colman.petals.R.string.hours_24
import br.com.colman.petals.R.string.what_clock_format_should_be_used
import br.com.colman.petals.settings.view.dialog.SelectFromListDialog
import br.com.colman.petals.utils.datetime.ClockFormatEnum
import compose.icons.TablerIcons
import compose.icons.tablericons.Clock

@Preview
@Composable
fun ClockListItem(
is24HoursFormat: Boolean = false,
clockFormatList: List<ClockFormatEnum> = listOf(),
clockFormatList: List<String> = listOf(),
setIs24HoursFormat: (Boolean) -> Unit = {}
) {
DialogListItem(
Expand All @@ -38,21 +38,17 @@ fun ClockListItem(
@Composable
private fun ClockDialog(
is24HoursFormat: Boolean = false,
clockFormatList: List<ClockFormatEnum> = listOf(),
clockFormatList: List<String> = listOf(),
setIs24HoursFormat: (Boolean) -> Unit = {},
onDismiss: () -> Unit = {},
) {
val context = LocalContext.current
val initialValue = if (is24HoursFormat) {
stringResource(id = R.string.hours_24)
} else {
stringResource(id = R.string.hours_12)
}
val initialValue = if (is24HoursFormat) stringResource(hours_24) else stringResource(hours_12)

SelectFromListDialog(
initialValue = initialValue,
possibleValues = clockFormatList.map { stringResource(it.nameRes) },
setValue = { value -> setIs24HoursFormat(value == context.getString(R.string.hours_24)) },
possibleValues = clockFormatList,
setValue = { value -> setIs24HoursFormat(value == context.getString(hours_24)) },
onDismiss = onDismiss,
label = clock_format_label
)
Expand Down

This file was deleted.

0 comments on commit c913401

Please sign in to comment.