diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/folder/detail/FolderDetailScreen.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/folder/detail/FolderDetailScreen.kt index d1b8bacb..bc0964bb 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/folder/detail/FolderDetailScreen.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/folder/detail/FolderDetailScreen.kt @@ -34,6 +34,7 @@ import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import com.pwhs.quickmem.R import com.pwhs.quickmem.core.data.enums.LearnFrom +import com.pwhs.quickmem.core.data.enums.LearnMode import com.pwhs.quickmem.core.utils.AppConstant import com.pwhs.quickmem.domain.model.study_set.GetStudySetResponseModel import com.pwhs.quickmem.presentation.app.folder.detail.component.FolderDetailStudySetList @@ -50,6 +51,11 @@ import com.ramcosta.composedestinations.annotation.RootGraph import com.ramcosta.composedestinations.generated.destinations.AddStudySetToFolderScreenDestination import com.ramcosta.composedestinations.generated.destinations.EditFolderScreenDestination import com.ramcosta.composedestinations.generated.destinations.FlipFlashCardScreenDestination +import com.ramcosta.composedestinations.generated.destinations.LearnByQuizScreenDestination +import com.ramcosta.composedestinations.generated.destinations.LearnByTrueFalseScreenDestination +import com.ramcosta.composedestinations.generated.destinations.LearnByTrueFalseScreenDestination.invoke +import com.ramcosta.composedestinations.generated.destinations.LearnByWriteScreenDestination +import com.ramcosta.composedestinations.generated.destinations.LearnByWriteScreenDestination.invoke import com.ramcosta.composedestinations.generated.destinations.ReportScreenDestination import com.ramcosta.composedestinations.generated.destinations.StudySetDetailScreenDestination import com.ramcosta.composedestinations.generated.destinations.UserDetailScreenDestination @@ -131,6 +137,63 @@ fun FolderDetailScreen( FolderDetailUiEvent.FolderDeleted -> { resultNavigator.navigateBack(true) } + + is FolderDetailUiEvent.OnNavigateToFlipFlashcard -> { + navigator.navigate( + FlipFlashCardScreenDestination( + studySetId = "", + studySetTitle = "", + studySetDescription = "", + studySetColorId = 0, + studySetSubjectId = 0, + folderId = uiState.id, + learnFrom = LearnFrom.FOLDER, + isGetAll = event.isGetAll + ) + ) + } + is FolderDetailUiEvent.OnNavigateToQuiz -> { + navigator.navigate( + LearnByQuizScreenDestination( + studySetId = "", + studySetTitle = "", + studySetDescription = "", + studySetColorId = 0, + studySetSubjectId = 0, + folderId = uiState.id, + learnFrom = LearnFrom.FOLDER, + isGetAll = event.isGetAll + ) + ) + } + is FolderDetailUiEvent.OnNavigateToTrueFalse -> { + navigator.navigate( + LearnByTrueFalseScreenDestination( + studySetId = "", + studySetTitle = "", + studySetDescription = "", + studySetColorId = 0, + studySetSubjectId = 0, + folderId = uiState.id, + learnFrom = LearnFrom.FOLDER, + isGetAll = event.isGetAll + ) + ) + } + is FolderDetailUiEvent.OnNavigateToWrite -> { + navigator.navigate( + LearnByWriteScreenDestination( + studySetId = "", + studySetTitle = "", + studySetDescription = "", + studySetColorId = 0, + studySetSubjectId = 0, + folderId = uiState.id, + learnFrom = LearnFrom.FOLDER, + isGetAll = event.isGetAll + ) + ) + } } } } @@ -154,20 +217,6 @@ fun FolderDetailScreen( ) }, onEditFolder = { viewModel.onEvent(FolderDetailUiAction.EditFolder) }, - onLearnFlipFlashcardClick = { - navigator.navigate( - FlipFlashCardScreenDestination( - studySetId = "", - studySetTitle = "", - studySetDescription = "", - studySetColorId = 0, - studySetSubjectId = 0, - folderId = uiState.id, - learnFrom = LearnFrom.FOLDER, - isGetAll = true - ) - ) - }, onNavigateBack = { resultNavigator.navigateBack(true) }, @@ -195,6 +244,10 @@ fun FolderDetailScreen( ) ) }, + totalFlashCards = uiState.totalFlashCards, + onNavigateToLearn = { learnMode, isGetAll -> + viewModel.onEvent(FolderDetailUiAction.NavigateToLearn(learnMode, isGetAll)) + }, ) } @@ -214,11 +267,12 @@ fun FolderDetail( onStudySetClick: (String) -> Unit = {}, onEditFolder: () -> Unit = {}, onDeleteFolder: () -> Unit = {}, - onLearnFlipFlashcardClick: () -> Unit = {}, onNavigateBack: () -> Unit = {}, onAddStudySet: () -> Unit = {}, onNavigateToUserDetail: () -> Unit = {}, - onReportClick: () -> Unit = {} + totalFlashCards: Int = 0, + onReportClick: () -> Unit = {}, + onNavigateToLearn: (LearnMode, Boolean) -> Unit = { _, _ -> }, ) { val context = LocalContext.current val formattedCreatedAt = formatDate(createdAt) @@ -234,7 +288,9 @@ fun FolderDetail( val sheetShowMoreState = rememberModalBottomSheetState() var showDeleteConfirmationDialog by remember { mutableStateOf(false) } var showStudyFolderBottomSheet by remember { mutableStateOf(false) } + var showGetAllDialog by remember { mutableStateOf(false) } val sheetStudyFolderState = rememberModalBottomSheetState() + var learningMode by remember { mutableStateOf(LearnMode.NONE) } Scaffold( modifier = modifier, @@ -346,7 +402,8 @@ fun FolderDetail( containerColor = colorScheme.surface, elevation = 0.dp, onClick = { - onLearnFlipFlashcardClick() + showGetAllDialog = true + learningMode = LearnMode.FLIP showStudyFolderBottomSheet = false }, ) @@ -355,24 +412,58 @@ fun FolderDetail( icon = R.drawable.ic_quiz, containerColor = colorScheme.surface, elevation = 0.dp, + onClick = { + showGetAllDialog = true + learningMode = LearnMode.QUIZ + showStudyFolderBottomSheet = false + } ) LearnModeCard( title = stringResource(R.string.txt_true_false), icon = R.drawable.ic_tf, containerColor = colorScheme.surface, elevation = 0.dp, - leadingText = stringResource(R.string.txt_coming_soon) + onClick = { + showGetAllDialog = true + learningMode = LearnMode.TRUE_FALSE + showStudyFolderBottomSheet = false + } ) LearnModeCard( title = stringResource(R.string.txt_write), icon = R.drawable.ic_write, containerColor = Color.Transparent, elevation = 0.dp, - leadingText = stringResource(R.string.txt_coming_soon) + onClick = { + showGetAllDialog = true + learningMode = LearnMode.WRITE + showStudyFolderBottomSheet = false + } ) } } } + if (showGetAllDialog && totalFlashCards > 10) { + QuickMemAlertDialog( + onDismissRequest = { + showGetAllDialog = false + onNavigateToLearn(learningMode, true) + learningMode = LearnMode.NONE + }, + onConfirm = { + showGetAllDialog = false + onNavigateToLearn(learningMode, false) + learningMode = LearnMode.NONE + }, + title = stringResource(R.string.txt_get_all), + text = stringResource(R.string.txt_are_you_sure_you_want_to_get_all_flashcards), + confirmButtonTitle = stringResource(R.string.txt_ok), + dismissButtonTitle = stringResource(R.string.txt_no_thanks), + ) + } else { + onNavigateToLearn(learningMode, true) + learningMode = LearnMode.NONE + } } @Preview(showBackground = true) diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/folder/detail/FolderDetailUiAction.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/folder/detail/FolderDetailUiAction.kt index 89a01fcb..6f0e8625 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/folder/detail/FolderDetailUiAction.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/folder/detail/FolderDetailUiAction.kt @@ -1,7 +1,10 @@ package com.pwhs.quickmem.presentation.app.folder.detail +import com.pwhs.quickmem.core.data.enums.LearnMode + sealed class FolderDetailUiAction { data object Refresh : FolderDetailUiAction() data object DeleteFolder : FolderDetailUiAction() data object EditFolder : FolderDetailUiAction() + data class NavigateToLearn(val learnMode: LearnMode, val isGetAll: Boolean) : FolderDetailUiAction() } \ No newline at end of file diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/folder/detail/FolderDetailUiEvent.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/folder/detail/FolderDetailUiEvent.kt index 1ed2d5df..24860f90 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/folder/detail/FolderDetailUiEvent.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/folder/detail/FolderDetailUiEvent.kt @@ -4,4 +4,8 @@ sealed class FolderDetailUiEvent { data object FolderDeleted : FolderDetailUiEvent() data object NavigateToEditFolder : FolderDetailUiEvent() data class ShowError(val message: String) : FolderDetailUiEvent() + data class OnNavigateToFlipFlashcard(val isGetAll: Boolean) : FolderDetailUiEvent() + data class OnNavigateToQuiz(val isGetAll: Boolean) : FolderDetailUiEvent() + data class OnNavigateToTrueFalse(val isGetAll: Boolean) : FolderDetailUiEvent() + data class OnNavigateToWrite(val isGetAll: Boolean) : FolderDetailUiEvent() } \ No newline at end of file diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/folder/detail/FolderDetailUiState.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/folder/detail/FolderDetailUiState.kt index 5af0d539..8ce7c76d 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/folder/detail/FolderDetailUiState.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/folder/detail/FolderDetailUiState.kt @@ -17,4 +17,5 @@ data class FolderDetailUiState( val updatedAt: String = "", val isLoading: Boolean = false, val isOwner: Boolean = false, + val totalFlashCards: Int = 0 ) \ No newline at end of file diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/folder/detail/FolderDetailViewModel.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/folder/detail/FolderDetailViewModel.kt index 2f7d9a78..98170243 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/folder/detail/FolderDetailViewModel.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/folder/detail/FolderDetailViewModel.kt @@ -3,11 +3,14 @@ package com.pwhs.quickmem.presentation.app.folder.detail import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.pwhs.quickmem.core.data.enums.LearnMode import com.pwhs.quickmem.core.datastore.AppManager import com.pwhs.quickmem.core.datastore.TokenManager import com.pwhs.quickmem.core.utils.Resources import com.pwhs.quickmem.domain.model.folder.SaveRecentAccessFolderRequestModel +import com.pwhs.quickmem.domain.model.study_set.GetStudySetResponseModel import com.pwhs.quickmem.domain.repository.FolderRepository +import com.pwhs.quickmem.presentation.app.folder.detail.FolderDetailUiEvent.* import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.flow.MutableStateFlow @@ -51,15 +54,39 @@ class FolderDetailViewModel @Inject constructor( _uiState.update { it.copy(isLoading = true) } deleteFolder() } else { - _uiEvent.trySend(FolderDetailUiEvent.ShowError("You can't delete this folder")) + _uiEvent.trySend(ShowError("You can't delete this folder")) } } FolderDetailUiAction.EditFolder -> { if (_uiState.value.isOwner) { - _uiEvent.trySend(FolderDetailUiEvent.NavigateToEditFolder) + _uiEvent.trySend(NavigateToEditFolder) } else { - _uiEvent.trySend(FolderDetailUiEvent.ShowError("You can't edit this folder")) + _uiEvent.trySend(ShowError("You can't edit this folder")) + } + } + + is FolderDetailUiAction.NavigateToLearn -> { + when (event.learnMode) { + LearnMode.FLIP -> { + _uiEvent.trySend(OnNavigateToFlipFlashcard(event.isGetAll)) + } + + LearnMode.QUIZ -> { + _uiEvent.trySend(OnNavigateToQuiz(event.isGetAll)) + } + + LearnMode.TRUE_FALSE -> { + _uiEvent.trySend(OnNavigateToTrueFalse(event.isGetAll)) + } + + LearnMode.WRITE -> { + _uiEvent.trySend(OnNavigateToWrite(event.isGetAll)) + } + + else -> { + // Do nothing + } } } } @@ -77,6 +104,7 @@ class FolderDetailViewModel @Inject constructor( is Resources.Success -> { resource.data?.let { data -> val isOwner = appManager.userId.firstOrNull() == data.owner.id + val totalFlashCards = calculateTotalFlashCards(data.studySets ?: emptyList()) _uiState.update { it.copy( title = data.title, @@ -89,12 +117,14 @@ class FolderDetailViewModel @Inject constructor( createdAt = data.createdAt, updatedAt = data.updatedAt, isLoading = false, - isOwner = isOwner + isOwner = isOwner, + totalFlashCards = totalFlashCards ) } } ?: run { - _uiEvent.send(FolderDetailUiEvent.ShowError("Folder not found")) + _uiEvent.send(ShowError("Folder not found")) } + Timber.d("") } is Resources.Error -> { @@ -109,7 +139,7 @@ class FolderDetailViewModel @Inject constructor( private fun deleteFolder() { viewModelScope.launch { val token = tokenManager.accessToken.firstOrNull() ?: run { - _uiEvent.send(FolderDetailUiEvent.ShowError("Please login again!")) + _uiEvent.send(ShowError("Please login again!")) return@launch } folderRepository.deleteFolder(token, _uiState.value.id).collectLatest { resource -> @@ -123,7 +153,7 @@ class FolderDetailViewModel @Inject constructor( resource.data?.let { Timber.d("Folder deleted") _uiState.update { it.copy(isLoading = false) } - _uiEvent.send(FolderDetailUiEvent.FolderDeleted) + _uiEvent.send(FolderDeleted) } } @@ -164,4 +194,12 @@ class FolderDetailViewModel @Inject constructor( } } } + + private fun calculateTotalFlashCards(studySets: List): Int { + var totalFlashCards = 0 + studySets.forEach { studySet -> + totalFlashCards += studySet.flashcardCount + } + return totalFlashCards + } } \ No newline at end of file diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/detail/StudySetDetailScreen.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/detail/StudySetDetailScreen.kt index da54a939..698a70b5 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/detail/StudySetDetailScreen.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/detail/StudySetDetailScreen.kt @@ -250,6 +250,8 @@ fun StudySetDetailScreen( studySetDescription = uiState.description, studySetColorId = uiState.colorModel.id, studySetSubjectId = uiState.subject.id, + folderId = "", + learnFrom = LearnFrom.STUDY_SET, isGetAll = event.isGetAll ) ) @@ -263,6 +265,8 @@ fun StudySetDetailScreen( studySetDescription = uiState.description, studySetColorId = uiState.colorModel.id, studySetSubjectId = uiState.subject.id, + folderId = "", + learnFrom = LearnFrom.STUDY_SET, isGetAll = event.isGetAll ) ) @@ -276,6 +280,8 @@ fun StudySetDetailScreen( studySetDescription = uiState.description, studySetColorId = uiState.colorModel.id, studySetSubjectId = uiState.subject.id, + folderId = "", + learnFrom = LearnFrom.STUDY_SET, isGetAll = event.isGetAll ) ) 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 64d62875..f641dee9 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 @@ -18,6 +18,7 @@ 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.core.data.enums.LearnFrom import com.pwhs.quickmem.ui.theme.QuickMemTheme @OptIn(ExperimentalMaterial3Api::class) @@ -32,7 +33,8 @@ fun StudyTopAppBar( shouldShowRestart: Boolean = true, isGetAll: Boolean = false, isPlaySound: Boolean = false, - onChangeIsPlaySound: (Boolean) -> Unit = {} + onChangeIsPlaySound: (Boolean) -> Unit = {}, + learnFrom: LearnFrom ) { CenterAlignedTopAppBar( modifier = modifier, @@ -57,7 +59,7 @@ fun StudyTopAppBar( } }, actions = { - if (shouldShowRestart && isGetAll) { + if (shouldShowRestart) { IconButton( onClick = { onChangeIsPlaySound(!isPlaySound) } ) { @@ -69,13 +71,15 @@ fun StudyTopAppBar( modifier = Modifier.size(22.dp) ) } - IconButton( - onClick = onRestartClicked - ) { - Icon( - imageVector = Default.RestartAlt, - contentDescription = stringResource(R.string.txt_restart) - ) + if (learnFrom != LearnFrom.FOLDER && isGetAll) { + IconButton( + onClick = onRestartClicked + ) { + Icon( + imageVector = Default.RestartAlt, + contentDescription = stringResource(R.string.txt_restart) + ) + } } } } @@ -90,6 +94,7 @@ fun StudyTopAppBarPreview() { currentCardIndex = 0, totalCards = 10, onBackClicked = {}, + learnFrom = LearnFrom.STUDY_SET ) } } \ No newline at end of file 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 4c2dcc2e..368f1d7d 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 @@ -43,6 +43,7 @@ import com.msusman.compose.cardstack.SwipeDirection import com.msusman.compose.cardstack.SwipeMethod import com.msusman.compose.cardstack.rememberStackState import com.pwhs.quickmem.R +import com.pwhs.quickmem.core.data.enums.LearnFrom import com.pwhs.quickmem.domain.model.flashcard.FlashCardResponseModel import com.pwhs.quickmem.presentation.app.study_set.component.StudyCardBottomSheet import com.pwhs.quickmem.presentation.app.study_set.studies.flip.component.FlipFlashCardButton @@ -132,7 +133,8 @@ fun FlipFlashCardScreen( onContinueLearningClicked = { viewModel.onEvent(FlipFlashCardUiAction.OnContinueLearningClicked) }, - isGetAll = uiState.isGetAll + isGetAll = uiState.isGetAll, + learnFrom = uiState.learnFrom ) } @@ -160,7 +162,8 @@ fun FlipFlashCard( onUpdateCountStillLearning: (Boolean, String) -> Unit = { _, _ -> }, onRestartClicked: () -> Unit = { }, onContinueLearningClicked: () -> Unit = { }, - isGetAll: Boolean = false + isGetAll: Boolean = false, + learnFrom: LearnFrom = LearnFrom.STUDY_SET ) { var showHintBottomSheet by remember { mutableStateOf(false) @@ -210,7 +213,8 @@ fun FlipFlashCard( shouldShowRestart = !isEndOfList, isGetAll = isGetAll, isPlaySound = isPlaySound, - onChangeIsPlaySound = onChangeIsPlaySound + onChangeIsPlaySound = onChangeIsPlaySound, + learnFrom = learnFrom ) } ) { innerPadding -> diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/quiz/LearnByQuizArgs.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/quiz/LearnByQuizArgs.kt index 88b21cc5..c8a7f669 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/quiz/LearnByQuizArgs.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/quiz/LearnByQuizArgs.kt @@ -1,10 +1,14 @@ package com.pwhs.quickmem.presentation.app.study_set.studies.quiz +import com.pwhs.quickmem.core.data.enums.LearnFrom + data class LearnByQuizArgs( val studySetId: String, val studySetTitle: String, val studySetDescription: String, val studySetColorId: Int, val studySetSubjectId: Int, + val folderId: String, + val learnFrom: LearnFrom, val isGetAll: Boolean, ) 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 527d983c..bb9b0159 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 @@ -43,6 +43,7 @@ import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import com.pwhs.quickmem.R +import com.pwhs.quickmem.core.data.enums.LearnFrom import com.pwhs.quickmem.core.data.enums.QuizStatus import com.pwhs.quickmem.core.data.states.RandomAnswer import com.pwhs.quickmem.core.data.states.WrongAnswer @@ -119,6 +120,7 @@ fun LearnByQuizScreen( viewModel.onEvent(LearnByQuizUiAction.RestartLearn) }, isGetAll = uiState.isGetAll, + learnFrom = uiState.learnFrom, isPlaySound = uiState.isPlaySound, onChangeIsPlaySound = { viewModel.onEvent(LearnByQuizUiAction.OnChangeIsPlaySound(it)) @@ -147,6 +149,7 @@ fun LearnByQuiz( onRestartClicked: () -> Unit = {}, isGetAll: Boolean = false, isPlaySound: Boolean = false, + learnFrom: LearnFrom = LearnFrom.STUDY_SET, onChangeIsPlaySound: (Boolean) -> Unit = {} ) { var canResetState by remember { mutableStateOf(false) } @@ -186,7 +189,7 @@ fun LearnByQuiz( } }, actions = { - if (!isEndOfList && isGetAll) { + if (!isEndOfList) { IconButton( onClick = { onChangeIsPlaySound(!isPlaySound) } ) { @@ -211,14 +214,16 @@ fun LearnByQuiz( ) } } - IconButton( - onClick = onRestartClicked - ) { - Icon( - imageVector = Default.RestartAlt, - contentDescription = "Restart", - tint = studySetColor - ) + if (learnFrom != LearnFrom.FOLDER && isGetAll) { + IconButton( + onClick = onRestartClicked + ) { + Icon( + imageVector = Default.RestartAlt, + contentDescription = "Restart", + tint = studySetColor + ) + } } } } diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/quiz/LearnByQuizUiState.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/quiz/LearnByQuizUiState.kt index 04785699..0c362e70 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/quiz/LearnByQuizUiState.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/quiz/LearnByQuizUiState.kt @@ -1,5 +1,6 @@ package com.pwhs.quickmem.presentation.app.study_set.studies.quiz +import com.pwhs.quickmem.core.data.enums.LearnFrom import com.pwhs.quickmem.core.data.states.RandomAnswer import com.pwhs.quickmem.core.data.states.WrongAnswer import com.pwhs.quickmem.domain.model.color.ColorModel @@ -14,6 +15,8 @@ data class LearnFlashCardUiState( val studySetTitle: String = "", val studySetDescription: String = "", val studySetCardCount: Int = 0, + val learnFrom: LearnFrom = LearnFrom.STUDY_SET, + val folderId: String = "", val studySetColor: ColorModel = ColorModel(), val studySetSubject: SubjectModel = SubjectModel(), val flashCardList: List = emptyList(), 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 9c3d42b3..dab3c62f 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 @@ -6,6 +6,7 @@ import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.viewModelScope import com.pwhs.quickmem.R +import com.pwhs.quickmem.core.data.enums.LearnFrom import com.pwhs.quickmem.core.data.enums.LearnMode import com.pwhs.quickmem.core.data.enums.QuizStatus import com.pwhs.quickmem.core.data.enums.ResetType @@ -56,9 +57,13 @@ class LearnByQuizViewModel @Inject constructor( val studySetDescription = savedStateHandle.get("studySetDescription") ?: "" val studySetColorId = savedStateHandle.get("studySetColorId") ?: 0 val studySetSubjectId = savedStateHandle.get("studySetSubjectId") ?: 0 + val folderId = savedStateHandle.get("folderId") ?: "" + val learnFrom = savedStateHandle.get("learnFrom") ?: LearnFrom.STUDY_SET _uiState.update { it.copy( studySetId = studySetId, + folderId = folderId, + learnFrom = learnFrom, isGetAll = isGetAll, studySetTitle = studySetTitle, studySetDescription = studySetDescription, @@ -135,52 +140,107 @@ class LearnByQuizViewModel @Inject constructor( viewModelScope.launch { val token = tokenManager.accessToken.firstOrNull() ?: "" val studySetId = _uiState.value.studySetId - val isGetAll = _uiState.value.isEndOfList - flashCardRepository.getFlashCardsByStudySetId( - token = token, - studySetId = studySetId, - learnMode = LearnMode.QUIZ, - isGetAll = isGetAll - ).collect { resource -> - when (resource) { - is Resources.Error -> { - _uiState.update { it.copy(isLoading = false) } - } + val folderId = _uiState.value.folderId + val learnFrom = _uiState.value.learnFrom + val isGetAll = _uiState.value.isGetAll + when (learnFrom) { + LearnFrom.STUDY_SET -> { + flashCardRepository.getFlashCardsByStudySetId( + token = token, + studySetId = studySetId, + learnMode = LearnMode.QUIZ, + isGetAll = isGetAll + ).collect { resource -> + when (resource) { + is Resources.Error -> { + _uiState.update { it.copy(isLoading = false) } + } - is Resources.Loading -> { - _uiState.update { it.copy(isLoading = true) } - } + is Resources.Loading -> { + _uiState.update { it.copy(isLoading = true) } + } - is Resources.Success -> { - if (resource.data.isNullOrEmpty()) { - _uiState.update { - it.copy( - learningTime = 0, - isLoading = false, - isEndOfList = true - ) + is Resources.Success -> { + if (resource.data.isNullOrEmpty()) { + _uiState.update { + it.copy( + learningTime = 0, + isLoading = false, + isEndOfList = true + ) + } + playCompleteSound() + _uiEvent.send(LearnByQuizUiEvent.Finished) + return@collect + } + + val flashCards = resource.data + val currentCard = flashCards.firstOrNull() + val randomAnswers = generateRandomAnswers(flashCards, currentCard) + + _uiState.update { + it.copy( + flashCardList = flashCards, + randomAnswers = randomAnswers, + isLoading = false, + currentFlashCard = currentCard, + nextFlashCard = flashCards.getOrNull(1) + ) + } } - playCompleteSound() - _uiEvent.send(LearnByQuizUiEvent.Finished) - return@collect } + } + } - val flashCards = resource.data - val currentCard = flashCards.firstOrNull() - val randomAnswers = generateRandomAnswers(flashCards, currentCard) + LearnFrom.FOLDER -> { + flashCardRepository.getFlashCardsByFolderId( + token = token, + folderId = folderId, + learnMode = LearnMode.QUIZ, + isGetAll = isGetAll + ).collect { resource -> + when (resource) { + is Resources.Error -> { + _uiState.update { it.copy(isLoading = false) } + } - _uiState.update { - it.copy( - flashCardList = flashCards, - randomAnswers = randomAnswers, - isLoading = false, - currentFlashCard = currentCard, - nextFlashCard = flashCards.getOrNull(1) - ) + is Resources.Loading -> { + _uiState.update { it.copy(isLoading = true) } + } + + is Resources.Success -> { + if (resource.data.isNullOrEmpty()) { + _uiState.update { + it.copy( + learningTime = 0, + isLoading = false, + isEndOfList = true + ) + } + playCompleteSound() + _uiEvent.send(LearnByQuizUiEvent.Finished) + return@collect + } + + val flashCards = resource.data + val currentCard = flashCards.firstOrNull() + val randomAnswers = generateRandomAnswers(flashCards, currentCard) + + _uiState.update { + it.copy( + flashCardList = flashCards, + randomAnswers = randomAnswers, + isLoading = false, + currentFlashCard = currentCard, + nextFlashCard = flashCards.getOrNull(1) + ) + } + } } } } + LearnFrom.CLASS -> TODO() } } } diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/true_false/LearnByTrueFalseArgs.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/true_false/LearnByTrueFalseArgs.kt index 88ee8a9c..1a9c0d78 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/true_false/LearnByTrueFalseArgs.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/true_false/LearnByTrueFalseArgs.kt @@ -1,10 +1,14 @@ package com.pwhs.quickmem.presentation.app.study_set.studies.true_false +import com.pwhs.quickmem.core.data.enums.LearnFrom + data class LearnByTrueFalseArgs( val studySetId: String, val studySetTitle: String, val studySetDescription: String, val studySetColorId: Int, val studySetSubjectId: Int, + val folderId: String, + val learnFrom: LearnFrom, val isGetAll: Boolean, ) 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 6a57cc27..333e9749 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 @@ -49,6 +49,7 @@ import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel import coil.compose.AsyncImage import com.pwhs.quickmem.R +import com.pwhs.quickmem.core.data.enums.LearnFrom import com.pwhs.quickmem.domain.model.flashcard.FlashCardResponseModel import com.pwhs.quickmem.presentation.app.study_set.studies.component.UnfinishedLearningBottomSheet import com.pwhs.quickmem.presentation.app.study_set.studies.true_false.component.TrueFalseButton @@ -114,6 +115,7 @@ fun LearnByTrueFalseScreen( ) }, isGetAll = uiState.isGetAll, + learnFrom = uiState.learnFrom, isPlaySound = uiState.isPlaySound, onChangeIsPlaySound = { viewModel.onEvent(LearnByTrueFalseUiAction.OnChangeIsPlaySound(it)) @@ -140,7 +142,8 @@ fun LearnByTrueFalse( onContinueLearningClicked: () -> Unit = {}, isGetAll: Boolean = false, isPlaySound: Boolean = false, - onChangeIsPlaySound: (Boolean) -> Unit = {} + onChangeIsPlaySound: (Boolean) -> Unit = {}, + learnFrom: LearnFrom = LearnFrom.FOLDER ) { var isImageViewerOpen by remember { mutableStateOf(false) } var definitionImageUri by remember { mutableStateOf("") } @@ -176,7 +179,7 @@ fun LearnByTrueFalse( } }, actions = { - if (!isEndOfList && isGetAll) { + if (!isEndOfList) { IconButton( onClick = { onChangeIsPlaySound(!isPlaySound) } ) { @@ -188,14 +191,16 @@ fun LearnByTrueFalse( modifier = Modifier.size(22.dp) ) } - IconButton( - onClick = onRestart - ) { - Icon( - imageVector = Default.RestartAlt, - contentDescription = "Restart", - tint = studySetColor - ) + if (learnFrom != LearnFrom.FOLDER && isGetAll) { + IconButton( + onClick = onRestart + ) { + Icon( + imageVector = Default.RestartAlt, + contentDescription = "Restart", + tint = studySetColor + ) + } } } } diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/true_false/LearnByTrueFalseUiState.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/true_false/LearnByTrueFalseUiState.kt index 506fcd1f..5f65465e 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/true_false/LearnByTrueFalseUiState.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/true_false/LearnByTrueFalseUiState.kt @@ -1,5 +1,6 @@ package com.pwhs.quickmem.presentation.app.study_set.studies.true_false +import com.pwhs.quickmem.core.data.enums.LearnFrom import com.pwhs.quickmem.domain.model.color.ColorModel import com.pwhs.quickmem.domain.model.flashcard.FlashCardResponseModel import com.pwhs.quickmem.domain.model.subject.SubjectModel @@ -24,6 +25,8 @@ data class LearnByTrueFalseUiState( val randomQuestion: TrueFalseQuestion? = null, val nextFlashCard: FlashCardResponseModel? = null, val currentFlashCard: FlashCardResponseModel? = null, + val learnFrom: LearnFrom = LearnFrom.STUDY_SET, + val folderId: String = "", ) data class TrueFalseQuestion( 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 8dc650fc..f794b75e 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 @@ -6,6 +6,7 @@ import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.viewModelScope import com.pwhs.quickmem.R +import com.pwhs.quickmem.core.data.enums.LearnFrom import com.pwhs.quickmem.core.data.enums.LearnMode import com.pwhs.quickmem.core.data.enums.ResetType import com.pwhs.quickmem.core.data.enums.TrueFalseStatus @@ -55,8 +56,12 @@ class LearnByTrueFalseViewModel @Inject constructor( val studySetDescription = savedStateHandle.get("studySetDescription") ?: "" val studySetColorId = savedStateHandle.get("studySetColorId") ?: 0 val studySetSubjectId = savedStateHandle.get("studySetSubjectId") ?: 0 + val folderId = savedStateHandle.get("folderId") ?: "" + val learnFrom = savedStateHandle.get("learnFrom") ?: LearnFrom.STUDY_SET _uiState.update { it.copy( + folderId = folderId, + learnFrom = learnFrom, studySetId = studySetId, isGetAll = isGetAll, studySetTitle = studySetTitle, @@ -133,52 +138,108 @@ class LearnByTrueFalseViewModel @Inject constructor( viewModelScope.launch { val token = tokenManager.accessToken.firstOrNull() ?: "" val studySetId = _uiState.value.studySetId + val folderId = _uiState.value.folderId + val learnFrom = _uiState.value.learnFrom val isGetAll = _uiState.value.isGetAll - flashCardRepository.getFlashCardsByStudySetId( - token = token, - studySetId = studySetId, - learnMode = LearnMode.TRUE_FALSE, - isGetAll = isGetAll - ).collect { resource -> - when (resource) { - is Resources.Error -> { - _uiState.update { it.copy(isLoading = false) } - } + when (learnFrom) { + LearnFrom.STUDY_SET -> { + flashCardRepository.getFlashCardsByStudySetId( + token = token, + studySetId = studySetId, + learnMode = LearnMode.TRUE_FALSE, + isGetAll = isGetAll + ).collect { resource -> + when (resource) { + is Resources.Error -> { + _uiState.update { it.copy(isLoading = false) } + } - is Resources.Loading -> { - _uiState.update { it.copy(isLoading = true) } - } + is Resources.Loading -> { + _uiState.update { it.copy(isLoading = true) } + } - is Resources.Success -> { - if (resource.data.isNullOrEmpty()) { - _uiState.update { - it.copy( - learningTime = 0, - isLoading = false, - isEndOfList = true - ) + is Resources.Success -> { + if (resource.data.isNullOrEmpty()) { + _uiState.update { + it.copy( + learningTime = 0, + isLoading = false, + isEndOfList = true + ) + } + playCompleteSound() + _uiEvent.send(LearnByTrueFalseUiEvent.Finished) + return@collect + } + + val flashCards = resource.data + val currentCard = flashCards.firstOrNull() + val question = generateQuestion(flashCards, currentCard) + + _uiState.update { it: LearnByTrueFalseUiState -> + it.copy( + flashCardList = flashCards, + randomQuestion = question, + isLoading = false, + currentFlashCard = currentCard, + nextFlashCard = flashCards.getOrNull(1) + ) + } } - playCompleteSound() - _uiEvent.send(LearnByTrueFalseUiEvent.Finished) - return@collect } - val flashCards = resource.data - val currentCard = flashCards.firstOrNull() - val question = generateQuestion(flashCards, currentCard) + } + } - _uiState.update { - it.copy( - flashCardList = flashCards, - randomQuestion = question, - isLoading = false, - currentFlashCard = currentCard, - nextFlashCard = flashCards.getOrNull(1) - ) + LearnFrom.FOLDER -> { + flashCardRepository.getFlashCardsByFolderId( + token = token, + folderId = folderId, + learnMode = LearnMode.TRUE_FALSE, + isGetAll = isGetAll + ).collect { resource -> + when (resource) { + is Resources.Error -> { + _uiState.update { it.copy(isLoading = false) } + } + + is Resources.Loading -> { + _uiState.update { it.copy(isLoading = true) } + } + + is Resources.Success -> { + if (resource.data.isNullOrEmpty()) { + _uiState.update { + it.copy( + learningTime = 0, + isLoading = false, + isEndOfList = true + ) + } + playCompleteSound() + _uiEvent.send(LearnByTrueFalseUiEvent.Finished) + return@collect + } + + val flashCards = resource.data + val currentCard = flashCards.firstOrNull() + val question = generateQuestion(flashCards, currentCard) + + _uiState.update { + it.copy( + flashCardList = flashCards, + randomQuestion = question, + isLoading = false, + currentFlashCard = currentCard, + nextFlashCard = flashCards.getOrNull(1) + ) + } + } } } } + LearnFrom.CLASS -> TODO() } } } diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/write/LearnByWriteArgs.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/write/LearnByWriteArgs.kt index d1968904..337c93ca 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/write/LearnByWriteArgs.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/write/LearnByWriteArgs.kt @@ -1,5 +1,7 @@ package com.pwhs.quickmem.presentation.app.study_set.studies.write +import com.pwhs.quickmem.core.data.enums.LearnFrom + data class LearnByWriteArgs( val studySetId: String, val studySetTitle: String, @@ -7,4 +9,6 @@ data class LearnByWriteArgs( val studySetColorId: Int, val studySetSubjectId: Int, val isGetAll: Boolean, + val folderId: String, + val learnFrom: LearnFrom, ) 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 33b352eb..c95f6aba 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 @@ -62,6 +62,7 @@ import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel import coil.compose.AsyncImage import com.pwhs.quickmem.R +import com.pwhs.quickmem.core.data.enums.LearnFrom import com.pwhs.quickmem.core.data.enums.WriteStatus import com.pwhs.quickmem.domain.model.flashcard.FlashCardResponseModel import com.pwhs.quickmem.presentation.app.study_set.studies.component.UnfinishedLearningBottomSheet @@ -126,6 +127,7 @@ fun LearnByWriteScreen( viewModel.onEvent(LearnByWriteUiAction.OnAnswer(id, status, answer)) }, isGetAll = uiState.isGetAll, + learnFrom = uiState.learnFrom, isPlaySound = uiState.isPlaySound, onChangeIsPlaySound = { viewModel.onEvent(LearnByWriteUiAction.OnChangeIsPlaySound(it)) @@ -153,6 +155,7 @@ fun LearnByWrite( isGetAll: Boolean = false, isPlaySound: Boolean = false, onChangeIsPlaySound: (Boolean) -> Unit = { }, + learnFrom: LearnFrom = LearnFrom.STUDY_SET ) { var isImageViewerOpen by remember { mutableStateOf(false) } var definitionImageUri by remember { mutableStateOf("") } @@ -199,7 +202,7 @@ fun LearnByWrite( } }, actions = { - if (!isEndOfList && isGetAll) { + if (!isEndOfList) { IconButton( onClick = { onChangeIsPlaySound(!isPlaySound) } ) { @@ -211,17 +214,19 @@ fun LearnByWrite( modifier = Modifier.size(22.dp) ) } - IconButton( - onClick = { - userAnswer = "" - onRestart() + if (learnFrom != LearnFrom.FOLDER && isGetAll) { + IconButton( + onClick = { + userAnswer = "" + onRestart() + } + ) { + Icon( + imageVector = Default.RestartAlt, + contentDescription = stringResource(R.string.txt_restart), + tint = studySetColor + ) } - ) { - Icon( - imageVector = Default.RestartAlt, - contentDescription = stringResource(R.string.txt_restart), - tint = studySetColor - ) } } } diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/write/LearnByWriteUiState.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/write/LearnByWriteUiState.kt index dc960aeb..69ac8a4d 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/write/LearnByWriteUiState.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/studies/write/LearnByWriteUiState.kt @@ -1,5 +1,6 @@ package com.pwhs.quickmem.presentation.app.study_set.studies.write +import com.pwhs.quickmem.core.data.enums.LearnFrom import com.pwhs.quickmem.domain.model.color.ColorModel import com.pwhs.quickmem.domain.model.flashcard.FlashCardResponseModel import com.pwhs.quickmem.domain.model.subject.SubjectModel @@ -24,6 +25,8 @@ data class LearnByTrueFalseUiState( val writeQuestion: WriteQuestion? = null, val nextFlashCard: FlashCardResponseModel? = null, val currentFlashCard: FlashCardResponseModel? = null, + val learnFrom: LearnFrom = LearnFrom.STUDY_SET, + val folderId: String = "", ) data class WriteQuestion( 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 d10da9fc..58d2b5d7 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 @@ -6,6 +6,7 @@ import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.viewModelScope import com.pwhs.quickmem.R +import com.pwhs.quickmem.core.data.enums.LearnFrom import com.pwhs.quickmem.core.data.enums.LearnMode import com.pwhs.quickmem.core.data.enums.ResetType import com.pwhs.quickmem.core.data.enums.WriteStatus @@ -55,8 +56,12 @@ class LearnByWriteViewModel @Inject constructor( val studySetDescription = savedStateHandle.get("studySetDescription") ?: "" val studySetColorId = savedStateHandle.get("studySetColorId") ?: 0 val studySetSubjectId = savedStateHandle.get("studySetSubjectId") ?: 0 + val folderId = savedStateHandle.get("folderId") ?: "" + val learnFrom = savedStateHandle.get("learnFrom") ?: LearnFrom.STUDY_SET _uiState.update { it.copy( + folderId = folderId, + learnFrom = learnFrom, isGetAll = isGetAll, studySetId = studySetId, studySetTitle = studySetTitle, @@ -134,51 +139,106 @@ class LearnByWriteViewModel @Inject constructor( viewModelScope.launch { val token = tokenManager.accessToken.firstOrNull() ?: "" val studySetId = _uiState.value.studySetId + val folderId = _uiState.value.folderId + val learnFrom = _uiState.value.learnFrom val isGetAll = _uiState.value.isGetAll - flashCardRepository.getFlashCardsByStudySetId( - token = token, - studySetId = studySetId, - learnMode = LearnMode.WRITE, - isGetAll = isGetAll - ).collect { resource -> - when (resource) { - is Resources.Error -> { - _uiState.update { it.copy(isLoading = false) } - } + when (learnFrom) { + LearnFrom.STUDY_SET -> { + flashCardRepository.getFlashCardsByStudySetId( + token = token, + studySetId = studySetId, + learnMode = LearnMode.WRITE, + isGetAll = isGetAll + ).collect { resource -> + when (resource) { + is Resources.Error -> { + _uiState.update { it.copy(isLoading = false) } + } - is Resources.Loading -> { - _uiState.update { it.copy(isLoading = true) } - } + is Resources.Loading -> { + _uiState.update { it.copy(isLoading = true) } + } - is Resources.Success -> { - if (resource.data.isNullOrEmpty()) { - _uiState.update { - it.copy( - learningTime = 0, - isLoading = false, - isEndOfList = true - ) + is Resources.Success -> { + if (resource.data.isNullOrEmpty()) { + _uiState.update { + it.copy( + learningTime = 0, + isLoading = false, + isEndOfList = true + ) + } + playCompleteSound() + _uiEvent.send(LearnByWriteUiEvent.Finished) + return@collect + } + + val flashCards = resource.data + val currentCard = flashCards.firstOrNull() + + _uiState.update { + it.copy( + flashCardList = flashCards, + writeQuestion = generateQuestion(currentCard), + isLoading = false, + currentFlashCard = currentCard, + nextFlashCard = flashCards.getOrNull(1) + ) + } } - playCompleteSound() - _uiEvent.send(LearnByWriteUiEvent.Finished) - return@collect } - val flashCards = resource.data - val currentCard = flashCards.firstOrNull() + } + } - _uiState.update { - it.copy( - flashCardList = flashCards, - writeQuestion = generateQuestion(currentCard), - isLoading = false, - currentFlashCard = currentCard, - nextFlashCard = flashCards.getOrNull(1) - ) + LearnFrom.FOLDER -> { + flashCardRepository.getFlashCardsByFolderId( + token = token, + folderId = folderId, + learnMode = LearnMode.WRITE, + isGetAll = isGetAll + ).collect { resource -> + when (resource) { + is Resources.Error -> { + _uiState.update { it.copy(isLoading = false) } + } + + is Resources.Loading -> { + _uiState.update { it.copy(isLoading = true) } + } + + is Resources.Success -> { + if (resource.data.isNullOrEmpty()) { + _uiState.update { + it.copy( + learningTime = 0, + isLoading = false, + isEndOfList = true + ) + } + playCompleteSound() + _uiEvent.send(LearnByWriteUiEvent.Finished) + return@collect + } + + val flashCards = resource.data + val currentCard = flashCards.firstOrNull() + + _uiState.update { + it.copy( + flashCardList = flashCards, + writeQuestion = generateQuestion(currentCard), + isLoading = false, + currentFlashCard = currentCard, + nextFlashCard = flashCards.getOrNull(1) + ) + } + } } } } + LearnFrom.CLASS -> TODO() } } }