Skip to content

Commit

Permalink
Rewritten the top level destination
Browse files Browse the repository at this point in the history
  • Loading branch information
JackEblan committed Sep 20, 2024
1 parent 3f3a5ad commit c3ef678
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -50,35 +54,27 @@ fun SwrNavHost(modifier: Modifier = Modifier) {

val scope = rememberCoroutineScope()

val topLevelDestinations = listOf(
CategoryDestination(),
NewsDestination(),
SettingsDestination(),
AboutDestination(),
)

NavHost(
modifier = modifier,
navController = swrNavHostController,
startDestination = HomeRouteData::class,
) {
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,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand Down

0 comments on commit c3ef678

Please sign in to comment.