Skip to content

Commit

Permalink
fix(ui): sửa lỗi lấy màu của study set
Browse files Browse the repository at this point in the history
- dùng di cho token manager và app manager
- sửa lỗi ngôn ngữ
- sửa lỗi giao diện mà study set detail
  • Loading branch information
nqmgaming committed Dec 11, 2024
1 parent 9b5c431 commit 4c98b36
Show file tree
Hide file tree
Showing 12 changed files with 414 additions and 411 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@ 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
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -157,7 +162,6 @@ class StudySetDetailViewModel @Inject constructor(
}

is Resources.Error -> {
Timber.d("Error")
_uiState.update { it.copy(isLoading = false) }
}
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ class FlipFlashCardViewModel @Inject constructor(
val isGetAll = savedStateHandle.get<Boolean>("isGetAll") ?: false
val studySetTitle = savedStateHandle.get<String>("studySetTitle") ?: ""
val studySetDescription = savedStateHandle.get<String>("studySetDescription") ?: ""
val studySetColorId = savedStateHandle.get<Int>("studySetColorId") ?: 0
val studySetSubjectId = savedStateHandle.get<Int>("studySetSubjectId") ?: 0
val studySetColorId = savedStateHandle.get<Int>("studySetColorId") ?: 1
val studySetSubjectId = savedStateHandle.get<Int>("studySetSubjectId") ?: 1
val folderId = savedStateHandle.get<String>("folderId") ?: ""
val learnFrom = savedStateHandle.get<LearnFrom>("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()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class LearnByQuizViewModel @Inject constructor(
val isGetAll = savedStateHandle.get<Boolean>("isGetAll") ?: false
val studySetTitle = savedStateHandle.get<String>("studySetTitle") ?: ""
val studySetDescription = savedStateHandle.get<String>("studySetDescription") ?: ""
val studySetColorId = savedStateHandle.get<Int>("studySetColorId") ?: 0
val studySetSubjectId = savedStateHandle.get<Int>("studySetSubjectId") ?: 0
val studySetColorId = savedStateHandle.get<Int>("studySetColorId") ?: 1
val studySetSubjectId = savedStateHandle.get<Int>("studySetSubjectId") ?: 1
val folderId = savedStateHandle.get<String>("folderId") ?: ""
val learnFrom = savedStateHandle.get<LearnFrom>("learnFrom") ?: LearnFrom.STUDY_SET
_uiState.update {
Expand All @@ -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()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class LearnByTrueFalseViewModel @Inject constructor(
val isGetAll = savedStateHandle.get<Boolean>("isGetAll") ?: false
val studySetTitle = savedStateHandle.get<String>("studySetTitle") ?: ""
val studySetDescription = savedStateHandle.get<String>("studySetDescription") ?: ""
val studySetColorId = savedStateHandle.get<Int>("studySetColorId") ?: 0
val studySetSubjectId = savedStateHandle.get<Int>("studySetSubjectId") ?: 0
val studySetColorId = savedStateHandle.get<Int>("studySetColorId") ?: 1
val studySetSubjectId = savedStateHandle.get<Int>("studySetSubjectId") ?: 1
val folderId = savedStateHandle.get<String>("folderId") ?: ""
val learnFrom = savedStateHandle.get<LearnFrom>("learnFrom") ?: LearnFrom.STUDY_SET
_uiState.update {
Expand All @@ -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()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class LearnByWriteViewModel @Inject constructor(
val isGetAll = savedStateHandle.get<Boolean>("isGetAll") ?: false
val studySetTitle = savedStateHandle.get<String>("studySetTitle") ?: ""
val studySetDescription = savedStateHandle.get<String>("studySetDescription") ?: ""
val studySetColorId = savedStateHandle.get<Int>("studySetColorId") ?: 0
val studySetSubjectId = savedStateHandle.get<Int>("studySetSubjectId") ?: 0
val studySetColorId = savedStateHandle.get<Int>("studySetColorId") ?: 1
val studySetSubjectId = savedStateHandle.get<Int>("studySetSubjectId") ?: 1
val folderId = savedStateHandle.get<String>("folderId") ?: ""
val learnFrom = savedStateHandle.get<LearnFrom>("learnFrom") ?: LearnFrom.STUDY_SET
_uiState.update {
Expand All @@ -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()
)
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-vi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -481,5 +481,5 @@
<string name="txt_when_you_make_a_study_set_public_anyone_can_see_it_and_use_it">Khi bạn công khai bộ học, bất kỳ ai cũng có thể xem và sử dụng nó.</string>
<string name="txt_study_set_created">Bộ học đã được tạo</string>
<string name="txt_study_set_edited">Bộ học đã được chỉnh sửa</string>
<string name="txt_current_flip_status">Trạng thái lật hiện tại</string>
<string name="txt_current_flip_status">Quá trình học lật thẻ hiện tại</string>
</resources>

0 comments on commit 4c98b36

Please sign in to comment.