diff --git a/app/build.gradle.kts b/app/build.gradle.kts index b84993d..c009308 100755 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -53,8 +53,8 @@ android { applicationId = "com.application.moviesapp" minSdk = 24 targetSdk = 33 - versionCode = 23 - versionName = "1.0.22" + versionCode = 24 + versionName = "1.0.23" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" vectorDrawables { diff --git a/app/src/main/java/com/application/moviesapp/ui/home/HomeActivity.kt b/app/src/main/java/com/application/moviesapp/ui/home/HomeActivity.kt index 206d5b7..e907d8c 100755 --- a/app/src/main/java/com/application/moviesapp/ui/home/HomeActivity.kt +++ b/app/src/main/java/com/application/moviesapp/ui/home/HomeActivity.kt @@ -92,7 +92,7 @@ class HomeActivity : BaseActivity() { modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background ) { - if (viewModel.getUserInfo() != null) { + if (viewModel.getUserInfo() != null && viewModel.getUserInfo()?.isEmailVerified == true) { HomeApp() } else { OnboardingApp() diff --git a/app/src/main/java/com/application/moviesapp/ui/onboarding/OnboardingApp.kt b/app/src/main/java/com/application/moviesapp/ui/onboarding/OnboardingApp.kt index 6c8cae2..95c4540 100755 --- a/app/src/main/java/com/application/moviesapp/ui/onboarding/OnboardingApp.kt +++ b/app/src/main/java/com/application/moviesapp/ui/onboarding/OnboardingApp.kt @@ -7,7 +7,12 @@ import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.result.ActivityResultRegistryOwner import androidx.activity.result.IntentSenderRequest import androidx.activity.result.contract.ActivityResultContracts +import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.ExperimentalLayoutApi +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.padding import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.ArrowBack @@ -19,6 +24,7 @@ import androidx.compose.material3.Scaffold import androidx.compose.material3.SnackbarDuration import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHostState +import androidx.compose.material3.Text import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable @@ -29,6 +35,8 @@ import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.viewmodel.compose.viewModel import androidx.navigation.NavHostController @@ -79,7 +87,33 @@ fun OnboardingApp(modifier: Modifier = Modifier, Scaffold( topBar = { OnboardingAppBar(currentScreen = backStackEntry?.destination?.route ?: OnboardingScreen.Start.name, canNavigateBack = navController.previousBackStackEntry != null) { navController.navigateUp() } }, - snackbarHost = { SnackbarHost(snackbarHostState) } + snackbarHost = { + SnackbarHost(snackbarHostState) { + androidx.compose.material3.Snackbar( + modifier = modifier.padding(8.dp), + containerColor = MaterialTheme.colorScheme.background, + contentColor = MaterialTheme.colorScheme.onPrimary + ) { + Row(horizontalArrangement = Arrangement.SpaceBetween) { + Text(text = it.visuals.message, fontWeight = FontWeight.SemiBold) + + Spacer(modifier = modifier.weight(1f)) + + + Text( + text = it.visuals.actionLabel ?: "", + fontWeight = FontWeight.SemiBold, + color = MaterialTheme.colorScheme.primary, + modifier = modifier.clickable( + onClick = { it.performAction() }, + interactionSource = remember { MutableInteractionSource() }, + indication = null + ) + ) + } + } + } + } ) { innerPadding -> NavHost(modifier = modifier.padding(innerPadding), navController = navController, @@ -135,7 +169,10 @@ fun OnboardingApp(modifier: Modifier = Modifier, onGithubSignInClick = { onboardingViewModel.signInGithub(context as Activity) }, onSocialSignIn = onSocialSignIn, snackbarHostState = snackbarHostState, - signupUIState = signupUIState + signupUIState = signupUIState, + sendVerificationEmail = { onSuccess, onFailure -> + onboardingViewModel.sendVerificationEmail(onSuccess, onFailure) + } ) } diff --git a/app/src/main/java/com/application/moviesapp/ui/onboarding/login/LoginWithPasswordScreen.kt b/app/src/main/java/com/application/moviesapp/ui/onboarding/login/LoginWithPasswordScreen.kt index 9901fbc..13574bb 100755 --- a/app/src/main/java/com/application/moviesapp/ui/onboarding/login/LoginWithPasswordScreen.kt +++ b/app/src/main/java/com/application/moviesapp/ui/onboarding/login/LoginWithPasswordScreen.kt @@ -130,13 +130,23 @@ fun LoginWithPasswordScreen(modifier: Modifier = Modifier, isLoading = false Timber.tag("Login").d("Google Success") - if (it.data.additionalUserInfo?.isNewUser == true) { - (context as Activity).finish() - AccountSetupActivity.startActivity(context as Activity) - } else { - (context as Activity).finish() - HomeActivity.startActivity((context as Activity)) + if (it.data.user?.isEmailVerified == true) { + if (it.data.additionalUserInfo?.isNewUser == true) { + (context as Activity).finish() + AccountSetupActivity.startActivity(context as Activity) + } else { + (context as Activity).finish() + HomeActivity.startActivity((context as Activity)) + } } + +// if (it.data.additionalUserInfo?.isNewUser == true) { +// (context as Activity).finish() +// AccountSetupActivity.startActivity(context as Activity) +// } else { +// (context as Activity).finish() +// HomeActivity.startActivity((context as Activity)) +// } } } } diff --git a/app/src/main/java/com/application/moviesapp/ui/onboarding/signup/SignupWithPasswordScreen.kt b/app/src/main/java/com/application/moviesapp/ui/onboarding/signup/SignupWithPasswordScreen.kt index 7f40e6e..1e1f272 100755 --- a/app/src/main/java/com/application/moviesapp/ui/onboarding/signup/SignupWithPasswordScreen.kt +++ b/app/src/main/java/com/application/moviesapp/ui/onboarding/signup/SignupWithPasswordScreen.kt @@ -88,7 +88,8 @@ fun SignupWithPasswordScreen(modifier: Modifier = Modifier, onSocialSignIn: SharedFlow>? = null, onSignInClick: () -> Unit = { }, snackbarHostState: SnackbarHostState = SnackbarHostState(), - signupUIState: OnboardUIState = OnboardUIState()) { + signupUIState: OnboardUIState = OnboardUIState(), + sendVerificationEmail: (() -> Unit, (Exception) -> Unit) -> Unit = { _, _ -> }) { val context = LocalContext.current val coroutineScope = rememberCoroutineScope() @@ -135,12 +136,27 @@ fun SignupWithPasswordScreen(modifier: Modifier = Modifier, isLoading = false Timber.tag("Login").d("Google Success") - if (it.data.additionalUserInfo?.isNewUser == true) { - (context as Activity).finish() - AccountSetupActivity.startActivity(context as Activity) + if (it.data.user?.isEmailVerified == true) { + if (it.data.additionalUserInfo?.isNewUser == true) { + (context as Activity).finish() + AccountSetupActivity.startActivity(context as Activity) + } else { + (context as Activity).finish() + HomeActivity.startActivity((context as Activity)) + } } else { - (context as Activity).finish() - HomeActivity.startActivity((context as Activity)) + sendVerificationEmail( + { + coroutineScope.launch { + snackbarHostState.showSnackbar(message = "Check your inbox to verify email.") + } + }, + { + coroutineScope.launch { + snackbarHostState.showSnackbar(message = it.message.toString()) + } + } + ) } } } diff --git a/app/src/main/java/com/application/moviesapp/ui/viewmodel/OnboardingViewModel.kt b/app/src/main/java/com/application/moviesapp/ui/viewmodel/OnboardingViewModel.kt index c1838c2..50885be 100755 --- a/app/src/main/java/com/application/moviesapp/ui/viewmodel/OnboardingViewModel.kt +++ b/app/src/main/java/com/application/moviesapp/ui/viewmodel/OnboardingViewModel.kt @@ -236,6 +236,17 @@ class OnboardingViewModel @Inject constructor(private val movieGenresUseCase: Mo passwordResetUseCase.sendOtp(email) } + + fun sendVerificationEmail(onSuccess: () -> Unit, onFailure: (Exception) -> Unit) { + auth.currentUser?.sendEmailVerification()?.addOnCompleteListener { task -> + if (task.isSuccessful) { + onSuccess() + } else { + task.exception?.let { onFailure(it) } + } + } + } + init { showLoading() }