mirror of
https://github.com/AdrianKuta/KahootQuiz.git
synced 2025-10-30 16:33:42 +01:00
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.