Skip to content

Commit

Permalink
feat: tạo các màn hình cho: learn, flip, test, match flashcard
Browse files Browse the repository at this point in the history
  • Loading branch information
nqmgaming committed Oct 20, 2024
1 parent 2cf55fb commit 4e28adb
Show file tree
Hide file tree
Showing 22 changed files with 471 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ import com.ramcosta.composedestinations.annotation.RootGraph
import com.ramcosta.composedestinations.generated.destinations.CreateFlashCardScreenDestination
import com.ramcosta.composedestinations.generated.destinations.EditFlashCardScreenDestination
import com.ramcosta.composedestinations.generated.destinations.EditStudySetScreenDestination
import com.ramcosta.composedestinations.generated.destinations.FlipFlashCardScreenDestination
import com.ramcosta.composedestinations.generated.destinations.LearnFlashCardScreenDestination
import com.ramcosta.composedestinations.generated.destinations.MatchFlashCardScreenDestination
import com.ramcosta.composedestinations.generated.destinations.StudySetInfoScreenDestination
import com.ramcosta.composedestinations.generated.destinations.TestFlashCardScreenDestination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.result.NavResult
import com.ramcosta.composedestinations.result.ResultBackNavigator
Expand All @@ -61,7 +65,11 @@ fun StudySetDetailScreen(
resultNavigator: ResultBackNavigator<Boolean>,
resultBakFlashCard: ResultRecipient<CreateFlashCardScreenDestination, Boolean>,
resultEditStudySet: ResultRecipient<EditStudySetScreenDestination, Boolean>,
resultEditFlashCard: ResultRecipient<EditFlashCardScreenDestination, Boolean>
resultEditFlashCard: ResultRecipient<EditFlashCardScreenDestination, Boolean>,
resultFlipFlashCard: ResultRecipient<FlipFlashCardScreenDestination, Boolean>,
resultLearnFlashCard: ResultRecipient<LearnFlashCardScreenDestination, Boolean>,
resultTestFlashCard: ResultRecipient<TestFlashCardScreenDestination, Boolean>,
resultMatchFlashCard: ResultRecipient<MatchFlashCardScreenDestination, Boolean>
) {
val uiState by viewModel.uiState.collectAsState()

Expand Down Expand Up @@ -97,6 +105,50 @@ fun StudySetDetailScreen(
}
}

resultFlipFlashCard.onNavResult { result ->
when (result) {
is NavResult.Canceled -> {}
is NavResult.Value -> {
if (result.value) {
viewModel.onEvent(StudySetDetailUiAction.Refresh)
}
}
}
}

resultLearnFlashCard.onNavResult { result ->
when (result) {
is NavResult.Canceled -> {}
is NavResult.Value -> {
if (result.value) {
viewModel.onEvent(StudySetDetailUiAction.Refresh)
}
}
}
}

resultTestFlashCard.onNavResult { result ->
when (result) {
is NavResult.Canceled -> {}
is NavResult.Value -> {
if (result.value) {
viewModel.onEvent(StudySetDetailUiAction.Refresh)
}
}
}
}

resultMatchFlashCard.onNavResult { result ->
when (result) {
is NavResult.Canceled -> {}
is NavResult.Value -> {
if (result.value) {
viewModel.onEvent(StudySetDetailUiAction.Refresh)
}
}
}
}

