Skip to content

Commit

Permalink
fix: đa ngôn ngữ cho subject
Browse files Browse the repository at this point in the history
  • Loading branch information
nqmgaming committed Dec 11, 2024
1 parent 4c98b36 commit 64da27c
Show file tree
Hide file tree
Showing 18 changed files with 472 additions and 304 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ data class SubjectResponseDto(
val id: Int,

@SerializedName("name")
val name: String
val name: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import com.pwhs.quickmem.domain.model.subject.SubjectModel

fun SubjectResponseDto.toSubjectModel() = SubjectModel(
id = id,
name = name,
subjectName = SubjectModel.defaultSubjects.first { it.id == id }.subjectName
)

fun SubjectModel.toSubjectResponseDto() = SubjectResponseDto(
id = id,
name = name,
)
541 changes: 272 additions & 269 deletions app/src/main/java/com/pwhs/quickmem/domain/model/subject/SubjectModel.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fun AddStudySetToClassItem(
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
Text(
text = studySet.subject?.name ?: SubjectModel.defaultSubjects[0].name,
text = stringResource(studySet.subject?.subjectName ?: SubjectModel.defaultSubjects[0].subjectName),
style = typography.bodySmall.copy(
color = colorScheme.onSurface.copy(alpha = 0.6f)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fun AddStudySetToFolderItem(
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
Text(
text = studySet.subject?.name ?: SubjectModel.defaultSubjects[0].name,
text = stringResource(studySet.subject?.subjectName ?: SubjectModel.defaultSubjects[0].subjectName),
style = typography.bodySmall.copy(
color = colorScheme.onSurface.copy(alpha = 0.6f)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,8 @@ private fun HomeScreenPreview() {
Home(
subjects = listOf(
SubjectModel(
1,
"General",
id = 1,
subjectName = R.string.txt_general,
iconRes = R.drawable.ic_all,
color = Color(0xFF7f60f9),
studySetCount = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fun StudySetHomeItem(
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
Text(
text = studySet?.subject?.name ?: SubjectModel.defaultSubjects[0].name,
text = stringResource(studySet?.subject?.subjectName ?: SubjectModel.defaultSubjects[0].subjectName),
style = typography.bodySmall.copy(
color = colorScheme.onSurface.copy(alpha = 0.6f)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
Expand Down Expand Up @@ -47,15 +48,15 @@ fun SubjectItem(
verticalAlignment = Alignment.CenterVertically,
) {
Icon(
painter = painterResource(id = subject.iconRes!!),
contentDescription = subject.name,
painter = painterResource(id = subject.iconRes ?: R.drawable.ic_all),
contentDescription = stringResource(subject.subjectName),
tint = subject.color!!,
modifier = Modifier
.size(35.dp)
)

Text(
text = subject.name,
text = stringResource(subject.subjectName),
style = typography.titleMedium.copy(
color = colorScheme.onSurface,
fontWeight = FontWeight.Bold
Expand All @@ -69,8 +70,12 @@ fun SubjectItem(

Text(
text = when (subject.studySetCount) {
1 -> "${subject.studySetCount} Study Set"
else -> "${subject.studySetCount} Study Sets"
0 -> stringResource(R.string.txt_no_study_sets)
1 -> stringResource(R.string.txt_one_study_set)
else -> stringResource(
R.string.txt_study_sets_library,
subject.studySetCount
)
},
style = typography.bodyMedium.copy(
color = colorScheme.onSurface,
Expand All @@ -89,10 +94,10 @@ fun SubjectItemPreview() {
onSearchStudySetBySubject = {},
subject = SubjectModel(
id = 1,
name = "All",
subjectName = R.string.txt_general,
iconRes = R.drawable.ic_all,
color = Color(0xFF7f60f9),
description = "Agriculture is the study of farming and cultivation of land."
subjectDescription = R.string.txt_general_subjects_that_do_not_fit_into_specific_categories,
),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.pwhs.quickmem.presentation.app.home.search_by_subject

import android.widget.Toast
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -87,9 +88,10 @@ fun SearchStudySetBySubjectScreen(
icon = uiState.icon,
studySetCount = uiState.studySetCount,
isLoading = uiState.isLoading,
nameSubject = uiState.subject?.name ?: "",
nameSubject = uiState.subject?.subjectName ?: R.string.txt_general,
colorSubject = uiState.subject?.color ?: Color.Blue,
descriptionSubject = uiState.subject?.description ?: "",
descriptionSubject = uiState.subject?.subjectDescription
?: R.string.txt_general_subjects_that_do_not_fit_into_specific_categories,
studySets = studySetItems,
onNavigateBack = {
resultBackNavigator.navigateBack(true)
Expand All @@ -108,11 +110,11 @@ fun SearchStudySetBySubject(
modifier: Modifier = Modifier,
studySets: LazyPagingItems<GetStudySetResponseModel>? = null,
onStudySetClick: (GetStudySetResponseModel?) -> Unit = {},
nameSubject: String = "",
@StringRes nameSubject: Int = R.string.txt_general,
colorSubject: Color,
@DrawableRes icon: Int = R.drawable.ic_all,
studySetCount: Int = 0,
descriptionSubject: String = "",
@StringRes descriptionSubject: Int = R.string.txt_general_subjects_that_do_not_fit_into_specific_categories,
isLoading: Boolean = false,
onNavigateBack: () -> Unit,
onStudySetRefresh: () -> Unit = {},
Expand All @@ -126,11 +128,11 @@ fun SearchStudySetBySubject(
topBar = {
SearchStudySetBySubjectTopAppBar(
onNavigateBack = onNavigateBack,
name = nameSubject,
name = stringResource(nameSubject),
color = colorSubject,
icon = icon,
studySetCount = studySetCount,
description = descriptionSubject,
description = stringResource(descriptionSubject),
onAddStudySet = onAddStudySet
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ fun SearchStudySetBySubjectTopAppBar(
title = {
Column {
Row(
modifier = Modifier.padding(vertical = 8.dp),
modifier = Modifier
.padding(vertical = 8.dp)
.padding(end = 16.dp),
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import androidx.compose.material3.CardDefaults.cardColors
import androidx.compose.material3.CardDefaults.elevatedCardElevation
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MaterialTheme.colorScheme
import androidx.compose.material3.MaterialTheme.typography
import androidx.compose.material3.Scaffold
Expand Down Expand Up @@ -105,7 +104,7 @@ fun StudySetItem(
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
Text(
text = studySet?.subject?.name ?: SubjectModel.defaultSubjects[0].name,
text = stringResource(studySet?.subject?.subjectName ?: SubjectModel.defaultSubjects[0].subjectName),
style = typography.bodySmall.copy(
color = colorScheme.onSurface.copy(alpha = 0.6f)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fun FilterStudySetBottomSheet(
var searchSubjectQuery by remember { mutableStateOf("") }

val filteredSubjects = SubjectModel.defaultSubjects.filter {
it.name.contains(searchSubjectQuery, ignoreCase = true)
stringResource(it.subjectName).contains(searchSubjectQuery, ignoreCase = true)
}

LazyColumn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.pwhs.quickmem.R
Expand Down Expand Up @@ -98,15 +99,15 @@ fun StudySetSubjectBottomSheet(
verticalAlignment = Alignment.CenterVertically,
) {
Icon(
painter = painterResource(id = subject.iconRes!!),
contentDescription = subject.name,
painter = painterResource(id = subject.iconRes ?: R.drawable.ic_all),
contentDescription = stringResource(subject.subjectName),
tint = subject.color!!,
modifier = Modifier
.size(24.dp)
)

Text(
text = subject.name,
text = stringResource(subject.subjectName),
style = typography.bodyMedium.copy(
color = colorScheme.onSurface,
fontWeight = FontWeight.Bold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.pwhs.quickmem.R
Expand All @@ -31,16 +32,16 @@ fun StudySetSubjectInput(
modifier = modifier.padding(top = 10.dp)
) {
Text(
text = "Subject",
text = stringResource(R.string.txt_subject),
style = typography.bodyMedium.copy(
fontWeight = FontWeight.Bold
)
)
OutlinedTextField(
shape = RoundedCornerShape(10.dp),
value = subjectModel!!.name,
value = stringResource(subjectModel?.subjectName ?: R.string.txt_general),
onValueChange = { },
placeholder = { Text("Subject") },
placeholder = { Text(stringResource(R.string.txt_general)) },
modifier = Modifier
.fillMaxWidth()
.padding(top = 5.dp)
Expand All @@ -50,8 +51,10 @@ fun StudySetSubjectInput(
readOnly = true,
leadingIcon = {
Icon(
painter = painterResource(id = subjectModel.iconRes!!),
contentDescription = subjectModel.name,
painter = painterResource(id = subjectModel?.iconRes ?: R.drawable.ic_all),
contentDescription = stringResource(
subjectModel?.subjectName ?: R.string.txt_general
),
modifier = Modifier.size(24.dp),
tint = Color.Black
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fun CreateStudySet(
mutableStateOf("")
}
val filteredSubjects = SubjectModel.defaultSubjects.filter {
it.name.contains(searchSubjectQuery, ignoreCase = true)
stringResource(it.subjectName).contains(searchSubjectQuery, ignoreCase = true)
}
val imeState = rememberImeState()
val scrollState = rememberScrollState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fun EditStudySet(
mutableStateOf("")
}
val filteredSubjects = SubjectModel.defaultSubjects.filter {
it.name.contains(searchSubjectQuery, ignoreCase = true)
stringResource(it.subjectName).contains(searchSubjectQuery, ignoreCase = true)
}
val imeState = rememberImeState()
val scrollState = rememberScrollState()
Expand Down
Loading

0 comments on commit 64da27c

Please sign in to comment.