mirror of
https://github.com/AdrianKuta/KahootQuiz.git
synced 2026-02-03 02:50:42 +01:00
feat: Implement question timer and update toolbar UI
This commit introduces a timer for questions in the `QuizScreen` and updates the toolbar to display the current question number out of the total.
Key changes:
- **UI Layer (`ui:quiz` module):**
- In `QuizScreen.kt`:
- Added a `TimerBar` composable to visually represent the remaining time for a question. This bar animates its width and displays the remaining seconds.
- Updated the `Toolbar` composable to display the current question index and total number of questions (e.g., "1/10").
- Passed `currentQuestionIndex`, `totalQuestions`, `totalTimeSeconds`, and `remainingTimeSeconds` from `QuizUiState` to the respective composables.
- Updated previews to reflect new `QuizUiState` properties.
- Used `RoundedCornerShape(percent = 50)` for more consistent rounded corners in the `Toolbar`.
- In `QuizScreenViewModel.kt`:
- Added `_remainingTimeSeconds` MutableStateFlow to track the countdown.
- Modified `QuizUiState` to include `currentQuestionIndex`, `totalQuestions`, `totalTimeSeconds`, and `remainingTimeSeconds`.
- Implemented `startCountdown()` logic to decrease `_remainingTimeSeconds` every second.
- The timer is started when the ViewModel is initialized and for each new question.
- When a choice is selected, the timer is cancelled.
- If the timer runs out before a choice is selected, `_selectedChoiceIndex` is set to -1 to indicate a timeout.
- The `uiState` flow now combines `getQuizUseCase()`, `_selectedChoiceIndex`, and `_remainingTimeSeconds` to derive the `QuizUiState`.
- **Design System (`core:designsystem` module):**
- Added `Purple` color definition in `Color.kt` for use in the `TimerBar`.
- Reordered color definitions alphabetically.
This commit is contained in:
@@ -19,11 +19,12 @@ val Purple40 = Color(0xFF6650a4)
|
||||
val PurpleGrey40 = Color(0xFF625b71)
|
||||
val Pink40 = Color(0xFF7D5260)
|
||||
|
||||
val Grey = Color(0xFFFAFAFA)
|
||||
val Pink = Color(0xFFFF99AA)
|
||||
val Red = Color(0xFFFF3355)
|
||||
val Red2 = Color(0xFFE21B3C)
|
||||
val Blue2 = Color(0xFF1368CE)
|
||||
val Yellow3 = Color(0xFFD89E00)
|
||||
val Green = Color(0xFF66BF39)
|
||||
val Green2 = Color(0xFF26890C)
|
||||
val Grey = Color(0xFFFAFAFA)
|
||||
val Pink = Color(0xFFFF99AA)
|
||||
val Purple = Color(0xFF864CBF)
|
||||
val Red = Color(0xFFFF3355)
|
||||
val Red2 = Color(0xFFE21B3C)
|
||||
val Yellow3 = Color(0xFFD89E00)
|
||||
|
||||
Reference in New Issue
Block a user