From 959ac2444e03bfba9f055e2ccdcc441b194d651c Mon Sep 17 00:00:00 2001 From: Nguyen Quang Minh Date: Sun, 29 Dec 2024 22:39:08 +0700 Subject: [PATCH] =?UTF-8?q?feat(study=20set):=20truy=E1=BB=81n=20subjectId?= =?UTF-8?q?=20qua=20m=C3=A0n=20h=C3=ACnh=20t=E1=BA=A1o=20study=20set=20-?= =?UTF-8?q?=20s=E1=BB=ADa=20l=E1=BA=A1i=20dialog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/classes/detail/ClassDetailScreen.kt | 2 + .../app/folder/detail/FolderDetailScreen.kt | 1 + .../SearchStudySetBySubjectScreen.kt | 25 ++++--- .../SearchStudySetBySubjectTopAppBar.kt | 67 ++++++++++--------- .../presentation/app/library/LibraryScreen.kt | 2 +- .../study_set/create/CreateStudySetArgs.kt | 5 ++ .../study_set/create/CreateStudySetScreen.kt | 4 +- .../create/CreateStudySetViewModel.kt | 12 ++++ .../study_set/detail/StudySetDetailScreen.kt | 7 +- 9 files changed, 80 insertions(+), 45 deletions(-) create mode 100644 app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/create/CreateStudySetArgs.kt diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/classes/detail/ClassDetailScreen.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/classes/detail/ClassDetailScreen.kt index 72159bff..2f1e8152 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/classes/detail/ClassDetailScreen.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/classes/detail/ClassDetailScreen.kt @@ -490,6 +490,7 @@ fun ClassDetail( text = stringResource(R.string.txt_are_you_sure_you_want_to_delete_this_class), confirmButtonTitle = stringResource(R.string.txt_delete), dismissButtonTitle = stringResource(R.string.txt_cancel), + buttonColor = colorScheme.error, ) } @@ -506,6 +507,7 @@ fun ClassDetail( text = stringResource(R.string.txt_are_you_sure_you_want_to_exit_this_class), confirmButtonTitle = stringResource(R.string.txt_exit), dismissButtonTitle = stringResource(R.string.txt_cancel), + buttonColor = colorScheme.error, ) } 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 d3769eb8..ef1204f0 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 @@ -393,6 +393,7 @@ fun FolderDetail( text = stringResource(R.string.txt_are_you_sure_you_want_to_delete_this_folder), confirmButtonTitle = stringResource(R.string.txt_delete), dismissButtonTitle = stringResource(R.string.txt_cancel), + buttonColor = colorScheme.error, ) } FolderMenuBottomSheet( diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/home/search_by_subject/SearchStudySetBySubjectScreen.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/home/search_by_subject/SearchStudySetBySubjectScreen.kt index d4d814f7..3286a7bb 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/home/search_by_subject/SearchStudySetBySubjectScreen.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/home/search_by_subject/SearchStudySetBySubjectScreen.kt @@ -62,7 +62,7 @@ fun SearchStudySetBySubjectScreen( modifier: Modifier = Modifier, viewModel: SearchStudySetBySubjectViewModel = hiltViewModel(), navigator: DestinationsNavigator, - resultBackNavigator: ResultBackNavigator + resultBackNavigator: ResultBackNavigator, ) { val uiState by viewModel.uiState.collectAsState() val context = LocalContext.current @@ -92,10 +92,9 @@ fun SearchStudySetBySubjectScreen( icon = uiState.icon, studySetCount = uiState.studySetCount, isLoading = uiState.isLoading, - nameSubject = uiState.subject?.subjectName ?: R.string.txt_general, + nameSubject = uiState.subject?.subjectName, colorSubject = uiState.subject?.color ?: Color.Blue, - descriptionSubject = uiState.subject?.subjectDescription - ?: R.string.txt_general_subjects_that_do_not_fit_into_specific_categories, + descriptionSubject = uiState.subject?.subjectDescription, studySets = studySetItems, onNavigateBack = { resultBackNavigator.navigateBack(true) @@ -104,7 +103,11 @@ fun SearchStudySetBySubjectScreen( viewModel.onEvent(SearchStudySetBySubjectUiAction.RefreshStudySets) }, onAddStudySet = { - navigator.navigate(CreateStudySetScreenDestination()) + navigator.navigate( + CreateStudySetScreenDestination( + subjectId = uiState.subject?.id ?: 1 + ) + ) } ) } @@ -114,15 +117,15 @@ fun SearchStudySetBySubject( modifier: Modifier = Modifier, studySets: LazyPagingItems? = null, onStudySetClick: (GetStudySetResponseModel?) -> Unit = {}, - @StringRes nameSubject: Int = R.string.txt_general, + @StringRes nameSubject: Int? = null, colorSubject: Color = colorScheme.primary, - @DrawableRes icon: Int = R.drawable.ic_all, + @DrawableRes icon: Int? = null, studySetCount: Int = 0, - @StringRes descriptionSubject: Int = R.string.txt_general_subjects_that_do_not_fit_into_specific_categories, + @StringRes descriptionSubject: Int? = null, isLoading: Boolean = false, onNavigateBack: () -> Unit = {}, onStudySetRefresh: () -> Unit = {}, - onAddStudySet: () -> Unit = {} + onAddStudySet: () -> Unit = {}, ) { var searchQuery by remember { mutableStateOf("") } @@ -132,11 +135,11 @@ fun SearchStudySetBySubject( topBar = { SearchStudySetBySubjectTopAppBar( onNavigateBack = onNavigateBack, - name = stringResource(nameSubject), + name = nameSubject?.let { stringResource(it) }, color = colorSubject, icon = icon, studySetCount = studySetCount, - description = stringResource(descriptionSubject), + description = descriptionSubject?.let { stringResource(it) }, onAddStudySet = onAddStudySet ) } diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/home/search_by_subject/component/SearchStudySetBySubjectTopAppBar.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/home/search_by_subject/component/SearchStudySetBySubjectTopAppBar.kt index dd9c44f6..fcd062d7 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/home/search_by_subject/component/SearchStudySetBySubjectTopAppBar.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/home/search_by_subject/component/SearchStudySetBySubjectTopAppBar.kt @@ -40,13 +40,13 @@ import com.pwhs.quickmem.util.gradientBackground @Composable fun SearchStudySetBySubjectTopAppBar( modifier: Modifier = Modifier, - name: String = "", - description: String = "", + name: String? = null, + description: String? = null, color: Color, studySetCount: Int = 0, - @DrawableRes icon: Int = R.drawable.ic_all, + @DrawableRes icon: Int? = null, onNavigateBack: () -> Unit, - onAddStudySet: () -> Unit = {} + onAddStudySet: () -> Unit = {}, ) { LargeTopAppBar( modifier = modifier.background(color.gradientBackground()), @@ -62,24 +62,28 @@ fun SearchStudySetBySubjectTopAppBar( horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.CenterVertically ) { - Icon( - painter = painterResource(id = icon), - contentDescription = null, - tint = colorScheme.onSurface, - modifier = Modifier - .size(30.dp) - .padding(end = 8.dp) - ) - Text( - text = name, - style = typography.titleMedium.copy( - fontWeight = FontWeight.Bold, - color = colorScheme.onSurface, - fontSize = 20.sp - ), - maxLines = 1, - overflow = TextOverflow.Ellipsis - ) + icon?.let { + Icon( + painter = painterResource(id = icon), + contentDescription = null, + tint = colorScheme.onSurface, + modifier = Modifier + .size(30.dp) + .padding(end = 8.dp) + ) + } + name?.let { + Text( + text = name, + style = typography.titleMedium.copy( + fontWeight = FontWeight.Bold, + color = colorScheme.onSurface, + fontSize = 20.sp + ), + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) + } } Text( text = stringResource(R.string.txt_sets, studySetCount), @@ -89,14 +93,16 @@ fun SearchStudySetBySubjectTopAppBar( maxLines = 1, overflow = TextOverflow.Ellipsis ) - Text( - text = description, - style = typography.bodyMedium.copy( - color = colorScheme.secondary - ), - maxLines = 2, - overflow = TextOverflow.Ellipsis - ) + description?.let { + Text( + text = description, + style = typography.bodyMedium.copy( + color = colorScheme.secondary + ), + maxLines = 2, + overflow = TextOverflow.Ellipsis + ) + } } }, expandedHeight = 150.dp, @@ -128,6 +134,7 @@ fun SearchStudySetBySubjectTopAppBar( } @Preview(showSystemUi = true) +@Preview(showSystemUi = true, locale = "vi") @Composable fun TopBarSearchPreview() { QuickMemTheme { diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/library/LibraryScreen.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/library/LibraryScreen.kt index 51ab57c9..9998b853 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/library/LibraryScreen.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/library/LibraryScreen.kt @@ -157,7 +157,7 @@ fun LibraryScreen( ) }, navigateToCreateStudySet = { - navigator.navigate(CreateStudySetScreenDestination) + navigator.navigate(CreateStudySetScreenDestination()) }, navigateToCreateClass = { navigator.navigate(CreateClassScreenDestination) diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/create/CreateStudySetArgs.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/create/CreateStudySetArgs.kt new file mode 100644 index 00000000..73695051 --- /dev/null +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/create/CreateStudySetArgs.kt @@ -0,0 +1,5 @@ +package com.pwhs.quickmem.presentation.app.study_set.create + +data class CreateStudySetArgs( + val subjectId: Int? = null, +) \ No newline at end of file diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/create/CreateStudySetScreen.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/create/CreateStudySetScreen.kt index 1d05fb64..6229b8e7 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/create/CreateStudySetScreen.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/create/CreateStudySetScreen.kt @@ -48,7 +48,9 @@ import com.ramcosta.composedestinations.annotation.RootGraph import com.ramcosta.composedestinations.generated.destinations.StudySetDetailScreenDestination import com.ramcosta.composedestinations.navigation.DestinationsNavigator -@Destination +@Destination( + navArgs = CreateStudySetArgs::class +) @Composable fun CreateStudySetScreen( modifier: Modifier = Modifier, diff --git a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/create/CreateStudySetViewModel.kt b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/create/CreateStudySetViewModel.kt index 561f299b..020d21a2 100644 --- a/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/create/CreateStudySetViewModel.kt +++ b/app/src/main/java/com/pwhs/quickmem/presentation/app/study_set/create/CreateStudySetViewModel.kt @@ -1,5 +1,6 @@ package com.pwhs.quickmem.presentation.app.study_set.create +import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.pwhs.quickmem.R @@ -7,6 +8,7 @@ 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.study_set.CreateStudySetRequestModel +import com.pwhs.quickmem.domain.model.subject.SubjectModel import com.pwhs.quickmem.domain.repository.StudySetRepository import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.channels.Channel @@ -24,6 +26,7 @@ class CreateStudySetViewModel @Inject constructor( private val studySetRepository: StudySetRepository, private val tokenManager: TokenManager, private val appManager: AppManager, + savedStateHandle: SavedStateHandle, ) : ViewModel() { private val _uiState = MutableStateFlow(CreateStudySetUiState()) val uiState = _uiState.asStateFlow() @@ -31,6 +34,15 @@ class CreateStudySetViewModel @Inject constructor( private val _uiEvent = Channel() val uiEvent = _uiEvent.receiveAsFlow() + init { + val subjectId: Int? = savedStateHandle.get("subjectId") + if (subjectId != null) { + _uiState.update { + it.copy(subjectModel = SubjectModel.defaultSubjects.first { it.id == subjectId }) + } + } + } + fun onEvent(event: CreateStudySetUiAction) { when (event) { is CreateStudySetUiAction.ColorChanged -> { 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 9d7722a5..b77689e4 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 @@ -230,8 +230,10 @@ fun StudySetDetailScreen( } is StudySetDetailUiEvent.StudySetCopied -> { - Toast.makeText(context, - context.getString(R.string.txt_study_set_copied), Toast.LENGTH_SHORT).show() + Toast.makeText( + context, + context.getString(R.string.txt_study_set_copied), Toast.LENGTH_SHORT + ).show() navigator.navigate( StudySetDetailScreenDestination( id = event.newStudySetId, @@ -631,6 +633,7 @@ fun StudySetDetail( text = stringResource(R.string.txt_are_you_sure_you_want_to_delete_this_study_set), confirmButtonTitle = stringResource(R.string.txt_delete), dismissButtonTitle = stringResource(R.string.txt_cancel), + buttonColor = colorScheme.error, ) }