|
@@ -4,6 +4,7 @@ package com.vpn.fastestvpnservice.screens
|
|
import android.content.res.Configuration
|
|
import android.content.res.Configuration
|
|
import android.gesture.Gesture
|
|
import android.gesture.Gesture
|
|
import android.util.Log
|
|
import android.util.Log
|
|
|
|
+import android.widget.TextView
|
|
import android.widget.Toast
|
|
import android.widget.Toast
|
|
import androidx.activity.OnBackPressedCallback
|
|
import androidx.activity.OnBackPressedCallback
|
|
import androidx.compose.foundation.BorderStroke
|
|
import androidx.compose.foundation.BorderStroke
|
|
@@ -35,11 +36,13 @@ import androidx.compose.foundation.text.KeyboardActionScope
|
|
import androidx.compose.foundation.text.KeyboardActions
|
|
import androidx.compose.foundation.text.KeyboardActions
|
|
import androidx.compose.foundation.text.KeyboardOptions
|
|
import androidx.compose.foundation.text.KeyboardOptions
|
|
import androidx.compose.material.icons.Icons
|
|
import androidx.compose.material.icons.Icons
|
|
|
|
+import androidx.compose.material.icons.filled.AddAlert
|
|
import androidx.compose.material.icons.filled.Email
|
|
import androidx.compose.material.icons.filled.Email
|
|
import androidx.compose.material.icons.filled.Home
|
|
import androidx.compose.material.icons.filled.Home
|
|
import androidx.compose.material.icons.filled.Lock
|
|
import androidx.compose.material.icons.filled.Lock
|
|
import androidx.compose.material.icons.filled.Visibility
|
|
import androidx.compose.material.icons.filled.Visibility
|
|
import androidx.compose.material.icons.filled.VisibilityOff
|
|
import androidx.compose.material.icons.filled.VisibilityOff
|
|
|
|
+import androidx.compose.material.icons.filled.Warning
|
|
import androidx.compose.material.icons.outlined.Visibility
|
|
import androidx.compose.material.icons.outlined.Visibility
|
|
import androidx.compose.material3.Button
|
|
import androidx.compose.material3.Button
|
|
import androidx.compose.material3.ButtonColors
|
|
import androidx.compose.material3.ButtonColors
|
|
@@ -50,6 +53,9 @@ import androidx.compose.material3.ElevatedButton
|
|
import androidx.compose.material3.Icon
|
|
import androidx.compose.material3.Icon
|
|
import androidx.compose.material3.IconButton
|
|
import androidx.compose.material3.IconButton
|
|
import androidx.compose.material3.MaterialTheme
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
|
+import androidx.compose.material3.OutlinedTextField
|
|
|
|
+import androidx.compose.material3.Shapes
|
|
|
|
+import androidx.compose.material3.SnackbarDefaults
|
|
import androidx.compose.material3.Text
|
|
import androidx.compose.material3.Text
|
|
import androidx.compose.material3.TextField
|
|
import androidx.compose.material3.TextField
|
|
import androidx.compose.material3.TextFieldColors
|
|
import androidx.compose.material3.TextFieldColors
|
|
@@ -102,6 +108,7 @@ import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.AddText
|
|
import com.vpn.fastestvpnservice.sealedClass.Screen
|
|
import com.vpn.fastestvpnservice.sealedClass.Screen
|
|
import com.vpn.fastestvpnservice.ui.theme.outfitFontFamily
|
|
import com.vpn.fastestvpnservice.ui.theme.outfitFontFamily
|
|
import com.vpn.fastestvpnservice.viewmodels.LoginViewModel
|
|
import com.vpn.fastestvpnservice.viewmodels.LoginViewModel
|
|
|
|
+import com.vpn.fastestvpnservice.views.CustomValidation
|
|
import kotlinx.coroutines.delay
|
|
import kotlinx.coroutines.delay
|
|
import kotlin.coroutines.coroutineContext
|
|
import kotlin.coroutines.coroutineContext
|
|
import kotlin.random.Random
|
|
import kotlin.random.Random
|
|
@@ -119,6 +126,11 @@ fun Login(navHostController: NavHostController) {
|
|
var textChanged by remember { mutableStateOf("") }
|
|
var textChanged by remember { mutableStateOf("") }
|
|
var passwordChanged by remember { mutableStateOf("") }
|
|
var passwordChanged by remember { mutableStateOf("") }
|
|
var passwordVisible by remember { mutableStateOf(false) }
|
|
var passwordVisible by remember { mutableStateOf(false) }
|
|
|
|
+ var showErrorEmail by remember { mutableStateOf(false) }
|
|
|
|
+ var showErrorPass1 by remember { mutableStateOf(false) }
|
|
|
|
+ var showErrorPass2 by remember { mutableStateOf(false) }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
val context = LocalContext.current
|
|
val context = LocalContext.current
|
|
var basePreferenceHelper = BasePreferenceHelper(context)
|
|
var basePreferenceHelper = BasePreferenceHelper(context)
|
|
@@ -167,7 +179,7 @@ fun Login(navHostController: NavHostController) {
|
|
Spacer(modifier = Modifier.height(50.dp))
|
|
Spacer(modifier = Modifier.height(50.dp))
|
|
|
|
|
|
TextMsg(
|
|
TextMsg(
|
|
- text = "Welcome Back!",
|
|
|
|
|
|
+ text = "Welcome Back! $showErrorPass2",
|
|
color = Color.White,
|
|
color = Color.White,
|
|
style = MaterialTheme.typography.displayLarge
|
|
style = MaterialTheme.typography.displayLarge
|
|
)
|
|
)
|
|
@@ -185,6 +197,7 @@ fun Login(navHostController: NavHostController) {
|
|
|
|
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
|
|
|
|
|
+
|
|
TextField(
|
|
TextField(
|
|
value = textChanged,
|
|
value = textChanged,
|
|
onValueChange = {
|
|
onValueChange = {
|
|
@@ -206,7 +219,8 @@ fun Login(navHostController: NavHostController) {
|
|
.height(60.dp)
|
|
.height(60.dp)
|
|
.border(
|
|
.border(
|
|
1.dp,
|
|
1.dp,
|
|
- color = colorResource(id = R.color.white),
|
|
|
|
|
|
+ color = if (showErrorEmail) colorResource(id = R.color.red)
|
|
|
|
+ else colorResource(id = R.color.white),
|
|
shape = RoundedCornerShape(16.dp)
|
|
shape = RoundedCornerShape(16.dp)
|
|
)
|
|
)
|
|
.clickable() { },
|
|
.clickable() { },
|
|
@@ -256,8 +270,23 @@ fun Login(navHostController: NavHostController) {
|
|
|
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+ if (showErrorEmail) {
|
|
|
|
+ ShowErrorRow(errorText = "Email is Empty")
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
|
|
|
|
|
|
+ val color = if (showErrorPass1) {
|
|
|
|
+ colorResource(id = R.color.red)
|
|
|
|
+ }
|
|
|
|
+ else if (showErrorPass2) {
|
|
|
|
+ colorResource(id = R.color.red)
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ colorResource(id = R.color.grey_password_field)
|
|
|
|
+ }
|
|
|
|
+
|
|
TextField(
|
|
TextField(
|
|
value = passwordChanged,
|
|
value = passwordChanged,
|
|
onValueChange = {
|
|
onValueChange = {
|
|
@@ -281,11 +310,11 @@ fun Login(navHostController: NavHostController) {
|
|
.height(60.dp)
|
|
.height(60.dp)
|
|
.border(
|
|
.border(
|
|
1.dp,
|
|
1.dp,
|
|
- color = colorResource(id = R.color.grey_password_field),
|
|
|
|
|
|
+ color = color,
|
|
shape = RoundedCornerShape(16.dp)
|
|
shape = RoundedCornerShape(16.dp)
|
|
)
|
|
)
|
|
.background(color = colorResource(id = R.color.transparent))
|
|
.background(color = colorResource(id = R.color.transparent))
|
|
- .clickable() { },
|
|
|
|
|
|
+ .clickable() {},
|
|
|
|
|
|
shape = RoundedCornerShape(15.dp),
|
|
shape = RoundedCornerShape(15.dp),
|
|
// placeholder = {
|
|
// placeholder = {
|
|
@@ -368,6 +397,14 @@ fun Login(navHostController: NavHostController) {
|
|
}
|
|
}
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+ if (showErrorPass1) {
|
|
|
|
+ ShowErrorRow(errorText = "Password is Empty")
|
|
|
|
+ }
|
|
|
|
+ else if (showErrorPass2) {
|
|
|
|
+ ShowErrorRow(errorText = "Should be 3 or more!")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
Spacer(modifier = Modifier.height(20.dp))
|
|
ClickableText(
|
|
ClickableText(
|
|
onClick = {
|
|
onClick = {
|
|
@@ -396,7 +433,19 @@ fun Login(navHostController: NavHostController) {
|
|
textChanged,
|
|
textChanged,
|
|
passwordChanged,
|
|
passwordChanged,
|
|
loginViewModel = loginViewModel,
|
|
loginViewModel = loginViewModel,
|
|
- basePreferenceHelper
|
|
|
|
|
|
+ basePreferenceHelper,
|
|
|
|
+ showErrorEmail = {
|
|
|
|
+ showErrorEmail = it
|
|
|
|
+ },
|
|
|
|
+ showErrorEmail,
|
|
|
|
+ showErrorPass = {
|
|
|
|
+ showErrorPass1 = it
|
|
|
|
+ },
|
|
|
|
+ showErrorPass1,
|
|
|
|
+ showErrorPass2 = {
|
|
|
|
+ showErrorPass2 = it
|
|
|
|
+ },
|
|
|
|
+ showErrorPass2
|
|
)
|
|
)
|
|
Row (
|
|
Row (
|
|
modifier = Modifier
|
|
modifier = Modifier
|
|
@@ -404,31 +453,36 @@ fun Login(navHostController: NavHostController) {
|
|
.padding(57.dp),
|
|
.padding(57.dp),
|
|
){
|
|
){
|
|
TextMsgSignUp(navHostController = navHostController, loginViewModel, readOnly!!)
|
|
TextMsgSignUp(navHostController = navHostController, loginViewModel, readOnly!!)
|
|
-// Text(
|
|
|
|
-// modifier = Modifier
|
|
|
|
-// .padding(0.dp),
|
|
|
|
-// fontSize = 14.sp,
|
|
|
|
-// fontWeight = FontWeight.Normal,
|
|
|
|
-// fontStyle = FontStyle.Normal,
|
|
|
|
-// text = "Don't have an account? ",
|
|
|
|
-// color = Color.White,
|
|
|
|
-// )
|
|
|
|
-// ClickableText(
|
|
|
|
-// onClick = {
|
|
|
|
-// navHostController.navigate(Screen.SignUp.route)
|
|
|
|
-// },
|
|
|
|
-// modifier = Modifier
|
|
|
|
-// .padding(0.dp),
|
|
|
|
-// style = TextStyle(
|
|
|
|
-// fontSize = 14.sp,
|
|
|
|
-// fontStyle = FontStyle.Normal,
|
|
|
|
-// color = colorResource(id = R.color.yellow_text),
|
|
|
|
-// ),
|
|
|
|
-// text = AnnotatedString(" Sign Up"),
|
|
|
|
-// )
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
|
|
|
|
+@Composable
|
|
|
|
+fun ColumnScope.ShowErrorRow(
|
|
|
|
+ errorText: String
|
|
|
|
+) {
|
|
|
|
+ Row(
|
|
|
|
+ verticalAlignment = Alignment.CenterVertically,
|
|
|
|
+ modifier = Modifier
|
|
|
|
+ .align(Alignment.Start)
|
|
|
|
+ .padding(start = 16.dp, top = 8.dp)
|
|
|
|
+ ) {
|
|
|
|
+ Icon(imageVector = Icons.Default.Warning,
|
|
|
|
+ contentDescription = "Error",
|
|
|
|
+ tint = colorResource(id = R.color.red),
|
|
|
|
+ modifier = Modifier.size(14.dp)
|
|
|
|
+ )
|
|
|
|
+ Text(text = errorText,
|
|
|
|
+ style = TextStyle(
|
|
|
|
+ fontFamily = outfitFontFamily,
|
|
|
|
+ fontWeight = FontWeight.Normal,
|
|
|
|
+ fontSize = 14.sp,
|
|
|
|
+ color = colorResource(id = R.color.red)
|
|
|
|
+ ),
|
|
|
|
+ modifier = Modifier.padding(start = 5.dp)
|
|
|
|
+ )
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Composable
|
|
@Composable
|
|
@@ -477,10 +531,16 @@ fun BoxScope.SignInButton(
|
|
email: String,
|
|
email: String,
|
|
password: String,
|
|
password: String,
|
|
loginViewModel: LoginViewModel,
|
|
loginViewModel: LoginViewModel,
|
|
- prefHelper: BasePreferenceHelper
|
|
|
|
|
|
+ prefHelper: BasePreferenceHelper,
|
|
|
|
+ showErrorEmail: (Boolean) -> Unit,
|
|
|
|
+ isError: Boolean,
|
|
|
|
+ showErrorPass: (Boolean) -> Unit,
|
|
|
|
+ isErrorPass: Boolean,
|
|
|
|
+ showErrorPass2: (Boolean) -> Unit,
|
|
|
|
+ isErrorPass2: Boolean
|
|
) {
|
|
) {
|
|
// var showLoader by remember { mutableStateOf(false) }
|
|
// var showLoader by remember { mutableStateOf(false) }
|
|
-
|
|
|
|
|
|
+// Log.d("test_login_text", "$email $password")
|
|
if (loginViewModel.liveDataLoginStatus.value == true) {
|
|
if (loginViewModel.liveDataLoginStatus.value == true) {
|
|
var progress by remember { mutableFloatStateOf(0.1F) }
|
|
var progress by remember { mutableFloatStateOf(0.1F) }
|
|
|
|
|
|
@@ -503,6 +563,28 @@ fun BoxScope.SignInButton(
|
|
strokeWidth = 5.dp,
|
|
strokeWidth = 5.dp,
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
+ val customValidation = CustomValidation()
|
|
|
|
+
|
|
|
|
+ if (isError) {
|
|
|
|
+ if (email.isNotEmpty()) {
|
|
|
|
+ showErrorEmail(false)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (isErrorPass) {
|
|
|
|
+ if (password.isNotEmpty()) {
|
|
|
|
+ showErrorPass(false)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (isErrorPass2) {
|
|
|
|
+ if (password.isNotEmpty()) {
|
|
|
|
+ val isErrorPassSize = customValidation.isValidPassword(password)
|
|
|
|
+ if (isErrorPassSize) {
|
|
|
|
+ showErrorPass2(false)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
Button(
|
|
Button(
|
|
modifier = Modifier
|
|
modifier = Modifier
|
|
@@ -517,19 +599,37 @@ fun BoxScope.SignInButton(
|
|
.clickable() { },
|
|
.clickable() { },
|
|
onClick = {
|
|
onClick = {
|
|
Log.d("test_api_response live", "Login Clicked:")
|
|
Log.d("test_api_response live", "Login Clicked:")
|
|
|
|
+
|
|
|
|
+ val isErrors = customValidation.isValidText(email, "Email")
|
|
|
|
+ showErrorEmail(!isErrors)
|
|
|
|
+
|
|
|
|
+ val isError1 = customValidation.isValidText(password, "Password")
|
|
|
|
+ showErrorPass(!isError1)
|
|
|
|
+
|
|
|
|
+ val isError2 = customValidation.isValidPassword(password)
|
|
|
|
+ if (password.isNotEmpty()) {
|
|
|
|
+ showErrorPass2(!isError2)
|
|
|
|
+ }
|
|
|
|
+
|
|
// showLoader = true
|
|
// showLoader = true
|
|
if (loginViewModel.liveDataLoginStatus.value == false) {
|
|
if (loginViewModel.liveDataLoginStatus.value == false) {
|
|
Log.d("test_api_response live", "SignIn: $email $password")
|
|
Log.d("test_api_response live", "SignIn: $email $password")
|
|
|
|
|
|
- if (email.isNotEmpty() && password.isNotEmpty()) {
|
|
|
|
- loginViewModel.setLoginStatus(true)
|
|
|
|
- loginViewModel.loginRequest(
|
|
|
|
- email,
|
|
|
|
- password,
|
|
|
|
- "android",
|
|
|
|
- "11",
|
|
|
|
- "3.2.4"
|
|
|
|
- )
|
|
|
|
|
|
+ if (customValidation.isValidText(email, "Email") &&
|
|
|
|
+ customValidation.isValidText(password, "Password") &&
|
|
|
|
+ customValidation.isValidPassword(password)) {
|
|
|
|
+ Log.d("test_login_text", "true")
|
|
|
|
+
|
|
|
|
+ if (email.isNotEmpty() && password.isNotEmpty()) {
|
|
|
|
+ loginViewModel.setLoginStatus(true)
|
|
|
|
+ loginViewModel.loginRequest(
|
|
|
|
+ email,
|
|
|
|
+ password,
|
|
|
|
+ "android",
|
|
|
|
+ "11",
|
|
|
|
+ "3.2.4"
|
|
|
|
+ )
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -543,7 +643,8 @@ fun BoxScope.SignInButton(
|
|
)
|
|
)
|
|
{
|
|
{
|
|
Text(text = "Sign In",
|
|
Text(text = "Sign In",
|
|
- style = MaterialTheme.typography.titleMedium
|
|
|
|
|
|
+ style = MaterialTheme.typography.titleMedium,
|
|
|
|
+ textAlign = TextAlign.Center
|
|
)
|
|
)
|
|
|
|
|
|
val loginData by loginViewModel.liveDataUserResponse.observeAsState()
|
|
val loginData by loginViewModel.liveDataUserResponse.observeAsState()
|