Skip to content

Commit

Permalink
Merge branch 'main' into feat/language
Browse files Browse the repository at this point in the history
  • Loading branch information
nqmgaming authored Dec 2, 2024
2 parents 5924a81 + c4b7e38 commit 1c2bc83
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
Expand Down Expand Up @@ -111,7 +110,7 @@ fun StudySetDetailTopAppBar(
VerticalDivider(
modifier = Modifier
.padding(horizontal = 8.dp)
.height(16.dp)
.size(16.dp)
)
Text(
when (flashCardCount) {
Expand All @@ -130,7 +129,7 @@ fun StudySetDetailTopAppBar(
colors = TopAppBarDefaults.topAppBarColors(
containerColor = Color.Transparent,
),
expandedHeight = if (isAIGenerated) 165.dp else 120.dp,
expandedHeight = if(isAIGenerated) 165.dp else 120.dp,
collapsedHeight = 56.dp,
navigationIcon = {
IconButton(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.pwhs.quickmem.presentation.app.study_set.studies.component

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme.colorScheme
import androidx.compose.material3.MaterialTheme.shapes
import androidx.compose.material3.MaterialTheme.typography
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.SheetState
import androidx.compose.material3.Text
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun UnfinishedLearningBottomSheet(
modifier: Modifier = Modifier,
onDismissRequest: () -> Unit = {},
onKeepLearningClick: () -> Unit = {},
onEndSessionClick: () -> Unit = {},
showUnfinishedLearningBottomSheet: Boolean = false,
sheetShowMoreState: SheetState = rememberModalBottomSheetState(),
) {
if (showUnfinishedLearningBottomSheet) {
ModalBottomSheet(
modifier = modifier,
onDismissRequest = onDismissRequest,
sheetState = sheetShowMoreState
) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = "Wait, don't go yet! You'll miss out on completing this study set!",
style = typography.titleLarge,
modifier = Modifier.padding(bottom = 16.dp)
)
Button(
onClick = onKeepLearningClick,
modifier = Modifier
.fillMaxWidth(),
shape = shapes.medium
) {
Text(
text = "Keep Learning",
style = typography.bodyMedium.copy(
fontWeight = FontWeight.Bold
)
)
}
OutlinedButton(
onClick = onEndSessionClick,
colors = ButtonDefaults.outlinedButtonColors(
contentColor = colorScheme.onSurface.copy(alpha = 0.6f)
),
modifier = Modifier
.padding(top = 4.dp)
.fillMaxWidth(),
shape = shapes.medium
) {
Text(
text = "End Session",
style = typography.bodyMedium.copy(
fontWeight = FontWeight.Bold
)
)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import com.pwhs.quickmem.presentation.app.study_set.studies.flip.component.FlipF
import com.pwhs.quickmem.presentation.app.study_set.studies.flip.component.FlipFlashCardStatusRow
import com.pwhs.quickmem.presentation.app.study_set.studies.flip.component.StudyFlipFlashCard
import com.pwhs.quickmem.presentation.app.study_set.studies.component.StudyTopAppBar
import com.pwhs.quickmem.presentation.app.study_set.studies.component.UnfinishedLearningBottomSheet
import com.pwhs.quickmem.presentation.component.LoadingOverlay
import com.pwhs.quickmem.ui.theme.QuickMemTheme
import com.pwhs.quickmem.util.toColor
Expand All @@ -71,6 +72,7 @@ fun FlipFlashCardScreen(
) {
val uiState by viewModel.uiState.collectAsState()
val context = LocalContext.current

LaunchedEffect(key1 = true) {
viewModel.uiEvent.collect { event ->
when (event) {
Expand All @@ -93,7 +95,7 @@ fun FlipFlashCardScreen(
isSwipingRight = uiState.isSwipingRight,
isEndOfList = uiState.isEndOfList,
learningTime = uiState.learningTime,
onBackClicked = {
onEndSessionClick = {
viewModel.onEvent(FlipFlashCardUiAction.OnBackClicked)
},
currentCardIndex = uiState.currentCardIndex,
Expand Down Expand Up @@ -143,7 +145,7 @@ fun FlipFlashCard(
isSwipingRight: Boolean = false,
isEndOfList: Boolean = false,
learningTime: Long = 0L,
onBackClicked: () -> Unit = { },
onEndSessionClick: () -> Unit = { },
onUpdatedCardIndex: (Int) -> Unit = { },
onSwipeRight: (Boolean) -> Unit = { },
onSwipeLeft: (Boolean) -> Unit = { },
Expand All @@ -160,6 +162,7 @@ fun FlipFlashCard(
}
val hintBottomSheetState = rememberModalBottomSheetState()
val explanationBottomSheetState = rememberModalBottomSheetState()
var showUnfinishedLearningBottomSheet by remember { mutableStateOf(false) }
val stillLearningColor = Color(0xffd05700)
val knownColor = Color(0xff18ae79)
val stackState = rememberStackState()
Expand All @@ -183,7 +186,13 @@ fun FlipFlashCard(
StudyTopAppBar(
currentCardIndex = currentCardIndex,
totalCards = flashCards.size,
onBackClicked = onBackClicked,
onBackClicked = {
if (isEndOfList) {
onEndSessionClick()
} else {
showUnfinishedLearningBottomSheet = true
}
},
isEnOfSet = isEndOfList,
onRestartClicked = {
onRestartClicked()
Expand Down Expand Up @@ -426,6 +435,23 @@ fun FlipFlashCard(
isShowBottomSheet = showExplanationBottomSheet,
sheetState = explanationBottomSheetState
)

if (showUnfinishedLearningBottomSheet) {
UnfinishedLearningBottomSheet(
showUnfinishedLearningBottomSheet = showUnfinishedLearningBottomSheet,
onDismissRequest = {
showUnfinishedLearningBottomSheet = false
},
onKeepLearningClick = {
showUnfinishedLearningBottomSheet = false
},
onEndSessionClick = {
onEndSessionClick()
showUnfinishedLearningBottomSheet = false
}
)
}

}

@Preview(showBackground = true, device = Devices.PIXEL_7_PRO)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import com.pwhs.quickmem.core.data.enums.QuizStatus
import com.pwhs.quickmem.core.data.states.RandomAnswer
import com.pwhs.quickmem.core.data.states.WrongAnswer
import com.pwhs.quickmem.domain.model.flashcard.FlashCardResponseModel
import com.pwhs.quickmem.presentation.app.study_set.studies.component.UnfinishedLearningBottomSheet
import com.pwhs.quickmem.presentation.app.study_set.studies.quiz.component.QuizFlashCardFinish
import com.pwhs.quickmem.presentation.app.study_set.studies.quiz.component.QuizView
import com.pwhs.quickmem.presentation.component.LoadingOverlay
Expand Down Expand Up @@ -85,7 +86,7 @@ fun LearnByQuizScreen(
LearnByQuiz(
modifier = modifier,
isLoading = uiState.isLoading,
onNavigateBack = {
onEndSessionClick = {
resultNavigator.navigateBack(true)
},
wrongAnswerCount = uiState.wrongAnswerCount,
Expand Down Expand Up @@ -122,7 +123,7 @@ fun LearnByQuizScreen(
@Composable
fun LearnByQuiz(
modifier: Modifier = Modifier,
onNavigateBack: () -> Unit = {},
onEndSessionClick: () -> Unit = {},
isLoading: Boolean = false,
wrongAnswerCount: Int = 0,
listWrongAnswer: List<WrongAnswer> = emptyList(),
Expand All @@ -141,6 +142,7 @@ fun LearnByQuiz(
var canResetState by remember { mutableStateOf(false) }
val showHintBottomSheet = remember { mutableStateOf(false) }
val hintBottomSheetState = rememberModalBottomSheetState()
var showUnfinishedLearningBottomSheet by remember { mutableStateOf(false) }
var selectedAnswer by remember { mutableStateOf<String?>(null) }
val scope = rememberCoroutineScope()
var debounceJob: Job? = null
Expand All @@ -158,7 +160,13 @@ fun LearnByQuiz(
},
navigationIcon = {
IconButton(
onClick = onNavigateBack
onClick = {
if (isEndOfList) {
onEndSessionClick()
} else {
showUnfinishedLearningBottomSheet = true
}
}
) {
Icon(
imageVector = Default.Clear,
Expand Down Expand Up @@ -308,6 +316,22 @@ fun LearnByQuiz(
}
}
}

if (showUnfinishedLearningBottomSheet) {
UnfinishedLearningBottomSheet(
showUnfinishedLearningBottomSheet = showUnfinishedLearningBottomSheet,
onDismissRequest = {
showUnfinishedLearningBottomSheet = false
},
onKeepLearningClick = {
showUnfinishedLearningBottomSheet = false
},
onEndSessionClick = {
onEndSessionClick()
showUnfinishedLearningBottomSheet = false
}
)
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import androidx.hilt.navigation.compose.hiltViewModel
import coil.compose.AsyncImage
import com.pwhs.quickmem.R
import com.pwhs.quickmem.domain.model.flashcard.FlashCardResponseModel
import com.pwhs.quickmem.presentation.app.study_set.studies.component.UnfinishedLearningBottomSheet
import com.pwhs.quickmem.presentation.app.study_set.studies.true_false.component.TrueFalseButton
import com.pwhs.quickmem.presentation.app.study_set.studies.true_false.component.TrueFalseFlashcardFinish
import com.pwhs.quickmem.presentation.component.LoadingOverlay
Expand Down Expand Up @@ -84,7 +85,7 @@ fun LearnByTrueFalseScreen(
}
LearnByTrueFalse(
modifier = modifier,
onNavigateBack = {
onEndSessionClick = {
viewModel.onEvent(LearnByTrueFalseUiAction.OnBackClicked)
},
isLoading = uiState.isLoading,
Expand Down Expand Up @@ -123,7 +124,7 @@ fun LearnByTrueFalse(
studySetColor: Color = MaterialTheme.colorScheme.primary,
flashCardList: List<FlashCardResponseModel> = emptyList(),
randomQuestion: TrueFalseQuestion? = null,
onNavigateBack: () -> Unit = {},
onEndSessionClick: () -> Unit = {},
onRestart: () -> Unit = {},
onAnswer: (Boolean, String) -> Unit = { _, _ -> },
wrongAnswerCount: Int = 0,
Expand All @@ -133,6 +134,8 @@ fun LearnByTrueFalse(
) {
var isImageViewerOpen by remember { mutableStateOf(false) }
var definitionImageUri by remember { mutableStateOf("") }
var showUnfinishedLearningBottomSheet by remember { mutableStateOf(false) }

Scaffold(
topBar = {
CenterAlignedTopAppBar(
Expand All @@ -147,7 +150,13 @@ fun LearnByTrueFalse(
},
navigationIcon = {
IconButton(
onClick = onNavigateBack
onClick = {
if (isEndOfList) {
onEndSessionClick()
} else {
showUnfinishedLearningBottomSheet = true
}
}
) {
Icon(
imageVector = Default.Clear,
Expand Down Expand Up @@ -360,6 +369,22 @@ fun LearnByTrueFalse(
}
)
}

if (showUnfinishedLearningBottomSheet) {
UnfinishedLearningBottomSheet(
showUnfinishedLearningBottomSheet = showUnfinishedLearningBottomSheet,
onDismissRequest = {
showUnfinishedLearningBottomSheet = false
},
onKeepLearningClick = {
showUnfinishedLearningBottomSheet = false
},
onEndSessionClick = {
onEndSessionClick()
showUnfinishedLearningBottomSheet = false
}
)
}
}
}
}
Expand Down
Loading

0 comments on commit 1c2bc83

Please sign in to comment.