Browse Source

validation added on login and also showing snackbar custom..

Khubaib 1 year ago
parent
commit
a211fbea88

+ 325 - 303
app/src/main/java/com/vpn/fastestvpnservice/screens/LoginScreen.kt

@@ -30,11 +30,14 @@ import androidx.compose.foundation.layout.height
 import androidx.compose.foundation.layout.padding
 import androidx.compose.foundation.layout.size
 import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.rememberScrollState
 import androidx.compose.foundation.shape.RoundedCornerShape
 import androidx.compose.foundation.text.ClickableText
 import androidx.compose.foundation.text.KeyboardActionScope
 import androidx.compose.foundation.text.KeyboardActions
 import androidx.compose.foundation.text.KeyboardOptions
+import androidx.compose.material.Snackbar
+import androidx.compose.material.SnackbarDuration
 import androidx.compose.material.icons.Icons
 import androidx.compose.material.icons.filled.AddAlert
 import androidx.compose.material.icons.filled.Email
@@ -44,6 +47,7 @@ import androidx.compose.material.icons.filled.Visibility
 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.rememberScaffoldState
 import androidx.compose.material3.Button
 import androidx.compose.material3.ButtonColors
 import androidx.compose.material3.ButtonDefaults
@@ -54,8 +58,11 @@ import androidx.compose.material3.Icon
 import androidx.compose.material3.IconButton
 import androidx.compose.material3.MaterialTheme
 import androidx.compose.material3.OutlinedTextField
+import androidx.compose.material3.Scaffold
 import androidx.compose.material3.Shapes
 import androidx.compose.material3.SnackbarDefaults
+import androidx.compose.material3.SnackbarHost
+import androidx.compose.material3.SnackbarHostState
 import androidx.compose.material3.Text
 import androidx.compose.material3.TextField
 import androidx.compose.material3.TextFieldColors
@@ -69,6 +76,7 @@ import androidx.compose.runtime.mutableFloatStateOf
 import androidx.compose.runtime.mutableStateOf
 import androidx.compose.runtime.remember
 import androidx.compose.runtime.rememberCompositionContext
+import androidx.compose.runtime.rememberCoroutineScope
 import androidx.compose.ui.Alignment
 import androidx.compose.ui.ExperimentalComposeUiApi
 import androidx.compose.ui.Modifier
@@ -109,352 +117,355 @@ import com.vpn.fastestvpnservice.sealedClass.Screen
 import com.vpn.fastestvpnservice.ui.theme.outfitFontFamily
 import com.vpn.fastestvpnservice.viewmodels.LoginViewModel
 import com.vpn.fastestvpnservice.views.CustomValidation
+import com.vpn.fastestvpnservice.views.ShowCustomSnackBar
 import kotlinx.coroutines.delay
