Skip to content

Commit

Permalink
create null handler in register, welcome, and login screen
Browse files Browse the repository at this point in the history
create handler in SplashScreen to navigate wallpaperscreen
  • Loading branch information
fchrgrib committed Jun 3, 2023
1 parent 1aaf365 commit 04b3214
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 120 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.wallpapercollect.presentation.ui.firstviews.start

import android.annotation.SuppressLint
import android.util.Log
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.clickable
Expand All @@ -13,7 +12,6 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -24,7 +22,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand All @@ -35,7 +32,6 @@ import com.example.wallpapercollect.api.models.Status
import com.example.wallpapercollect.api.models.Token
import com.example.wallpapercollect.api.models.Url
import com.example.wallpapercollect.api.models.UserLogIn
import com.example.wallpapercollect.presentation.MainActivity
import com.example.wallpapercollect.presentation.ui.navigation.NavigationRouters
import com.example.wallpapercollect.presentation.ui.theme.blue500
import com.example.wallpapercollect.presentation.ui.theme.brand500
Expand All @@ -50,32 +46,17 @@ import com.example.wallpapercollect.presentation.viewmodel.auth.Login
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import com.google.android.gms.auth.api.signin.GoogleSignInClient
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import okhttp3.internal.wait
import kotlin.concurrent.thread


