Add an OutputTransformation for the minutes input field
And some viewmodel optimizations
This commit is contained in:
@@ -37,6 +37,7 @@ fun MinuteInputField(
|
||||
state = state,
|
||||
lineLimits = TextFieldLineLimits.SingleLine,
|
||||
inputTransformation = MinutesInputTransformation,
|
||||
outputTransformation = MinutesOutputTransformation,
|
||||
keyboardOptions = KeyboardOptions(
|
||||
keyboardType = KeyboardType.NumberPassword,
|
||||
imeAction = imeAction
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package org.nsh07.pomodoro.ui.settingsScreen
|
||||
|
||||
import androidx.compose.foundation.text.input.InputTransformation
|
||||
import androidx.compose.foundation.text.input.OutputTransformation
|
||||
import androidx.compose.foundation.text.input.TextFieldBuffer
|
||||
import androidx.compose.foundation.text.input.insert
|
||||
import androidx.core.text.isDigitsOnly
|
||||
|
||||
object MinutesInputTransformation : InputTransformation {
|
||||
@@ -10,4 +12,14 @@ object MinutesInputTransformation : InputTransformation {
|
||||
revertAllChanges()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object MinutesOutputTransformation : OutputTransformation {
|
||||
override fun TextFieldBuffer.transformOutput() {
|
||||
if (this.length == 0) {
|
||||
insert(0, "00")
|
||||
} else if (this.toString().toInt() < 10) {
|
||||
insert(0, "0")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,18 +72,18 @@ fun SettingsScreen(
|
||||
)
|
||||
|
||||
LazyColumn(
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 16.dp)
|
||||
) {
|
||||
item {
|
||||
Text(
|
||||
"Durations",
|
||||
"Timer",
|
||||
style = typography.titleSmall,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 8.dp)
|
||||
.padding(horizontal = 8.dp, vertical = 14.dp)
|
||||
)
|
||||
}
|
||||
item {
|
||||
@@ -93,7 +93,10 @@ fun SettingsScreen(
|
||||
.fillMaxWidth()
|
||||
.horizontalScroll(rememberScrollState())
|
||||
) {
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp)
|
||||
) {
|
||||
MinuteInputField(
|
||||
state = focusTimeInputFieldState,
|
||||
shape = RoundedCornerShape(
|
||||
@@ -112,7 +115,10 @@ fun SettingsScreen(
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.width(2.dp))
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp)
|
||||
) {
|
||||
MinuteInputField(
|
||||
state = shortBreakTimeInputFieldState,
|
||||
shape = RoundedCornerShape(4.dp),
|
||||
@@ -126,7 +132,10 @@ fun SettingsScreen(
|
||||
)
|
||||
}
|
||||
Spacer(Modifier.width(2.dp))
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp)
|
||||
) {
|
||||
MinuteInputField(
|
||||
state = longBreakTimeInputFieldState,
|
||||
shape = RoundedCornerShape(
|
||||
|
||||
@@ -231,11 +231,10 @@ class UiViewModel(
|
||||
.debounce(500)
|
||||
.collect {
|
||||
if (it.isNotEmpty()) {
|
||||
preferenceRepository.saveIntPreference(
|
||||
focusTime = preferenceRepository.saveIntPreference(
|
||||
"focus_time",
|
||||
it.toString().toInt() * 60 * 1000
|
||||
)
|
||||
updateTimerConstants(restart = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -244,11 +243,10 @@ class UiViewModel(
|
||||
.debounce(500)
|
||||
.collect {
|
||||
if (it.isNotEmpty()) {
|
||||
preferenceRepository.saveIntPreference(
|
||||
focusTime = preferenceRepository.saveIntPreference(
|
||||
"short_break_time",
|
||||
it.toString().toInt() * 60 * 1000
|
||||
)
|
||||
updateTimerConstants(restart = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -257,11 +255,10 @@ class UiViewModel(
|
||||
.debounce(500)
|
||||
.collect {
|
||||
if (it.isNotEmpty()) {
|
||||
preferenceRepository.saveIntPreference(
|
||||
focusTime = preferenceRepository.saveIntPreference(
|
||||
"long_break_time",
|
||||
it.toString().toInt() * 60 * 1000
|
||||
)
|
||||
updateTimerConstants(restart = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user