From ed373554a32a8190e57de761c2c5e12869a6173e Mon Sep 17 00:00:00 2001 From: VawnDao <134820492+VawnDao@users.noreply.github.com> Date: Fri, 6 Dec 2024 18:59:22 +0700 Subject: [PATCH] =?UTF-8?q?feat(study):=20b=E1=BA=ADt=20t=E1=BA=AFt=20?= =?UTF-8?q?=C3=A2m=20thanh=20trong=20khi=20h=E1=BB=8Dc=20(#88)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daocon <134820492+Daocon@users.noreply.github.com> --- .../studies/component/StudyTopAppBar.kt | 16 +++++++++++++ .../studies/flip/FlipFlashCardScreen.kt | 10 +++++++- .../studies/flip/FlipFlashCardUiAction.kt | 1 + .../studies/flip/FlipFlashCardViewModel.kt | 9 ++++++++ .../studies/quiz/LearnByQuizScreen.kt | 23 +++++++++++++++++-- .../studies/quiz/LearnByQuizUiAction.kt | 1 + .../studies/quiz/LearnByQuizViewModel.kt | 9 ++++++++ .../true_false/LearnByTrueFalseScreen.kt | 22 ++++++++++++++++-- .../true_false/LearnByTrueFalseUiAction.kt | 1 + .../true_false/LearnByTrueFalseViewModel.kt | 9 ++++++++ .../studies/write/LearnByWriteScreen.kt | 22 ++++++++++++++++-- .../studies/write/LearnByWriteUiAction.kt | 1 + .../studies/write/LearnByWriteViewModel.kt | 9 ++++++++ app/src/main/res/drawable/ic_volume_off.xml | 9 ++++++++ 14 files changed, 135 insertions(+), 7 deletions(-) create mode 100644 app/src/main/res/drawable/ic_volume_off.xml diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/component/StudyTopAppBar.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/component/StudyTopAppBar.kt index a7902f5b..64d62875 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/component/StudyTopAppBar.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/component/StudyTopAppBar.kt @@ -1,5 +1,6 @@ package com.pwhs.quickmem.presentation.app.study_set.studies.component +import androidx.compose.foundation.layout.size import androidx.compose.material.icons.Icons.Default import androidx.compose.material.icons.filled.Clear import androidx.compose.material.icons.filled.RestartAlt @@ -11,9 +12,11 @@ import androidx.compose.material3.MaterialTheme.typography import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.PreviewLightDark +import androidx.compose.ui.unit.dp import com.pwhs.quickmem.R import com.pwhs.quickmem.ui.theme.QuickMemTheme @@ -28,6 +31,8 @@ fun StudyTopAppBar( onRestartClicked: () -> Unit = {}, shouldShowRestart: Boolean = true, isGetAll: Boolean = false, + isPlaySound: Boolean = false, + onChangeIsPlaySound: (Boolean) -> Unit = {} ) { CenterAlignedTopAppBar( modifier = modifier, @@ -53,6 +58,17 @@ fun StudyTopAppBar( }, actions = { if (shouldShowRestart && isGetAll) { + IconButton( + onClick = { onChangeIsPlaySound(!isPlaySound) } + ) { + Icon( + painter = if (isPlaySound) painterResource(id = R.drawable.ic_sound) else painterResource( + id = R.drawable.ic_volume_off + ), + contentDescription = "Sound", + modifier = Modifier.size(22.dp) + ) + } IconButton( onClick = onRestartClicked ) { diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/flip/FlipFlashCardScreen.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/flip/FlipFlashCardScreen.kt index 290a09cf..4c2dcc2e 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/flip/FlipFlashCardScreen.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/flip/FlipFlashCardScreen.kt @@ -94,6 +94,10 @@ fun FlipFlashCardScreen( isSwipingLeft = uiState.isSwipingLeft, isSwipingRight = uiState.isSwipingRight, isEndOfList = uiState.isEndOfList, + isPlaySound = uiState.isPlaySound, + onChangeIsPlaySound = { + viewModel.onEvent(FlipFlashCardUiAction.OnChangeIsPlaySound(it)) + }, learningTime = uiState.learningTime, onEndSessionClick = { viewModel.onEvent(FlipFlashCardUiAction.OnBackClicked) @@ -145,6 +149,8 @@ fun FlipFlashCard( isSwipingLeft: Boolean = false, isSwipingRight: Boolean = false, isEndOfList: Boolean = false, + isPlaySound: Boolean = false, + onChangeIsPlaySound: (Boolean) -> Unit = { }, learningTime: Long = 0L, onEndSessionClick: () -> Unit = { }, onUpdatedCardIndex: (Int) -> Unit = { }, @@ -202,7 +208,9 @@ fun FlipFlashCard( stackState.reset() }, shouldShowRestart = !isEndOfList, - isGetAll = isGetAll + isGetAll = isGetAll, + isPlaySound = isPlaySound, + onChangeIsPlaySound = onChangeIsPlaySound ) } ) { innerPadding -> diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/flip/FlipFlashCardUiAction.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/flip/FlipFlashCardUiAction.kt index aafb8b73..2061193a 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/flip/FlipFlashCardUiAction.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/flip/FlipFlashCardUiAction.kt @@ -18,4 +18,5 @@ sealed class FlipFlashCardUiAction { data object OnRestartClicked : FlipFlashCardUiAction() data object OnContinueLearningClicked : FlipFlashCardUiAction() data object OnBackClicked : FlipFlashCardUiAction() + data class OnChangeIsPlaySound(val isPlaySound: Boolean) : FlipFlashCardUiAction() } \ No newline at end of file diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/flip/FlipFlashCardViewModel.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/flip/FlipFlashCardViewModel.kt index d6a521ad..e7cb76cf 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/flip/FlipFlashCardViewModel.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/flip/FlipFlashCardViewModel.kt @@ -197,6 +197,15 @@ class FlipFlashCardViewModel @Inject constructor( } _uiEvent.trySend(FlipFlashCardUiEvent.Back) } + + is FlipFlashCardUiAction.OnChangeIsPlaySound -> { + _uiState.update { + it.copy(isPlaySound = event.isPlaySound) + } + viewModelScope.launch { + appManager.saveIsPlaySound(event.isPlaySound) + } + } } } diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/quiz/LearnByQuizScreen.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/quiz/LearnByQuizScreen.kt index 5dfeeaa1..527d983c 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/quiz/LearnByQuizScreen.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/quiz/LearnByQuizScreen.kt @@ -7,6 +7,7 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons.Default import androidx.compose.material.icons.automirrored.filled.NavigateNext @@ -35,6 +36,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview @@ -116,7 +118,11 @@ fun LearnByQuizScreen( onRestartClicked = { viewModel.onEvent(LearnByQuizUiAction.RestartLearn) }, - isGetAll = uiState.isGetAll + isGetAll = uiState.isGetAll, + isPlaySound = uiState.isPlaySound, + onChangeIsPlaySound = { + viewModel.onEvent(LearnByQuizUiAction.OnChangeIsPlaySound(it)) + } ) } @@ -139,7 +145,9 @@ fun LearnByQuiz( isEndOfList: Boolean = false, onContinueLearningClicked: () -> Unit = {}, onRestartClicked: () -> Unit = {}, - isGetAll: Boolean = false + isGetAll: Boolean = false, + isPlaySound: Boolean = false, + onChangeIsPlaySound: (Boolean) -> Unit = {} ) { var canResetState by remember { mutableStateOf(false) } val showHintBottomSheet = remember { mutableStateOf(false) } @@ -179,6 +187,17 @@ fun LearnByQuiz( }, actions = { if (!isEndOfList && isGetAll) { + IconButton( + onClick = { onChangeIsPlaySound(!isPlaySound) } + ) { + Icon( + painter = if (isPlaySound) painterResource(id = R.drawable.ic_sound) else painterResource( + id = R.drawable.ic_volume_off + ), + contentDescription = "Sound", + modifier = Modifier.size(22.dp) + ) + } if (!flashCard?.hint.isNullOrEmpty()) { IconButton( onClick = { diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/quiz/LearnByQuizUiAction.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/quiz/LearnByQuizUiAction.kt index 47930ac5..681f0602 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/quiz/LearnByQuizUiAction.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/quiz/LearnByQuizUiAction.kt @@ -12,4 +12,5 @@ sealed class LearnByQuizUiAction { data object ContinueLearnWrongAnswer : LearnByQuizUiAction() data object RestartLearn : LearnByQuizUiAction() data object OnBackClicked : LearnByQuizUiAction() + data class OnChangeIsPlaySound(val isPlaySound: Boolean) : LearnByQuizUiAction() } \ No newline at end of file diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/quiz/LearnByQuizViewModel.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/quiz/LearnByQuizViewModel.kt index a5308fe4..9c3d42b3 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/quiz/LearnByQuizViewModel.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/quiz/LearnByQuizViewModel.kt @@ -119,6 +119,15 @@ class LearnByQuizViewModel @Inject constructor( } _uiEvent.trySend(LearnByQuizUiEvent.Back) } + + is LearnByQuizUiAction.OnChangeIsPlaySound -> { + _uiState.update { + it.copy(isPlaySound = event.isPlaySound) + } + viewModelScope.launch { + appManager.saveIsPlaySound(event.isPlaySound) + } + } } } diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/true_false/LearnByTrueFalseScreen.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/true_false/LearnByTrueFalseScreen.kt index 2a66e80c..6a57cc27 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/true_false/LearnByTrueFalseScreen.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/true_false/LearnByTrueFalseScreen.kt @@ -41,6 +41,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp @@ -112,7 +113,11 @@ fun LearnByTrueFalseScreen( ) ) }, - isGetAll = uiState.isGetAll + isGetAll = uiState.isGetAll, + isPlaySound = uiState.isPlaySound, + onChangeIsPlaySound = { + viewModel.onEvent(LearnByTrueFalseUiAction.OnChangeIsPlaySound(it)) + } ) } @@ -133,7 +138,9 @@ fun LearnByTrueFalse( learningTime: Long = 0, listWrongAnswer: List = emptyList(), onContinueLearningClicked: () -> Unit = {}, - isGetAll: Boolean = false + isGetAll: Boolean = false, + isPlaySound: Boolean = false, + onChangeIsPlaySound: (Boolean) -> Unit = {} ) { var isImageViewerOpen by remember { mutableStateOf(false) } var definitionImageUri by remember { mutableStateOf("") } @@ -170,6 +177,17 @@ fun LearnByTrueFalse( }, actions = { if (!isEndOfList && isGetAll) { + IconButton( + onClick = { onChangeIsPlaySound(!isPlaySound) } + ) { + Icon( + painter = if (isPlaySound) painterResource(id = R.drawable.ic_sound) else painterResource( + id = R.drawable.ic_volume_off + ), + contentDescription = "Sound", + modifier = Modifier.size(22.dp) + ) + } IconButton( onClick = onRestart ) { diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/true_false/LearnByTrueFalseUiAction.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/true_false/LearnByTrueFalseUiAction.kt index ee5488a8..68ef6a26 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/true_false/LearnByTrueFalseUiAction.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/true_false/LearnByTrueFalseUiAction.kt @@ -10,4 +10,5 @@ sealed class LearnByTrueFalseUiAction { data object ContinueLearnWrongAnswer : LearnByTrueFalseUiAction() data object RestartLearn : LearnByTrueFalseUiAction() data object OnBackClicked : LearnByTrueFalseUiAction() + data class OnChangeIsPlaySound(val isPlaySound: Boolean) : LearnByTrueFalseUiAction() } \ No newline at end of file diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/true_false/LearnByTrueFalseViewModel.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/true_false/LearnByTrueFalseViewModel.kt index b6b8b16b..8dc650fc 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/true_false/LearnByTrueFalseViewModel.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/true_false/LearnByTrueFalseViewModel.kt @@ -117,6 +117,15 @@ class LearnByTrueFalseViewModel @Inject constructor( } _uiEvent.trySend(LearnByTrueFalseUiEvent.Back) } + + is LearnByTrueFalseUiAction.OnChangeIsPlaySound -> { + _uiState.update { + it.copy(isPlaySound = event.isPlaySound) + } + viewModelScope.launch { + appManager.saveIsPlaySound(event.isPlaySound) + } + } } } diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/write/LearnByWriteScreen.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/write/LearnByWriteScreen.kt index f1b0c504..33b352eb 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/write/LearnByWriteScreen.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/write/LearnByWriteScreen.kt @@ -52,6 +52,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.ImeAction @@ -124,7 +125,11 @@ fun LearnByWriteScreen( onSubmitAnswer = { id, status, answer -> viewModel.onEvent(LearnByWriteUiAction.OnAnswer(id, status, answer)) }, - isGetAll = uiState.isGetAll + isGetAll = uiState.isGetAll, + isPlaySound = uiState.isPlaySound, + onChangeIsPlaySound = { + viewModel.onEvent(LearnByWriteUiAction.OnChangeIsPlaySound(it)) + } ) } @@ -145,7 +150,9 @@ fun LearnByWrite( listWrongAnswer: List = emptyList(), onContinueLearningClicked: () -> Unit = {}, onSubmitAnswer: (String, WriteStatus, String) -> Unit = { _, _, _ -> }, - isGetAll: Boolean = false + isGetAll: Boolean = false, + isPlaySound: Boolean = false, + onChangeIsPlaySound: (Boolean) -> Unit = { }, ) { var isImageViewerOpen by remember { mutableStateOf(false) } var definitionImageUri by remember { mutableStateOf("") } @@ -193,6 +200,17 @@ fun LearnByWrite( }, actions = { if (!isEndOfList && isGetAll) { + IconButton( + onClick = { onChangeIsPlaySound(!isPlaySound) } + ) { + Icon( + painter = if (isPlaySound) painterResource(id = R.drawable.ic_sound) else painterResource( + id = R.drawable.ic_volume_off + ), + contentDescription = "Sound", + modifier = Modifier.size(22.dp) + ) + } IconButton( onClick = { userAnswer = "" diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/write/LearnByWriteUiAction.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/write/LearnByWriteUiAction.kt index e877aff1..837fed8f 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/write/LearnByWriteUiAction.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/write/LearnByWriteUiAction.kt @@ -13,4 +13,5 @@ sealed class LearnByWriteUiAction { data object ContinueLearnWrongAnswer : LearnByWriteUiAction() data object RestartLearn : LearnByWriteUiAction() data object OnBackClicked : LearnByWriteUiAction() + data class OnChangeIsPlaySound(val isPlaySound: Boolean) : LearnByWriteUiAction() } \ No newline at end of file diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/write/LearnByWriteViewModel.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/write/LearnByWriteViewModel.kt index cfa3fd68..d10da9fc 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/write/LearnByWriteViewModel.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/write/LearnByWriteViewModel.kt @@ -118,6 +118,15 @@ class LearnByWriteViewModel @Inject constructor( } _uiEvent.trySend(LearnByWriteUiEvent.Back) } + + is LearnByWriteUiAction.OnChangeIsPlaySound -> { + _uiState.update { + it.copy(isPlaySound = event.isPlaySound) + } + viewModelScope.launch { + appManager.saveIsPlaySound(event.isPlaySound) + } + } } } diff --git a/app/src/main/res/drawable/ic_volume_off.xml b/app/src/main/res/drawable/ic_volume_off.xml new file mode 100644 index 00000000..138cb22a --- /dev/null +++ b/app/src/main/res/drawable/ic_volume_off.xml @@ -0,0 +1,9 @@ + + +