|
@@ -12,6 +12,7 @@ import android.os.LocaleList
|
|
|
import android.provider.Settings
|
|
|
import android.util.Log
|
|
|
import androidx.activity.ComponentActivity
|
|
|
+import androidx.appcompat.app.AppCompatDelegate
|
|
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
|
|
import androidx.compose.foundation.Image
|
|
|
import androidx.compose.foundation.LocalOverscrollConfiguration
|
|
@@ -37,6 +38,7 @@ 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.BottomSheetDefaults
|
|
@@ -82,6 +84,7 @@ import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
|
|
import androidx.compose.ui.platform.LocalView
|
|
|
import androidx.compose.ui.res.colorResource
|
|
|
import androidx.compose.ui.res.painterResource
|
|
|
+import androidx.compose.ui.res.stringResource
|
|
|
import androidx.compose.ui.text.TextStyle
|
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
|
import androidx.compose.ui.unit.Dp
|
|
@@ -89,7 +92,9 @@ 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
|
|
|
import androidx.core.content.ContextCompat.startActivity
|
|
|
+import androidx.core.os.LocaleListCompat
|
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
|
import androidx.navigation.NavHostController
|
|
|
import com.vpn.fastestvpnservice.MainActivity
|
|
@@ -116,15 +121,20 @@ import com.vpn.fastestvpnservice.viewmodels.SplashViewModel
|
|
|
import de.blinkt.openvpn.core.App
|
|
|
import kotlinx.coroutines.delay
|
|
|
import kotlinx.coroutines.launch
|
|
|
+import java.util.Locale
|
|
|
|
|
|
var isSwitch: MutableState<Boolean> = mutableStateOf(false)
|
|
|
|
|
|
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class)
|
|
|
@Composable
|
|
|
fun Settings(navHostController: NavHostController, activity: ComponentActivity) {
|
|
|
+// Log.d("test_settings_screen", "Settings")
|
|
|
+// Log.d("test_settings_screen", AppCompatDelegate.getApplicationLocales().toString())
|
|
|
+
|
|
|
val context = LocalContext.current
|
|
|
val basePreferenceHelper = BasePreferenceHelper(context)
|
|
|
var isLaunched by remember { mutableStateOf(false) }
|
|
|
+ var settingsString by remember { mutableStateOf(context.getString(R.string.settings)) }
|
|
|
|
|
|
isSwitch.value = basePreferenceHelper.getLaunchState()
|
|
|
|
|
@@ -161,16 +171,21 @@ fun Settings(navHostController: NavHostController, activity: ComponentActivity)
|
|
|
// )
|
|
|
// }
|
|
|
|
|
|
+ val settingsStr = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
|
+ context.getString(R.string.settings)
|
|
|
+ } else {
|
|
|
+ settingsString
|
|
|
+ }
|
|
|
Spacer(modifier = Modifier.height(50.dp))
|
|
|
AddTextSettings(
|
|
|
- text = context.resources.getString(R.string.settings),
|
|
|
+ text = settingsStr,
|
|
|
size = 28.sp,
|
|
|
color = MaterialTheme.colorScheme.primary,
|
|
|
style = MaterialTheme.typography.headlineLarge
|
|
|
)
|
|
|
AddRowSettingsColumn(
|
|
|
icon = R.drawable.vpn_protocols3x,
|
|
|
- text = "VPN Protocols"
|
|
|
+ text = context.getString(R.string.vpn_protocols)
|
|
|
)
|
|
|
/* Commenting so far ...*/
|
|
|
|
|
@@ -188,7 +203,7 @@ fun Settings(navHostController: NavHostController, activity: ComponentActivity)
|
|
|
|
|
|
AddRowSettingsSmart(
|
|
|
icon = R.drawable.smart_connect3x,
|
|
|
- text = "Smart Connect",
|
|
|
+ text = stringResource(id = R.string.smart_connect),
|
|
|
isRowShown = true,
|
|
|
isSheetShown = false,
|
|
|
navHostController
|
|
@@ -221,8 +236,6 @@ fun Settings(navHostController: NavHostController, activity: ComponentActivity)
|
|
|
icon = Icons.Default.DarkMode,
|
|
|
text = "Appearance")
|
|
|
|
|
|
-// SelectLanguage(icon = Icons.Default.Language, text = "Language")
|
|
|
-
|
|
|
AddRowLaunchSwitch(
|
|
|
icon = Icons.Filled.RocketLaunch,
|
|
|
text = "Launch On Startup",
|
|
@@ -232,6 +245,10 @@ fun Settings(navHostController: NavHostController, activity: ComponentActivity)
|
|
|
}
|
|
|
)
|
|
|
|
|
|
+ SelectLanguage(icon = Icons.Default.Language, text = "Language") {
|
|
|
+ settingsString = it
|
|
|
+ }
|
|
|
+
|
|
|
if (isLaunched) {
|
|
|
AlertDialog(
|
|
|
onDismissRequest = { isLaunched = false },
|
|
@@ -1046,6 +1063,7 @@ fun AddRowDarkLightTheme(
|
|
|
fun SelectLanguage(
|
|
|
icon: ImageVector,
|
|
|
text: String,
|
|
|
+ changeLanguage: (String) -> Unit
|
|
|
) {
|
|
|
var isLanguageSheetOpen by remember { mutableStateOf(false) }
|
|
|
val sheetState = rememberModalBottomSheetState()
|
|
@@ -1162,27 +1180,28 @@ fun SelectLanguage(
|
|
|
selected = language == languages[0],
|
|
|
onClick = {
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
|
- when (language.name) {
|
|
|
- languages[0].name -> {
|
|
|
- context.getSystemService(LocaleManager::class.java).applicationLocales =
|
|
|
- LocaleList.forLanguageTags(language.code)
|
|
|
- }
|
|
|
-
|
|
|
- languages[1].name -> {
|
|
|
- context.getSystemService(LocaleManager::class.java).applicationLocales =
|
|
|
- LocaleList.forLanguageTags(language.code)
|
|
|
- }
|
|
|
-
|
|
|
- languages[2].name -> {
|
|
|
- context.getSystemService(LocaleManager::class.java).applicationLocales =
|
|
|
- LocaleList.forLanguageTags(language.code)
|
|
|
- }
|
|
|
-
|
|
|
- languages[3].name -> {
|
|
|
- context.getSystemService(LocaleManager::class.java).applicationLocales =
|
|
|
- LocaleList.forLanguageTags(language.code)
|
|
|
- }
|
|
|
- }
|
|
|
+ context.getSystemService(LocaleManager::class.java).applicationLocales =
|
|
|
+ LocaleList.forLanguageTags(language.code)
|
|
|
+ } else {
|
|
|
+ AppCompatDelegate.setApplicationLocales(
|
|
|
+ LocaleListCompat.forLanguageTags(
|
|
|
+ language.code
|
|
|
+ )
|
|
|
+ )
|
|
|
+ context.resources.updateConfiguration(
|
|
|
+ context.resources.configuration.apply {
|
|
|
+ setLocale(Locale.forLanguageTag(language.code))
|
|
|
+ },
|
|
|
+ context.resources.displayMetrics
|
|
|
+ )
|
|
|
+// Log.d(
|
|
|
+// "test_settings_screen",
|
|
|
+// "Click = " + AppCompatDelegate
|
|
|
+// .getApplicationLocales()
|
|
|
+// .toString()
|
|
|
+// )
|
|
|
+ changeLanguage(context.getString(R.string.settings))
|
|
|
+
|
|
|
}
|
|
|
isLanguageSheetOpen = false
|
|
|
},
|