|
@@ -32,12 +32,15 @@ import androidx.compose.material3.AlertDialog
|
|
|
import androidx.compose.material3.Button
|
|
|
import androidx.compose.material3.ButtonDefaults
|
|
|
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.getValue
|
|
|
+import androidx.compose.runtime.livedata.observeAsState
|
|
|
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
|
|
@@ -59,17 +62,29 @@ import androidx.compose.ui.text.style.TextAlign
|
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
+import androidx.lifecycle.viewmodel.compose.viewModel
|
|
|
import androidx.navigation.NavHostController
|
|
|
import androidx.navigation.compose.rememberNavController
|
|
|
import com.vpn.fastestvpnservice.R
|
|
|
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.ShowCustomSnackBar
|
|
|
+import kotlinx.coroutines.launch
|
|
|
|
|
|
@Composable
|
|
|
fun ChangePassword(navHostController: NavHostController) {
|
|
|
val keyboardController = LocalSoftwareKeyboardController.current
|
|
|
val focusManager = LocalFocusManager.current
|
|
|
+ val accountViewModel: AccountViewModel = viewModel()
|
|
|
+ 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("") }
|
|
|
|
|
|
Box(
|
|
|
modifier = Modifier
|
|
@@ -82,6 +97,9 @@ fun ChangePassword(navHostController: NavHostController) {
|
|
|
}
|
|
|
}
|
|
|
) {
|
|
|
+ ShowCustomSnackBar(snackBarState, R.color.yellow_text, R.color.dark_blue_gray_text)
|
|
|
+ ShowCustomSnackBar(snackBarStateRed, R.color.Red, R.color.white)
|
|
|
+
|
|
|
HeaderRowCP(navHostController = navHostController)
|
|
|
|
|
|
Column(
|
|
@@ -93,15 +111,26 @@ fun ChangePassword(navHostController: NavHostController) {
|
|
|
.background(Color.Transparent)
|
|
|
|
|
|
) {
|
|
|
- TextFieldCurrPass()
|
|
|
+ TextFieldCurrPass() {
|
|
|
+ currentPassword = it
|
|
|
+ }
|
|
|
Spacer(modifier = Modifier.height(25.dp))
|
|
|
- TextFieldNewPass()
|
|
|
+ TextFieldNewPass() {
|
|
|
+ newPassword = it
|
|
|
+ }
|
|
|
Spacer(modifier = Modifier.height(25.dp))
|
|
|
- TextFieldReWriteNewPass()
|
|
|
+ TextFieldReWriteNewPass() {
|
|
|
+ confirmPassword = it
|
|
|
+ }
|
|
|
|
|
|
Button(
|
|
|
onClick = {
|
|
|
Log.d("test_button", "onClick")
|
|
|
+ Log.d("ChangePassword: ","TextFieldCurrPass = $currentPassword $newPassword $confirmPassword")
|
|
|
+
|
|
|
+ accountViewModel.changePassword(
|
|
|
+ currentPassword, newPassword, confirmPassword
|
|
|
+ )
|
|
|
},
|
|
|
modifier = Modifier
|
|
|
.padding(
|
|
@@ -128,13 +157,33 @@ fun ChangePassword(navHostController: NavHostController) {
|
|
|
fontStyle = FontStyle.Normal
|
|
|
)
|
|
|
)
|
|
|
+
|
|
|
+ val changePasswordResponse = accountViewModel.liveDataChangePassword.observeAsState()
|
|
|
+ changePasswordResponse.value?.let { data ->
|
|
|
+ Log.d("ChangePassword: ","ChangePassword Response F_API: ${data.status} ${data.message}")
|
|
|
+
|
|
|
+ if (data.status) {
|
|
|
+ coroutineScope.launch {
|
|
|
+ data.message?.let { it1 -> snackBarState.showSnackbar(it1) }
|
|
|
+ }
|
|
|
+// currentPassword = ""
|
|
|
+// newPassword = ""
|
|
|
+// confirmPassword = ""
|
|
|
+ } else {
|
|
|
+ coroutineScope.launch {
|
|
|
+ data.message?.let { it1 -> snackBarStateRed.showSnackbar(it1) }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ accountViewModel.mutableLiveDataChangePassword.value = null
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
|
-fun ColumnScope.TextFieldCurrPass() {
|
|
|
+fun ColumnScope.TextFieldCurrPass(currentPassword: (String) -> Unit) {
|
|
|
val keyboardController = LocalSoftwareKeyboardController.current
|
|
|
val focusManager = LocalFocusManager.current
|
|
|
|
|
@@ -150,6 +199,7 @@ fun ColumnScope.TextFieldCurrPass() {
|
|
|
onValueChange = {
|
|
|
Log.d("onClick_test", "onValueChange -> ")
|
|
|
passwordChanged = it
|
|
|
+ currentPassword(passwordChanged)
|
|
|
},
|
|
|
|
|
|
textStyle = customTextStyle,
|
|
@@ -249,7 +299,7 @@ fun ColumnScope.TextFieldCurrPass() {
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
|
-fun ColumnScope.TextFieldNewPass() {
|
|
|
+fun ColumnScope.TextFieldNewPass(newPassword: (String) -> Unit) {
|
|
|
val keyboardController = LocalSoftwareKeyboardController.current
|
|
|
val focusManager = LocalFocusManager.current
|
|
|
|
|
@@ -264,6 +314,7 @@ fun ColumnScope.TextFieldNewPass() {
|
|
|
onValueChange = {
|
|
|
Log.d("onClick_test", "onValueChange -> ")
|
|
|
passwordChanged = it
|
|
|
+ newPassword(passwordChanged)
|
|
|
},
|
|
|
|
|
|
textStyle = customTextStyle,
|
|
@@ -365,7 +416,7 @@ fun ColumnScope.TextFieldNewPass() {
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
|
-fun ColumnScope.TextFieldReWriteNewPass() {
|
|
|
+fun ColumnScope.TextFieldReWriteNewPass(confirmPassword: (String) -> Unit) {
|
|
|
val keyboardController = LocalSoftwareKeyboardController.current
|
|
|
val focusManager = LocalFocusManager.current
|
|
|
|
|
@@ -380,6 +431,7 @@ fun ColumnScope.TextFieldReWriteNewPass() {
|
|
|
onValueChange = {
|
|
|
Log.d("onClick_test", "onValueChange -> ")
|
|
|
passwordChanged = it
|
|
|
+ confirmPassword(passwordChanged)
|
|
|
},
|
|
|
|
|
|
textStyle = customTextStyle,
|