|
@@ -7,7 +7,9 @@ import android.os.Looper
|
|
|
import android.util.Log
|
|
|
import android.widget.Toast
|
|
|
import androidx.compose.animation.AnimatedVisibility
|
|
|
+import androidx.compose.foundation.ExperimentalFoundationApi
|
|
|
import androidx.compose.foundation.Image
|
|
|
+import androidx.compose.foundation.LocalOverscrollConfiguration
|
|
|
import androidx.compose.foundation.background
|
|
|
import androidx.compose.foundation.gestures.detectTapGestures
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
@@ -22,7 +24,9 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
import androidx.compose.foundation.layout.height
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
import androidx.compose.foundation.layout.size
|
|
|
+import androidx.compose.foundation.rememberScrollState
|
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
+import androidx.compose.foundation.verticalScroll
|
|
|
import androidx.compose.material3.AlertDialog
|
|
|
import androidx.compose.material3.Button
|
|
|
import androidx.compose.material3.ButtonDefaults
|
|
@@ -32,6 +36,7 @@ import androidx.compose.material3.MaterialTheme
|
|
|
import androidx.compose.material3.Surface
|
|
|
import androidx.compose.material3.Text
|
|
|
import androidx.compose.runtime.Composable
|
|
|
+import androidx.compose.runtime.CompositionLocalProvider
|
|
|
import androidx.compose.runtime.LaunchedEffect
|
|
|
import androidx.compose.runtime.getValue
|
|
|
import androidx.compose.runtime.livedata.observeAsState
|
|
@@ -75,201 +80,204 @@ import kotlinx.coroutines.delay
|
|
|
|
|
|
//var LocalLoggedOut = staticCompositionLocalOf<Boolean> { false }
|
|
|
|
|
|
-@OptIn(ExperimentalMaterial3Api::class)
|
|
|
+@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
|
|
|
@Composable
|
|
|
fun Account(navHostController: NavHostController,
|
|
|
settingsNavHostController: NavHostController)
|
|
|
{
|
|
|
-
|
|
|
var isLoggedOut by remember { mutableStateOf(false) }
|
|
|
var isDelete by remember { mutableStateOf(false) }
|
|
|
-
|
|
|
val context = LocalContext.current
|
|
|
val basePreferenceHelper = BasePreferenceHelper(context)
|
|
|
-
|
|
|
val accountViewModel: AccountViewModel = viewModel()
|
|
|
|
|
|
- Box(modifier = Modifier
|
|
|
- .background(MaterialTheme.colorScheme.background)
|
|
|
- .fillMaxSize()
|
|
|
+ CompositionLocalProvider(
|
|
|
+ LocalOverscrollConfiguration provides null
|
|
|
+ ) {
|
|
|
+ Box(modifier = Modifier
|
|
|
+ .background(MaterialTheme.colorScheme.background)
|
|
|
+ .fillMaxSize()
|
|
|
+ .padding(vertical = 10.dp)
|
|
|
+ .verticalScroll(rememberScrollState())
|
|
|
// contentAlignment = Alignment.Center
|
|
|
|
|
|
- ) {
|
|
|
- Column(
|
|
|
- verticalArrangement = Arrangement.Top,
|
|
|
- horizontalAlignment = Alignment.Start,
|
|
|
- modifier = Modifier
|
|
|
- .padding(start = 16.dp, end = 24.dp)
|
|
|
- .fillMaxSize()
|
|
|
) {
|
|
|
- Spacer(modifier = Modifier.height(60.dp))
|
|
|
- AddTextAccount(
|
|
|
- text = "Account",
|
|
|
- size = 28.sp,
|
|
|
- color = MaterialTheme.colorScheme.primary
|
|
|
- )
|
|
|
- AddRowAccount("Email:", basePreferenceHelper.getUser()?.userinfo?.email ?: "")
|
|
|
- AddRowAccount("Product:", basePreferenceHelper.getProduct()?.productName ?: "")
|
|
|
- AddRowAccount("Account Status:", basePreferenceHelper.getProduct()?.status ?: "")
|
|
|
-
|
|
|
- Surface(
|
|
|
+ Column(
|
|
|
+ verticalArrangement = Arrangement.Top,
|
|
|
+ horizontalAlignment = Alignment.Start,
|
|
|
modifier = Modifier
|
|
|
- .padding(top = 24.dp, bottom = 0.dp)
|
|
|
- .height(1.dp)
|
|
|
- .fillMaxWidth(),
|
|
|
- color = colorResource(id = R.color.gray_icon)
|
|
|
- ) {}
|
|
|
-
|
|
|
- AddRowAccountIcon(
|
|
|
- icon = painterResource(id = R.drawable.subscription3x),
|
|
|
- text = "Upgrade Subscription",
|
|
|
- onClick = {
|
|
|
- navHostController.navigate(
|
|
|
- Screen.Subscription.route
|
|
|
- )
|
|
|
- }
|
|
|
- )
|
|
|
- AddRowAccountIcon(
|
|
|
- icon = painterResource(id = R.drawable.fav3x),
|
|
|
- text = "Favorite Servers",
|
|
|
- onClick = {
|
|
|
- navHostController.navigate(
|
|
|
- Screen.FavoriteServers.route
|
|
|
- )
|
|
|
- }
|
|
|
- )
|
|
|
- AddRowAccountIcon(
|
|
|
- icon = painterResource(id = R.drawable.lock3x),
|
|
|
- text = "Change Password",
|
|
|
- onClick = {
|
|
|
- navHostController.navigate(
|
|
|
- Screen.ChangePassword.route
|
|
|
- )
|
|
|
- }
|
|
|
- )
|
|
|
- AddRowAccountIcon(
|
|
|
- icon = painterResource(id = R.drawable.delete3x),
|
|
|
- text = "Delete Account",
|
|
|
- onClick = {
|
|
|
- isDelete = true
|
|
|
- Log.d("islogoutClicked?", "isDelete Yes")
|
|
|
- }
|
|
|
- )
|
|
|
- AddRowAccountIcon(
|
|
|
- icon = painterResource(id = R.drawable.logout3x),
|
|
|
- text = "Logout",
|
|
|
- onClick = {
|
|
|
- isLoggedOut = true
|
|
|
- Log.d("islogoutClicked?", "Yes")
|
|
|
- }
|
|
|
- )
|
|
|
- }
|
|
|
+ .padding(start = 16.dp, end = 24.dp)
|
|
|
+ .fillMaxSize()
|
|
|
+ ) {
|
|
|
+ Spacer(modifier = Modifier.height(60.dp))
|
|
|
+ AddTextAccount(
|
|
|
+ text = "Account",
|
|
|
+ size = 28.sp,
|
|
|
+ color = MaterialTheme.colorScheme.primary
|
|
|
+ )
|
|
|
+ AddRowAccount("Email:", basePreferenceHelper.getUser()?.userinfo?.email ?: "")
|
|
|
+ AddRowAccount("Product:", basePreferenceHelper.getProduct()?.productName ?: "")
|
|
|
+ AddRowAccount("Account Status:", basePreferenceHelper.getProduct()?.status ?: "")
|
|
|
+
|
|
|
+ Surface(
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(top = 24.dp, bottom = 0.dp)
|
|
|
+ .height(1.dp)
|
|
|
+ .fillMaxWidth(),
|
|
|
+ color = colorResource(id = R.color.gray_icon)
|
|
|
+ ) {}
|
|
|
+
|
|
|
+ AddRowAccountIcon(
|
|
|
+ icon = painterResource(id = R.drawable.subscription3x),
|
|
|
+ text = "Upgrade Subscription",
|
|
|
+ onClick = {
|
|
|
+ navHostController.navigate(
|
|
|
+ Screen.Subscription.route
|
|
|
+ )
|
|
|
+ }
|
|
|
+ )
|
|
|
+ AddRowAccountIcon(
|
|
|
+ icon = painterResource(id = R.drawable.fav3x),
|
|
|
+ text = "Favorite Servers",
|
|
|
+ onClick = {
|
|
|
+ navHostController.navigate(
|
|
|
+ Screen.FavoriteServers.route
|
|
|
+ )
|
|
|
+ }
|
|
|
+ )
|
|
|
+ AddRowAccountIcon(
|
|
|
+ icon = painterResource(id = R.drawable.lock3x),
|
|
|
+ text = "Change Password",
|
|
|
+ onClick = {
|
|
|
+ navHostController.navigate(
|
|
|
+ Screen.ChangePassword.route
|
|
|
+ )
|
|
|
+ }
|
|
|
+ )
|
|
|
+ AddRowAccountIcon(
|
|
|
+ icon = painterResource(id = R.drawable.delete3x),
|
|
|
+ text = "Delete Account",
|
|
|
+ onClick = {
|
|
|
+ isDelete = true
|
|
|
+ Log.d("islogoutClicked?", "isDelete Yes")
|
|
|
+ }
|
|
|
+ )
|
|
|
+ AddRowAccountIcon(
|
|
|
+ icon = painterResource(id = R.drawable.logout3x),
|
|
|
+ text = "Logout",
|
|
|
+ onClick = {
|
|
|
+ isLoggedOut = true
|
|
|
+ Log.d("islogoutClicked?", "Yes")
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
|
|
|
- if (isLoggedOut) {
|
|
|
- Log.d("islogoutClicked", "isLoggedOut$isLoggedOut")
|
|
|
+ if (isLoggedOut) {
|
|
|
+ Log.d("islogoutClicked", "isLoggedOut$isLoggedOut")
|
|
|
|
|
|
- AlertDialog(
|
|
|
- onDismissRequest = { isLoggedOut = false },
|
|
|
- properties = DialogProperties(),
|
|
|
- modifier = Modifier
|
|
|
- .fillMaxWidth()
|
|
|
- .height(228.dp)
|
|
|
+ AlertDialog(
|
|
|
+ onDismissRequest = { isLoggedOut = false },
|
|
|
+ properties = DialogProperties(),
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .height(228.dp)
|
|
|
) {
|
|
|
- LogoutDialog("Logout Account",
|
|
|
- "Are you sure to logout the account?",
|
|
|
- onCancel = {
|
|
|
- isLoggedOut = false
|
|
|
- },
|
|
|
- settingsNavHostController,
|
|
|
- isLoggedOut,
|
|
|
- isDelete,
|
|
|
- basePreferenceHelper,
|
|
|
- accountViewModel
|
|
|
+ LogoutDialog("Logout Account",
|
|
|
+ "Are you sure to logout the account?",
|
|
|
+ onCancel = {
|
|
|
+ isLoggedOut = false
|
|
|
+ },
|
|
|
+ settingsNavHostController,
|
|
|
+ isLoggedOut,
|
|
|
+ isDelete,
|
|
|
+ basePreferenceHelper,
|
|
|
+ accountViewModel
|
|
|
)
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (isDelete) {
|
|
|
- Log.d("islogoutClicked", "isDelete$isDelete")
|
|
|
+ if (isDelete) {
|
|
|
+ Log.d("islogoutClicked", "isDelete$isDelete")
|
|
|
|
|
|
- AlertDialog(
|
|
|
- onDismissRequest = { isDelete = false },
|
|
|
- properties = DialogProperties(),
|
|
|
- modifier = Modifier
|
|
|
- .fillMaxWidth()
|
|
|
- .height(228.dp)
|
|
|
- ) {
|
|
|
- LogoutDialog("Delete Account",
|
|
|
- "Are you sure to delete the account?",
|
|
|
- onCancel = { isDelete = false },
|
|
|
- settingsNavHostController,
|
|
|
- isLoggedOut,
|
|
|
- isDelete,
|
|
|
- basePreferenceHelper,
|
|
|
- accountViewModel
|
|
|
+ AlertDialog(
|
|
|
+ onDismissRequest = { isDelete = false },
|
|
|
+ properties = DialogProperties(),
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .height(228.dp)
|
|
|
+ ) {
|
|
|
+ LogoutDialog("Delete Account",
|
|
|
+ "Are you sure to delete the account?",
|
|
|
+ onCancel = { isDelete = false },
|
|
|
+ settingsNavHostController,
|
|
|
+ isLoggedOut,
|
|
|
+ isDelete,
|
|
|
+ basePreferenceHelper,
|
|
|
+ accountViewModel
|
|
|
)
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (accountViewModel.liveDataLogoutStatus.value == true) {
|
|
|
- var progress by remember { mutableFloatStateOf(0.1F) }
|
|
|
+ if (accountViewModel.liveDataLogoutStatus.value == true) {
|
|
|
+ var progress by remember { mutableFloatStateOf(0.1F) }
|
|
|
|
|
|
- LaunchedEffect(key1 = Unit) {
|
|
|
- for (i in 1..100) {
|
|
|
- progress = i.toFloat()/100F
|
|
|
- delay(100)
|
|
|
+ LaunchedEffect(key1 = Unit) {
|
|
|
+ for (i in 1..100) {
|
|
|
+ progress = i.toFloat()/100F
|
|
|
+ delay(100)
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- CircularProgressIndicator(
|
|
|
- progress = { progress },
|
|
|
- modifier = Modifier
|
|
|
- .align(Alignment.Center)
|
|
|
- .size(50.dp),
|
|
|
- color = colorResource(id = R.color.yellow_text),
|
|
|
- strokeWidth = 5.dp,
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
- val logoutResponse = accountViewModel.liveDataLogout.observeAsState().value
|
|
|
- logoutResponse?.let {
|
|
|
- Log.d("test_button_log", "logout api response")
|
|
|
- accountViewModel.setLogoutStatus(false)
|
|
|
- if (it) {
|
|
|
- Log.d("test_api_response","Logout live: $logoutResponse")
|
|
|
- basePreferenceHelper.setLoggedInState(false)
|
|
|
- basePreferenceHelper.clearAllData()
|
|
|
- settingsNavHostController.popBackStack()
|
|
|
- settingsNavHostController.navigate(Screen.Started.route)
|
|
|
-
|
|
|
- val widgetIntent = Intent(context, SimpleAppWidget::class.java)
|
|
|
- widgetIntent.action = SimpleAppWidget.ACTION_LOGOUT
|
|
|
- context.sendBroadcast(widgetIntent)
|
|
|
- }
|
|
|
- else {
|
|
|
- Log.d("test_api_response","Logout false: $logoutResponse")
|
|
|
- accountViewModel.mutableLiveDataLogoutStatus.value = false
|
|
|
- Toast.makeText(context, logoutResponse.toString(), Toast.LENGTH_SHORT).show()
|
|
|
+ CircularProgressIndicator(
|
|
|
+ progress = { progress },
|
|
|
+ modifier = Modifier
|
|
|
+ .align(Alignment.Center)
|
|
|
+ .size(50.dp),
|
|
|
+ color = colorResource(id = R.color.yellow_text),
|
|
|
+ strokeWidth = 5.dp,
|
|
|
+ )
|
|
|
}
|
|
|
- accountViewModel.mutableLiveDataLogout.value = null
|
|
|
- }
|
|
|
|
|
|
- val deleteResponse = accountViewModel.liveDataDelete.observeAsState().value
|
|
|
- deleteResponse?.let {
|
|
|
- accountViewModel.setLogoutStatus(false)
|
|
|
- if (it.status) {
|
|
|
- Log.d("test_api_response","Delete live: ${deleteResponse.status}")
|
|
|
- basePreferenceHelper.setLoggedInState(false)
|
|
|
- basePreferenceHelper.clearAllData()
|
|
|
- settingsNavHostController.popBackStack()
|
|
|
- settingsNavHostController.navigate(Screen.Started.route)
|
|
|
+ val logoutResponse = accountViewModel.liveDataLogout.observeAsState().value
|
|
|
+ logoutResponse?.let {
|
|
|
+ Log.d("test_button_log", "logout api response")
|
|
|
+ accountViewModel.setLogoutStatus(false)
|
|
|
+ if (it) {
|
|
|
+ Log.d("test_api_response","Logout live: $logoutResponse")
|
|
|
+ basePreferenceHelper.setLoggedInState(false)
|
|
|
+ basePreferenceHelper.clearAllData()
|
|
|
+ settingsNavHostController.popBackStack()
|
|
|
+ settingsNavHostController.navigate(Screen.Started.route)
|
|
|
+
|
|
|
+ val widgetIntent = Intent(context, SimpleAppWidget::class.java)
|
|
|
+ widgetIntent.action = SimpleAppWidget.ACTION_LOGOUT
|
|
|
+ context.sendBroadcast(widgetIntent)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Log.d("test_api_response","Logout false: $logoutResponse")
|
|
|
+ accountViewModel.mutableLiveDataLogoutStatus.value = false
|
|
|
+ Toast.makeText(context, logoutResponse.toString(), Toast.LENGTH_SHORT).show()
|
|
|
+ }
|
|
|
+ accountViewModel.mutableLiveDataLogout.value = null
|
|
|
}
|
|
|
- else {
|
|
|
- Log.d("test_api_response","Delete false: ${deleteResponse.status}")
|
|
|
- accountViewModel.mutableLiveDataDeleteStatus.value = false
|
|
|
- Toast.makeText(context, deleteResponse.status.toString(), Toast.LENGTH_SHORT).show()
|
|
|
+
|
|
|
+ val deleteResponse = accountViewModel.liveDataDelete.observeAsState().value
|
|
|
+ deleteResponse?.let {
|
|
|
+ accountViewModel.setLogoutStatus(false)
|
|
|
+ if (it.status) {
|
|
|
+ Log.d("test_api_response","Delete live: ${deleteResponse.status}")
|
|
|
+ basePreferenceHelper.setLoggedInState(false)
|
|
|
+ basePreferenceHelper.clearAllData()
|
|
|
+ settingsNavHostController.popBackStack()
|
|
|
+ settingsNavHostController.navigate(Screen.Started.route)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Log.d("test_api_response","Delete false: ${deleteResponse.status}")
|
|
|
+ accountViewModel.mutableLiveDataDeleteStatus.value = false
|
|
|
+ Toast.makeText(context, deleteResponse.status.toString(), Toast.LENGTH_SHORT).show()
|
|
|
+ }
|
|
|
+ accountViewModel.mutableLiveDataDelete.value = null
|
|
|
}
|
|
|
- accountViewModel.mutableLiveDataDelete.value = null
|
|
|
}
|
|
|
}
|
|
|
}
|