@OptIn(DelicateCoroutinesApi::class)
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@Composable
fun LoginScreen(
login: Login = hiltViewModel(),
navController: NavController,
gsc:GoogleSignInClient
) {
// val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
// .requestIdToken(stringResource(R.string.google_token))
// .requestProfile()
// .requestEmail()
// .build()
//
// val gsc = GoogleSignIn.getClient(LocalContext.current,gso)
val account: GoogleSignInAccount? = GoogleSignIn.getLastSignedInAccount(LocalContext.current)

val account: GoogleSignInAccount? = GoogleSignIn.getLastSignedInAccount(LocalContext.current)

val statusLoginEmailDefaultSession = login.loginEmailDefault.collectAsState(Status("")).value
val statusLoginGoogleSession = login.loginGoogleSession.collectAsState(Status("")).value
Expand Down Expand Up @@ -119,13 +100,6 @@ fun LoginScreen(
password = password
)
)
if(statusLoginEmailDefaultSession.status == "ok"){
isLoginEmailDefaultSessionClicked = false

navController.navigate(NavigationRouters.WALLPAPER){
popUpTo(NavigationRouters.LOGIN){ inclusive = true}
}
}
},
onClickLoginFacebookSession = {
login.getLoginFacebookSession()
Expand All @@ -145,6 +119,14 @@ fun LoginScreen(
//TODO do something if user insert invalid data


if(statusLoginEmailDefaultSession.status == "ok"){
isLoginEmailDefaultSessionClicked = false

navController.navigate(NavigationRouters.WALLPAPER){
popUpTo(NavigationRouters.LOGIN){ inclusive = true}
}
}

if (statusLoginGoogleSession.status == "ok") {
isLoginGoogleSessionClicked = false

Expand All @@ -153,31 +135,23 @@ fun LoginScreen(
}
return
}

if (isLoginGoogleSessionClicked) {
if (account != null) {
login.postLoginGoogleSession(Token(account.idToken ?: ""))

}
}
return
if (account != null) login.postLoginGoogleSession(Token(account.idToken ?: ""))

return
}

if(
statusLoginFacebookSession.status == "ok"&&
isLoginFacebookSessionClicked
){
isLoginFacebookSessionClicked = false

//
//
// TODO make facebook login session can use as mobile
return
}

//
//
// if(
// statusLoginFacebookSession.status == "ok"&&
// isLoginFacebookSessionClicked
// ){
// isLoginFacebookSessionClicked = false
//
//// TODO make facebook login session can use as mobile
// return
// }
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand All @@ -41,7 +40,6 @@ import com.example.wallpapercollect.api.models.Status
import com.example.wallpapercollect.api.models.Token
import com.example.wallpapercollect.api.models.Url
import com.example.wallpapercollect.api.models.UserRegister
import com.example.wallpapercollect.presentation.MainActivity
import com.example.wallpapercollect.presentation.ui.navigation.NavigationRouters
import com.example.wallpapercollect.presentation.ui.theme.blue500
import com.example.wallpapercollect.presentation.ui.theme.brand500
Expand All @@ -55,10 +53,8 @@ import com.example.wallpapercollect.presentation.viewmodel.auth.Register
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import com.google.android.gms.auth.api.signin.GoogleSignInClient
import com.google.android.gms.auth.api.signin.GoogleSignInOptions


// TODO make null handler in register screen
@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter", "SetJavaScriptEnabled")
@Composable
fun RegisterEmailScreen(
Expand All @@ -67,20 +63,8 @@ fun RegisterEmailScreen(
gsc:GoogleSignInClient
) {

val launcher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult(),
onResult = {}
)
// val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
// .requestIdToken(stringResource(R.string.google_token))
// .requestProfile()
// .requestEmail()
// .build()
//
// val gsc = GoogleSignIn.getClient(LocalContext.current,gso)
val account: GoogleSignInAccount? = GoogleSignIn.getLastSignedInAccount(LocalContext.current)


var isRegisterEmailDefaultSessionClicked by rememberSaveable { mutableStateOf(false) }
var isRegisterGoogleSessionClicked by rememberSaveable { mutableStateOf(false) }
var isRegisterFacebookSessionClicked by rememberSaveable { mutableStateOf(false) }
Expand All @@ -89,6 +73,10 @@ fun RegisterEmailScreen(
val statusRegisterGoogleSession = register.registerGoogleSession.collectAsState(Status("")).value
val statusRegisterFacebookSession = register.registerFacebookSession.collectAsState(Url("","")).value

val launcher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult(),
onResult = {isRegisterGoogleSessionClicked = true}
)

var email by rememberSaveable { mutableStateOf("") }
var fullName by rememberSaveable { mutableStateOf("") }
Expand Down Expand Up @@ -128,7 +116,6 @@ fun RegisterEmailScreen(
isRegisterEmailDefaultSessionClicked = true
},
onClickRegisterGoogle = {
isRegisterGoogleSessionClicked = true
launcher.launch(gsc.signInIntent)

},
Expand All @@ -155,35 +142,30 @@ fun RegisterEmailScreen(
return
}

if (
statusRegisterGoogleSession.status=="ok"&&
account!!.idToken!=""&&
isRegisterGoogleSessionClicked
){
if (statusRegisterGoogleSession.status=="ok"){
isRegisterGoogleSessionClicked = false

navController.navigate(NavigationRouters.LOGIN){
popUpTo(NavigationRouters.REGISTER){inclusive = true}
}
return
}
if (
account!!.idToken!=""&&
isRegisterGoogleSessionClicked
){
register.postRegisterGoogleSession(Token(account.idToken?:""))
if (isRegisterGoogleSessionClicked){

if(account!=null) register.postRegisterGoogleSession(Token(account.idToken?:""))

return
}
//TODO make login/register facebook can run in this mobie app

if (
statusRegisterFacebookSession.status == "ok"&&
isRegisterFacebookSessionClicked
){
isRegisterFacebookSessionClicked = false
isRegisterFacebookSessionClicked = false //TODO make login/register facebook can run in this mobie app

return
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ import androidx.navigation.NavController
import com.example.wallpapercollect.presentation.ui.navigation.NavigationRouters
import com.example.wallpapercollect.presentation.viewmodel.profile.Profile
import com.example.wallpapercollect.splashlightv3.SplashLightV3
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
//import com.example.wallpapercollect.splashlightv3.SplashLightV3
import kotlinx.coroutines.delay


@Composable
fun SplashScreen(
navController: NavController,
profile: Profile = hiltViewModel()
navController: NavController
) {
val context = LocalContext.current
val info = profile.profileInfo.collectAsState().value
val account: GoogleSignInAccount? = GoogleSignIn.getLastSignedInAccount(context)
SplashLightV3()

var navigateStart by remember{ mutableStateOf(false) }
Expand All @@ -37,7 +38,7 @@ fun SplashScreen(

if(navigateStart){
navigateStart = false
if (info.status =="ok") {
if (account!=null) {
navController.navigate(NavigationRouters.WALLPAPER){
popUpTo(NavigationRouters.SPLASHSCREEN){inclusive = true}
}
Expand Down
Loading

0 comments on commit 04b3214

Please sign in to comment.