wrap splash in route
This commit is contained in:
parent
95140e1739
commit
c401a29061
2 changed files with 45 additions and 11 deletions
|
@ -31,6 +31,7 @@ import be.ugent.sel.studeez.screens.profile.EditProfileRoute
|
|||
import be.ugent.sel.studeez.screens.profile.ProfileRoute
|
||||
import be.ugent.sel.studeez.screens.session.SessionScreen
|
||||
import be.ugent.sel.studeez.screens.sign_up.SignUpRoute
|
||||
import be.ugent.sel.studeez.screens.splash.SplashRoute
|
||||
import be.ugent.sel.studeez.screens.splash.SplashScreen
|
||||
import be.ugent.sel.studeez.screens.timer_overview.TimerOverviewScreen
|
||||
import be.ugent.sel.studeez.screens.timer_selection.TimerSelectionScreen
|
||||
|
@ -101,7 +102,7 @@ fun NavGraphBuilder.studeezGraph(appState: StudeezAppstate) {
|
|||
}
|
||||
|
||||
composable(StudeezDestinations.SPLASH_SCREEN) {
|
||||
SplashScreen(openAndPopUp)
|
||||
SplashRoute(openAndPopUp, viewModel = hiltViewModel())
|
||||
}
|
||||
|
||||
composable(StudeezDestinations.LOGIN_SCREEN) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package be.ugent.sel.studeez.screens.splash
|
||||
|
||||
import android.window.SplashScreen
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
|
@ -15,7 +16,7 @@ import androidx.compose.runtime.LaunchedEffect
|
|||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import be.ugent.sel.studeez.common.composable.BasicButton
|
||||
import be.ugent.sel.studeez.common.ext.basicButton
|
||||
import kotlinx.coroutines.delay
|
||||
|
@ -24,14 +25,26 @@ import be.ugent.sel.studeez.R.string as AppText
|
|||
private const val SPLASH_TIMEOUT = 500L
|
||||
|
||||
@Composable
|
||||
fun SplashScreen(
|
||||
fun SplashRoute(
|
||||
openAndPopUp: (String, String) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
viewModel: SplashViewModel = hiltViewModel()
|
||||
viewModel: SplashViewModel,
|
||||
) {
|
||||
SplashScreen(
|
||||
modifier = modifier,
|
||||
onAppStart = { viewModel.onAppStart(openAndPopUp) },
|
||||
showError = viewModel.showError.value
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SplashScreen(
|
||||
modifier: Modifier = Modifier,
|
||||
onAppStart: () -> Unit,
|
||||
showError: Boolean,
|
||||
) {
|
||||
Column(
|
||||
modifier =
|
||||
modifier
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.fillMaxHeight()
|
||||
.background(color = MaterialTheme.colors.background)
|
||||
|
@ -39,17 +52,37 @@ fun SplashScreen(
|
|||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
if (viewModel.showError.value) {
|
||||
if (showError) {
|
||||
Text(text = stringResource(AppText.generic_error))
|
||||
|
||||
BasicButton(AppText.try_again, Modifier.basicButton()) { viewModel.onAppStart(openAndPopUp) }
|
||||
BasicButton(
|
||||
AppText.try_again,
|
||||
Modifier.basicButton(),
|
||||
onClick = onAppStart,
|
||||
)
|
||||
} else {
|
||||
CircularProgressIndicator(color = MaterialTheme.colors.onBackground)
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(true) {
|
||||
delay(SPLASH_TIMEOUT)
|
||||
viewModel.onAppStart(openAndPopUp)
|
||||
onAppStart()
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun SplashPreview() {
|
||||
SplashScreen(
|
||||
onAppStart = {},
|
||||
showError = false,
|
||||
)
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun SplashErrorPreview() {
|
||||
SplashScreen(
|
||||
onAppStart = {},
|
||||
showError = true,
|
||||
)
|
||||
}
|
Reference in a new issue