tmp
This commit is contained in:
parent
7898a51252
commit
8fbe3c0b7b
21 changed files with 359 additions and 35 deletions
|
|
@ -1,5 +1,10 @@
|
|||
package com.pixelized.biblib.ui.composable.screen
|
||||
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
|
|
@ -19,6 +24,7 @@ import androidx.compose.ui.Alignment
|
|||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
|
|
@ -28,7 +34,11 @@ import androidx.compose.ui.text.input.VisualTransformation
|
|||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import com.google.android.gms.auth.api.signin.GoogleSignIn
|
||||
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
|
||||
import com.google.android.gms.common.api.ApiException
|
||||
import com.pixelized.biblib.R
|
||||
import com.pixelized.biblib.ui.MainActivity
|
||||
import com.pixelized.biblib.ui.theme.BibLibTheme
|
||||
import com.pixelized.biblib.ui.viewmodel.AuthenticationViewModel
|
||||
import com.pixelized.biblib.ui.viewmodel.NavigationViewModel
|
||||
|
|
@ -43,10 +53,35 @@ fun LoginScreenComposablePreview() {
|
|||
|
||||
@Composable
|
||||
fun LoginScreenComposable(
|
||||
|
||||
navigationViewModel: NavigationViewModel = viewModel(),
|
||||
authenticationViewModel: AuthenticationViewModel = viewModel(),
|
||||
) {
|
||||
val navigationViewModel = viewModel<NavigationViewModel>()
|
||||
val authenticationViewModel = viewModel<AuthenticationViewModel>()
|
||||
// TODO : c'est de la merde ça
|
||||
val activity = LocalContext.current as MainActivity
|
||||
val result = remember { mutableStateOf<String?>(null) }
|
||||
val launcher =
|
||||
rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
try {
|
||||
val task = GoogleSignIn.getSignedInAccountFromIntent(it.data)
|
||||
val account: GoogleSignInAccount? = task.getResult(ApiException::class.java)
|
||||
|
||||
val idToken = account?.idToken
|
||||
// if (idToken != null) {
|
||||
// viewModel.loginWithGoogle(idToken).observeLogin()
|
||||
// } else {
|
||||
// Toast.makeText(requireActivity(), "GoogleSignIn missing Token", Toast.LENGTH_SHORT).show()
|
||||
// }
|
||||
Log.e("AuthLoginFragment", "idToken: $idToken")
|
||||
} catch (exception: Exception) {
|
||||
// Toast.makeText(requireActivity(), "GoogleSignIn exception: ${exception.message}", Toast.LENGTH_SHORT).show()
|
||||
Log.e("AuthLoginFragment", exception.message, exception)
|
||||
}
|
||||
// // Here we just update the state, but you could imagine
|
||||
// // pre-processing the result, or updating a MutableSharedFlow that
|
||||
// // your composable collects
|
||||
// result.value = it
|
||||
}
|
||||
|
||||
val typography = MaterialTheme.typography
|
||||
|
||||
Column(
|
||||
|
|
@ -102,14 +137,12 @@ fun LoginScreenComposable(
|
|||
modifier = Modifier.padding(end = 8.dp),
|
||||
colors = outlinedButtonColors(),
|
||||
onClick = {
|
||||
// TODO:
|
||||
navigationViewModel.navigateTo(NavigationViewModel.Screen.MainScreen)
|
||||
authenticationViewModel.register()
|
||||
}) {
|
||||
Text(text = stringResource(id = R.string.action_register))
|
||||
}
|
||||
Button(onClick = {
|
||||
// TODO:
|
||||
navigationViewModel.navigateTo(NavigationViewModel.Screen.MainScreen)
|
||||
authenticationViewModel.login()
|
||||
}) {
|
||||
Text(text = stringResource(id = R.string.action_login))
|
||||
}
|
||||
|
|
@ -121,8 +154,7 @@ fun LoginScreenComposable(
|
|||
modifier = Modifier.fillMaxWidth(),
|
||||
colors = outlinedButtonColors(),
|
||||
onClick = {
|
||||
// TODO:
|
||||
navigationViewModel.navigateTo(NavigationViewModel.Screen.MainScreen)
|
||||
launcher.launch(activity.googleSignIn.signInIntent)
|
||||
}) {
|
||||
Image(
|
||||
modifier = Modifier.padding(end = 8.dp),
|
||||
|
|
@ -189,7 +221,7 @@ private fun PasswordField(
|
|||
private fun CredentialRemember(viewModel: AuthenticationViewModel, modifier: Modifier = Modifier) {
|
||||
val credential = viewModel.rememberCredential.observeAsState()
|
||||
Row(modifier = modifier.clickable {
|
||||
viewModel.updateRememberCredential(credential = credential.value?.not() ?: false)
|
||||
viewModel.updateRememberCredential(rememberCredential = credential.value?.not() ?: false)
|
||||
}) {
|
||||
Checkbox(
|
||||
modifier = Modifier.align(Alignment.CenterVertically),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue