|
@@ -9,6 +9,7 @@ import android.os.Build
|
|
|
import android.os.Bundle
|
|
|
import android.os.Handler
|
|
|
import android.os.LocaleList
|
|
|
+import android.os.Looper
|
|
|
import android.provider.Settings
|
|
|
import android.util.Log
|
|
|
import android.widget.Toast
|
|
@@ -21,6 +22,7 @@ import androidx.compose.foundation.gestures.detectTapGestures
|
|
|
import androidx.compose.foundation.isSystemInDarkTheme
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
import androidx.compose.foundation.layout.Box
|
|
|
+import androidx.compose.foundation.layout.BoxScope
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
import androidx.compose.foundation.layout.ColumnScope
|
|
|
import androidx.compose.foundation.layout.Row
|
|
@@ -34,11 +36,15 @@ import androidx.compose.foundation.lazy.LazyColumn
|
|
|
import androidx.compose.foundation.lazy.items
|
|
|
import androidx.compose.foundation.rememberScrollState
|
|
|
import androidx.compose.foundation.selection.selectable
|
|
|
+import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
import androidx.compose.foundation.verticalScroll
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
import androidx.compose.material.icons.filled.DarkMode
|
|
|
import androidx.compose.material.icons.filled.Language
|
|
|
import androidx.compose.material.icons.filled.RocketLaunch
|
|
|
+import androidx.compose.material3.AlertDialog
|
|
|
+import androidx.compose.material3.Button
|
|
|
+import androidx.compose.material3.ButtonDefaults
|
|
|
import androidx.compose.material3.DockedSearchBar
|
|
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
|
|
import androidx.compose.material3.Icon
|
|
@@ -66,6 +72,8 @@ import androidx.compose.ui.Alignment
|
|
|
import androidx.compose.ui.Modifier
|
|
|
import androidx.compose.ui.draw.alpha
|
|
|
import androidx.compose.ui.draw.scale
|
|
|
+import androidx.compose.ui.focus.FocusRequester
|
|
|
+import androidx.compose.ui.focus.onFocusChanged
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
import androidx.compose.ui.graphics.ColorFilter
|
|
|
import androidx.compose.ui.graphics.toArgb
|
|
@@ -83,6 +91,7 @@ import androidx.compose.ui.unit.Dp
|
|
|
import androidx.compose.ui.unit.TextUnit
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
+import androidx.compose.ui.window.DialogProperties
|
|
|
import androidx.core.content.ContextCompat.startActivity
|
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
|
import androidx.navigation.NavHostController
|
|
@@ -100,16 +109,20 @@ import com.vpn.fastestvpnservice.screens.searchListViewModelSplash
|
|
|
import com.vpn.fastestvpnservice.screens.serverListViewModelSplash
|
|
|
import com.vpn.fastestvpnservice.sealedClass.BottomBarScreen
|
|
|
import com.vpn.fastestvpnservice.sealedClass.Screen
|
|
|
+import com.vpn.fastestvpnservice.ui.theme.customTypography
|
|
|
+import com.vpn.fastestvpnservice.utils.VPNConnectionsUtil
|
|
|
+import com.vpn.fastestvpnservice.viewmodels.AccountViewModel
|
|
|
import com.vpn.fastestvpnservice.viewmodels.HomeViewModel
|
|
|
import com.vpn.fastestvpnservice.viewmodels.ServerListViewModel
|
|
|
import de.blinkt.openvpn.core.App
|
|
|
import kotlinx.coroutines.delay
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
|
-@OptIn(ExperimentalFoundationApi::class)
|
|
|
+@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class)
|
|
|
@Composable
|
|
|
fun Settings(navHostController: NavHostController, activity: ComponentActivity) {
|
|
|
val context = LocalContext.current
|
|
|
+ var isLaunched by remember { mutableStateOf(false) }
|
|
|
|
|
|
CompositionLocalProvider(
|
|
|
LocalOverscrollConfiguration provides null
|
|
@@ -204,13 +217,37 @@ fun Settings(navHostController: NavHostController, activity: ComponentActivity)
|
|
|
icon = Icons.Default.DarkMode,
|
|
|
text = "Theme")
|
|
|
|
|
|
- SelectLanguage(icon = Icons.Default.Language, text = "Language")
|
|
|
+// SelectLanguage(icon = Icons.Default.Language, text = "Language")
|
|
|
|
|
|
- AddRowLaunchSwitch(icon = Icons.Filled.RocketLaunch, text = "Launch On Startup", activity)
|
|
|
+ AddRowLaunchSwitch(
|
|
|
+ icon = Icons.Filled.RocketLaunch,
|
|
|
+ text = "Launch On Startup",
|
|
|
+ activity,
|
|
|
+ onClick = {
|
|
|
+ isLaunched = true
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ if (isLaunched) {
|
|
|
+ AlertDialog(
|
|
|
+ onDismissRequest = { isLaunched = false },
|
|
|
+ properties = DialogProperties(),
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .height(280.dp)
|
|
|
+ ) {
|
|
|
+ LaunchDialog(
|
|
|
+ onCancel = {
|
|
|
+ isLaunched = false
|
|
|
+ },
|
|
|
+ context,
|
|
|
+ activity
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
private fun gotoVPNSettings(context: Context) {
|
|
@@ -309,7 +346,12 @@ fun ColumnScope.AddRowSwitch(icon: Int, text: String) {
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
|
-fun ColumnScope.AddRowLaunchSwitch(icon: ImageVector, text: String, activity: ComponentActivity) {
|
|
|
+fun ColumnScope.AddRowLaunchSwitch(
|
|
|
+ icon: ImageVector,
|
|
|
+ text: String,
|
|
|
+ activity: ComponentActivity,
|
|
|
+ onClick: () -> Unit
|
|
|
+) {
|
|
|
val context = LocalContext.current
|
|
|
val basePreferenceHelper = BasePreferenceHelper(context)
|
|
|
Row(
|
|
@@ -362,15 +404,17 @@ fun ColumnScope.AddRowLaunchSwitch(icon: ImageVector, text: String, activity: Co
|
|
|
var isSwitch by remember { mutableStateOf(basePreferenceHelper.getLaunchState()) }
|
|
|
Switch(
|
|
|
checked = isSwitch,
|
|
|
- onCheckedChange = {
|
|
|
- isSwitch = it
|
|
|
- basePreferenceHelper.saveLaunchState(isSwitch)
|
|
|
- if (isSwitch) {
|
|
|
+ onCheckedChange = { state ->
|
|
|
+ if (state) {
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && !Settings.canDrawOverlays(context)) {
|
|
|
- val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION)
|
|
|
- intent.data = Uri.parse("package:${activity.packageName}")
|
|
|
- activity.startActivityForResult(intent, 12345)
|
|
|
+ onClick()
|
|
|
+ } else {
|
|
|
+ isSwitch = true
|
|
|
+ basePreferenceHelper.saveLaunchState(true)
|
|
|
}
|
|
|
+ } else {
|
|
|
+ isSwitch = false
|
|
|
+ basePreferenceHelper.saveLaunchState(false)
|
|
|
}
|
|
|
},
|
|
|
modifier = Modifier.scale(0.8F),
|
|
@@ -388,6 +432,142 @@ fun ColumnScope.AddRowLaunchSwitch(icon: ImageVector, text: String, activity: Co
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
|
+fun ColumnScope.LaunchDialog(
|
|
|
+ onCancel : () -> Unit,
|
|
|
+ context: Context,
|
|
|
+ activity: ComponentActivity
|
|
|
+) {
|
|
|
+ var isButtonFocused1 by remember { mutableStateOf(false) }
|
|
|
+ var isButtonFocused2 by remember { mutableStateOf(false) }
|
|
|
+
|
|
|
+
|
|
|
+ Surface(
|
|
|
+ color = colorResource(id = R.color.white),
|
|
|
+ modifier = Modifier
|
|
|
+ .background(Color.Transparent)
|
|
|
+ .fillMaxWidth()
|
|
|
+ ,
|
|
|
+ shape = RoundedCornerShape(18.dp)
|
|
|
+ ) {
|
|
|
+ Column(
|
|
|
+ verticalArrangement = Arrangement.Top,
|
|
|
+ horizontalAlignment = Alignment.CenterHorizontally,
|
|
|
+ modifier = Modifier
|
|
|
+// .background(MaterialTheme.colorScheme.onBackground)
|
|
|
+ .background(MaterialTheme.colorScheme.onBackground)
|
|
|
+ ) {
|
|
|
+ Log.d("islogoutClicked", "AlertDialog")
|
|
|
+
|
|
|
+ Text(text = "Launch On Startup Permission",
|
|
|
+// color = MaterialTheme.colorScheme.primary,
|
|
|
+ color = MaterialTheme.colorScheme.primary,
|
|
|
+ maxLines = 2,
|
|
|
+ style = MaterialTheme.typography.customTypography.displayLarge,
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(top = 30.dp, start = 25.dp)
|
|
|
+ .align(Alignment.Start)
|
|
|
+ )
|
|
|
+ Text(text = "Step 1. Press Enable Button",
|
|
|
+// color = MaterialTheme.colorScheme.primary,
|
|
|
+ color = MaterialTheme.colorScheme.primary,
|
|
|
+ style = MaterialTheme.typography.labelMedium,
|
|
|
+ maxLines = 1,
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(top = 25.dp, start = 25.dp)
|
|
|
+ .align(Alignment.Start)
|
|
|
+ )
|
|
|
+ Text(text = "Step 2. Search FastestVPN",
|
|
|
+// color = MaterialTheme.colorScheme.primary,
|
|
|
+ color = MaterialTheme.colorScheme.primary,
|
|
|
+ style = MaterialTheme.typography.labelMedium,
|
|
|
+ maxLines = 1,
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(top = 15.dp, start = 25.dp)
|
|
|
+ .align(Alignment.Start)
|
|
|
+ )
|
|
|
+ Text(text = "Step 3. Allow Permission",
|
|
|
+// color = MaterialTheme.colorScheme.primary,
|
|
|
+ color = MaterialTheme.colorScheme.primary,
|
|
|
+ style = MaterialTheme.typography.labelMedium,
|
|
|
+ maxLines = 1,
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(top = 15.dp, start = 25.dp)
|
|
|
+ .align(Alignment.Start)
|
|
|
+ )
|
|
|
+ Row (
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(top = 34.dp),
|
|
|
+ horizontalArrangement = Arrangement.SpaceBetween,
|
|
|
+ verticalAlignment = Alignment.Bottom
|
|
|
+ ) {
|
|
|
+ Button(
|
|
|
+ onClick = {
|
|
|
+ Log.d("test_button", "No")
|
|
|
+ onCancel()
|
|
|
+ },
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(
|
|
|
+ start = 15.dp, end = 5.dp,
|
|
|
+ bottom = 0.dp, top = 0.dp
|
|
|
+ )
|
|
|
+ .onFocusChanged {
|
|
|
+ isButtonFocused1 = it.isFocused
|
|
|
+ }
|
|
|
+ .background(colorResource(id = R.color.transparent))
|
|
|
+ .weight(1F)
|
|
|
+ .height(52.dp),
|
|
|
+
|
|
|
+ shape = RoundedCornerShape(15.dp),
|
|
|
+ colors = ButtonDefaults.buttonColors(
|
|
|
+ contentColor = colorResource(id = R.color.white),
|
|
|
+ containerColor = colorResource(id = R.color.light_blue),
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ {
|
|
|
+ Text(text = "Cancel",
|
|
|
+ style = MaterialTheme.typography.labelLarge)
|
|
|
+ Log.d("test_button", "RowScope")
|
|
|
+ }
|
|
|
+
|
|
|
+ Button(
|
|
|
+ onClick = {
|
|
|
+ Log.d("test_button", "Logout Yes")
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && !Settings.canDrawOverlays(context)) {
|
|
|
+ val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION)
|
|
|
+ intent.data = Uri.parse("package:${activity.packageName}")
|
|
|
+ activity.startActivityForResult(intent, 12345)
|
|
|
+ }
|
|
|
+
|
|
|
+ onCancel()
|
|
|
+ },
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(
|
|
|
+ start = 5.dp, end = 15.dp,
|
|
|
+ bottom = 0.dp, top = 0.dp
|
|
|
+ )
|
|
|
+ .background(colorResource(id = R.color.transparent))
|
|
|
+ .onFocusChanged {
|
|
|
+ isButtonFocused2 = it.isFocused
|
|
|
+ }
|
|
|
+ .weight(1F)
|
|
|
+ .height(52.dp),
|
|
|
+ shape = RoundedCornerShape(15.dp),
|
|
|
+ colors = ButtonDefaults.buttonColors(
|
|
|
+ contentColor = colorResource(id = R.color.white),
|
|
|
+ containerColor = colorResource(id = R.color.red),
|
|
|
+ ),
|
|
|
+ )
|
|
|
+ {
|
|
|
+ Text(text = "Enable",
|
|
|
+ style = MaterialTheme.typography.labelLarge)
|
|
|
+ Log.d("test_button", "RowScope")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+@Composable
|
|
|
fun ColumnScope.AddRowSettings(
|
|
|
icon: Int,
|
|
|
text: String,
|