@@ -250,7 +250,7 @@ fun SharedTransitionScope.AlwaysOnDisplay(
|
||||
text = timerState.timeStr,
|
||||
style = TextStyle(
|
||||
fontFamily = googleFlex400,
|
||||
fontSize = 56.sp,
|
||||
fontSize = if (timerState.timeStr.length < 6) 56.sp else 52.sp,
|
||||
letterSpacing = (-2).sp,
|
||||
fontFeatureSettings = "tnum"
|
||||
),
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package org.nsh07.pomodoro.ui.settingsScreen.components
|
||||
|
||||
import androidx.compose.animation.animateColorAsState
|
||||
import androidx.compose.animation.core.animateDpAsState
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
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.motionScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Shape
|
||||
@@ -49,13 +51,14 @@ fun MinuteInputField(
|
||||
enabled: Boolean,
|
||||
shape: Shape,
|
||||
modifier: Modifier = Modifier,
|
||||
inputTransformation: MinutesInputTransformation = MinutesInputTransformation2Digits,
|
||||
imeAction: ImeAction = ImeAction.Next
|
||||
) {
|
||||
BasicTextField(
|
||||
state = state,
|
||||
enabled = enabled,
|
||||
lineLimits = TextFieldLineLimits.SingleLine,
|
||||
inputTransformation = MinutesInputTransformation,
|
||||
inputTransformation = inputTransformation,
|
||||
// outputTransformation = MinutesOutputTransformation,
|
||||
keyboardOptions = KeyboardOptions(
|
||||
keyboardType = KeyboardType.NumberPassword,
|
||||
@@ -70,13 +73,18 @@ fun MinuteInputField(
|
||||
),
|
||||
cursorBrush = SolidColor(colorScheme.onSurface),
|
||||
decorator = { innerTextField ->
|
||||
val text = state.text
|
||||
val width by animateDpAsState(
|
||||
if (text.length < 3) 112.dp else 140.dp,
|
||||
motionScheme.defaultSpatialSpec()
|
||||
)
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
modifier = modifier
|
||||
.size(112.dp, 100.dp)
|
||||
.size(width, 100.dp)
|
||||
.background(
|
||||
animateColorAsState(
|
||||
if (state.text.isNotEmpty())
|
||||
if (text.isNotEmpty())
|
||||
listItemColors.containerColor
|
||||
else colorScheme.errorContainer,
|
||||
motionScheme.defaultEffectsSpec()
|
||||
|
||||
@@ -21,19 +21,27 @@ import androidx.compose.foundation.text.input.InputTransformation
|
||||
import androidx.compose.foundation.text.input.TextFieldBuffer
|
||||
import androidx.core.text.isDigitsOnly
|
||||
|
||||
object MinutesInputTransformation : InputTransformation {
|
||||
class MinutesInputTransformation(val maxDigits: Int) : InputTransformation {
|
||||
override fun TextFieldBuffer.transformInput() {
|
||||
if (!this.asCharSequence().isDigitsOnly() || this.length > 2) {
|
||||
if (!this.asCharSequence().isDigitsOnly() || this.length > maxDigits) {
|
||||
revertAllChanges()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//object MinutesOutputTransformation : OutputTransformation {
|
||||
// override fun TextFieldBuffer.transformOutput() {
|
||||
// when (this.length) {
|
||||
// 0 -> insert(0, "00")
|
||||
// 1 -> insert(0, "0")
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
val MinutesInputTransformation2Digits = MinutesInputTransformation(2)
|
||||
val MinutesInputTransformation3Digits = MinutesInputTransformation(3)
|
||||
|
||||
/*
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -87,6 +87,7 @@ import org.nsh07.pomodoro.R
|
||||
import org.nsh07.pomodoro.ui.mergePaddingValues
|
||||
import org.nsh07.pomodoro.ui.settingsScreen.SettingsSwitchItem
|
||||
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.viewModel.SettingsAction
|
||||
import org.nsh07.pomodoro.ui.settingsScreen.viewModel.SettingsState
|
||||
@@ -265,6 +266,7 @@ fun TimerSettings(
|
||||
topEnd = topListItemShape.bottomStart,
|
||||
bottomEnd = topListItemShape.bottomStart
|
||||
),
|
||||
inputTransformation = MinutesInputTransformation3Digits,
|
||||
imeAction = ImeAction.Next
|
||||
)
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ fun SharedTransitionScope.TimerScreen(
|
||||
text = timerState.timeStr,
|
||||
style = TextStyle(
|
||||
fontFamily = googleFlex600,
|
||||
fontSize = 72.sp,
|
||||
fontSize = if (timerState.timeStr.length < 6) 72.sp else 64.sp,
|
||||
letterSpacing = (-2.6).sp,
|
||||
fontFeatureSettings = "tnum"
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user