mirror of
https://github.com/AdrianKuta/KahootQuiz.git
synced 2025-10-30 16:33:42 +01:00
This commit introduces a timer for each question in the `QuizScreen` and enables navigation to the next question upon answering or when the timer expires.
Key changes:
- **UI Layer (`ui:quiz` module):**
- **QuizScreen.kt:**
- Refactored `QuizScreen` to use `LazyColumn` for better performance and to support animated item changes.
- Implemented a "Continue" button that appears after a choice is selected, allowing the user to proceed to the next question.
- The `Choices` layout was changed from `LazyVerticalGrid` to `FlowRow` for more flexible item arrangement.
- Added a loading state (`CircularProgressIndicator`) while quiz data is being fetched.
- Question images are now clipped with rounded corners.
- `ScreenUiState` (formerly `QuizUiState`) now holds `selectedChoiceIndex` directly instead of a separate `AnswerUiState`.
- The `onContinue` callback is passed to the `QuizScreen` to handle advancing to the next question.
- Added `animateContentSize` to the main `LazyColumn` for smoother transitions.
- **QuizScreenViewModel.kt:**
- Introduced `QuizUiState` (sealed interface with `Loading` and `Success` states) to represent the state of quiz data fetching.
- Introduced `ScreenUiState` (sealed interface with `Loading` and `Success` states) to represent the overall screen state, including the current question, selected answer, and timer.
- Implemented timer logic:
- A countdown timer starts for each question.
- The timer is cancelled when an answer is selected.
- `_remainingTimeSeconds` now defaults to -1 to indicate the timer hasn't started for the current question yet.
- Implemented `onContinue()` function to:
- Advance to the `_currentQuestionIndex`.
- Reset `_selectedChoiceIndex`.
- Start the timer for the new question.
- The initial quiz fetch now populates the `quiz` StateFlow.
- The timer starts automatically when the first question of a successfully loaded quiz is ready.
- `TimerState` data class was created to encapsulate timer-related information.