|
@@ -2,14 +2,17 @@ package com.vpn.fastestvpnservice.screens.bottomNavBarScreens
|
|
|
|
|
|
import android.app.Activity
|
|
|
import android.app.LocaleManager
|
|
|
-import android.app.PendingIntent
|
|
|
import android.content.Context
|
|
|
import android.content.Intent
|
|
|
+import android.net.Uri
|
|
|
import android.os.Build
|
|
|
import android.os.Bundle
|
|
|
import android.os.Handler
|
|
|
import android.os.LocaleList
|
|
|
+import android.provider.Settings
|
|
|
import android.util.Log
|
|
|
+import android.widget.Toast
|
|
|
+import androidx.activity.ComponentActivity
|
|
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
|
|
import androidx.compose.foundation.Image
|
|
|
import androidx.compose.foundation.LocalOverscrollConfiguration
|
|
@@ -35,6 +38,7 @@ 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.DockedSearchBar
|
|
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
|
|
import androidx.compose.material3.Icon
|
|
@@ -104,7 +108,7 @@ import kotlinx.coroutines.launch
|
|
|
|
|
|
@OptIn(ExperimentalFoundationApi::class)
|
|
|
@Composable
|
|
|
-fun Settings(navHostController: NavHostController) {
|
|
|
+fun Settings(navHostController: NavHostController, activity: ComponentActivity) {
|
|
|
val context = LocalContext.current
|
|
|
|
|
|
CompositionLocalProvider(
|
|
@@ -201,6 +205,8 @@ fun Settings(navHostController: NavHostController) {
|
|
|
text = "Theme")
|
|
|
|
|
|
SelectLanguage(icon = Icons.Default.Language, text = "Language")
|
|
|
+
|
|
|
+ AddRowLaunchSwitch(icon = Icons.Filled.RocketLaunch, text = "Launch On Startup", activity)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -303,6 +309,85 @@ fun ColumnScope.AddRowSwitch(icon: Int, text: String) {
|
|
|
}
|
|
|
|
|
|
@Composable
|
|
|
+fun ColumnScope.AddRowLaunchSwitch(icon: ImageVector, text: String, activity: ComponentActivity) {
|
|
|
+ val context = LocalContext.current
|
|
|
+ val basePreferenceHelper = BasePreferenceHelper(context)
|
|
|
+ Row(
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .padding(top = 40.dp, end = 13.dp)
|
|
|
+ .background(Color.Transparent)
|
|
|
+ .height(30.dp),
|
|
|
+ horizontalArrangement = Arrangement.Start,
|
|
|
+ verticalAlignment = Alignment.CenterVertically
|
|
|
+ ) {
|
|
|
+
|
|
|
+ Surface(
|
|
|
+ modifier = Modifier.padding(start = 0.dp),
|
|
|
+ color = Color.Transparent
|
|
|
+ ) {
|
|
|
+ Image(
|
|
|
+ imageVector = icon,
|
|
|
+ contentDescription = "Launch on startup",
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(start = 0.dp)
|
|
|
+ .size(24.dp)
|
|
|
+ .weight(1f),
|
|
|
+ colorFilter = ColorFilter.tint(
|
|
|
+ MaterialTheme.colorScheme.primary)
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ Surface(
|
|
|
+ modifier = Modifier.padding(start = 0.dp),
|
|
|
+ color = Color.Transparent
|
|
|
+ ) {
|
|
|
+ Text(text = text,
|
|
|
+ style = MaterialTheme.typography.titleSmall,
|
|
|
+ color = MaterialTheme.colorScheme.primary,
|
|
|
+ maxLines = 1,
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(start = 18.dp, end = 0.dp)
|
|
|
+ .weight(1f)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ Spacer(modifier = Modifier.weight(1f))
|
|
|
+
|
|
|
+ Surface(
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(start = 0.dp, end = 0.dp)
|
|
|
+ .align(Alignment.CenterVertically),
|
|
|
+ color = Color.Transparent
|
|
|
+ ) {
|
|
|
+ var isSwitch by remember { mutableStateOf(basePreferenceHelper.getLaunchState()) }
|
|
|
+ Switch(
|
|
|
+ checked = isSwitch,
|
|
|
+ onCheckedChange = {
|
|
|
+ isSwitch = it
|
|
|
+ basePreferenceHelper.saveLaunchState(isSwitch)
|
|
|
+ if (isSwitch) {
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ modifier = Modifier.scale(0.8F),
|
|
|
+ colors = SwitchDefaults.colors(
|
|
|
+ checkedThumbColor = Color.White,
|
|
|
+ checkedTrackColor = MaterialTheme.colorScheme.surfaceContainerLowest,
|
|
|
+ uncheckedThumbColor = MaterialTheme.colorScheme.onSecondaryContainer,
|
|
|
+ uncheckedTrackColor = MaterialTheme.colorScheme.surfaceContainerHighest,
|
|
|
+ uncheckedBorderColor = MaterialTheme.colorScheme.surfaceContainerHighest
|
|
|
+ ),
|
|
|
+ thumbContent = {}
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+@Composable
|
|
|
fun ColumnScope.AddRowSettings(
|
|
|
icon: Int,
|
|
|
text: String,
|
|
@@ -1294,5 +1379,5 @@ fun ColumnScope.AddTextSettings(
|
|
|
@Preview
|
|
|
@Composable
|
|
|
fun SettingsPreview() {
|
|
|
- Settings(rememberNavController())
|
|
|
+// Settings(rememberNavController(), ComponentActivity())
|
|
|
}
|