Skip to content

Commit

Permalink
added progress dialog in sign-in screen
Browse files Browse the repository at this point in the history
  • Loading branch information
binayshaw7777 committed May 19, 2024
1 parent 01ded61 commit a5f646b
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import androidx.core.view.WindowCompat
import androidx.hilt.navigation.compose.hiltViewModel
import com.binay.shaw.justap.R
import com.binay.shaw.justap.presentation.authentication.FirebaseViewModel
import com.binay.shaw.justap.presentation.components.MyButton
import com.binay.shaw.justap.presentation.components.ProgressDialog
import com.binay.shaw.justap.presentation.themes.DMSansFontFamily
import com.binay.shaw.justap.presentation.themes.JusTapTheme
Expand Down Expand Up @@ -161,22 +162,24 @@ fun ForgotPasswordContent(

Spacer(Modifier.weight(1f))

Button(
onClick = {
if (context.isNetworkAvailable()) {
isLoading = true
firebaseViewModel.resetPassword(userEmail)
} else {
Toast.makeText(context, context.getString(R.string.noInternet), Toast.LENGTH_SHORT).show()
}
},
MyButton(
text = stringResource(R.string.sendResetLink),
modifier = Modifier
.fillMaxWidth()
.align(Alignment.End),
colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.primaryContainer),
enabled = enableSendEmailButton
) {
Text("Login", color = MaterialTheme.colorScheme.onPrimaryContainer)
if (context.isNetworkAvailable()) {
isLoading = true
firebaseViewModel.resetPassword(userEmail)
} else {
Toast.makeText(
context,
context.getString(R.string.noInternet),
Toast.LENGTH_SHORT
).show()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.binay.shaw.justap.presentation.authentication.signInScreen

import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
Expand All @@ -22,8 +23,6 @@ import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Key
import androidx.compose.material.icons.filled.MailOutline
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
Expand Down Expand Up @@ -51,15 +50,18 @@ import androidx.core.view.WindowCompat
import androidx.hilt.navigation.compose.hiltViewModel
import com.binay.shaw.justap.R
import com.binay.shaw.justap.presentation.MainActivity
import com.binay.shaw.justap.presentation.authentication.FirebaseViewModel
import com.binay.shaw.justap.presentation.authentication.forgotPassword.ForgotPasswordScreen
import com.binay.shaw.justap.presentation.components.MyButton
import com.binay.shaw.justap.presentation.components.ProgressDialog
import com.binay.shaw.justap.presentation.themes.DMSansFontFamily
import com.binay.shaw.justap.presentation.themes.JusTapTheme
import com.binay.shaw.justap.utilities.Util.findActivity
import com.binay.shaw.justap.utilities.Util.isNetworkAvailable
import com.binay.shaw.justap.utilities.Validator.Companion.isValidEmail
import com.binay.shaw.justap.utilities.Validator.Companion.isValidPassword
import com.binay.shaw.justap.utilities.onClick
import com.binay.shaw.justap.viewModel.AccountsViewModel
import com.binay.shaw.justap.presentation.authentication.FirebaseViewModel
import com.binay.shaw.justap.viewModel.LocalUserViewModel
import dagger.hilt.android.AndroidEntryPoint

Expand Down Expand Up @@ -104,6 +106,7 @@ fun SignInScreenContent(
}
val userLiveData by firebaseViewModel.userLiveData.observeAsState()
val errorLiveData by firebaseViewModel.errorLiveData.observeAsState()
var isLoading by remember { mutableStateOf(false) }

LaunchedEffect(userLiveData) {

Expand All @@ -116,7 +119,7 @@ fun SignInScreenContent(
accountsViewModel.insertAccount(account)
}
}

isLoading = false
val intent = Intent(context, MainActivity::class.java)
context.findActivity()?.let {
it.startActivity(intent)
Expand All @@ -125,6 +128,17 @@ fun SignInScreenContent(
}
}

LaunchedEffect(errorLiveData) {
errorLiveData?.let { error ->
isLoading = false
Toast.makeText(context, error, Toast.LENGTH_SHORT).show()
}
}

if (isLoading) {
ProgressDialog {}
}

Box(
modifier = Modifier
.fillMaxSize()
Expand Down Expand Up @@ -190,35 +204,39 @@ fun SignInScreenContent(
Spacer(Modifier.height(12.dp))

Text(
stringResource(R.string.forgot_password), modifier = Modifier
.align(Alignment.End)
.onClick {
context
.findActivity()
?.let {
it.startActivity(Intent(it, ForgotPasswordScreen::class.java))
}
})
text = stringResource(R.string.forgot_password), modifier = Modifier
.align(Alignment.End)
.onClick {
context
.findActivity()
?.let {
it.startActivity(Intent(it, ForgotPasswordScreen::class.java))
}
},
color = MaterialTheme.colorScheme.primary
)

Spacer(Modifier.weight(1f))

Button(
onClick = {
firebaseViewModel.logInUser(
userEmail, userPassword
)
},
MyButton(
text = stringResource(R.string.login),
enabled = enableLoginButton,
modifier = Modifier
.fillMaxWidth()
.align(Alignment.End),
colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.primaryContainer),
enabled = enableLoginButton
.align(Alignment.End)
) {
Text(
stringResource(R.string.login),
color = MaterialTheme.colorScheme.onPrimaryContainer,
style = TextStyle(fontWeight = FontWeight.Bold, fontFamily = DMSansFontFamily)
)
if (context.isNetworkAvailable()) {
isLoading = true
firebaseViewModel.logInUser(
userEmail, userPassword
)
} else {
Toast.makeText(
context,
context.getString(R.string.noInternet),
Toast.LENGTH_SHORT
).show()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.sp
import com.binay.shaw.justap.utilities.Logger
import com.binay.shaw.justap.presentation.themes.DMSansFontFamily
Expand All @@ -28,6 +30,8 @@ fun MyButton(
colors: ButtonColors = ButtonDefaults.buttonColors(
containerColor = MaterialTheme.colorScheme.primaryContainer
),
textColors: Color = MaterialTheme.colorScheme.onPrimaryContainer,
textSize: TextUnit = 14.sp,
elevation: ButtonElevation? = ButtonDefaults.buttonElevation(),
border: BorderStroke? = null,
contentPadding: PaddingValues = ButtonDefaults.ContentPadding,
Expand All @@ -47,9 +51,9 @@ fun MyButton(
) {
Text(
text = text,
color = MaterialTheme.colorScheme.onPrimaryContainer,
color = textColors,
fontFamily = DMSansFontFamily,
fontSize = 14.sp
fontSize = textSize
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
Expand All @@ -28,10 +29,10 @@ import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.binay.shaw.justap.R
import com.binay.shaw.justap.utilities.Util
import com.binay.shaw.justap.presentation.introduction.onboarding.OnboardingScreen
import com.binay.shaw.justap.presentation.MainActivity
import com.binay.shaw.justap.presentation.authentication.signInScreen.SignInScreen
import com.binay.shaw.justap.presentation.themes.JusTapTheme
import com.binay.shaw.justap.utilities.Util
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.delay

Expand All @@ -52,14 +53,17 @@ class SplashScreen : ComponentActivity() {

setContent {
JusTapTheme {
SplashContent(this@SplashScreen)
SplashContent(activity = this@SplashScreen)
}
}
}
}

@Composable
fun SplashContent(activity: Activity) {
fun SplashContent(
activity: Activity,
modifier: Modifier = Modifier
) {

var isUserLoggedIn: Boolean by remember {
mutableStateOf(false)
Expand All @@ -68,22 +72,22 @@ fun SplashContent(activity: Activity) {
LaunchedEffect(Unit) {
isUserLoggedIn = Util.isUserLoggedIn()

val intent: Intent = if (isUserLoggedIn) {
Intent(activity, MainActivity::class.java)
val activityToIntent = if (isUserLoggedIn) {
MainActivity::class.java
} else {
Intent(activity, OnboardingScreen::class.java)
SignInScreen::class.java
}

activity.run {
delay(1_000L)
startActivity(intent)
startActivity(Intent(this, activityToIntent))
finish()
}
}

Surface(
modifier = Modifier.fillMaxSize(),
color = Color.White
modifier = Modifier.fillMaxSize().then(modifier),
color = MaterialTheme.colorScheme.background
) {
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
Image(
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-hi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<string name="EditProfile">प्रोफ़ाइल एडिट करें</string>
<string name="AboutUs">हमारे बारे में</string>
<string name="LogIn">LogIn</string>
<string name="SendResetLink">रीसेट लिंक भेजें</string>
<string name="sendResetLink">रीसेट लिंक भेजें</string>
<string name="HowToUse">इसका उपयोग कैसे करें?</string>
<string name="HowToUseDescription">एक बार जब आप निचले दाएं कोने में तैरते हुए बटन से खाते जोड़ लेते हैं, तो आप सूची में अपने सभी अकाउंट को देख सकते हैं जैसा कि दिखाया गया है।\n\nसूची में प्रदर्शित होता है:\n1.नाम\n2.लोगो\n3.आपका अकाउंट डेटा\n4.स्विच\n\nस्विच को चालू/बंद करने से अकाउंट को आपकी QR को स्कैन किए जाने पर परिणाम में दिखाने/प्रतिबंधित करने की अनुमति मिलती है।\nदूसरे शब्दों में, स्विच को बंद करने से यह स्कैनर के परिणाम स्क्रीन में नहीं दिखाई देगा, और इसे चालू करने से यह दिखाई देगा और क्लिक करने योग्य भी होगा।</string>
<string name="EnterURLorUsername">यहाँ क्या ऐड करना चाहते हैं?</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<string name="EditProfile">Edit Profile</string>
<string name="AboutUs">About us</string>
<string name="LogIn">Log In</string>
<string name="SendResetLink">Send reset link</string>
<string name="sendResetLink">Send reset link</string>
<string name="HowToUse">How to use?</string>
<string name="HowToUseDescription">Once you add the accounts from the floating button at the bottom right corner, you can see all your accounts in the list as shown.\n\nThe list displays:\n1.Name\n2.Logo\n3.Your account data\n4.Switch\n\nTurning on/off the switch will allow/restrict the account to show in the result when your QR is scanned.\nIn other words, turning off the switch will not show it in the scanner\'s result screen, and turning it on will show and will be clickable as well.</string>
<string name="EnterURLorUsername">What to add here?</string>
Expand Down

0 comments on commit a5f646b

Please sign in to comment.