LaunchedEffect(key1 = true) {
viewModel.uiEvent.collect { event ->
when (event) {
Expand Down Expand Up @@ -205,6 +257,26 @@ fun StudySetDetailScreen(
},
onResetProgress = {
viewModel.onEvent(StudySetDetailUiAction.OnResetProgressClicked(uiState.id))
},
onNavigateToLearnFlashCard = {
navigator.navigate(
LearnFlashCardScreenDestination()
)
},
onNavigateToTestFlashCard = {
navigator.navigate(
TestFlashCardScreenDestination()
)
},
onNavigateToMatchFlashCard = {
navigator.navigate(
MatchFlashCardScreenDestination()
)
},
onNavigateToFlipFlashCard = {
navigator.navigate(
FlipFlashCardScreenDestination()
)
}
)
}
Expand All @@ -229,7 +301,11 @@ fun StudySetDetail(
onToggleStarredFlashCard: (String, Boolean) -> Unit = { _, _ -> },
onEditStudySet: () -> Unit = {},
onDeleteStudySet: () -> Unit = {},
onResetProgress: () -> Unit = {}
onResetProgress: () -> Unit = {},
onNavigateToLearnFlashCard: () -> Unit = {},
onNavigateToTestFlashCard: () -> Unit = {},
onNavigateToMatchFlashCard: () -> Unit = {},
onNavigateToFlipFlashCard: () -> Unit = {},
) {
val context = LocalContext.current
var tabIndex by remember { mutableIntStateOf(0) }
Expand Down Expand Up @@ -308,7 +384,11 @@ fun StudySetDetail(
onDeleteFlashCardClick = onDeleteFlashCard,
onToggleStarClick = onToggleStarredFlashCard,
onEditFlashCardClick = onEditFlashCard,
onAddFlashCardClick = onAddFlashcard
onAddFlashCardClick = onAddFlashcard,
onNavigateToLearnFlashCard = onNavigateToLearnFlashCard,
onNavigateToTestFlashCard = onNavigateToTestFlashCard,
onNavigateToMatchFlashCard = onNavigateToMatchFlashCard,
onNavigateToFlipFlashCard = onNavigateToFlipFlashCard
)

1 -> ProgressTabScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ fun MaterialTabScreen(
onEditFlashCardClick: () -> Unit = {},
onToggleStarClick: (String, Boolean) -> Unit = { _, _ -> },
onAddFlashCardClick: () -> Unit = {},
onNavigateToLearnFlashCard: () -> Unit = {},
onNavigateToTestFlashCard: () -> Unit = {},
onNavigateToMatchFlashCard: () -> Unit = {},
onNavigateToFlipFlashCard: () -> Unit = {},
) {
val menuBottomSheetState = rememberModalBottomSheetState()
var showMenu by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -153,28 +157,28 @@ fun MaterialTabScreen(
LearnModeCard(
title = "Flip Flashcards",
icon = R.drawable.ic_flipcard,
onClick = {}
onClick = onNavigateToFlipFlashCard
)
}
item {
LearnModeCard(
title = "Learn",
icon = R.drawable.ic_learn,
onClick = {}
onClick = onNavigateToLearnFlashCard
)
}
item {
LearnModeCard(
title = "Test",
icon = R.drawable.ic_test,
onClick = {}
onClick = onNavigateToTestFlashCard
)
}
item {
LearnModeCard(
title = "Match",
icon = R.drawable.ic_match_card,
onClick = {}
onClick = onNavigateToMatchFlashCard
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.pwhs.quickmem.presentation.app.study_set.study.flip_flashcard

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.hilt.navigation.compose.hiltViewModel
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.annotation.RootGraph
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.result.ResultBackNavigator

@Destination<RootGraph>
@Composable
fun FlipFlashCardScreen(
modifier: Modifier = Modifier,
navigator: DestinationsNavigator,
resultNavigator: ResultBackNavigator<Boolean>,
viewModel: FlipFlashCardViewModel = hiltViewModel()
) {
val uiState by viewModel.uiState.collectAsState()
LaunchedEffect(key1 = true) {
viewModel.uiEvent.collect { event ->
when (event) {
else -> {}
}

}
}
FlipFlashCard(modifier = modifier)
}

@Composable
fun FlipFlashCard(modifier: Modifier = Modifier) {
Scaffold { innerPadding ->
Column(
modifier = modifier.padding(innerPadding)
) {
Text(
text = "FlipFlashCardScreen",
style = MaterialTheme.typography.bodyLarge
)
}
}
}

@Preview
@Composable
private fun FlipFlashCardScreenPreview() {
MaterialTheme {
FlipFlashCard()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.pwhs.quickmem.presentation.app.study_set.study.flip_flashcard

sealed class FlipFlashCardUiAction {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.pwhs.quickmem.presentation.app.study_set.study.flip_flashcard

sealed class FlipFlashCardUiEvent {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.pwhs.quickmem.presentation.app.study_set.study.flip_flashcard

data class FlipFlashCardUiState(
val isLoading: Boolean = false,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.pwhs.quickmem.presentation.app.study_set.study.flip_flashcard

import androidx.lifecycle.ViewModel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.receiveAsFlow
import javax.inject.Inject

class FlipFlashCardViewModel @Inject constructor() : ViewModel() {
private val _uiState = MutableStateFlow(FlipFlashCardUiState())
val uiState = _uiState.asStateFlow()

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

fun onEvent(event: FlipFlashCardUiEvent) {
when (event) {
else -> {}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.pwhs.quickmem.presentation.app.study_set.study.learn

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.hilt.navigation.compose.hiltViewModel
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.annotation.RootGraph
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.result.ResultBackNavigator

@Destination<RootGraph>
@Composable
fun LearnFlashCardScreen(
modifier: Modifier = Modifier,
resultNavigator: ResultBackNavigator<Boolean>,
navigator: DestinationsNavigator,
viewModel: LearnFlashCardViewModel = hiltViewModel()
) {
val uiState by viewModel.uiState.collectAsState()
LaunchedEffect(key1 = true) {
viewModel.uiEvent.collect { event ->
when (event) {
else -> {}
}

}
}
LearnFlashCard(modifier = modifier)
}

@Composable
fun LearnFlashCard(modifier: Modifier = Modifier) {
Scaffold { innerPadding ->
Column(
modifier = modifier.padding(innerPadding)
) {
Text(
text = "LearnFlashCardScreen",
style = MaterialTheme.typography.bodyLarge
)
}
}
}

@Preview
@Composable
private fun LearnFlashCardScreenPreview() {
MaterialTheme {
LearnFlashCard()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.pwhs.quickmem.presentation.app.study_set.study.learn

sealed class LearnFlashCardUiAction {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.pwhs.quickmem.presentation.app.study_set.study.learn

sealed class LearnFlashCardUiEvent {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.pwhs.quickmem.presentation.app.study_set.study.learn

data class LearnFlashCardUiState(
val isLoading: Boolean = false,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.pwhs.quickmem.presentation.app.study_set.study.learn

import androidx.lifecycle.ViewModel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.receiveAsFlow
import javax.inject.Inject

class LearnFlashCardViewModel @Inject constructor() : ViewModel() {
private val _uiState = MutableStateFlow(LearnFlashCardUiState())
val uiState = _uiState.asStateFlow()

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

fun onEvent(event: LearnFlashCardUiEvent) {
when (event) {
else -> {}
}
}
}
Loading

0 comments on commit 4e28adb

Please sign in to comment.