Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,10 @@ class Dependencies(
setPreferenceValuesByKeys = preferenceRepository::setValuesByKey,
)

fun bottomBarViewModel(): BottomBarViewModel =
fun bottomBarViewModel() =
BottomBarViewModel(
resultRepository::countAllNotViewedFlow,
countAllNotViewedFlow = resultRepository::countAllNotViewedFlow,
runBackgroundStateFlow = runBackgroundStateManager::observeState,
)

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.update
import org.ooni.probe.data.models.RunBackgroundState

class BottomBarViewModel(countAllNotViewedFlow: () -> Flow<Long>) : ViewModel() {
class BottomBarViewModel(
countAllNotViewedFlow: () -> Flow<Long>,
runBackgroundStateFlow: () -> Flow<RunBackgroundState>,
) : ViewModel() {
private val _state = MutableStateFlow(State())
val state: StateFlow<State> = _state.asStateFlow()

Expand All @@ -20,9 +24,16 @@ class BottomBarViewModel(countAllNotViewedFlow: () -> Flow<Long>) : ViewModel()
_state.update { it.copy(notViewedCount = count) }
}
.launchIn(viewModelScope)

runBackgroundStateFlow()
.onEach { runState ->
_state.update { it.copy(areTestsRunning = runState !is RunBackgroundState.Idle) }
}
.launchIn(viewModelScope)
}

data class State(
val notViewedCount: Long = 0L,
val areTestsRunning: Boolean = false,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package org.ooni.probe.ui.navigation

import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Badge
import androidx.compose.material3.BadgedBox
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar
Expand Down Expand Up @@ -45,16 +48,25 @@ fun BottomNavigationBar(
modifier = customMinHeightModifier,
) {
MAIN_NAVIGATION_SCREENS.forEach { screen ->
val isCurrentScreen = entry?.destination?.hasRoute(screen::class) == true
NavigationBarItem(
icon = {
NavigationBadgeBox(
state = state,
screen = screen,
) {
Icon(
painterResource(screen.iconRes),
contentDescription = stringResource(screen.titleRes),
)
if (
screen == Screen.Dashboard && !isCurrentScreen && state.areTestsRunning
) {
CircularProgressIndicator(
modifier = Modifier.padding(2.dp).size(20.dp),
)
} else {
Icon(
painterResource(screen.iconRes),
contentDescription = stringResource(screen.titleRes),
)
}
}
},
label = {
Expand All @@ -63,7 +75,7 @@ fun BottomNavigationBar(
textAlign = TextAlign.Center,
)
},
selected = entry?.destination?.hasRoute(screen::class) == true,
selected = isCurrentScreen,
onClick = { navController.navigateToMainScreen(screen) },
colors = NavigationBarItemDefaults.colors(
indicatorColor = MaterialTheme.colorScheme.primaryContainer,
Expand Down
Loading