Add ability to skip to the next mode
This commit is contained in:
@@ -41,6 +41,7 @@ fun AppScreen(
|
||||
showBrandTitle = showBrandTitle,
|
||||
progress = { progress },
|
||||
resetTimer = viewModel::resetTimer,
|
||||
skipTimer = viewModel::skipTimer,
|
||||
toggleTimer = viewModel::toggleTimer,
|
||||
modifier = modifier
|
||||
)
|
||||
|
||||
@@ -67,6 +67,7 @@ fun TimerScreen(
|
||||
showBrandTitle: Boolean,
|
||||
progress: () -> Float,
|
||||
resetTimer: () -> Unit,
|
||||
skipTimer: () -> Unit,
|
||||
toggleTimer: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
@@ -228,7 +229,7 @@ fun TimerScreen(
|
||||
maxLines = 1
|
||||
)
|
||||
}
|
||||
val interactionSources = remember { List(2) { MutableInteractionSource() } }
|
||||
val interactionSources = remember { List(3) { MutableInteractionSource() } }
|
||||
ButtonGroup(
|
||||
overflowIndicator = { state ->
|
||||
FilledTonalIconButton(
|
||||
@@ -243,11 +244,13 @@ fun TimerScreen(
|
||||
containerColor = colorContainer
|
||||
),
|
||||
shapes = IconButtonDefaults.shapes(),
|
||||
modifier = Modifier.size(64.dp, 96.dp)
|
||||
modifier = Modifier
|
||||
.size(64.dp, 96.dp)
|
||||
) {
|
||||
Icon(
|
||||
painterResource(R.drawable.more_vert_large),
|
||||
contentDescription = "More"
|
||||
contentDescription = "More",
|
||||
modifier = Modifier.size(32.dp)
|
||||
)
|
||||
}
|
||||
},
|
||||
@@ -263,10 +266,10 @@ fun TimerScreen(
|
||||
checkedContentColor = onColor
|
||||
),
|
||||
shapes = IconButtonDefaults.toggleableShapes(),
|
||||
interactionSource = interactionSources[1],
|
||||
interactionSource = interactionSources[0],
|
||||
modifier = Modifier
|
||||
.size(width = 128.dp, height = 96.dp)
|
||||
.animateWidth(interactionSources[1])
|
||||
.animateWidth(interactionSources[0])
|
||||
) {
|
||||
if (uiState.timerRunning) {
|
||||
Icon(
|
||||
@@ -306,6 +309,7 @@ fun TimerScreen(
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
customItem(
|
||||
{
|
||||
FilledTonalIconButton(
|
||||
@@ -314,10 +318,10 @@ fun TimerScreen(
|
||||
containerColor = colorContainer
|
||||
),
|
||||
shapes = IconButtonDefaults.shapes(),
|
||||
interactionSource = interactionSources[0],
|
||||
interactionSource = interactionSources[1],
|
||||
modifier = Modifier
|
||||
.size(96.dp)
|
||||
.animateWidth(interactionSources[0])
|
||||
.animateWidth(interactionSources[1])
|
||||
) {
|
||||
Icon(
|
||||
painterResource(R.drawable.restart_large),
|
||||
@@ -342,6 +346,43 @@ fun TimerScreen(
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
customItem(
|
||||
{
|
||||
FilledTonalIconButton(
|
||||
onClick = skipTimer,
|
||||
colors = IconButtonDefaults.filledTonalIconButtonColors(
|
||||
containerColor = colorContainer
|
||||
),
|
||||
shapes = IconButtonDefaults.shapes(),
|
||||
interactionSource = interactionSources[2],
|
||||
modifier = Modifier
|
||||
.size(64.dp, 96.dp)
|
||||
.animateWidth(interactionSources[2])
|
||||
) {
|
||||
Icon(
|
||||
painterResource(R.drawable.skip_next_large),
|
||||
contentDescription = "Skip to next",
|
||||
modifier = Modifier.size(32.dp)
|
||||
)
|
||||
}
|
||||
},
|
||||
{ state ->
|
||||
DropdownMenuItem(
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
painterResource(R.drawable.skip_next),
|
||||
"Skip to next"
|
||||
)
|
||||
},
|
||||
text = { Text("Skip to next") },
|
||||
onClick = {
|
||||
skipTimer()
|
||||
state.dismiss()
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -374,8 +415,7 @@ fun TimerScreen(
|
||||
|
||||
@Preview(
|
||||
showSystemUi = true,
|
||||
device = Devices.PIXEL_9_PRO,
|
||||
// widthDp = 200
|
||||
device = Devices.PIXEL_9_PRO
|
||||
)
|
||||
@Composable
|
||||
fun TimerScreenPreview() {
|
||||
@@ -383,6 +423,6 @@ fun TimerScreenPreview() {
|
||||
timeStr = "03:34", nextTimeStr = "5:00", timerMode = TimerMode.FOCUS, timerRunning = true
|
||||
)
|
||||
TomatoTheme {
|
||||
TimerScreen(uiState, false, { 0.3f }, {}, {})
|
||||
TimerScreen(uiState, false, { 0.3f }, {}, {}, {})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,43 @@ class UiViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun skipTimer() {
|
||||
startTime = 0L
|
||||
pauseTime = 0L
|
||||
pauseDuration = 0L
|
||||
cycles = (cycles + 1) % 8
|
||||
|
||||
if (cycles % 2 == 0) {
|
||||
_time.update { focusTime }
|
||||
_uiState.update { currentState ->
|
||||
currentState.copy(
|
||||
timerMode = TimerMode.FOCUS,
|
||||
timeStr = millisecondsToStr(time.value),
|
||||
totalTime = time.value,
|
||||
nextTimerMode = if (cycles == 6) TimerMode.LONG_BREAK else TimerMode.SHORT_BREAK,
|
||||
nextTimeStr = if (cycles == 6) millisecondsToStr(
|
||||
longBreakTime
|
||||
) else millisecondsToStr(
|
||||
shortBreakTime
|
||||
)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
val long = cycles == 7
|
||||
_time.update { if (long) longBreakTime else shortBreakTime }
|
||||
|
||||
_uiState.update { currentState ->
|
||||
currentState.copy(
|
||||
timerMode = if (long) TimerMode.LONG_BREAK else TimerMode.SHORT_BREAK,
|
||||
timeStr = millisecondsToStr(time.value),
|
||||
totalTime = time.value,
|
||||
nextTimerMode = TimerMode.FOCUS,
|
||||
nextTimeStr = millisecondsToStr(focusTime)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun toggleTimer() {
|
||||
if (uiState.value.timerRunning) {
|
||||
_uiState.update { currentState ->
|
||||
@@ -85,7 +122,7 @@ class UiViewModel : ViewModel() {
|
||||
startTime = 0L
|
||||
pauseTime = 0L
|
||||
pauseDuration = 0L
|
||||
cycles++
|
||||
cycles = (cycles + 1) % 8
|
||||
|
||||
if (cycles % 2 == 0) {
|
||||
_time.update { focusTime }
|
||||
@@ -94,8 +131,8 @@ class UiViewModel : ViewModel() {
|
||||
timerMode = TimerMode.FOCUS,
|
||||
timeStr = millisecondsToStr(time.value),
|
||||
totalTime = time.value,
|
||||
nextTimerMode = if (cycles % 6 == 0) TimerMode.LONG_BREAK else TimerMode.SHORT_BREAK,
|
||||
nextTimeStr = if (cycles % 6 == 0) millisecondsToStr(
|
||||
nextTimerMode = if (cycles == 6) TimerMode.LONG_BREAK else TimerMode.SHORT_BREAK,
|
||||
nextTimeStr = if (cycles == 6) millisecondsToStr(
|
||||
longBreakTime
|
||||
) else millisecondsToStr(
|
||||
shortBreakTime
|
||||
@@ -103,7 +140,7 @@ class UiViewModel : ViewModel() {
|
||||
)
|
||||
}
|
||||
} else {
|
||||
val long = cycles % 7 == 0
|
||||
val long = cycles == 7
|
||||
_time.update { if (long) longBreakTime else shortBreakTime }
|
||||
|
||||
_uiState.update { currentState ->
|
||||
|
||||
Reference in New Issue
Block a user