diff --git a/app/src/main/kotlin/com/eblan/socialworkreviewer/navigation/SwrNavHost.kt b/app/src/main/kotlin/com/eblan/socialworkreviewer/navigation/SwrNavHost.kt index baae3f7..7dc5c13 100644 --- a/app/src/main/kotlin/com/eblan/socialworkreviewer/navigation/SwrNavHost.kt +++ b/app/src/main/kotlin/com/eblan/socialworkreviewer/navigation/SwrNavHost.kt @@ -38,6 +38,10 @@ import com.eblan.socialworkreviewer.feature.question.navigation.navigateToQuesti import com.eblan.socialworkreviewer.feature.question.navigation.questionScreen import com.eblan.socialworkreviewer.feature.settings.navigation.navigateToSettings import com.eblan.socialworkreviewer.feature.settings.navigation.settingsScreen +import com.eblan.socialworkreviewer.navigation.TopLevelDestination.ABOUT +import com.eblan.socialworkreviewer.navigation.TopLevelDestination.CATEGORY +import com.eblan.socialworkreviewer.navigation.TopLevelDestination.NEWS +import com.eblan.socialworkreviewer.navigation.TopLevelDestination.SETTINGS import kotlinx.coroutines.launch @Composable @@ -50,13 +54,6 @@ fun SwrNavHost(modifier: Modifier = Modifier) { val scope = rememberCoroutineScope() - val topLevelDestinations = listOf( - CategoryDestination(), - NewsDestination(), - SettingsDestination(), - AboutDestination(), - ) - NavHost( modifier = modifier, navController = swrNavHostController, @@ -64,21 +61,20 @@ fun SwrNavHost(modifier: Modifier = Modifier) { ) { homeScreen( snackbarHostState = snackbarHostState, - topLevelDestinations = topLevelDestinations, + topLevelDestinations = TopLevelDestination.entries, startDestination = CategoryRouteData::class, onItemClick = { homeNavHostController, homeDestination -> when (homeDestination) { - is CategoryDestination -> homeNavHostController.navigateToCategoryScreen() - is NewsDestination -> homeNavHostController.navigateToNewsScreen() - is SettingsDestination -> homeNavHostController.navigateToSettings() - is AboutDestination -> homeNavHostController.navigateToAboutScreen() + CATEGORY -> homeNavHostController.navigateToCategoryScreen() + NEWS -> homeNavHostController.navigateToNewsScreen() + SETTINGS -> homeNavHostController.navigateToSettings() + ABOUT -> homeNavHostController.navigateToAboutScreen() } }, onShowSnackBar = { message -> scope.launch { snackbarHostState.showSnackbar( message = message, - withDismissAction = true, duration = SnackbarDuration.Indefinite, ) } diff --git a/app/src/main/kotlin/com/eblan/socialworkreviewer/navigation/TopLevelDestination.kt b/app/src/main/kotlin/com/eblan/socialworkreviewer/navigation/TopLevelDestination.kt index 828f516..63acf3a 100644 --- a/app/src/main/kotlin/com/eblan/socialworkreviewer/navigation/TopLevelDestination.kt +++ b/app/src/main/kotlin/com/eblan/socialworkreviewer/navigation/TopLevelDestination.kt @@ -27,46 +27,37 @@ import com.eblan.socialworkreviewer.feature.news.navigation.NewsRouteData import com.eblan.socialworkreviewer.feature.settings.navigation.SettingsRouteData import kotlin.reflect.KClass -class CategoryDestination : HomeDestination { - override val label: Int - get() = R.string.category - override val icon: ImageVector - get() = Swr.Category - override val contentDescription: Int - get() = R.string.category - override val route: KClass<*> - get() = CategoryRouteData::class -} +enum class TopLevelDestination( + override val label: Int, + override val icon: ImageVector, + override val contentDescription: Int, + override val route: KClass<*>, +) : HomeDestination { + CATEGORY( + label = R.string.category, + icon = Swr.Category, + contentDescription = R.string.category, + route = CategoryRouteData::class, + ), -class NewsDestination : HomeDestination { - override val label: Int - get() = R.string.news - override val icon: ImageVector - get() = Swr.Campaign - override val contentDescription: Int - get() = R.string.news - override val route: KClass<*> - get() = NewsRouteData::class -} + NEWS( + label = R.string.news, + icon = Swr.Campaign, + contentDescription = R.string.news, + route = NewsRouteData::class, + ), -class SettingsDestination : HomeDestination { - override val label: Int - get() = R.string.settings - override val icon: ImageVector - get() = Swr.Settings - override val contentDescription: Int - get() = R.string.settings - override val route: KClass<*> - get() = SettingsRouteData::class -} + SETTINGS( + label = R.string.settings, + icon = Swr.Settings, + contentDescription = R.string.settings, + route = SettingsRouteData::class, + ), -class AboutDestination : HomeDestination { - override val label: Int - get() = R.string.about - override val icon: ImageVector - get() = Swr.Info - override val contentDescription: Int - get() = R.string.about - override val route: KClass<*> - get() = AboutRouteData::class + ABOUT( + label = R.string.about, + icon = Swr.Info, + contentDescription = R.string.about, + route = AboutRouteData::class, + ) } diff --git a/core/domain/src/main/kotlin/com/eblan/socialworkreviewer/core/domain/UpdateChoiceUseCase.kt b/core/domain/src/main/kotlin/com/eblan/socialworkreviewer/core/domain/UpdateChoiceUseCase.kt index 2810db3..6910391 100644 --- a/core/domain/src/main/kotlin/com/eblan/socialworkreviewer/core/domain/UpdateChoiceUseCase.kt +++ b/core/domain/src/main/kotlin/com/eblan/socialworkreviewer/core/domain/UpdateChoiceUseCase.kt @@ -41,13 +41,13 @@ class UpdateChoiceUseCase @Inject constructor( } private suspend fun singleChoice(choice: Choice) { - val oldChoice = choiceRepository.selectedChoices.find { oldChoice -> + choiceRepository.selectedChoices.find { oldChoice -> choice.question == oldChoice.question && choice != oldChoice + }?.let { oldChoice -> + choiceRepository.replaceChoice(oldChoice = oldChoice, newChoice = choice) } - if (oldChoice != null) { - choiceRepository.replaceChoice(oldChoice = oldChoice, newChoice = choice) - } else { + if (choice !in choiceRepository.selectedChoices) { choiceRepository.addChoice(choice) } } diff --git a/feature/question/src/main/kotlin/com/eblan/socialworkreviewer/feature/question/screen/CorrectChoicesScreen.kt b/feature/question/src/main/kotlin/com/eblan/socialworkreviewer/feature/question/screen/CorrectChoicesScreen.kt index be8101e..2bf195c 100644 --- a/feature/question/src/main/kotlin/com/eblan/socialworkreviewer/feature/question/screen/CorrectChoicesScreen.kt +++ b/feature/question/src/main/kotlin/com/eblan/socialworkreviewer/feature/question/screen/CorrectChoicesScreen.kt @@ -190,7 +190,10 @@ private fun CorrectChoicesTopBar( Spacer(modifier = Modifier.width(5.dp)) - Text(text = lastCountDownTime ?: "Time's Up!", fontWeight = FontWeight.Bold) + Text( + text = if (lastCountDownTime.isNullOrBlank()) "Time's up!" else lastCountDownTime, + fontWeight = FontWeight.Bold, + ) } } diff --git a/feature/question/src/main/kotlin/com/eblan/socialworkreviewer/feature/question/screen/OnBoardingScreen.kt b/feature/question/src/main/kotlin/com/eblan/socialworkreviewer/feature/question/screen/OnBoardingScreen.kt index 1ef17a1..9092026 100644 --- a/feature/question/src/main/kotlin/com/eblan/socialworkreviewer/feature/question/screen/OnBoardingScreen.kt +++ b/feature/question/src/main/kotlin/com/eblan/socialworkreviewer/feature/question/screen/OnBoardingScreen.kt @@ -214,7 +214,7 @@ private fun Statistics( AverageCircularProgressIndicator( progress = { (average / 100).toFloat() }, modifier = Modifier.size(100.dp), - strokeWidth = 4.dp, + strokeWidth = 5.dp, strokeCap = StrokeCap.Round, trackColor = ProgressIndicatorDefaults.linearTrackColor, ) {