Delegate and Inject ErrorMonitor

pull/1461/head
TM 1 year ago
parent 18c57eb937
commit dd996ff7f7

@ -96,7 +96,7 @@ fun NiaApp(
val snackbarHostState = remember { SnackbarHostState() }
val isOffline by appState.isOffline.collectAsStateWithLifecycle()
val errorMessage by appState.errorMessage.collectAsStateWithLifecycle()
val snackbarMessage by appState.snackbarMessage.collectAsStateWithLifecycle()
// If user is not connected to the internet show a snack bar to inform them.
val notConnectedMessage = stringResource(R.string.not_connected)
@ -108,8 +108,8 @@ fun NiaApp(
)
}
}
LaunchedEffect(errorMessage) {
errorMessage?.let {
LaunchedEffect(snackbarMessage) {
snackbarMessage?.let {
val snackBarResult = snackbarHostState.showSnackbar(
message = it.message,
actionLabel = "Continue",

@ -89,7 +89,7 @@ class NiaAppState(
errorMonitor: ErrorMonitor,
userNewsResourceRepository: UserNewsResourceRepository,
timeZoneMonitor: TimeZoneMonitor,
) {
) : ErrorMonitor by errorMonitor {
val currentDestination: NavDestination?
@Composable get() = navController
.currentBackStackEntryAsState().value?.destination
@ -110,7 +110,7 @@ class NiaAppState(
initialValue = false,
)
val errorMessage = errorMonitor.errorMessage.stateIn(
val snackbarMessage = errorMessage.stateIn(
scope = coroutineScope,
started = SharingStarted.WhileSubscribed(5_000),
initialValue = null,

@ -21,12 +21,13 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.update
import java.util.UUID
import javax.inject.Inject
/**
* Interface implementation for handling general errors.
*/
class SnackbarErrorMonitor : ErrorMonitor {
class SnackbarErrorMonitor @Inject constructor() : ErrorMonitor {
/**
* List of [ErrorMessage] to be shown to the user, via Snackbar.
*/

Loading…
Cancel
Save