Show app name in title bar on app start

This commit is contained in:
Nishant Mishra
2025-07-01 20:22:05 +05:30
parent 2157ce49a9
commit d83950f2b9
4 changed files with 35 additions and 5 deletions

View File

@@ -3,10 +3,17 @@ package org.nsh07.pomodoro.ui
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.withContext
import org.nsh07.pomodoro.ui.timerScreen.TimerScreen
import org.nsh07.pomodoro.ui.viewModel.UiViewModel
@@ -20,9 +27,18 @@ fun AppScreen(
val remainingTime by viewModel.time.collectAsStateWithLifecycle()
val progress by rememberUpdatedState((uiState.totalTime.toFloat() - remainingTime) / uiState.totalTime)
var showBrandTitle by remember { mutableStateOf(true) }
LaunchedEffect(Unit) {
withContext(Dispatchers.IO) {
delay(1500)
showBrandTitle = false
}
}
TimerScreen(
uiState = uiState,
showBrandTitle = showBrandTitle,
progress = { progress },
resetTimer = viewModel::resetTimer,
toggleTimer = viewModel::toggleTimer,

View File

@@ -62,6 +62,7 @@ import org.nsh07.pomodoro.ui.viewModel.UiState
@Composable
fun TimerScreen(
uiState: UiState,
showBrandTitle: Boolean,
progress: () -> Float,
resetTimer: () -> Unit,
toggleTimer: () -> Unit,
@@ -95,7 +96,7 @@ fun TimerScreen(
TopAppBar(
title = {
AnimatedContent(
uiState.timerMode,
if (!showBrandTitle) uiState.timerMode else TimerMode.BRAND,
transitionSpec = {
slideInVertically(
animationSpec = motionScheme.slowSpatialSpec(),
@@ -109,6 +110,19 @@ fun TimerScreen(
}
) {
when (it) {
TimerMode.BRAND ->
Text(
"Tomato",
style = TextStyle(
fontFamily = interDisplayBlack,
fontSize = 32.sp,
lineHeight = 32.sp,
color = colorScheme.onErrorContainer
),
textAlign = TextAlign.Center,
modifier = Modifier.width(200.dp)
)
TimerMode.FOCUS ->
Text(
"Focus",
@@ -289,7 +303,7 @@ fun TimerScreen(
when (uiState.nextTimerMode) {
TimerMode.FOCUS -> "Focus"
TimerMode.SHORT_BREAK -> "Short Break"
TimerMode.LONG_BREAK -> "Long Break"
else -> "Long Break"
},
style = typography.titleMediumEmphasized
)
@@ -309,6 +323,6 @@ fun TimerScreenPreview() {
timeStr = "03:34", nextTimeStr = "5:00", timerMode = TimerMode.SHORT_BREAK
)
TomatoTheme {
TimerScreen(uiState, { 0.3f }, {}, {})
TimerScreen(uiState, false,{ 0.3f }, {}, {})
}
}

View File

@@ -10,5 +10,5 @@ data class UiState(
)
enum class TimerMode {
FOCUS, SHORT_BREAK, LONG_BREAK
FOCUS, SHORT_BREAK, LONG_BREAK, BRAND
}

View File

@@ -76,7 +76,7 @@ class UiViewModel : ViewModel() {
focusTime - (SystemClock.elapsedRealtime() - startTime - pauseDuration).toInt()
TimerMode.SHORT_BREAK ->
shortBreakTime - (SystemClock.elapsedRealtime() - startTime - pauseDuration).toInt()
TimerMode.LONG_BREAK ->
else ->
longBreakTime - (SystemClock.elapsedRealtime() - startTime - pauseDuration).toInt()
}
}