feat(ui): add support for 3-digit focus session durations

Closes #175
This commit is contained in:
Nishant Mishra
2025-12-19 19:22:46 +05:30
parent 1af146d427
commit 1cb04bef7d
5 changed files with 33 additions and 15 deletions

View File

@@ -250,7 +250,7 @@ fun SharedTransitionScope.AlwaysOnDisplay(
text = timerState.timeStr, text = timerState.timeStr,
style = TextStyle( style = TextStyle(
fontFamily = googleFlex400, fontFamily = googleFlex400,
fontSize = 56.sp, fontSize = if (timerState.timeStr.length < 6) 56.sp else 52.sp,
letterSpacing = (-2).sp, letterSpacing = (-2).sp,
fontFeatureSettings = "tnum" fontFeatureSettings = "tnum"
), ),

View File

@@ -18,6 +18,7 @@
package org.nsh07.pomodoro.ui.settingsScreen.components package org.nsh07.pomodoro.ui.settingsScreen.components
import androidx.compose.animation.animateColorAsState import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
@@ -29,6 +30,7 @@ import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.MaterialTheme.colorScheme import androidx.compose.material3.MaterialTheme.colorScheme
import androidx.compose.material3.MaterialTheme.motionScheme import androidx.compose.material3.MaterialTheme.motionScheme
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Shape import androidx.compose.ui.graphics.Shape
@@ -49,13 +51,14 @@ fun MinuteInputField(
enabled: Boolean, enabled: Boolean,
shape: Shape, shape: Shape,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
inputTransformation: MinutesInputTransformation = MinutesInputTransformation2Digits,
imeAction: ImeAction = ImeAction.Next imeAction: ImeAction = ImeAction.Next
) { ) {
BasicTextField( BasicTextField(
state = state, state = state,
enabled = enabled, enabled = enabled,
lineLimits = TextFieldLineLimits.SingleLine, lineLimits = TextFieldLineLimits.SingleLine,
inputTransformation = MinutesInputTransformation, inputTransformation = inputTransformation,
// outputTransformation = MinutesOutputTransformation, // outputTransformation = MinutesOutputTransformation,
keyboardOptions = KeyboardOptions( keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.NumberPassword, keyboardType = KeyboardType.NumberPassword,
@@ -70,13 +73,18 @@ fun MinuteInputField(
), ),
cursorBrush = SolidColor(colorScheme.onSurface), cursorBrush = SolidColor(colorScheme.onSurface),
decorator = { innerTextField -> decorator = { innerTextField ->
val text = state.text
val width by animateDpAsState(
if (text.length < 3) 112.dp else 140.dp,
motionScheme.defaultSpatialSpec()
)
Box( Box(
contentAlignment = Alignment.Center, contentAlignment = Alignment.Center,
modifier = modifier modifier = modifier
.size(112.dp, 100.dp) .size(width, 100.dp)
.background( .background(
animateColorAsState( animateColorAsState(
if (state.text.isNotEmpty()) if (text.isNotEmpty())
listItemColors.containerColor listItemColors.containerColor
else colorScheme.errorContainer, else colorScheme.errorContainer,
motionScheme.defaultEffectsSpec() motionScheme.defaultEffectsSpec()

View File

@@ -21,19 +21,27 @@ import androidx.compose.foundation.text.input.InputTransformation
import androidx.compose.foundation.text.input.TextFieldBuffer import androidx.compose.foundation.text.input.TextFieldBuffer
import androidx.core.text.isDigitsOnly import androidx.core.text.isDigitsOnly
object MinutesInputTransformation : InputTransformation { class MinutesInputTransformation(val maxDigits: Int) : InputTransformation {
override fun TextFieldBuffer.transformInput() { override fun TextFieldBuffer.transformInput() {
if (!this.asCharSequence().isDigitsOnly() || this.length > 2) { if (!this.asCharSequence().isDigitsOnly() || this.length > maxDigits) {
revertAllChanges() revertAllChanges()
} }
} }
} }
//object MinutesOutputTransformation : OutputTransformation { val MinutesInputTransformation2Digits = MinutesInputTransformation(2)
// override fun TextFieldBuffer.transformOutput() { val MinutesInputTransformation3Digits = MinutesInputTransformation(3)
// when (this.length) {
// 0 -> insert(0, "00") /*
// 1 -> insert(0, "0") This OutputTransformation results in a crash with some keyboard apps, so I'm not using it right now
// } I might start using this later when this issue is resolved upstream in Compose
// }
//} object MinutesOutputTransformation : OutputTransformation {
override fun TextFieldBuffer.transformOutput() {
when (this.length) {
0 -> insert(0, "00")
1 -> insert(0, "0")
}
}
}
*/

View File

@@ -87,6 +87,7 @@ import org.nsh07.pomodoro.R
import org.nsh07.pomodoro.ui.mergePaddingValues import org.nsh07.pomodoro.ui.mergePaddingValues
import org.nsh07.pomodoro.ui.settingsScreen.SettingsSwitchItem import org.nsh07.pomodoro.ui.settingsScreen.SettingsSwitchItem
import org.nsh07.pomodoro.ui.settingsScreen.components.MinuteInputField import org.nsh07.pomodoro.ui.settingsScreen.components.MinuteInputField
import org.nsh07.pomodoro.ui.settingsScreen.components.MinutesInputTransformation3Digits
import org.nsh07.pomodoro.ui.settingsScreen.components.PlusDivider import org.nsh07.pomodoro.ui.settingsScreen.components.PlusDivider
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsAction import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsAction
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsState import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsState
@@ -265,6 +266,7 @@ fun TimerSettings(
topEnd = topListItemShape.bottomStart, topEnd = topListItemShape.bottomStart,
bottomEnd = topListItemShape.bottomStart bottomEnd = topListItemShape.bottomStart
), ),
inputTransformation = MinutesInputTransformation3Digits,
imeAction = ImeAction.Next imeAction = ImeAction.Next
) )
} }

View File

@@ -301,7 +301,7 @@ fun SharedTransitionScope.TimerScreen(
text = timerState.timeStr, text = timerState.timeStr,
style = TextStyle( style = TextStyle(
fontFamily = googleFlex600, fontFamily = googleFlex600,
fontSize = 72.sp, fontSize = if (timerState.timeStr.length < 6) 72.sp else 64.sp,
letterSpacing = (-2.6).sp, letterSpacing = (-2.6).sp,
fontFeatureSettings = "tnum" fontFeatureSettings = "tnum"
), ),