Skip to content

Commit

Permalink
feat(study set): truyền subjectId qua màn hình tạo study set
Browse files Browse the repository at this point in the history
- sửa lại dialog
  • Loading branch information
nqmgaming committed Dec 29, 2024
1 parent d802ad6 commit 959ac24
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}

Expand All @@ -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,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fun SearchStudySetBySubjectScreen(
modifier: Modifier = Modifier,
viewModel: SearchStudySetBySubjectViewModel = hiltViewModel(),
navigator: DestinationsNavigator,
resultBackNavigator: ResultBackNavigator<Boolean>
resultBackNavigator: ResultBackNavigator<Boolean>,
) {
val uiState by viewModel.uiState.collectAsState()
val context = LocalContext.current
Expand Down Expand Up @@ -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)
Expand All @@ -104,7 +103,11 @@ fun SearchStudySetBySubjectScreen(
viewModel.onEvent(SearchStudySetBySubjectUiAction.RefreshStudySets)
},
onAddStudySet = {
navigator.navigate(CreateStudySetScreenDestination())
navigator.navigate(
CreateStudySetScreenDestination(
subjectId = uiState.subject?.id ?: 1
)
)
}
)
}
Expand All @@ -114,15 +117,15 @@ fun SearchStudySetBySubject(
modifier: Modifier = Modifier,
studySets: LazyPagingItems<GetStudySetResponseModel>? = 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("") }

Expand All @@ -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
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand All @@ -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),
Expand All @@ -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,
Expand Down Expand Up @@ -128,6 +134,7 @@ fun SearchStudySetBySubjectTopAppBar(
}

@Preview(showSystemUi = true)
@Preview(showSystemUi = true, locale = "vi")
@Composable
fun TopBarSearchPreview() {
QuickMemTheme {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ fun LibraryScreen(
)
},
navigateToCreateStudySet = {
navigator.navigate(CreateStudySetScreenDestination)
navigator.navigate(CreateStudySetScreenDestination())
},
navigateToCreateClass = {
navigator.navigate(CreateClassScreenDestination)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.pwhs.quickmem.presentation.app.study_set.create

data class CreateStudySetArgs(
val subjectId: Int? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ import com.ramcosta.composedestinations.annotation.RootGraph
import com.ramcosta.composedestinations.generated.destinations.StudySetDetailScreenDestination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator

@Destination<RootGraph>
@Destination<RootGraph>(
navArgs = CreateStudySetArgs::class
)
@Composable
fun CreateStudySetScreen(
modifier: Modifier = Modifier,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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
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
Expand All @@ -24,13 +26,23 @@ 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()

private val _uiEvent = Channel<CreateStudySetUiEvent>()
val uiEvent = _uiEvent.receiveAsFlow()

init {
val subjectId: Int? = savedStateHandle.get<Int>("subjectId")
if (subjectId != null) {
_uiState.update {
it.copy(subjectModel = SubjectModel.defaultSubjects.first { it.id == subjectId })
}
}
}

fun onEvent(event: CreateStudySetUiAction) {
when (event) {
is CreateStudySetUiAction.ColorChanged -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)
}

Expand Down

0 comments on commit 959ac24

Please sign in to comment.