Fix dumb mistake with google sign in.

This commit is contained in:
Thomas Andres Gomez 2021-05-14 12:06:24 +02:00
parent 1e58752008
commit 4b5893cf43
7 changed files with 67 additions and 43 deletions

View file

@ -3,6 +3,7 @@ package com.pixelized.biblib.ui.composable.screen
import android.content.Intent
import android.net.Uri
import android.util.Log
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.expandVertically
@ -51,6 +52,7 @@ import com.pixelized.biblib.ui.viewmodel.credential.CredentialViewModel
import com.pixelized.biblib.ui.viewmodel.credential.ICredentialViewModel
import com.pixelized.biblib.ui.viewmodel.navigation.INavigationViewModel
import com.pixelized.biblib.ui.viewmodel.navigation.NavigationViewModel
import kotlinx.coroutines.delay
private const val LE_LOAD_BOOK = "LE_LOAD_BOOK"
@ -62,6 +64,10 @@ fun LoginScreenComposable(
authenticationViewModel: IAuthenticationViewModel = viewModel<AuthenticationViewModel>(),
bookViewModel: IBooksViewModel = viewModel<BooksViewModel>()
) {
LaunchedEffect("merde") {
authenticationViewModel.clearState()
}
Box(
modifier = Modifier
.fillMaxWidth()
@ -105,11 +111,11 @@ private fun LoginScreenDialogComposable(
authenticationViewModel: IAuthenticationViewModel,
booksViewModel: IBooksViewModel,
) {
val authState = authenticationViewModel.state.observeAsState()
val bookState = booksViewModel.state.observeAsState()
val authState by authenticationViewModel.state.observeAsState()
val bookState by booksViewModel.state.observeAsState()
val visible = authState.value is IAuthenticationViewModel.State.Error
|| bookState.value is IBooksViewModel.State.Error
val visible = authState !is IAuthenticationViewModel.State.Initial
|| bookState !is IBooksViewModel.State.Initial
CrossFadeOverlay(
modifier = Modifier.clickable {
@ -121,19 +127,19 @@ private fun LoginScreenDialogComposable(
) {
AnimatedVisibility(
modifier = Modifier.align(Alignment.Center),
visible = authState.value is IAuthenticationViewModel.State.Error,
visible = authState is IAuthenticationViewModel.State.Error,
initiallyVisible = false,
enter = expandVertically(Alignment.CenterVertically),
exit = shrinkVertically(Alignment.CenterVertically),
) {
ErrorCard(
message = stringResource(id = R.string.error_authentication),
exception = (authState.value as? IAuthenticationViewModel.State.Error)?.exception
exception = (authState as? IAuthenticationViewModel.State.Error)?.exception
)
}
AnimatedVisibility(
modifier = Modifier.align(Alignment.Center),
visible = authState.value is IAuthenticationViewModel.State.Loading,
visible = authState is IAuthenticationViewModel.State.Loading,
initiallyVisible = false,
enter = expandVertically(Alignment.CenterVertically),
exit = shrinkVertically(Alignment.CenterVertically),
@ -144,7 +150,7 @@ private fun LoginScreenDialogComposable(
}
AnimatedVisibility(
modifier = Modifier.align(Alignment.Center),
visible = (authState.value as? IAuthenticationViewModel.State.Finished)?.logged
visible = (authState as? IAuthenticationViewModel.State.Finished)?.logged
?: false,
initiallyVisible = false,
enter = expandVertically(Alignment.CenterVertically),
@ -156,19 +162,19 @@ private fun LoginScreenDialogComposable(
}
AnimatedVisibility(
modifier = Modifier.align(Alignment.Center),
visible = bookState.value is IBooksViewModel.State.Error,
visible = bookState is IBooksViewModel.State.Error,
initiallyVisible = false,
enter = expandVertically(Alignment.CenterVertically),
exit = shrinkVertically(Alignment.CenterVertically),
) {
ErrorCard(
message = stringResource(id = R.string.error_book),
exception = (bookState.value as? IBooksViewModel.State.Error)?.exception
exception = (bookState as? IBooksViewModel.State.Error)?.exception
)
}
AnimatedVisibility(
modifier = Modifier.align(Alignment.Center),
visible = bookState.value is IBooksViewModel.State.Loading,
visible = bookState is IBooksViewModel.State.Loading,
initiallyVisible = false,
enter = expandVertically(Alignment.CenterVertically),
exit = shrinkVertically(Alignment.CenterVertically),
@ -179,7 +185,7 @@ private fun LoginScreenDialogComposable(
}
AnimatedVisibility(
modifier = Modifier.align(Alignment.Center),
visible = bookState.value is IBooksViewModel.State.Finished,
visible = bookState is IBooksViewModel.State.Finished,
initiallyVisible = false,
enter = expandVertically(Alignment.CenterVertically),
exit = shrinkVertically(Alignment.CenterVertically),
@ -197,18 +203,20 @@ private fun LoginScreenNavigationComposable(
authenticationViewModel: IAuthenticationViewModel,
bookViewModel: IBooksViewModel,
) {
val authenticationState = authenticationViewModel.state.observeAsState()
(authenticationState.value as? IAuthenticationViewModel.State.Finished)?.let {
val authenticationState by authenticationViewModel.state.observeAsState()
(authenticationState as? IAuthenticationViewModel.State.Finished)?.let {
if (it.logged) {
LaunchedEffect(LE_LOAD_BOOK) {
delay(1000)
bookViewModel.updateBooks()
}
val bookLoadingState = bookViewModel.state.observeAsState()
if (bookLoadingState.value is IBooksViewModel.State.Finished) {
navigationViewModel.navigateTo(INavigationViewModel.Screen.MainScreen)
}
}
}
val bookLoadingState by bookViewModel.state.observeAsState()
if (bookLoadingState is IBooksViewModel.State.Finished) {
navigationViewModel.navigateTo(INavigationViewModel.Screen.MainScreen)
}
}
@Composable
@ -379,15 +387,11 @@ private fun CredentialRemember(
@Composable
fun LoginScreenComposablePreview() {
BibLibTheme {
val navigationViewModel = INavigationViewModel.Mock()
val credentialViewModel = ICredentialViewModel.Mock()
val authenticationViewModel = IAuthenticationViewModel.Mock()
val bookViewModel = IBooksViewModel.Mock()
LoginScreenComposable(
navigationViewModel,
credentialViewModel,
authenticationViewModel,
bookViewModel,
navigationViewModel = INavigationViewModel.Mock(),
credentialViewModel = ICredentialViewModel.Mock(),
authenticationViewModel = IAuthenticationViewModel.Mock(),
bookViewModel = IBooksViewModel.Mock(),
)
}
}