|
@@ -31,13 +31,16 @@ import androidx.compose.material.icons.outlined.Visibility
|
|
|
import androidx.compose.material3.AlertDialog
|
|
|
import androidx.compose.material3.Button
|
|
|
import androidx.compose.material3.ButtonDefaults
|
|
|
+import androidx.compose.material3.CircularProgressIndicator
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
import androidx.compose.material3.SnackbarHostState
|
|
|
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.livedata.observeAsState
|
|
|
+import androidx.compose.runtime.mutableFloatStateOf
|
|
|
import androidx.compose.runtime.mutableStateOf
|
|
|
import androidx.compose.runtime.remember
|
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
@@ -70,7 +73,9 @@ import com.vpn.fastestvpnservice.beans.subscriptionPackageList
|
|
|
import com.vpn.fastestvpnservice.customItems.getSelectedPosition
|
|
|
import com.vpn.fastestvpnservice.ui.theme.customTypography2
|
|
|
import com.vpn.fastestvpnservice.viewmodels.AccountViewModel
|
|
|
+import com.vpn.fastestvpnservice.views.CustomValidation
|
|
|
import com.vpn.fastestvpnservice.views.ShowCustomSnackBar
|
|
|
+import kotlinx.coroutines.delay
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
|
@Composable
|
|
@@ -81,10 +86,10 @@ fun ChangePassword(navHostController: NavHostController) {
|
|
|
val snackBarState = remember { SnackbarHostState() }
|
|
|
val snackBarStateRed = remember { SnackbarHostState() }
|
|
|
val coroutineScope = rememberCoroutineScope()
|
|
|
-
|
|
|
var currentPassword by remember { mutableStateOf("") }
|
|
|
var newPassword by remember { mutableStateOf("") }
|
|
|
var confirmPassword by remember { mutableStateOf("") }
|
|
|
+ var isShowLoader by remember { mutableStateOf(false) }
|
|
|
|
|
|
Box(
|
|
|
modifier = Modifier
|
|
@@ -100,6 +105,31 @@ fun ChangePassword(navHostController: NavHostController) {
|
|
|
ShowCustomSnackBar(snackBarState, R.color.switch_green, R.color.white)
|
|
|
ShowCustomSnackBar(snackBarStateRed, R.color.Red, R.color.white)
|
|
|
|
|
|
+ if (isShowLoader) {
|
|
|
+ Log.d("ChangePassword: ","isShowLoader = $isShowLoader")
|
|
|
+ var progress by remember { mutableFloatStateOf(0.1F) }
|
|
|
+
|
|
|
+ LaunchedEffect(key1 = Unit) {
|
|
|
+ while (true) {
|
|
|
+ for (i in 1..100) {
|
|
|
+ progress = i.toFloat()/100F
|
|
|
+ delay(150)
|
|
|
+ }
|
|
|
+ progress = 0.1F
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ CircularProgressIndicator(
|
|
|
+ progress = { progress },
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(top = 150.dp)
|
|
|
+ .size(50.dp)
|
|
|
+ .align(Alignment.Center),
|
|
|
+ color = colorResource(id = R.color.yellow_text),
|
|
|
+ strokeWidth = 5.dp,
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
HeaderRowCP(navHostController = navHostController)
|
|
|
|
|
|
Column(
|
|
@@ -122,15 +152,41 @@ fun ChangePassword(navHostController: NavHostController) {
|
|
|
TextFieldReWriteNewPass() {
|
|
|
confirmPassword = it
|
|
|
}
|
|
|
+ val customValidation = CustomValidation()
|
|
|
+ val isCurrentPassword = customValidation.isValidText(currentPassword, "Password")
|
|
|
+ val isNewPassword = customValidation.isValidText(newPassword, "Password")
|
|
|
+ val isConfirmPassword = customValidation.isValidText(confirmPassword, "Password")
|
|
|
|
|
|
Button(
|
|
|
onClick = {
|
|
|
Log.d("test_button", "onClick")
|
|
|
- Log.d("ChangePassword: ","TextFieldCurrPass = $currentPassword $newPassword $confirmPassword")
|
|
|
+ Log.d("ChangePassword: ","TextFieldCurrPass = $isCurrentPassword $isNewPassword $isConfirmPassword")
|
|
|
+
|
|
|
+ if (isCurrentPassword && isNewPassword && isConfirmPassword)
|
|
|
+ {
|
|
|
+ Log.d("ChangePassword: ","TextFieldCurrPass = true inside API")
|
|
|
+ isShowLoader = true
|
|
|
+ accountViewModel.changePassword(
|
|
|
+ currentPassword, newPassword, confirmPassword
|
|
|
+ )
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Log.d("ChangePassword: ","TextFieldCurrPass = else")
|
|
|
+ if (!isCurrentPassword) {
|
|
|
+ coroutineScope.launch {
|
|
|
+ snackBarStateRed.showSnackbar("The current password field is required.")
|
|
|
+ }
|
|
|
+ } else if (!isNewPassword) {
|
|
|
+ coroutineScope.launch {
|
|
|
+ snackBarStateRed.showSnackbar("The new password field is required.")
|
|
|
+ }
|
|
|
+ } else if (!isConfirmPassword) {
|
|
|
+ coroutineScope.launch {
|
|
|
+ snackBarStateRed.showSnackbar("The confirm password field is required.")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- accountViewModel.changePassword(
|
|
|
- currentPassword, newPassword, confirmPassword
|
|
|
- )
|
|
|
},
|
|
|
modifier = Modifier
|
|
|
.padding(
|
|
@@ -161,7 +217,7 @@ fun ChangePassword(navHostController: NavHostController) {
|
|
|
val changePasswordResponse = accountViewModel.liveDataChangePassword.observeAsState()
|
|
|
changePasswordResponse.value?.let { data ->
|
|
|
Log.d("ChangePassword: ","ChangePassword Response F_API: ${data.status} ${data.message}")
|
|
|
-
|
|
|
+ isShowLoader = false
|
|
|
if (data.status) {
|
|
|
coroutineScope.launch {
|
|
|
data.message?.let { it1 -> snackBarState.showSnackbar(it1) }
|