Last active
October 9, 2022 18:40
-
-
Save sergei-mikhailovskii-idf/e1457f762e4a6233f64bb2abba294fa0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun SplashScreen(navController: NavController) { | |
val viewModelFactory: ViewModelProvider.Factory by rememberInstance() | |
val errorHandlerDelegate: ErrorHandlerDelegate by rememberInstance() | |
val viewModel = viewModel( | |
factory = viewModelFactory, | |
modelClass = SplashViewModel::class.java | |
) | |
LaunchedEffect(key1 = null) { | |
launch { | |
viewModel.failureSharedFlow.collect(errorHandlerDelegate::defaultHandleFailure) | |
} | |
} | |
Box {} | |
} | |
internal class ErrorHandlerDelegate( | |
private val context: Context, | |
private val snackbarService: SnackbarDelegate | |
) { | |
fun defaultHandleFailure(failure: Failure) { | |
when (failure) { | |
is Failure.ServerError -> snackbarService.showSnackbar( | |
SnackbarState.ERROR, | |
context.getString(R.string.error_server_error) | |
) | |
else -> {} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment