fix: google account login
This commit is contained in:
@@ -27,14 +27,15 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.viewinterop.AndroidView
|
import androidx.compose.ui.viewinterop.AndroidView
|
||||||
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
|
||||||
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import com.aurora.gplayapi.helpers.AuthHelper
|
import com.aurora.gplayapi.helpers.AuthHelper
|
||||||
import com.aurora.store.AuroraApp
|
import com.aurora.store.AuroraApp
|
||||||
import com.aurora.store.R
|
import com.aurora.store.R
|
||||||
import com.aurora.store.compose.navigation.Destination
|
import com.aurora.store.compose.navigation.Destination
|
||||||
import com.aurora.store.data.event.AuthEvent
|
import com.aurora.store.data.event.AuthEvent
|
||||||
import com.aurora.store.data.model.AccountType
|
import com.aurora.store.data.model.AuthState
|
||||||
import com.aurora.store.data.providers.AccountProvider
|
|
||||||
import com.aurora.store.util.AC2DMUtil
|
import com.aurora.store.util.AC2DMUtil
|
||||||
|
import com.aurora.store.util.Preferences
|
||||||
import com.aurora.store.viewmodel.auth.AuthViewModel
|
import com.aurora.store.viewmodel.auth.AuthViewModel
|
||||||
|
|
||||||
private const val EMBEDDED_SETUP_URL = "https://accounts.google.com/EmbeddedSetup"
|
private const val EMBEDDED_SETUP_URL = "https://accounts.google.com/EmbeddedSetup"
|
||||||
@@ -48,6 +49,7 @@ fun GoogleLoginScreen(
|
|||||||
viewModel: AuthViewModel = hiltViewModel()
|
viewModel: AuthViewModel = hiltViewModel()
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
val authState by viewModel.authState.collectAsStateWithLifecycle()
|
||||||
var progress by remember { mutableFloatStateOf(0f) }
|
var progress by remember { mutableFloatStateOf(0f) }
|
||||||
var isIndeterminate by remember { mutableStateOf(true) }
|
var isIndeterminate by remember { mutableStateOf(true) }
|
||||||
var isLoading by remember { mutableStateOf(true) }
|
var isLoading by remember { mutableStateOf(true) }
|
||||||
@@ -56,22 +58,32 @@ fun GoogleLoginScreen(
|
|||||||
AuroraApp.events.authEvent.collect { event ->
|
AuroraApp.events.authEvent.collect { event ->
|
||||||
if (event is AuthEvent.GoogleLogin) {
|
if (event is AuthEvent.GoogleLogin) {
|
||||||
if (event.success) {
|
if (event.success) {
|
||||||
AccountProvider.login(
|
viewModel.buildGoogleAuthData(
|
||||||
context,
|
|
||||||
event.email,
|
event.email,
|
||||||
event.token,
|
event.token,
|
||||||
AuthHelper.Token.AAS,
|
AuthHelper.Token.AAS
|
||||||
AccountType.GOOGLE
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(context, R.string.toast_aas_token_failed, Toast.LENGTH_LONG)
|
Toast.makeText(context, R.string.toast_aas_token_failed, Toast.LENGTH_LONG)
|
||||||
.show()
|
.show()
|
||||||
|
onNavigateTo(Destination.Splash)
|
||||||
}
|
}
|
||||||
onNavigateTo(Destination.Splash)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(authState) {
|
||||||
|
when (authState) {
|
||||||
|
AuthState.SignedIn, AuthState.Valid -> onNavigateTo(
|
||||||
|
Destination.Main(
|
||||||
|
Preferences.getInteger(context, Preferences.PREFERENCE_DEFAULT_SELECTED_TAB)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
is AuthState.Failed -> onNavigateTo(Destination.Splash)
|
||||||
|
else -> Unit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Column(modifier = Modifier.fillMaxSize()) {
|
Column(modifier = Modifier.fillMaxSize()) {
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
if (isIndeterminate) {
|
if (isIndeterminate) {
|
||||||
|
|||||||
Reference in New Issue
Block a user