|
@@ -25,20 +25,26 @@ import androidx.compose.foundation.text.KeyboardActions
|
|
|
import androidx.compose.foundation.text.KeyboardOptions
|
|
|
import androidx.compose.material3.Button
|
|
|
import androidx.compose.material3.ButtonDefaults
|
|
|
+import androidx.compose.material3.CircularProgressIndicator
|
|
|
import androidx.compose.material3.Icon
|
|
|
import androidx.compose.material3.IconButton
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
+import androidx.compose.material3.SnackbarHostState
|
|
|
import androidx.compose.material3.Surface
|
|
|
import androidx.compose.material3.Text
|
|
|
import androidx.compose.material3.TextField
|
|
|
import androidx.compose.material3.TextFieldDefaults
|
|
|
import androidx.compose.runtime.Composable
|
|
|
+import androidx.compose.runtime.LaunchedEffect
|
|
|
import androidx.compose.runtime.getValue
|
|
|
+import androidx.compose.runtime.mutableFloatStateOf
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
import androidx.compose.runtime.remember
|
|
|
+import androidx.compose.runtime.rememberCoroutineScope
|
|
|
import androidx.compose.runtime.setValue
|
|
|
import androidx.compose.ui.Alignment
|
|
|
import androidx.compose.ui.Modifier
|
|
|
+import androidx.compose.ui.draw.alpha
|
|
|
import androidx.compose.ui.draw.clip
|
|
|
import androidx.compose.ui.focus.FocusManager
|
|
|
import androidx.compose.ui.graphics.ColorFilter
|
|
@@ -59,7 +65,9 @@ import androidx.compose.ui.text.style.TextAlign
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
import com.fastest.pass.R
|
|
|
-import com.fastest.pass.login.data.model.LoginResult
|
|
|
+import com.fastest.views.ShowCustomSnackBar
|
|
|
+import kotlinx.coroutines.delay
|
|
|
+import kotlinx.coroutines.launch
|
|
|
|
|
|
enum class ClickType {
|
|
|
SIGNUP_CLICK,
|
|
@@ -72,7 +80,7 @@ enum class ClickType {
|
|
|
|
|
|
@Composable
|
|
|
fun LoginScreen(
|
|
|
- loginResult: LoginResult,
|
|
|
+ loader: Boolean,
|
|
|
clickType: (ClickType) -> Unit,
|
|
|
onLoginClickCredentials: (String, String) -> Unit
|
|
|
) {
|
|
@@ -80,10 +88,14 @@ fun LoginScreen(
|
|
|
val focusManager = LocalFocusManager.current
|
|
|
var emailLogin by remember { mutableStateOf("") }
|
|
|
var passwordLogin by remember { mutableStateOf("") }
|
|
|
+ val snackBarStateRed = remember { SnackbarHostState() }
|
|
|
+
|
|
|
+ Log.d("loginResult", "loader = $loader")
|
|
|
|
|
|
Box(
|
|
|
modifier = Modifier
|
|
|
.background(colorResource(id = R.color.blue_login))
|
|
|
+ .alpha(if (loader) 0.7f else 1f)
|
|
|
.fillMaxSize()
|
|
|
.statusBarsPadding()
|
|
|
.pointerInput(Unit) {
|
|
@@ -93,12 +105,15 @@ fun LoginScreen(
|
|
|
}
|
|
|
}
|
|
|
) {
|
|
|
+
|
|
|
Column(
|
|
|
modifier = Modifier
|
|
|
.fillMaxSize()
|
|
|
.padding(top = 0.dp)
|
|
|
.statusBarsPadding()
|
|
|
) {
|
|
|
+ ShowCustomSnackBar(snackBarStateRed, R.color.red_login_button, R.color.white)
|
|
|
+
|
|
|
ShowHeaderLogin(text = stringResource(R.string.login)) { clickType ->
|
|
|
clickType(clickType)
|
|
|
}
|
|
@@ -112,6 +127,7 @@ fun LoginScreen(
|
|
|
colorResource(id = R.color.light_gray_login),
|
|
|
)
|
|
|
) {
|
|
|
+
|
|
|
ShowWelcomeText(R.string.login_to_continue)
|
|
|
LoginTextField(keyboardController, focusManager, onEmailText = {
|
|
|
emailLogin = it
|
|
@@ -121,11 +137,18 @@ fun LoginScreen(
|
|
|
passwordLogin = it
|
|
|
})
|
|
|
Spacer(modifier = Modifier.height(25.dp))
|
|
|
- LoginButton(buttonText = R.string.login, clickType = { clickType ->
|
|
|
+ LoginButton(
|
|
|
+ buttonText = R.string.login,
|
|
|
+ clickType = { clickType ->
|
|
|
clickType(clickType)
|
|
|
- }, email = emailLogin, password = passwordLogin, onLoginClickCredentials = { email, password ->
|
|
|
+ },
|
|
|
+ email = emailLogin,
|
|
|
+ password = passwordLogin,
|
|
|
+ onLoginClickCredentials = { email, password ->
|
|
|
onLoginClickCredentials.invoke(email, password)
|
|
|
- })
|
|
|
+ },
|
|
|
+ snackBarStateRed = snackBarStateRed
|
|
|
+ )
|
|
|
ForgotPasswordText() { clickType ->
|
|
|
clickType(clickType)
|
|
|
}
|
|
@@ -134,21 +157,30 @@ fun LoginScreen(
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- when (loginResult) {
|
|
|
- is LoginResult.Error -> {
|
|
|
- Log.d("loginResult", "Error")
|
|
|
- }
|
|
|
- LoginResult.Loading -> {
|
|
|
- Log.d("loginResult", "Loading")
|
|
|
- }
|
|
|
- LoginResult.None -> {
|
|
|
- Log.d("loginResult", "None")
|
|
|
- }
|
|
|
- is LoginResult.Success -> {
|
|
|
- Log.d("loginResult", "Success")
|
|
|
+ if (loader) {
|
|
|
+ var progress by remember { mutableFloatStateOf(0.1F) }
|
|
|
+
|
|
|
+ LaunchedEffect(key1 = Unit) {
|
|
|
+ while (true) {
|
|
|
+ for (i in 1..100) {
|
|
|
+ progress = i.toFloat()/100F
|
|
|
+ delay(50)
|
|
|
+ }
|
|
|
+ progress = 0.1F
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ CircularProgressIndicator(
|
|
|
+ progress = { progress },
|
|
|
+ modifier = Modifier
|
|
|
+ .size(50.dp)
|
|
|
+ .align(Alignment.Center),
|
|
|
+ color = colorResource(id = R.color.yellow_text),
|
|
|
+ strokeWidth = 5.dp,
|
|
|
+ )
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -401,8 +433,12 @@ fun ColumnScope.LoginButton(
|
|
|
clickType: (ClickType) -> Unit,
|
|
|
email: String,
|
|
|
password: String,
|
|
|
- onLoginClickCredentials: (String, String) -> Unit
|
|
|
+ onLoginClickCredentials: (String, String) -> Unit,
|
|
|
+ snackBarStateRed: SnackbarHostState
|
|
|
) {
|
|
|
+ val coroutineScope = rememberCoroutineScope()
|
|
|
+ val context = LocalContext.current
|
|
|
+
|
|
|
Button(
|
|
|
modifier = Modifier
|
|
|
.padding(start = 30.dp, end = 30.dp)
|
|
@@ -416,6 +452,14 @@ fun ColumnScope.LoginButton(
|
|
|
|
|
|
if (email.isNotEmpty() && password.isNotEmpty()) {
|
|
|
onLoginClickCredentials.invoke(email, password)
|
|
|
+ } else if (email.isEmpty()) {
|
|
|
+ coroutineScope.launch {
|
|
|
+ snackBarStateRed.showSnackbar(context.getString(R.string.email_field_req))
|
|
|
+ }
|
|
|
+ } else if (password.isEmpty()) {
|
|
|
+ coroutineScope.launch {
|
|
|
+ snackBarStateRed.showSnackbar(context.getString(R.string.password_field_req))
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
shape = RoundedCornerShape(15.dp),
|