Skip to content

Commit

Permalink
feat(study set): chia nhỏ study set để học nhanh hơn
Browse files Browse the repository at this point in the history
- Sửa các lỗi giao diện
  • Loading branch information
nqmgaming committed Dec 2, 2024
1 parent 586d646 commit 7d651fa
Show file tree
Hide file tree
Showing 34 changed files with 505 additions and 287 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pwhs.quickmem.core.data.enums

enum class LearnMode(val mode: String) {
NONE("none"),
FLIP("flip"),
QUIZ("quiz"),
TRUE_FALSE("trueFalse"),
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/pwhs/quickmem/data/remote/ApiService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ interface ApiService {
suspend fun getFlashCardsByStudySetId(
@Header("Authorization") token: String,
@Path("id") id: String,
@Query("learnMode") learnMode: String
@Query("learnMode") learnMode: String,
@Query("isGetAll") isGetAll: Boolean
): List<FlashCardResponseDto>

@POST("flashcard")
Expand Down Expand Up @@ -388,7 +389,8 @@ interface ApiService {
suspend fun getFlashCardsByFolderId(
@Header("Authorization") token: String,
@Path("id") id: String,
@Query("learnMode") learnMode: String
@Query("learnMode") learnMode: String,
@Query("isGetAll") isGetAll: Boolean
): List<FlashCardResponseDto>

// Folder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,17 @@ class FlashCardRepositoryImpl @Inject constructor(
override suspend fun getFlashCardsByStudySetId(
token: String,
studySetId: String,
learnMode: LearnMode
learnMode: LearnMode,
isGetAll: Boolean
): Flow<Resources<List<FlashCardResponseModel>>> {
return flow {
emit(Resources.Loading(true))
try {
val response = apiService.getFlashCardsByStudySetId(
token = token,
id = studySetId,
learnMode = learnMode.mode
learnMode = learnMode.mode,
isGetAll = isGetAll
)
emit(Resources.Success(response.map { it.toModel() }))
} catch (e: HttpException) {
Expand All @@ -265,15 +267,17 @@ class FlashCardRepositoryImpl @Inject constructor(
override suspend fun getFlashCardsByFolderId(
token: String,
folderId: String,
learnMode: LearnMode
learnMode: LearnMode,
isGetAll: Boolean
): Flow<Resources<List<FlashCardResponseModel>>> {
return flow {
emit(Resources.Loading(true))
try {
val response = apiService.getFlashCardsByFolderId(
token = token,
id = folderId,
learnMode = learnMode.mode
learnMode = learnMode.mode,
isGetAll = isGetAll
)
emit(Resources.Success(response.map { it.toModel() }))
} catch (e: HttpException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ interface FlashCardRepository {
suspend fun getFlashCardsByStudySetId(
token: String,
studySetId: String,
learnMode: LearnMode
learnMode: LearnMode,
isGetAll: Boolean
): Flow<Resources<List<FlashCardResponseModel>>>

suspend fun getFlashCardsByFolderId(
token: String,
folderId: String,
learnMode: LearnMode
learnMode: LearnMode,
isGetAll: Boolean
): Flow<Resources<List<FlashCardResponseModel>>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ fun FolderDetailScreen(
studySetColorId = 0,
studySetSubjectId = 0,
folderId = uiState.id,
learnFrom = LearnFrom.FOLDER
learnFrom = LearnFrom.FOLDER,
isGetAll = true
)
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import androidx.hilt.navigation.compose.hiltViewModel
import com.pwhs.quickmem.R
import com.pwhs.quickmem.core.data.enums.FlipCardStatus
import com.pwhs.quickmem.core.data.enums.LearnFrom
import com.pwhs.quickmem.core.data.enums.LearnMode
import com.pwhs.quickmem.core.data.enums.QuizStatus
import com.pwhs.quickmem.core.data.enums.TrueFalseStatus
import com.pwhs.quickmem.core.data.enums.WriteStatus
Expand Down Expand Up @@ -172,15 +173,15 @@ fun StudySetDetailScreen(
LaunchedEffect(key1 = true) {
viewModel.uiEvent.collect { event ->
when (event) {
StudySetDetailUiEvent.FlashCardDeleted -> {
is StudySetDetailUiEvent.FlashCardDeleted -> {
viewModel.onEvent(StudySetDetailUiAction.Refresh)
}

StudySetDetailUiEvent.FlashCardStarred -> {
is StudySetDetailUiEvent.FlashCardStarred -> {
viewModel.onEvent(StudySetDetailUiAction.Refresh)
}

StudySetDetailUiEvent.NavigateToEditStudySet -> {
is StudySetDetailUiEvent.NavigateToEditStudySet -> {
navigator.navigate(
EditStudySetScreenDestination(
studySetId = uiState.id,
Expand All @@ -193,7 +194,7 @@ fun StudySetDetailScreen(
)
}

StudySetDetailUiEvent.NavigateToEditFlashCard -> {
is StudySetDetailUiEvent.NavigateToEditFlashCard -> {
val flashCard =
uiState.flashCards.find { it.id == uiState.idOfFlashCardSelected }
navigator.navigate(
Expand All @@ -208,12 +209,12 @@ fun StudySetDetailScreen(
)
}

StudySetDetailUiEvent.StudySetDeleted -> {
is StudySetDetailUiEvent.StudySetDeleted -> {
resultNavigator.setResult(true)
navigator.navigateUp()
}

StudySetDetailUiEvent.StudySetProgressReset -> {
is StudySetDetailUiEvent.StudySetProgressReset -> {
viewModel.onEvent(StudySetDetailUiAction.Refresh)
}

Expand All @@ -225,6 +226,60 @@ fun StudySetDetailScreen(
)
)
}

is StudySetDetailUiEvent.OnNavigateToFlipFlashcard -> {
navigator.navigate(
FlipFlashCardScreenDestination(
studySetId = uiState.id,
studySetTitle = uiState.title,
studySetDescription = uiState.description,
studySetColorId = uiState.colorModel.id,
studySetSubjectId = uiState.subject.id,
folderId = "",
learnFrom = LearnFrom.STUDY_SET,
isGetAll = event.isGetAll
)
)
}

is StudySetDetailUiEvent.OnNavigateToQuiz -> {
navigator.navigate(
LearnByQuizScreenDestination(
studySetId = uiState.id,
studySetTitle = uiState.title,
studySetDescription = uiState.description,
studySetColorId = uiState.colorModel.id,
studySetSubjectId = uiState.subject.id,
isGetAll = event.isGetAll
)
)
}

is StudySetDetailUiEvent.OnNavigateToTrueFalse -> {
navigator.navigate(
LearnByTrueFalseScreenDestination(
studySetId = uiState.id,
studySetTitle = uiState.title,
studySetDescription = uiState.description,
studySetColorId = uiState.colorModel.id,
studySetSubjectId = uiState.subject.id,
isGetAll = event.isGetAll
)
)
}

is StudySetDetailUiEvent.OnNavigateToWrite -> {
navigator.navigate(
LearnByWriteScreenDestination(
studySetId = uiState.id,
studySetTitle = uiState.title,
studySetDescription = uiState.description,
studySetColorId = uiState.colorModel.id,
studySetSubjectId = uiState.subject.id,
isGetAll = event.isGetAll
)
)
}
}
}
}
Expand Down Expand Up @@ -299,52 +354,6 @@ fun StudySetDetailScreen(
viewModel.onEvent(StudySetDetailUiAction.OnResetProgressClicked(uiState.id))
},
isAIGenerated = uiState.isAIGenerated,
onNavigateToQuiz = {
navigator.navigate(
LearnByQuizScreenDestination(
studySetId = uiState.id,
studySetTitle = uiState.title,
studySetDescription = uiState.description,
studySetColorId = uiState.colorModel.id,
studySetSubjectId = uiState.subject.id,
)
)
},
onNavigateToTrueFalse = {
navigator.navigate(
LearnByTrueFalseScreenDestination(
studySetId = uiState.id,
studySetTitle = uiState.title,
studySetDescription = uiState.description,
studySetColorId = uiState.colorModel.id,
studySetSubjectId = uiState.subject.id,
)
)
},
onNavigateToWrite = {
navigator.navigate(
LearnByWriteScreenDestination(
studySetId = uiState.id,
studySetTitle = uiState.title,
studySetDescription = uiState.description,
studySetColorId = uiState.colorModel.id,
studySetSubjectId = uiState.subject.id,
)
)
},
onNavigateToFlip = {
navigator.navigate(
FlipFlashCardScreenDestination(
studySetId = uiState.id,
studySetTitle = uiState.title,
studySetDescription = uiState.description,
studySetColorId = uiState.colorModel.id,
studySetSubjectId = uiState.subject.id,
folderId = "",
learnFrom = LearnFrom.STUDY_SET
)
)
},
onRefresh = {
viewModel.onEvent(StudySetDetailUiAction.Refresh)
},
Expand All @@ -367,7 +376,10 @@ fun StudySetDetailScreen(
username = uiState.user.username
)
)
}
},
onNavigateToLearn = { learnMode, isGetAll ->
viewModel.onEvent(StudySetDetailUiAction.NavigateToLearn(learnMode, isGetAll))
},
)
}

Expand Down Expand Up @@ -397,14 +409,11 @@ fun StudySetDetail(
onAddToFolder: () -> Unit = {},
onDeleteStudySet: () -> Unit = {},
onResetProgress: () -> Unit = {},
onNavigateToQuiz: () -> Unit = {},
onNavigateToTrueFalse: () -> Unit = {},
onNavigateToWrite: () -> Unit = {},
onNavigateToFlip: () -> Unit = {},
onRefresh: () -> Unit = {},
onNavigateToUserDetail: () -> Unit = {},
onCopyStudySet: () -> Unit = {},
onReportClick: () -> Unit = {}
onReportClick: () -> Unit = {},
onNavigateToLearn: (LearnMode, Boolean) -> Unit = { _, _ -> },
) {
val context = LocalContext.current
var tabIndex by rememberSaveable { mutableIntStateOf(0) }
Expand Down Expand Up @@ -498,17 +507,14 @@ fun StudySetDetail(
onToggleStarClick = onToggleStarredFlashCard,
onEditFlashCardClick = onEditFlashCard,
onAddFlashCardClick = onAddFlashcard,
onNavigateToQuiz = onNavigateToQuiz,
onNavigateToTrueFalse = onNavigateToTrueFalse,
onNavigateToWrite = onNavigateToWrite,
onNavigateToFlip = onNavigateToFlip,
onNavigateToLearn = onNavigateToLearn,
isOwner = true,
studySetColor = color,
learningPercentQuiz = if (flashCardCount > 0) (flashCards.count { it.quizStatus == QuizStatus.CORRECT.status } * 100 / flashCardCount) else 0,
learningPercentFlipped = if (flashCardCount > 0) (flashCards.count { it.flipStatus == FlipCardStatus.KNOW.name } * 100 / flashCardCount) else 0,
learningPercentWrite = if (flashCardCount > 0) (flashCards.count { it.writeStatus == WriteStatus.CORRECT.status } * 100 / flashCardCount) else 0,
learningPercentTrueFalse = if (flashCardCount > 0) (flashCards.count { it.trueFalseStatus == TrueFalseStatus.CORRECT.status } * 100 / flashCardCount) else 0,
onMakeCopyClick = onCopyStudySet
onMakeCopyClick = onCopyStudySet,
)

StudySetDetailEnum.PROGRESS.index -> ProgressTabScreen(
Expand All @@ -530,13 +536,10 @@ fun StudySetDetail(
onToggleStarClick = onToggleStarredFlashCard,
onEditFlashCardClick = onEditFlashCard,
onAddFlashCardClick = onAddFlashcard,
onNavigateToQuiz = onNavigateToQuiz,
onNavigateToTrueFalse = onNavigateToTrueFalse,
onNavigateToWrite = onNavigateToWrite,
onNavigateToFlip = onNavigateToFlip,
onNavigateToLearn = onNavigateToLearn,
isOwner = false,
onMakeCopyClick = onCopyStudySet,
studySetColor = color
studySetColor = color,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.pwhs.quickmem.presentation.app.study_set.detail

import com.pwhs.quickmem.core.data.enums.LearnMode

sealed class StudySetDetailUiAction {
data object Refresh : StudySetDetailUiAction()
data class OnIdOfFlashCardSelectedChanged(val id: String) : StudySetDetailUiAction()
Expand All @@ -12,4 +14,6 @@ sealed class StudySetDetailUiAction {
data object OnDeleteStudySetClicked : StudySetDetailUiAction()
data class OnResetProgressClicked(val id: String) : StudySetDetailUiAction()
data object OnMakeCopyClicked : StudySetDetailUiAction()
data class NavigateToLearn(val learnMode: LearnMode, val isGetAll: Boolean) :
StudySetDetailUiAction()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ sealed class StudySetDetailUiEvent {
data object StudySetDeleted : StudySetDetailUiEvent()
data object StudySetProgressReset : StudySetDetailUiEvent()
data class StudySetCopied(val newStudySetId: String) : StudySetDetailUiEvent()
data class OnNavigateToFlipFlashcard(val isGetAll: Boolean) : StudySetDetailUiEvent()
data class OnNavigateToQuiz(val isGetAll: Boolean) : StudySetDetailUiEvent()
data class OnNavigateToTrueFalse(val isGetAll: Boolean) : StudySetDetailUiEvent()
data class OnNavigateToWrite(val isGetAll: Boolean) : StudySetDetailUiEvent()
}
Loading

0 comments on commit 7d651fa

Please sign in to comment.