Skip to content

Commit

Permalink
feat(folder): học bằng folder
Browse files Browse the repository at this point in the history
- sửa lỗi giao diện vào logic
- đa ngôn ngữ cho một vài màn
  • Loading branch information
nqmgaming committed Dec 1, 2024
1 parent 5dd088a commit 7610ae8
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ class ClassDetailViewModel @Inject constructor(
}
}
_uiState.update { it.copy(id = id) }
getClassByID()
getClassById()
saveRecentAccessClass(classId = id)
}

fun onEvent(event: ClassDetailUiAction) {
when (event) {
is ClassDetailUiAction.Refresh -> {
getClassByID()
getClassById()
}

is ClassDetailUiAction.NavigateToWelcomeClicked -> {
Expand Down Expand Up @@ -130,7 +131,7 @@ class ClassDetailViewModel @Inject constructor(
}
}

private fun getClassByID() {
private fun getClassById() {
val id = _uiState.value.id
viewModelScope.launch {
val token = tokenManager.accessToken.firstOrNull() ?: ""
Expand Down Expand Up @@ -170,7 +171,6 @@ class ClassDetailViewModel @Inject constructor(
} ?: run {
_uiEvent.send(ClassDetailUiEvent.ShowError("Class not found"))
}
saveRecentAccessClass()
}
}
}
Expand Down Expand Up @@ -311,7 +311,7 @@ class ClassDetailViewModel @Inject constructor(
}

is Resources.Success -> {
getClassByID()
getClassById()
_uiState.update {
it.copy(
isLoading = false,
Expand Down Expand Up @@ -404,11 +404,10 @@ class ClassDetailViewModel @Inject constructor(
}
}

private fun saveRecentAccessClass() {
private fun saveRecentAccessClass(classId: String) {
viewModelScope.launch {
val token = tokenManager.accessToken.firstOrNull() ?: ""
val userId = appManager.userId.firstOrNull() ?: ""
val classId = _uiState.value.id
val saveRecentAccessClassRequestModel =
SaveRecentAccessClassRequestModel(userId, classId)
classRepository.saveRecentAccessClass(token, saveRecentAccessClassRequestModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.pwhs.quickmem.presentation.app.folder.detail
import android.content.Intent
import android.widget.Toast
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
Expand All @@ -11,6 +12,7 @@ import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme.colorScheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.Scaffold
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
Expand All @@ -22,7 +24,9 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
Expand All @@ -34,6 +38,7 @@ import com.pwhs.quickmem.domain.model.study_set.GetStudySetResponseModel
import com.pwhs.quickmem.presentation.app.folder.detail.component.FolderDetailStudySetList
import com.pwhs.quickmem.presentation.app.folder.detail.component.FolderDetailTopAppBar
import com.pwhs.quickmem.presentation.app.folder.detail.component.FolderMenuBottomSheet
import com.pwhs.quickmem.presentation.app.study_set.detail.material.LearnModeCard
import com.pwhs.quickmem.presentation.component.LoadingOverlay
import com.pwhs.quickmem.presentation.component.QuickMemAlertDialog
import com.pwhs.quickmem.ui.theme.QuickMemTheme
Expand Down Expand Up @@ -145,7 +150,9 @@ fun FolderDetailScreen(
)
},
onEditFolder = { viewModel.onEvent(FolderDetailUiAction.EditFolder) },
onStudyFolderClick = { viewModel.onEvent(FolderDetailUiAction.Refresh) },
onStudyFolderClick = {
//TODO: Implement study folder
},
onNavigateBack = {
resultNavigator.navigateBack(true)
},
Expand Down Expand Up @@ -192,15 +199,17 @@ fun FolderDetail(
val formattedCreatedAt = formatDate(createdAt)
val formattedUpdatedAt = formatDate(updatedAt)
val dateLabel = if (createdAt != updatedAt) {
"Modified $formattedUpdatedAt"
stringResource(R.string.txt_modified, formattedUpdatedAt)
} else {
"Created $formattedCreatedAt"
stringResource(R.string.txt_created, formattedCreatedAt)
}

val refreshState = rememberPullToRefreshState()
var showMoreBottomSheet by remember { mutableStateOf(false) }
val sheetShowMoreState = rememberModalBottomSheetState()
var showDeleteConfirmationDialog by remember { mutableStateOf(false) }
var showStudyFolderBottomSheet by remember { mutableStateOf(false) }
val sheetStudyFolderState = rememberModalBottomSheetState()

Scaffold(
modifier = modifier,
Expand All @@ -219,7 +228,9 @@ fun FolderDetail(
floatingActionButton = {
if (isOwner) {
FloatingActionButton(
onClick = onStudyFolderClick,
onClick = {
showStudyFolderBottomSheet = true
},
containerColor = colorScheme.secondary,
contentColor = colorScheme.onSecondary
) {
Expand Down Expand Up @@ -292,6 +303,48 @@ fun FolderDetail(
onDismissRequest = { showMoreBottomSheet = false },
isOwner = isOwner
)
if(showStudyFolderBottomSheet) {
ModalBottomSheet(
onDismissRequest = { showStudyFolderBottomSheet = false },
sheetState = sheetStudyFolderState,
containerColor = colorScheme.surface,
) {
Column (
modifier = Modifier
.padding(vertical = 16.dp),
horizontalAlignment = Alignment.CenterHorizontally
){
LearnModeCard(
title = stringResource(R.string.txt_flip_flashcards),
icon = R.drawable.ic_flipcard,
containerColor = colorScheme.surface,
elevation = 0.dp,
leadingText = stringResource(R.string.txt_coming_soon)
)
LearnModeCard(
title = stringResource(R.string.txt_quiz),
icon = R.drawable.ic_quiz,
containerColor = colorScheme.surface,
elevation = 0.dp,
leadingText = stringResource(R.string.txt_coming_soon)
)
LearnModeCard(
title = stringResource(R.string.txt_true_false),
icon = R.drawable.ic_tf,
containerColor = colorScheme.surface,
elevation = 0.dp,
leadingText = stringResource(R.string.txt_coming_soon)
)
LearnModeCard(
title = stringResource(R.string.txt_write),
icon = R.drawable.ic_write,
containerColor = Color.Transparent,
elevation = 0.dp,
leadingText = stringResource(R.string.txt_coming_soon)
)
}
}
}
}

@Preview(showBackground = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class FolderDetailViewModel @Inject constructor(
val id: String = savedStateHandle["id"] ?: ""
_uiState.update { it.copy(id = id) }
getFolderSetById(id)
saveRecentAccessFolder(id)
}

fun onEvent(event: FolderDetailUiAction) {
Expand Down Expand Up @@ -94,7 +95,6 @@ class FolderDetailViewModel @Inject constructor(
} ?: run {
_uiEvent.send(FolderDetailUiEvent.ShowError("Folder not found"))
}
saveRecentAccessFolder()
}

is Resources.Error -> {
Expand Down Expand Up @@ -138,11 +138,10 @@ class FolderDetailViewModel @Inject constructor(
}
}

private fun saveRecentAccessFolder() {
private fun saveRecentAccessFolder(folderId: String) {
viewModelScope.launch {
val token = tokenManager.accessToken.firstOrNull() ?: ""
val userId = appManager.userId.firstOrNull() ?: ""
val folderId = _uiState.value.id
val saveRecentAccessFolderRequestModel = SaveRecentAccessFolderRequestModel(
userId = userId,
folderId = folderId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.Intent
import android.net.Uri
import android.os.Build
import android.provider.Settings
import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
Expand Down Expand Up @@ -488,13 +487,13 @@ fun Setting(
}
}
item {
SettingTitleSection(title = "Scheduled Notifications")
SettingTitleSection(title = stringResource(R.string.txt_scheduled_notifications))
SettingCard {
Column(
modifier = Modifier.padding(16.dp)
) {
SettingSwitch(
title = "Study Reminders",
title = stringResource(R.string.txt_study_reminders),
value = enabledStudySchedule,
onChangeValue = {
if (isPushNotificationsEnabled) {
Expand All @@ -504,22 +503,16 @@ fun Setting(
}
}
)
HorizontalDivider()
SettingItem(
title = "Every day at",
leadingText = timeStudySchedule,
onClick = {
if (enabledStudySchedule) {
if (enabledStudySchedule) {
HorizontalDivider()
SettingItem(
title = stringResource(R.string.txt_every_day_at),
leadingText = timeStudySchedule,
onClick = {
showTimePicker = true
} else {
Toast.makeText(
context,
"Please enable Study Reminders",
Toast.LENGTH_SHORT
).show()
}
}
)
)
}
}
}
}
Expand Down Expand Up @@ -732,10 +725,10 @@ fun Setting(
onEnablePushNotifications(true)
onChangeStudyAlarm(true)
},
title = "Turn on notifications to receive study reminders",
text = "You need to enable notifications in the app settings to receive study reminders",
confirmButtonTitle = "Turn on notifications",
dismissButtonTitle = "Not now",
title = stringResource(R.string.txt_turn_on_notifications_to_receive_study_reminders),
text = stringResource(R.string.txt_you_need_to_enable_notifications_in_the_app_settings_to_receive_study_reminders),
confirmButtonTitle = stringResource(R.string.txt_turn_on_notifications),
dismissButtonTitle = stringResource(R.string.txt_not_now),
buttonColor = colorScheme.primary
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class StudySetDetailViewModel @Inject constructor(
val id: String = savedStateHandle["id"] ?: ""
_uiState.update { it.copy(id = id) }
initData()
saveRecentAccessStudySet(studySetId = id)
}

private fun initData() {
Expand Down Expand Up @@ -120,7 +121,6 @@ class StudySetDetailViewModel @Inject constructor(
isOwner = isOwner,
)
}
saveRecentAccessStudySet()
}

is Resources.Error -> {
Expand All @@ -132,11 +132,10 @@ class StudySetDetailViewModel @Inject constructor(
}
}

private fun saveRecentAccessStudySet() {
private fun saveRecentAccessStudySet(studySetId: String) {
viewModelScope.launch {
val token = tokenManager.accessToken.firstOrNull() ?: ""
val userId = appManager.userId.firstOrNull() ?: ""
val studySetId = _uiState.value.id
val saveRecentAccessStudySetRequestModel = SaveRecentAccessStudySetRequestModel(
userId = userId,
studySetId = studySetId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.compose.ui.layout.ContentScale
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 androidx.compose.ui.unit.dp
import com.pwhs.quickmem.R

Expand All @@ -32,15 +33,20 @@ fun LearnModeCard(
@DrawableRes icon: Int,
onClick: () -> Unit = {},
color: Color = colorScheme.primary,
learningPercentage: Int = 0
leadingText: String = "",
learningPercentage: Int? = null,
containerColor: Color = Color.White,
contentColor: Color = colorScheme.onSurface,
elevation: Dp = 5.dp
) {
Card(
colors = CardDefaults.cardColors(
containerColor = Color.White,
contentColor = colorScheme.onSurface
containerColor = containerColor,
contentColor = contentColor
),
elevation = CardDefaults.elevatedCardElevation(
defaultElevation = 5.dp
defaultElevation = elevation,
pressedElevation = elevation
),
onClick = onClick,
modifier = modifier
Expand Down Expand Up @@ -71,13 +77,21 @@ fun LearnModeCard(
),
modifier = Modifier.weight(1f)
)
Text(
text = "$learningPercentage%",
style = typography.bodyMedium.copy(
color = colorScheme.onSurface,
fontWeight = FontWeight.Bold
if (learningPercentage != null) {
LearnModeCard(
title = stringResource(R.string.txt_flip_flashcards),
icon = R.drawable.ic_flipcard,
)
)
}
if (leadingText.isNotEmpty()) {
Text(
text = leadingText,
style = typography.bodyMedium.copy(
color = colorScheme.onSurface,
fontWeight = FontWeight.Bold
)
)
}
}
}
}
11 changes: 11 additions & 0 deletions app/src/main/res/values-vi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,15 @@
<string name="txt_unauthorized">Vui lòng đăng ký hoặc đăng nhập vào ứng dụng</string>
<string name="txt_class_not_found">Không tìm thấy class</string>
<string name="txt_restart">Restart</string>
<string name="txt_turn_on_notifications_to_receive_study_reminders">Bật thông báo để nhận nhắc nhở học tập</string>
<string name="txt_you_need_to_enable_notifications_in_the_app_settings_to_receive_study_reminders">Bạn cần bật thông báo trong cài đặt ứng dụng để nhận nhắc nhở học tập</string>
<string name="txt_turn_on_notifications">Bật thông báo</string>
<string name="txt_not_now">Không phải bây giờ</string>
<string name="txt_scheduled_notifications">Thông báo đã lên lịch</string>
<string name="txt_study_reminders">Nhắc nhở học tập</string>
<string name="txt_every_day_at">Mỗi ngày vào lúc</string>
<string name="txt_please_enable_study_reminders">Vui lòng bật nhắc nhở học tập</string>
<string name="txt_modified">Đã chỉnh sửa vào %1$s</string>
<string name="txt_created">Đã tạo vào %1$s</string>
<string name="txt_coming_soon">Sắp ra mắt</string>
</resources>
Loading

0 comments on commit 7610ae8

Please sign in to comment.