Skip to content

Commit

Permalink
Merge pull request #92 from sheikh-20/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sheikh-20 authored Jun 27, 2024
2 parents 43d3385 + 23c6130 commit d2a2e73
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
// }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ fun SignupWithPasswordScreen(modifier: Modifier = Modifier,
onSocialSignIn: SharedFlow<Resource<AuthResult>>? = null,
onSignInClick: () -> Unit = { },
snackbarHostState: SnackbarHostState = SnackbarHostState(),
signupUIState: OnboardUIState = OnboardUIState()) {
signupUIState: OnboardUIState = OnboardUIState(),
sendVerificationEmail: (() -> Unit, (Exception) -> Unit) -> Unit = { _, _ -> }) {

val context = LocalContext.current
val coroutineScope = rememberCoroutineScope()
Expand Down Expand Up @@ -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())
}
}
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit d2a2e73

Please sign in to comment.