From 4c98b367910ce05350b69a034a3c633d7f07db38 Mon Sep 17 00:00:00 2001 From: Nguyen Quang Minh Date: Wed, 11 Dec 2024 13:45:27 +0700 Subject: [PATCH] =?UTF-8?q?fix(ui):=20s=E1=BB=ADa=20l=E1=BB=97i=20l?= =?UTF-8?q?=E1=BA=A5y=20m=C3=A0u=20c=E1=BB=A7a=20study=20set=20-=20d=C3=B9?= =?UTF-8?q?ng=20di=20cho=20token=20manager=20v=C3=A0=20app=20manager=20-?= =?UTF-8?q?=20s=E1=BB=ADa=20l=E1=BB=97i=20ng=C3=B4n=20ng=E1=BB=AF=20-=20s?= =?UTF-8?q?=E1=BB=ADa=20l=E1=BB=97i=20giao=20di=E1=BB=87n=20m=C3=A0=20stud?= =?UTF-8?q?y=20set=20detail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../quickmem/core/datastore/AppManager.kt | 3 +- .../quickmem/core/datastore/TokenManager.kt | 3 +- .../service/AppFirebaseMessagingService.kt | 9 +- .../detail/StudySetDetailViewModel.kt | 8 +- .../detail/material/MaterialTabScreen.kt | 618 +++++++++--------- .../detail/progress/ProgressTabScreen.kt | 138 ++-- .../detail/progress/StudySetDonutChart.kt | 8 +- .../studies/flip/FlipFlashCardViewModel.kt | 12 +- .../studies/quiz/LearnByQuizViewModel.kt | 8 +- .../true_false/LearnByTrueFalseViewModel.kt | 8 +- .../studies/write/LearnByWriteViewModel.kt | 8 +- app/src/main/res/values-vi/strings.xml | 2 +- 12 files changed, 414 insertions(+), 411 deletions(-) diff --git a/app/src/main/java/com/pwhs/quickmem/core/datastore/AppManager.kt b/app/src/main/java/com/pwhs/quickmem/core/datastore/AppManager.kt index f4dd52c4..6f81f041 100644 --- a/app/src/main/java/com/pwhs/quickmem/core/datastore/AppManager.kt +++ b/app/src/main/java/com/pwhs/quickmem/core/datastore/AppManager.kt @@ -10,8 +10,9 @@ import com.pwhs.quickmem.util.dataStore import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map import timber.log.Timber +import javax.inject.Inject -class AppManager(private val context: Context) { +class AppManager @Inject constructor(private val context: Context) { companion object { val IS_FIRST_RUN = booleanPreferencesKey("IS_FIRST_RUN") val IS_LOGGED_IN = booleanPreferencesKey("IS_LOGGED_IN") diff --git a/app/src/main/java/com/pwhs/quickmem/core/datastore/TokenManager.kt b/app/src/main/java/com/pwhs/quickmem/core/datastore/TokenManager.kt index d962187c..0eb27395 100644 --- a/app/src/main/java/com/pwhs/quickmem/core/datastore/TokenManager.kt +++ b/app/src/main/java/com/pwhs/quickmem/core/datastore/TokenManager.kt @@ -7,9 +7,10 @@ import com.pwhs.quickmem.util.dataStore import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map import timber.log.Timber +import javax.inject.Inject -class TokenManager(private val context: Context) { +class TokenManager @Inject constructor(private val context: Context) { companion object { val ACCESS_TOKEN = stringPreferencesKey("ACCESS_TOKEN") diff --git a/app/src/main/java/com/pwhs/quickmem/core/service/AppFirebaseMessagingService.kt b/app/src/main/java/com/pwhs/quickmem/core/service/AppFirebaseMessagingService.kt index b7a2d68b..9c757ced 100644 --- a/app/src/main/java/com/pwhs/quickmem/core/service/AppFirebaseMessagingService.kt +++ b/app/src/main/java/com/pwhs/quickmem/core/service/AppFirebaseMessagingService.kt @@ -16,6 +16,7 @@ import com.pwhs.quickmem.core.datastore.AppManager import com.pwhs.quickmem.core.datastore.TokenManager import com.pwhs.quickmem.data.dto.notification.DeviceTokenRequestDto import com.pwhs.quickmem.data.remote.ApiService +import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.firstOrNull @@ -23,10 +24,14 @@ import kotlinx.coroutines.launch import timber.log.Timber import javax.inject.Inject +@AndroidEntryPoint class AppFirebaseMessagingService : FirebaseMessagingService() { - private val tokenManager = TokenManager(this) - private val appManager = AppManager(this) + @Inject + lateinit var tokenManager: TokenManager + + @Inject + lateinit var appManager: AppManager @Inject lateinit var apiService: ApiService diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/detail/StudySetDetailViewModel.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/detail/StudySetDetailViewModel.kt index 809f46dd..a921a70c 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/detail/StudySetDetailViewModel.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/detail/StudySetDetailViewModel.kt @@ -33,7 +33,7 @@ class StudySetDetailViewModel @Inject constructor( private val studyTimeRepository: StudyTimeRepository, private val tokenManager: TokenManager, private val appManager: AppManager, - firebaseAnalytics: FirebaseAnalytics, + private val firebaseAnalytics: FirebaseAnalytics, savedStateHandle: SavedStateHandle, ) : ViewModel() { private val _uiState = MutableStateFlow(StudySetDetailUiState()) @@ -97,6 +97,11 @@ class StudySetDetailViewModel @Inject constructor( } is StudySetDetailUiAction.NavigateToLearn -> { + firebaseAnalytics.logEvent("navigate_to_learn") { + param("study_set_id", _uiState.value.id) + param("study_set_title", _uiState.value.title) + param("learn_mode", event.learnMode.mode) + } when (event.learnMode) { LearnMode.FLIP -> { _uiEvent.trySend(StudySetDetailUiEvent.OnNavigateToFlipFlashcard(event.isGetAll)) @@ -157,7 +162,6 @@ class StudySetDetailViewModel @Inject constructor( } is Resources.Error -> { - Timber.d("Error") _uiState.update { it.copy(isLoading = false) } } } diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/detail/material/MaterialTabScreen.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/detail/material/MaterialTabScreen.kt index 2bc5b434..b5710fb5 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/detail/material/MaterialTabScreen.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/detail/material/MaterialTabScreen.kt @@ -27,7 +27,6 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme.colorScheme import androidx.compose.material3.MaterialTheme.typography import androidx.compose.material3.ModalBottomSheet -import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.material3.rememberModalBottomSheetState import androidx.compose.runtime.Composable @@ -88,369 +87,366 @@ fun MaterialTabScreen( var learningMode by remember { mutableStateOf(LearnMode.NONE) } val context = LocalContext.current - Scaffold { innerPadding -> - Box( - modifier = modifier - .fillMaxSize() - .padding(innerPadding), - contentAlignment = Center - ) { - when { - flashCards.isEmpty() -> { - Column( - horizontalAlignment = CenterHorizontally, - modifier = Modifier.padding(16.dp) - ) { - Text( - text = stringResource(R.string.txt_add_your_material_to_get_started), - style = typography.titleLarge.copy( - fontWeight = Bold, - color = colorScheme.onSurface - ), - modifier = Modifier.padding(16.dp), - textAlign = TextAlign.Center - ) - Text( - text = stringResource(R.string.txt_this_study_set_can_contain_flashcards_notes_and_files_on_certain_topic), - textAlign = TextAlign.Center, - style = typography.bodyMedium.copy( - color = colorScheme.onSurface, - ), - ) - if (isOwner) { - Button( - onClick = onAddFlashCardClick, - modifier = Modifier.padding(16.dp) + Box( + modifier = modifier + .fillMaxSize(), + contentAlignment = Center + ) { + when { + flashCards.isEmpty() -> { + Column( + horizontalAlignment = CenterHorizontally, + modifier = Modifier.padding(16.dp) + ) { + Text( + text = stringResource(R.string.txt_add_your_material_to_get_started), + style = typography.titleLarge.copy( + fontWeight = Bold, + color = colorScheme.onSurface + ), + modifier = Modifier.padding(16.dp), + textAlign = TextAlign.Center + ) + Text( + text = stringResource(R.string.txt_this_study_set_can_contain_flashcards_notes_and_files_on_certain_topic), + textAlign = TextAlign.Center, + style = typography.bodyMedium.copy( + color = colorScheme.onSurface, + ), + ) + if (isOwner) { + Button( + onClick = onAddFlashCardClick, + modifier = Modifier.padding(16.dp) + ) { + Row( + verticalAlignment = CenterVertically ) { - Row( - verticalAlignment = CenterVertically - ) { - Icon( - Icons.Filled.Add, - contentDescription = stringResource(R.string.txt_add), - tint = colorScheme.background, - modifier = Modifier.padding(end = 8.dp) - ) - Text( - text = stringResource(R.string.txt_add_material), - style = typography.titleMedium.copy( - color = colorScheme.background - ) + Icon( + Icons.Filled.Add, + contentDescription = stringResource(R.string.txt_add), + tint = colorScheme.background, + modifier = Modifier.padding(end = 8.dp) + ) + Text( + text = stringResource(R.string.txt_add_material), + style = typography.titleMedium.copy( + color = colorScheme.background ) - } + ) } } } } + } - else -> { - LazyColumn( - modifier = Modifier - .fillMaxSize(), - horizontalAlignment = CenterHorizontally, - verticalArrangement = Arrangement.Top, - ) { - if (!isOwner) { - item { - Column( - horizontalAlignment = CenterHorizontally, - ) { - Button( - onClick = onMakeCopyClick, - modifier = Modifier.padding(16.dp), - shape = MaterialTheme.shapes.medium, - colors = ButtonDefaults.buttonColors( - containerColor = studySetColor - ) - ) { - Text( - text = stringResource(R.string.txt_make_a_copy), - style = typography.titleMedium.copy( - color = colorScheme.background - ) - ) - } - - Text( - text = stringResource(R.string.txt_you_can_not_edit_this_study_set_just_create_a_copy_of_it), - style = typography.bodyMedium.copy( - color = colorScheme.onSurface - ), - textAlign = TextAlign.Center, + else -> { + LazyColumn( + modifier = Modifier + .fillMaxSize(), + horizontalAlignment = CenterHorizontally, + verticalArrangement = Arrangement.Top, + ) { + if (!isOwner) { + item { + Column( + horizontalAlignment = CenterHorizontally, + ) { + Button( + onClick = onMakeCopyClick, + modifier = Modifier.padding(16.dp), + shape = MaterialTheme.shapes.medium, + colors = ButtonDefaults.buttonColors( + containerColor = studySetColor ) - } - } - } - - if (isOwner) { - item { - LazyRow( - modifier = Modifier.fillMaxWidth(), ) { - items(items = flashCards, key = { it.id }) { flashCard -> - StudySetFlipCard( - frontText = flashCard.term, - backText = flashCard.definition, - backgroundColor = colorScheme.background, - backImage = flashCard.definitionImageURL, + Text( + text = stringResource(R.string.txt_make_a_copy), + style = typography.titleMedium.copy( + color = colorScheme.background ) - } + ) } - } - item { Text( - text = stringResource(R.string.txt_choose_your_way_to_study), - style = typography.titleMedium.copy( - color = colorScheme.onSurface, - fontWeight = Bold + text = stringResource(R.string.txt_you_can_not_edit_this_study_set_just_create_a_copy_of_it), + style = typography.bodyMedium.copy( + color = colorScheme.onSurface ), - modifier = Modifier.padding(16.dp) - ) - } - - item { - LearnModeCard( - title = stringResource(R.string.txt_flip_flashcards), - icon = R.drawable.ic_flipcard, - onClick = { - showGetAllDialog = true - learningMode = LearnMode.FLIP - }, - color = studySetColor, - learningPercentage = learningPercentFlipped - ) - } - item { - LearnModeCard( - title = stringResource(R.string.txt_quiz), - icon = R.drawable.ic_quiz, - onClick = { - showGetAllDialog = true - learningMode = LearnMode.QUIZ - }, - color = studySetColor, - learningPercentage = learningPercentQuiz - ) - } - item { - LearnModeCard( - title = stringResource(R.string.txt_true_false), - icon = R.drawable.ic_tf, - onClick = { - showGetAllDialog = true - learningMode = LearnMode.TRUE_FALSE - }, - color = studySetColor, - learningPercentage = learningPercentTrueFalse - ) - } - item { - LearnModeCard( - title = stringResource(R.string.txt_write), - icon = R.drawable.ic_write, - onClick = { - showGetAllDialog = true - learningMode = LearnMode.WRITE - }, - color = studySetColor, - learningPercentage = learningPercentWrite + textAlign = TextAlign.Center, ) } } + } + if (isOwner) { item { - Row( - verticalAlignment = CenterVertically, - horizontalArrangement = SpaceBetween, - modifier = Modifier - .fillMaxWidth() - .padding(16.dp) + LazyRow( + modifier = Modifier.fillMaxWidth(), ) { - Text( - text = stringResource(R.string.txt_terms), - style = typography.titleMedium.copy( - color = colorScheme.onSurface, - fontWeight = Bold - ), - modifier = Modifier.weight(1f) - ) + items(items = flashCards, key = { it.id }) { flashCard -> + StudySetFlipCard( + frontText = flashCard.term, + backText = flashCard.definition, + backgroundColor = colorScheme.background, + backImage = flashCard.definitionImageURL, + ) + } } } - items(items = flashCards, key = { it.id }) { flashCards -> - CardDetail( - isOwner = isOwner, + item { + Text( + text = stringResource(R.string.txt_choose_your_way_to_study), + style = typography.titleMedium.copy( + color = colorScheme.onSurface, + fontWeight = Bold + ), + modifier = Modifier.padding(16.dp) + ) + } + + item { + LearnModeCard( + title = stringResource(R.string.txt_flip_flashcards), + icon = R.drawable.ic_flipcard, + onClick = { + showGetAllDialog = true + learningMode = LearnMode.FLIP + }, + color = studySetColor, + learningPercentage = learningPercentFlipped + ) + } + item { + LearnModeCard( + title = stringResource(R.string.txt_quiz), + icon = R.drawable.ic_quiz, + onClick = { + showGetAllDialog = true + learningMode = LearnMode.QUIZ + }, color = studySetColor, - front = flashCards.term, - back = flashCards.definition, - isStarred = flashCards.isStarred, - imageURL = flashCards.definitionImageURL, - isAIGenerated = flashCards.isAIGenerated, - onToggleStarClick = { isStarred -> - onToggleStarClick(flashCards.id, isStarred) + learningPercentage = learningPercentQuiz + ) + } + item { + LearnModeCard( + title = stringResource(R.string.txt_true_false), + icon = R.drawable.ic_tf, + onClick = { + showGetAllDialog = true + learningMode = LearnMode.TRUE_FALSE }, - onMenuClick = { - (flashCards.hint - ?: context.getString(R.string.txt_there_is_no_hint_for_this_flashcard)).also { - hint = it - } - (flashCards.explanation - ?: context.getString(R.string.txt_there_is_no_explanation_for_this_flashcard)).also { - explanation = it - } - showMenu = true - studySetId = flashCards.id - onFlashCardClick(flashCards.id) - } + color = studySetColor, + learningPercentage = learningPercentTrueFalse + ) + } + item { + LearnModeCard( + title = stringResource(R.string.txt_write), + icon = R.drawable.ic_write, + onClick = { + showGetAllDialog = true + learningMode = LearnMode.WRITE + }, + color = studySetColor, + learningPercentage = learningPercentWrite ) } + } + item { + Row( + verticalAlignment = CenterVertically, + horizontalArrangement = SpaceBetween, + modifier = Modifier + .fillMaxWidth() + .padding(16.dp) + ) { + Text( + text = stringResource(R.string.txt_terms), + style = typography.titleMedium.copy( + color = colorScheme.onSurface, + fontWeight = Bold + ), + modifier = Modifier.weight(1f) + ) + } } + + items(items = flashCards, key = { it.id }) { flashCards -> + CardDetail( + isOwner = isOwner, + color = studySetColor, + front = flashCards.term, + back = flashCards.definition, + isStarred = flashCards.isStarred, + imageURL = flashCards.definitionImageURL, + isAIGenerated = flashCards.isAIGenerated, + onToggleStarClick = { isStarred -> + onToggleStarClick(flashCards.id, isStarred) + }, + onMenuClick = { + (flashCards.hint + ?: context.getString(R.string.txt_there_is_no_hint_for_this_flashcard)).also { + hint = it + } + (flashCards.explanation + ?: context.getString(R.string.txt_there_is_no_explanation_for_this_flashcard)).also { + explanation = it + } + showMenu = true + studySetId = flashCards.id + onFlashCardClick(flashCards.id) + } + ) + } + } } } + } - if (showMenu) { - ModalBottomSheet( - sheetState = menuBottomSheetState, - onDismissRequest = { - showMenu = false - } - ) { - Column { + if (showMenu) { + ModalBottomSheet( + sheetState = menuBottomSheetState, + onDismissRequest = { + showMenu = false + } + ) { + Column { + ItemMenuBottomSheet( + onClick = { + showHint = true + showMenu = false + }, + icon = Filled.HelpOutline, + title = stringResource(R.string.txt_hint) + ) + ItemMenuBottomSheet( + onClick = { + showExplanation = true + showMenu = false + }, + icon = Filled.HelpOutline, + title = stringResource(R.string.txt_explanation) + ) + if (isOwner) { ItemMenuBottomSheet( onClick = { - showHint = true + onEditFlashCardClick() showMenu = false }, - icon = Filled.HelpOutline, - title = stringResource(R.string.txt_hint) + icon = Outlined.Edit, + title = stringResource(R.string.txt_edit) ) ItemMenuBottomSheet( onClick = { - showExplanation = true + showAlertDialog = true showMenu = false }, - icon = Filled.HelpOutline, - title = stringResource(R.string.txt_explanation) + icon = Default.DeleteOutline, + title = stringResource(R.string.txt_delete), + color = Color.Red, ) - if (isOwner) { - ItemMenuBottomSheet( - onClick = { - onEditFlashCardClick() - showMenu = false - }, - icon = Outlined.Edit, - title = stringResource(R.string.txt_edit) - ) - ItemMenuBottomSheet( - onClick = { - showAlertDialog = true - showMenu = false - }, - icon = Default.DeleteOutline, - title = stringResource(R.string.txt_delete), - color = Color.Red, - ) - } } } } + } - if (showHint) { - ModalBottomSheet( - sheetState = hintBottomSheet, - onDismissRequest = { - hint = "" - showHint = false - } - ) { - Column { - Text( - text = stringResource(R.string.txt_hint), - style = typography.titleMedium.copy( - color = colorScheme.onSurface, - fontWeight = Bold - ), - modifier = Modifier.padding(16.dp) - ) - Text( - text = hint, - style = typography.bodyMedium.copy( - color = colorScheme.onSurface, - ), - modifier = Modifier.padding(16.dp) - ) - } + if (showHint) { + ModalBottomSheet( + sheetState = hintBottomSheet, + onDismissRequest = { + hint = "" + showHint = false + } + ) { + Column { + Text( + text = stringResource(R.string.txt_hint), + style = typography.titleMedium.copy( + color = colorScheme.onSurface, + fontWeight = Bold + ), + modifier = Modifier.padding(16.dp) + ) + Text( + text = hint, + style = typography.bodyMedium.copy( + color = colorScheme.onSurface, + ), + modifier = Modifier.padding(16.dp) + ) } } + } - if (showExplanation) { - ModalBottomSheet( - sheetState = explanationBottomSheet, - onDismissRequest = { - hint = "" - showExplanation = false - } - ) { - Column { - Text( - text = stringResource(R.string.txt_explanation), - style = typography.titleMedium.copy( - color = colorScheme.onSurface, - fontWeight = Bold - ), - modifier = Modifier.padding(16.dp) - ) - Text( - text = explanation, - style = typography.bodyMedium.copy( - color = colorScheme.onSurface, - ), - modifier = Modifier.padding(16.dp) - ) - } + if (showExplanation) { + ModalBottomSheet( + sheetState = explanationBottomSheet, + onDismissRequest = { + hint = "" + showExplanation = false + } + ) { + Column { + Text( + text = stringResource(R.string.txt_explanation), + style = typography.titleMedium.copy( + color = colorScheme.onSurface, + fontWeight = Bold + ), + modifier = Modifier.padding(16.dp) + ) + Text( + text = explanation, + style = typography.bodyMedium.copy( + color = colorScheme.onSurface, + ), + modifier = Modifier.padding(16.dp) + ) } } + } - if (showAlertDialog) { - QuickMemAlertDialog( - onDismissRequest = { - showAlertDialog = false - }, - onConfirm = { - showAlertDialog = false - onDeleteFlashCardClick() - }, - title = stringResource(R.string.txt_delete_flashcard), - text = stringResource(R.string.txt_are_you_sure_you_want_to_delete_this_flashcard), - confirmButtonTitle = stringResource(R.string.txt_delete), - dismissButtonTitle = stringResource(R.string.txt_cancel), - buttonColor = colorScheme.error, - ) - } - if (showGetAllDialog && flashCards.size > 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 - } + if (showAlertDialog) { + QuickMemAlertDialog( + onDismissRequest = { + showAlertDialog = false + }, + onConfirm = { + showAlertDialog = false + onDeleteFlashCardClick() + }, + title = stringResource(R.string.txt_delete_flashcard), + text = stringResource(R.string.txt_are_you_sure_you_want_to_delete_this_flashcard), + confirmButtonTitle = stringResource(R.string.txt_delete), + dismissButtonTitle = stringResource(R.string.txt_cancel), + buttonColor = colorScheme.error, + ) + } + if (showGetAllDialog && flashCards.size > 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 } } diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/detail/progress/ProgressTabScreen.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/detail/progress/ProgressTabScreen.kt index 9bbdc14c..031b4e34 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/detail/progress/ProgressTabScreen.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/detail/progress/ProgressTabScreen.kt @@ -9,7 +9,6 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme.typography -import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment @@ -35,86 +34,83 @@ fun ProgressTabScreen( studyTime: GetStudyTimeByStudySetResponseModel? = null, color: Color = MaterialTheme.colorScheme.primary ) { - Scaffold { innerPadding -> - Box( - modifier = modifier - .padding(innerPadding) - .fillMaxSize() - .padding(horizontal = 16.dp), + Box( + modifier = modifier + .fillMaxSize() + .padding(horizontal = 16.dp), + ) { + LazyColumn( + modifier = Modifier + .fillMaxWidth() ) { - LazyColumn( - modifier = Modifier - .fillMaxWidth() - ) { - item { - Text( - text = stringResource(R.string.txt_your_progress), - style = typography.titleMedium.copy( - fontWeight = FontWeight.Bold, - fontSize = 24.sp - ) + item { + Text( + text = stringResource(R.string.txt_your_progress), + style = typography.titleMedium.copy( + fontWeight = FontWeight.Bold, + fontSize = 24.sp ) - } - item { - Column( - modifier = Modifier - .fillMaxWidth() - .padding(16.dp), - horizontalAlignment = Alignment.CenterHorizontally - ) { - when { - totalStudySet == 0 -> { - Text( - text = stringResource(R.string.txt_you_have_not_started_any_study_set_yet), - style = typography.bodyMedium.copy( - fontSize = 16.sp - ) + ) + } + item { + Column( + modifier = Modifier + .fillMaxWidth() + .padding(16.dp), + horizontalAlignment = Alignment.CenterHorizontally + ) { + when { + totalStudySet == 0 -> { + Text( + text = stringResource(R.string.txt_you_have_not_started_any_study_set_yet), + style = typography.bodyMedium.copy( + fontSize = 16.sp ) - } + ) + } - else -> { - StudySetDonutChart( - color = color, - studySetsNotLearn = studySetsNotLearnCount, - studySetsStillLearn = studySetsStillLearningCount, - studySetsMastered = studySetsKnowCount - ) - ProgressRow( - label = stringResource(R.string.txt_not_learned), - percentage = studySetsNotLearnCount * 100 / totalStudySet, - color = color.copy(alpha = 0.3f) - ) + else -> { + StudySetDonutChart( + color = color, + studySetsNotLearn = studySetsNotLearnCount, + studySetsStillLearn = studySetsStillLearningCount, + studySetsMastered = studySetsKnowCount + ) + ProgressRow( + label = stringResource(R.string.txt_not_learned), + percentage = studySetsNotLearnCount * 100 / totalStudySet, + color = color.copy(alpha = 0.3f) + ) - ProgressRow( - label = stringResource(R.string.txt_still_learning), - percentage = studySetsStillLearningCount * 100 / totalStudySet, - color = color.copy(alpha = 0.6f) - ) + ProgressRow( + label = stringResource(R.string.txt_still_learning), + percentage = studySetsStillLearningCount * 100 / totalStudySet, + color = color.copy(alpha = 0.6f) + ) - ProgressRow( - label = stringResource(R.string.txt_learn), - percentage = studySetsKnowCount * 100 / totalStudySet, - color = color - ) - Text( - text = stringResource(R.string.txt_current_flip_status), - style = typography.titleMedium.copy( - fontWeight = FontWeight.Bold, - ) + ProgressRow( + label = stringResource(R.string.txt_learn), + percentage = studySetsKnowCount * 100 / totalStudySet, + color = color + ) + Text( + text = stringResource(R.string.txt_current_flip_status), + style = typography.titleMedium.copy( + fontWeight = FontWeight.Bold, ) - } + ) } } } - item { - if (studyTime?.flip != 0 || studyTime.quiz != 0 || studyTime.total != 0 || studyTime.flip != 0) { - LearningBars( - studyTime = studyTime?.toStudyTimeModel(), - color = color, - modifier = Modifier - .height(300.dp) - ) - } + } + item { + if (studyTime?.flip != 0 || studyTime.quiz != 0 || studyTime.total != 0 || studyTime.flip != 0) { + LearningBars( + studyTime = studyTime?.toStudyTimeModel(), + color = color, + modifier = Modifier + .height(300.dp) + ) } } } diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/detail/progress/StudySetDonutChart.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/detail/progress/StudySetDonutChart.kt index 4c1fbf22..1210d3e4 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/detail/progress/StudySetDonutChart.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/detail/progress/StudySetDonutChart.kt @@ -47,15 +47,15 @@ fun StudySetDonutChart( ) { val total = (studySetsNotLearn + studySetsStillLearn + studySetsMastered).coerceAtLeast(0) val percentages = listOf( - studySetsNotLearn.coerceAtLeast(0).toFloat() / total, + studySetsMastered.coerceAtLeast(0).toFloat() / total, studySetsStillLearn.coerceAtLeast(0).toFloat() / total, - studySetsMastered.coerceAtLeast(0).toFloat() / total + studySetsNotLearn.coerceAtLeast(0).toFloat() / total, ) val colors = listOf( - color.copy(alpha = 0.3f), + color, color.copy(alpha = 0.6f), - color + color.copy(alpha = 0.3f), ) val animatedPercentage = percentages.map { target -> 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 e7cb76cf..c939862f 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 @@ -55,20 +55,20 @@ class FlipFlashCardViewModel @Inject constructor( val isGetAll = savedStateHandle.get("isGetAll") ?: false val studySetTitle = savedStateHandle.get("studySetTitle") ?: "" val studySetDescription = savedStateHandle.get("studySetDescription") ?: "" - val studySetColorId = savedStateHandle.get("studySetColorId") ?: 0 - val studySetSubjectId = savedStateHandle.get("studySetSubjectId") ?: 0 + val studySetColorId = savedStateHandle.get("studySetColorId") ?: 1 + val studySetSubjectId = savedStateHandle.get("studySetSubjectId") ?: 1 val folderId = savedStateHandle.get("folderId") ?: "" val learnFrom = savedStateHandle.get("learnFrom") ?: LearnFrom.STUDY_SET - _uiState.update { - it.copy( + _uiState.update { state -> + state.copy( learnFrom = learnFrom, isGetAll = isGetAll, folderId = folderId, studySetId = studySetId, studySetTitle = studySetTitle, studySetDescription = studySetDescription, - studySetColor = ColorModel.defaultColors[studySetColorId], - studySetSubject = SubjectModel.defaultSubjects[studySetSubjectId], + studySetColor = ColorModel.defaultColors.first { it.id == studySetColorId }, + studySetSubject = SubjectModel.defaultSubjects.first { it.id == studySetSubjectId }, startTime = System.currentTimeMillis() ) } 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 2e62d443..3c8539a9 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 @@ -55,8 +55,8 @@ class LearnByQuizViewModel @Inject constructor( val isGetAll = savedStateHandle.get("isGetAll") ?: false val studySetTitle = savedStateHandle.get("studySetTitle") ?: "" val studySetDescription = savedStateHandle.get("studySetDescription") ?: "" - val studySetColorId = savedStateHandle.get("studySetColorId") ?: 0 - val studySetSubjectId = savedStateHandle.get("studySetSubjectId") ?: 0 + val studySetColorId = savedStateHandle.get("studySetColorId") ?: 1 + val studySetSubjectId = savedStateHandle.get("studySetSubjectId") ?: 1 val folderId = savedStateHandle.get("folderId") ?: "" val learnFrom = savedStateHandle.get("learnFrom") ?: LearnFrom.STUDY_SET _uiState.update { @@ -67,8 +67,8 @@ class LearnByQuizViewModel @Inject constructor( isGetAll = isGetAll, studySetTitle = studySetTitle, studySetDescription = studySetDescription, - studySetColor = ColorModel.defaultColors[studySetColorId], - studySetSubject = SubjectModel.defaultSubjects[studySetSubjectId], + studySetColor = ColorModel.defaultColors.first { it.id == studySetColorId }, + studySetSubject = SubjectModel.defaultSubjects.first { it.id == studySetSubjectId }, startTime = System.currentTimeMillis() ) } 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 f794b75e..0d9923eb 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 @@ -54,8 +54,8 @@ class LearnByTrueFalseViewModel @Inject constructor( val isGetAll = savedStateHandle.get("isGetAll") ?: false val studySetTitle = savedStateHandle.get("studySetTitle") ?: "" val studySetDescription = savedStateHandle.get("studySetDescription") ?: "" - val studySetColorId = savedStateHandle.get("studySetColorId") ?: 0 - val studySetSubjectId = savedStateHandle.get("studySetSubjectId") ?: 0 + val studySetColorId = savedStateHandle.get("studySetColorId") ?: 1 + val studySetSubjectId = savedStateHandle.get("studySetSubjectId") ?: 1 val folderId = savedStateHandle.get("folderId") ?: "" val learnFrom = savedStateHandle.get("learnFrom") ?: LearnFrom.STUDY_SET _uiState.update { @@ -66,8 +66,8 @@ class LearnByTrueFalseViewModel @Inject constructor( isGetAll = isGetAll, studySetTitle = studySetTitle, studySetDescription = studySetDescription, - studySetColor = ColorModel.defaultColors[studySetColorId], - studySetSubject = SubjectModel.defaultSubjects[studySetSubjectId], + studySetColor = ColorModel.defaultColors.first { it.id == studySetColorId }, + studySetSubject = SubjectModel.defaultSubjects.first { it.id == studySetSubjectId }, startTime = System.currentTimeMillis() ) } 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 0e732d00..6f82b103 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 @@ -54,8 +54,8 @@ class LearnByWriteViewModel @Inject constructor( val isGetAll = savedStateHandle.get("isGetAll") ?: false val studySetTitle = savedStateHandle.get("studySetTitle") ?: "" val studySetDescription = savedStateHandle.get("studySetDescription") ?: "" - val studySetColorId = savedStateHandle.get("studySetColorId") ?: 0 - val studySetSubjectId = savedStateHandle.get("studySetSubjectId") ?: 0 + val studySetColorId = savedStateHandle.get("studySetColorId") ?: 1 + val studySetSubjectId = savedStateHandle.get("studySetSubjectId") ?: 1 val folderId = savedStateHandle.get("folderId") ?: "" val learnFrom = savedStateHandle.get("learnFrom") ?: LearnFrom.STUDY_SET _uiState.update { @@ -66,8 +66,8 @@ class LearnByWriteViewModel @Inject constructor( studySetId = studySetId, studySetTitle = studySetTitle, studySetDescription = studySetDescription, - studySetColor = ColorModel.defaultColors[studySetColorId], - studySetSubject = SubjectModel.defaultSubjects[studySetSubjectId], + studySetColor = ColorModel.defaultColors.first { it.id == studySetColorId }, + studySetSubject = SubjectModel.defaultSubjects.first { it.id == studySetSubjectId }, startTime = System.currentTimeMillis() ) } diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index c67bd11a..72740d3b 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -481,5 +481,5 @@ Khi bạn công khai bộ học, bất kỳ ai cũng có thể xem và sử dụng nó. Bộ học đã được tạo Bộ học đã được chỉnh sửa - Trạng thái lật hiện tại + Quá trình học lật thẻ hiện tại \ No newline at end of file