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.ExperimentalMaterial3Api
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.lifecycle.compose.collectAsStateWithLifecycle 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.timerScreen.TimerScreen
import org.nsh07.pomodoro.ui.viewModel.UiViewModel import org.nsh07.pomodoro.ui.viewModel.UiViewModel
@@ -20,9 +27,18 @@ fun AppScreen(
val remainingTime by viewModel.time.collectAsStateWithLifecycle() val remainingTime by viewModel.time.collectAsStateWithLifecycle()
val progress by rememberUpdatedState((uiState.totalTime.toFloat() - remainingTime) / uiState.totalTime) 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( TimerScreen(
uiState = uiState, uiState = uiState,
showBrandTitle = showBrandTitle,
progress = { progress }, progress = { progress },
resetTimer = viewModel::resetTimer, resetTimer = viewModel::resetTimer,
toggleTimer = viewModel::toggleTimer, toggleTimer = viewModel::toggleTimer,

View File

@@ -62,6 +62,7 @@ import org.nsh07.pomodoro.ui.viewModel.UiState
@Composable @Composable
fun TimerScreen( fun TimerScreen(
uiState: UiState, uiState: UiState,
showBrandTitle: Boolean,
progress: () -> Float, progress: () -> Float,
resetTimer: () -> Unit, resetTimer: () -> Unit,
toggleTimer: () -> Unit, toggleTimer: () -> Unit,
@@ -95,7 +96,7 @@ fun TimerScreen(
TopAppBar( TopAppBar(
title = { title = {
AnimatedContent( AnimatedContent(
uiState.timerMode, if (!showBrandTitle) uiState.timerMode else TimerMode.BRAND,
transitionSpec = { transitionSpec = {
slideInVertically( slideInVertically(
animationSpec = motionScheme.slowSpatialSpec(), animationSpec = motionScheme.slowSpatialSpec(),
@@ -109,6 +110,19 @@ fun TimerScreen(
} }
) { ) {
when (it) { 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 -> TimerMode.FOCUS ->
Text( Text(
"Focus", "Focus",
@@ -289,7 +303,7 @@ fun TimerScreen(
when (uiState.nextTimerMode) { when (uiState.nextTimerMode) {
TimerMode.FOCUS -> "Focus" TimerMode.FOCUS -> "Focus"
TimerMode.SHORT_BREAK -> "Short Break" TimerMode.SHORT_BREAK -> "Short Break"
TimerMode.LONG_BREAK -> "Long Break" else -> "Long Break"
}, },
style = typography.titleMediumEmphasized style = typography.titleMediumEmphasized
) )
@@ -309,6 +323,6 @@ fun TimerScreenPreview() {
timeStr = "03:34", nextTimeStr = "5:00", timerMode = TimerMode.SHORT_BREAK timeStr = "03:34", nextTimeStr = "5:00", timerMode = TimerMode.SHORT_BREAK
) )
TomatoTheme { TomatoTheme {
TimerScreen(uiState, { 0.3f }, {}, {}) TimerScreen(uiState, false,{ 0.3f }, {}, {})
} }
} }

View File

@@ -10,5 +10,5 @@ data class UiState(
) )
enum class TimerMode { 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() focusTime - (SystemClock.elapsedRealtime() - startTime - pauseDuration).toInt()
TimerMode.SHORT_BREAK -> TimerMode.SHORT_BREAK ->
shortBreakTime - (SystemClock.elapsedRealtime() - startTime - pauseDuration).toInt() shortBreakTime - (SystemClock.elapsedRealtime() - startTime - pauseDuration).toInt()
TimerMode.LONG_BREAK -> else ->
longBreakTime - (SystemClock.elapsedRealtime() - startTime - pauseDuration).toInt() longBreakTime - (SystemClock.elapsedRealtime() - startTime - pauseDuration).toInt()
} }
} }