+import kotlinx.coroutines.launch
 import kotlin.coroutines.coroutineContext
 import kotlin.random.Random
 
 @OptIn(ExperimentalComposeUiApi::class)
 @Composable
 fun Login(navHostController: NavHostController) {
+
     val keyboardController = LocalSoftwareKeyboardController.current
     val focusManager = LocalFocusManager.current
     val random = Random.nextInt(1,999)
-
     val loginViewModel: LoginViewModel = viewModel()
     val readOnly = loginViewModel.liveDataLoginStatus.observeAsState().value
-
     var textChanged by remember { mutableStateOf("") }
     var passwordChanged by remember { mutableStateOf("") }
     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
-    var basePreferenceHelper = BasePreferenceHelper(context)
+    val basePreferenceHelper = BasePreferenceHelper(context)
+    val snackBarState = remember { SnackbarHostState() }
 
-    Box(
-        modifier = Modifier
-            .fillMaxSize()
-            .paint(
-                painter = painterResource(id = R.drawable.bg_img3),
-                contentScale = ContentScale.FillBounds
-            )
-            .alpha(if (readOnly == true) 0.6F else 1F)
+    Scaffold(
+        content = { padding ->
+            Box(
+                modifier = Modifier
+                    .fillMaxSize()
+                    .paint(
+                        painter = painterResource(id = R.drawable.bg_img3),
+                        contentScale = ContentScale.FillBounds
+                    )
+                    .alpha(if (readOnly == true) 0.6F else 1F)
 //            .background(
 //                if (isSystemInDarkTheme()) Color.Black
 //                else Color.Transparent
 //            )
-            .pointerInput(Unit) {
-                detectTapGestures {
-                    focusManager.clearFocus()
-                    keyboardController?.hide()
-                }
-            }
-        ,
-//        contentAlignment = Alignment.Center
-
-    ) {
-        Column (
-            modifier = Modifier
-                .fillMaxHeight()
-                .fillMaxWidth()
-            ,
-            verticalArrangement = Arrangement.Top,
-            horizontalAlignment = Alignment.CenterHorizontally
-        ) {
-            Spacer(modifier = Modifier.height(132.dp))
-            Image(
-                painter = painterResource(
-                    id = R.drawable.fastestapp_logo3x),
-                contentDescription = "FastestVPN",
-                modifier = Modifier
-                    .size(width = 75.dp, height = 102.dp)
-                    .background(Color.Transparent)
-                    .padding(top = 0.dp)
-                ,
-            )
-            Spacer(modifier = Modifier.height(50.dp))
-
-            TextMsg(
-                text = "Welcome Back! $showErrorPass2",
-                color = Color.White,
-                style = MaterialTheme.typography.displayLarge
-            )
-            Spacer(modifier = Modifier.height(8.dp))
-            TextMsg(
-                text = "Please login to your account.",
-                color = colorResource(id = R.color.light_grey),
-                style = TextStyle(
-                    fontFamily = outfitFontFamily,
-                    fontWeight = FontWeight.Normal,
-                    fontSize = 14.sp,
-                    lineHeight = 30.sp,
-                )
-            )
+                    .pointerInput(Unit) {
+                        detectTapGestures {
+                            focusManager.clearFocus()
+                            keyboardController?.hide()
+                        }
+                    },
+            ) {
+                ShowCustomSnackBar(snackBarState)
+
+                Column (
+                    modifier = Modifier
+                        .fillMaxHeight()
+                        .fillMaxWidth()
+                    ,
+                    verticalArrangement = Arrangement.Top,
+                    horizontalAlignment = Alignment.CenterHorizontally
+                ) {
+                    Spacer(modifier = Modifier.height(132.dp))
+                    Image(
+                        painter = painterResource(
+                            id = R.drawable.fastestapp_logo3x),
+                        contentDescription = "FastestVPN",
+                        modifier = Modifier
+                            .size(width = 75.dp, height = 102.dp)
+                            .background(Color.Transparent)
+                            .padding(top = 0.dp)
+                        ,
+                    )
+                    Spacer(modifier = Modifier.height(50.dp))
 
-            Spacer(modifier = Modifier.height(20.dp))
-
-
-            TextField(
-                value = textChanged,
-                onValueChange = {
-                    textChanged = it
-                },
-                readOnly = readOnly!!,
-                textStyle = TextStyle(
-                    color = colorResource(id = R.color.white),
-                    fontFamily = outfitFontFamily,
-                    fontWeight = FontWeight.Normal,
-                    fontSize = 14.sp,
-                    lineHeight = 22.sp,
-                    letterSpacing = 0.21.sp
-                ),
-                modifier = Modifier
-                    .padding(start = 15.dp, end = 15.dp)
-                    .align(Alignment.Start)
-                    .fillMaxWidth()
-                    .height(60.dp)
-                    .border(
-                        1.dp,
-                        color = if (showErrorEmail) colorResource(id = R.color.red)
-                        else colorResource(id = R.color.white),
-                        shape = RoundedCornerShape(16.dp)
+                    TextMsg(
+                        text = "Welcome Back!",
+                        color = Color.White,
+                        style = MaterialTheme.typography.displayLarge
                     )
-                    .clickable() { },
+                    Spacer(modifier = Modifier.height(8.dp))
+                    TextMsg(
+                        text = "Please login to your account.",
+                        color = colorResource(id = R.color.light_grey),
+                        style = TextStyle(
+                            fontFamily = outfitFontFamily,
+                            fontWeight = FontWeight.Normal,
+                            fontSize = 14.sp,
+                            lineHeight = 30.sp,
+                        )
+                    )
+
+                    Spacer(modifier = Modifier.height(20.dp))
+
+
+                    TextField(
+                        value = textChanged,
+                        onValueChange = {
+                            textChanged = it
+                        },
+                        readOnly = readOnly!!,
+                        textStyle = TextStyle(
+                            color = colorResource(id = R.color.white),
+                            fontFamily = outfitFontFamily,
+                            fontWeight = FontWeight.Normal,
+                            fontSize = 14.sp,
+                            lineHeight = 22.sp,
+                            letterSpacing = 0.21.sp
+                        ),
+                        modifier = Modifier
+                            .padding(start = 15.dp, end = 15.dp)
+                            .align(Alignment.Start)
+                            .fillMaxWidth()
+                            .height(60.dp)
+                            .border(
+                                1.dp,
+                                color = if (showErrorEmail) colorResource(id = R.color.red)
+                                else colorResource(id = R.color.white),
+                                shape = RoundedCornerShape(16.dp)
+                            )
+                            .clickable() { },
 
 //                placeholder = {
 //                    Text(text = "Enter email address",
 //                        color = colorResource(id = R.color.white))
 //                },
-                label = {
-                    Text(text = "Email",
-                        style = TextStyle(
-                            colorResource(id = R.color.white)),
-                        fontFamily = outfitFontFamily,
-                        fontWeight = FontWeight.Medium,
-                        fontSize = 12.sp,
-                        )
-                },
-                leadingIcon = {
-                    Icon(
-                        painter = painterResource(id = R.drawable.sms3x),
-                        contentDescription = "Email Logo",
-                        tint = colorResource(id = R.color.white),
-                        modifier = Modifier
-                            .size(24.dp, 24.dp)
-                    )
-                },
-                maxLines = 1,
-                colors = TextFieldDefaults.colors(
-                    focusedLabelColor = Color.Blue,
-                    unfocusedContainerColor = colorResource(id = R.color.transparent),
-                    focusedContainerColor = colorResource(id = R.color.transparent),
-                    focusedIndicatorColor = colorResource(id = R.color.transparent),
-                    disabledIndicatorColor = colorResource(id = R.color.transparent),
-                    unfocusedIndicatorColor = colorResource(id = R.color.transparent),
-                    cursorColor = colorResource(id = R.color.white)
-                ),
-                keyboardOptions = KeyboardOptions(
-                    keyboardType = KeyboardType.Email,
-                    imeAction = ImeAction.Done
-                ),
-                keyboardActions = KeyboardActions(
-                    onDone = {
-                        focusManager.clearFocus()
-                        keyboardController?.hide()
-                    }
-                ),
+                        label = {
+                            Text(text = "Email",
+                                style = TextStyle(
+                                    colorResource(id = R.color.white)),
+                                fontFamily = outfitFontFamily,
+                                fontWeight = FontWeight.Medium,
+                                fontSize = 12.sp,
+                            )
+                        },
+                        leadingIcon = {
+                            Icon(
+                                painter = painterResource(id = R.drawable.sms3x),
+                                contentDescription = "Email Logo",
+                                tint = colorResource(id = R.color.white),
+                                modifier = Modifier
+                                    .size(24.dp, 24.dp)
+                            )
+                        },
+                        maxLines = 1,
+                        colors = TextFieldDefaults.colors(
+                            focusedLabelColor = Color.Blue,
+                            unfocusedContainerColor = colorResource(id = R.color.transparent),
+                            focusedContainerColor = colorResource(id = R.color.transparent),
+                            focusedIndicatorColor = colorResource(id = R.color.transparent),
+                            disabledIndicatorColor = colorResource(id = R.color.transparent),
+                            unfocusedIndicatorColor = colorResource(id = R.color.transparent),
+                            cursorColor = colorResource(id = R.color.white)
+                        ),
+                        keyboardOptions = KeyboardOptions(
+                            keyboardType = KeyboardType.Email,
+                            imeAction = ImeAction.Done
+                        ),
+                        keyboardActions = KeyboardActions(
+                            onDone = {
+                                focusManager.clearFocus()
+                                keyboardController?.hide()
+                            }
+                        ),
 
-            )
+                        )
 
-            if (showErrorEmail) {
-                ShowErrorRow(errorText = "Email is Empty")
+                    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)
-            }
+                    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(
-                value = passwordChanged,
-                onValueChange = {
-                    Log.d("onClick_test", "onValueChange -> ")
-                    passwordChanged = it
-                },
-                readOnly = readOnly,
-
-                textStyle = TextStyle(
-                    color = colorResource(id = R.color.white),
-                    fontFamily = outfitFontFamily,
-                    fontWeight = FontWeight.Normal,
-                    fontSize = 14.sp,
-                    lineHeight = 22.sp,
-                    letterSpacing = 0.21.sp
-                    ),
-                modifier = Modifier
-                    .padding(start = 15.dp, end = 15.dp)
-                    .align(Alignment.Start)
-                    .fillMaxWidth()
-                    .height(60.dp)
-                    .border(
-                        1.dp,
-                        color = color,
-                        shape = RoundedCornerShape(16.dp)
-                    )
-                    .background(color = colorResource(id = R.color.transparent))
-                    .clickable() {},
+                    TextField(
+                        value = passwordChanged,
+                        onValueChange = {
+//                            Log.d("onClick_test", "onValueChange -> ")
+                            passwordChanged = it
+                        },
+                        readOnly = readOnly,
+
+                        textStyle = TextStyle(
+                            color = colorResource(id = R.color.white),
+                            fontFamily = outfitFontFamily,
+                            fontWeight = FontWeight.Normal,
+                            fontSize = 14.sp,
+                            lineHeight = 22.sp,
+                            letterSpacing = 0.21.sp
+                        ),
+                        modifier = Modifier
+                            .padding(start = 15.dp, end = 15.dp)
+                            .align(Alignment.Start)
+                            .fillMaxWidth()
+                            .height(60.dp)
+                            .border(
+                                1.dp,
+                                color = color,
+                                shape = RoundedCornerShape(16.dp)
+                            )
+                            .background(color = colorResource(id = R.color.transparent))
+                            .clickable() {},
 
-                shape = RoundedCornerShape(15.dp),
+                        shape = RoundedCornerShape(15.dp),
 //                placeholder = {
 //                    Text(text = "Enter password",
 //                        color = colorResource(id = R.color.white))
 //                },
-                label = {
-                    Text(text = "Password",
-                        style = TextStyle(
-                            colorResource(id = R.color.white)),
-                        fontFamily = outfitFontFamily,
-                        fontWeight = FontWeight.Normal,
-                        fontSize = 16.sp,
-                    )
-                },
-                leadingIcon = {
-                    Icon(
-                        painter = painterResource(id = R.drawable.lock3x),
-                        contentDescription = "Password Logo",
-                        tint = colorResource(id = R.color.white),
-                        modifier = Modifier
-                            .size(24.dp, 24.dp)
-                    )
-                },
-                maxLines = 1,
-                colors = TextFieldDefaults.colors(
-                    focusedLabelColor = Color.Blue,
-                    unfocusedContainerColor = colorResource(id = R.color.grey_password_field),
-                    focusedContainerColor = colorResource(id = R.color.grey_password_field),
-                    focusedIndicatorColor = colorResource(id = R.color.transparent),
-                    disabledIndicatorColor = colorResource(id = R.color.transparent),
-                    unfocusedIndicatorColor = colorResource(id = R.color.transparent),
-                    cursorColor = colorResource(id = R.color.white)
-                ),
-                keyboardOptions = KeyboardOptions(
-                    keyboardType = KeyboardType.Password,
-                    imeAction = ImeAction.Done
-                ),
-                keyboardActions = KeyboardActions(
-                    onDone = {
-                        focusManager.clearFocus()
-                        keyboardController?.hide()
-                    }
-                ),
-                visualTransformation =
-                if (passwordVisible) VisualTransformation.Companion.None
+                        label = {
+                            Text(text = "Password",
+                                style = TextStyle(
+                                    colorResource(id = R.color.white)),
+                                fontFamily = outfitFontFamily,
+                                fontWeight = FontWeight.Normal,
+                                fontSize = 16.sp,
+                            )
+                        },
+                        leadingIcon = {
+                            Icon(
+                                painter = painterResource(id = R.drawable.lock3x),
+                                contentDescription = "Password Logo",
+                                tint = colorResource(id = R.color.white),
+                                modifier = Modifier
+                                    .size(24.dp, 24.dp)
+                            )
+                        },
+                        maxLines = 1,
+                        colors = TextFieldDefaults.colors(
+                            focusedLabelColor = Color.Blue,
+                            unfocusedContainerColor = colorResource(id = R.color.grey_password_field),
+                            focusedContainerColor = colorResource(id = R.color.grey_password_field),
+                            focusedIndicatorColor = colorResource(id = R.color.transparent),
+                            disabledIndicatorColor = colorResource(id = R.color.transparent),
+                            unfocusedIndicatorColor = colorResource(id = R.color.transparent),
+                            cursorColor = colorResource(id = R.color.white)
+                        ),
+                        keyboardOptions = KeyboardOptions(
+                            keyboardType = KeyboardType.Password,
+                            imeAction = ImeAction.Done
+                        ),
+                        keyboardActions = KeyboardActions(
+                            onDone = {
+                                focusManager.clearFocus()
+                                keyboardController?.hide()
+                            }
+                        ),
+                        visualTransformation =
+                        if (passwordVisible) VisualTransformation.Companion.None
                         else PasswordVisualTransformation(),
 
-                trailingIcon = {
+                        trailingIcon = {
 //                    val image
 //                            = if (passwordVisible) Icons.Filled.Visibility
 //                    else Icons.Filled.VisibilityOff
 
-                    val description = if (passwordVisible) "Hide Password"
-                    else "Show Password"
-
-                    IconButton(onClick = {
-                        if (!readOnly) {
-                            passwordVisible = !passwordVisible
+                            val description = if (passwordVisible) "Hide Password"
+                            else "Show Password"
+
+                            IconButton(onClick = {
+                                if (!readOnly) {
+                                    passwordVisible = !passwordVisible
+                                }
+                            })
+                            {
+                                if (passwordVisible) {
+                                    Icon(
+                                        imageVector = Icons.Outlined.Visibility,
+                                        contentDescription = description,
+                                        tint = colorResource(id = R.color.white),
+                                        modifier = Modifier.size(24.dp)
+                                    )
+                                }
+                                else {
+                                    Icon(
+                                        painter = painterResource(id = R.drawable.eye_slash3x),
+                                        contentDescription = description,
+                                        tint = colorResource(id = R.color.white),
+                                        modifier = Modifier.size(24.dp)
+                                    )
+                                }
+                            }
                         }
-                    })
-                    {
-                        if (passwordVisible) {
-                            Icon(
-                                imageVector = Icons.Outlined.Visibility,
-                                contentDescription = description,
-                                tint = colorResource(id = R.color.white),
-                                modifier = Modifier.size(24.dp)
-                            )
-                        }
-                        else {
-                            Icon(
-                                painter = painterResource(id = R.drawable.eye_slash3x),
-                                contentDescription = description,
-                                tint = colorResource(id = R.color.white),
-                                modifier = Modifier.size(24.dp)
-                            )
-                        }
-                    }
-                }
-                )
+                    )
 
-            if (showErrorPass1) {
-                ShowErrorRow(errorText = "Password is Empty")
-            }
-            else if (showErrorPass2) {
-                ShowErrorRow(errorText = "Should be 3 or more!")
-            }
+                    if (showErrorPass1) {
+                        ShowErrorRow(errorText = "Password is Empty")
+                    }
+                    else if (showErrorPass2) {
+                        ShowErrorRow(errorText = "Should be 3 or more!")
+                    }
 
 
-            Spacer(modifier = Modifier.height(20.dp))
-            ClickableText(
-                onClick = {
-                    if (!readOnly) {
-                        Log.d("onClick_test", "Forgot Password Clicked")
-                        navHostController.navigate(Screen.ForgotPassword.route)
-                    }
-                },
-                modifier = Modifier
-                    .padding(end = 15.dp)
-                    .align(Alignment.End),
-                style = TextStyle(
-                    fontSize = 16.sp,
-                    fontFamily = outfitFontFamily,
-                    fontWeight = FontWeight.Normal,
-                    textAlign = TextAlign.Right,
-                    color = colorResource(id = R.color.yellow_text),
-                ),
-                text = AnnotatedString("Forgot Password"),
-            )
+                    Spacer(modifier = Modifier.height(20.dp))
+                    ClickableText(
+                        onClick = {
+                            if (!readOnly) {
+//                                Log.d("onClick_test", "Forgot Password Clicked")
+                                navHostController.navigate(Screen.ForgotPassword.route)
+                            }
+                        },
+                        modifier = Modifier
+                            .padding(end = 15.dp)
+                            .align(Alignment.End),
+                        style = TextStyle(
+                            fontSize = 16.sp,
+                            fontFamily = outfitFontFamily,
+                            fontWeight = FontWeight.Normal,
+                            textAlign = TextAlign.Right,
+                            color = colorResource(id = R.color.yellow_text),
+                        ),
+                        text = AnnotatedString("Forgot Password"),
+                    )
 
-        }
+                }
 
-        SignInButton(
-            navHostController = navHostController,
-            textChanged,
-            passwordChanged,
-            loginViewModel = loginViewModel,
-            basePreferenceHelper,
-            showErrorEmail = {
-                showErrorEmail = it
-            },
-            showErrorEmail,
-            showErrorPass = {
-                showErrorPass1 = it
-            },
-            showErrorPass1,
-            showErrorPass2 = {
-                showErrorPass2 = it
-            },
-            showErrorPass2
-            )
-        Row (
-            modifier = Modifier
-                .align(Alignment.BottomCenter)
-                .padding(57.dp),
-        ){
-            TextMsgSignUp(navHostController = navHostController, loginViewModel, readOnly!!)
+                SignInButton(
+                    navHostController = navHostController,
+                    textChanged,
+                    passwordChanged,
+                    loginViewModel = loginViewModel,
+                    basePreferenceHelper,
+                    showErrorEmail = {
+                        showErrorEmail = it
+                    },
+                    showErrorEmail,
+                    showErrorPass = {
+                        showErrorPass1 = it
+                    },
+                    showErrorPass1,
+                    showErrorPass2 = {
+                        showErrorPass2 = it
+                    },
+                    showErrorPass2,
+                    snackBarState
+                )
+                Row (
+                    modifier = Modifier
+                        .align(Alignment.BottomCenter)
+                        .padding(57.dp),
+                ){
+                    TextMsgSignUp(navHostController = navHostController, loginViewModel, readOnly!!)
+                }
+            }
         }
-    }
+    )
 }
 
 
@@ -491,7 +502,7 @@ fun RowScope.TextMsgSignUp(
     loginViewModel: LoginViewModel,
     isEnabled: Boolean
 ) {
-        Text(
+    Text(
             modifier = Modifier
                 .padding(0.dp),
             text = "Don't have an account? ",
@@ -525,6 +536,7 @@ fun RowScope.TextMsgSignUp(
 
 }
 
+
 @Composable
 fun BoxScope.SignInButton(
     navHostController: NavHostController,
@@ -537,10 +549,12 @@ fun BoxScope.SignInButton(
     showErrorPass: (Boolean) -> Unit,
     isErrorPass: Boolean,
     showErrorPass2: (Boolean) -> Unit,
-    isErrorPass2: Boolean
+    isErrorPass2: Boolean,
+    snackBarState: SnackbarHostState
 ) {
-//    var showLoader by remember { mutableStateOf(false) }
-//    Log.d("test_login_text", "$email $password")
+    val scaffoldState = rememberScaffoldState()
+    val coroutineScope = rememberCoroutineScope()
+
     if (loginViewModel.liveDataLoginStatus.value == true) {
         var progress by remember { mutableFloatStateOf(0.1F) }
 
@@ -598,7 +612,7 @@ fun BoxScope.SignInButton(
             .height(60.dp)
             .clickable() { },
         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)
@@ -613,12 +627,12 @@ fun BoxScope.SignInButton(
 
 //            showLoader = true
             if (loginViewModel.liveDataLoginStatus.value == false) {
-                Log.d("test_api_response live", "SignIn: $email $password")
+//                Log.d("test_api_response live", "SignIn: $email $password")
 
                 if (customValidation.isValidText(email, "Email") &&
                     customValidation.isValidText(password, "Password") &&
                     customValidation.isValidPassword(password)) {
-                    Log.d("test_login_text", "true")
+//                    Log.d("test_login_text", "true")
 
                     if (email.isNotEmpty() && password.isNotEmpty()) {
                         loginViewModel.setLoginStatus(true)
@@ -642,6 +656,7 @@ fun BoxScope.SignInButton(
         ),
     )
     {
+
         Text(text = "Sign In",
             style = MaterialTheme.typography.titleMedium,
             textAlign = TextAlign.Center
@@ -649,7 +664,7 @@ fun BoxScope.SignInButton(
 
         val loginData by loginViewModel.liveDataUserResponse.observeAsState()
         loginData?.let { response ->
-            Log.d("test_api_response live", "live: ${loginData?.status} ${loginData?.message}")
+//            Log.d("test_api_response live", "live: ${loginData?.status} ${loginData?.message}")
             loginViewModel.setLoginStatus(false)
 //            showLoader = false
             if (response.status) {
@@ -660,7 +675,7 @@ fun BoxScope.SignInButton(
                     prefHelper.saveUser(it)
                     it.wireguard?.let { wg ->
                         prefHelper.saveWireGuard(wg)
-                        Log.d("test_wg_data", "Login:: ${wg.ip} ${wg.key}")
+//                        Log.d("test_wg_data", "Login:: ${wg.ip} ${wg.key}")
                     }
                     it.product?.let { it1 -> prefHelper.saveProduct(it1) }
                     prefHelper.saveEnabledProtocols(it.enabled_protocols)
@@ -672,20 +687,27 @@ fun BoxScope.SignInButton(
                         prefHelper.saveServerData(it)
                     }
 
-                    Log.d("bearer_token", it.token.toString())
+//                    Log.d("bearer_token", it.token.toString())
 
 //                    upgradePriceViewModel.getProducts()
 
                     prefHelper.getFcmToken().let {
                         loginViewModel.sendFcmToken(it)
-                        Log.d("Refreshed token: ", "Login: $it")
+//                        Log.d("Refreshed token: ", "Login: $it")
                     }
 
 
                     navHostController.popBackStack()
                     navHostController.navigate(Screen.BottomBarMainScreen.route)
                 }
-
+            }
+            else {
+                response.message?.let {
+//                    Log.d("test_login_msg", "${response.message}")
+                    coroutineScope.launch {
+                        snackBarState.showSnackbar(it)
+                    }
+                }
             }
             loginViewModel.mutableLiveDataUserResponse.value = null
         }

+ 60 - 0
app/src/main/java/com/vpn/fastestvpnservice/views/CustomSnackBar.kt

@@ -0,0 +1,60 @@
+package com.vpn.fastestvpnservice.views
+
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.material.Snackbar
+import androidx.compose.material3.Icon
+import androidx.compose.material3.SnackbarHost
+import androidx.compose.material3.SnackbarHostState
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.res.colorResource
+import androidx.compose.ui.res.painterResource
+import androidx.compose.ui.text.TextStyle
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+import com.vpn.fastestvpnservice.R
+import com.vpn.fastestvpnservice.ui.theme.outfitFontFamily
+
+@Composable
+fun ShowCustomSnackBar(snackBarState: SnackbarHostState) {
+    SnackbarHost(
+        hostState = snackBarState,
+        modifier = Modifier.padding(10.dp)
+    ) {data ->
+        Snackbar(
+            elevation = 0.dp,
+            backgroundColor = colorResource(id = R.color.yellow_text)
+        ) {
+            Box(
+                modifier = Modifier
+            ) {
+                Row(
+                    verticalAlignment = Alignment.CenterVertically,
+                    modifier = Modifier
+                ) {
+                    Icon(painter = painterResource(id = R.drawable.logo_black),
+                        contentDescription = "Error",
+                        tint = Color.Unspecified,
+                        modifier = Modifier.size(16.dp)
+                    )
+                    Text(text = data.visuals.message,
+                        style = TextStyle(
+                            fontFamily = outfitFontFamily,
+                            fontWeight = FontWeight.Medium,
+                            fontSize = 16.sp,
+                            color = colorResource(id = R.color.dark_blue_gray_text)
+                        ),
+                        modifier = Modifier.padding(start = 10.dp)
+                    )
+                }
+            }
+        }
+    }
+}