Browse Source

Set string resources on settings screen, split tunneling and notifications screen on TV for multi lingual

Khubaib 8 months ago
parent
commit
dfc4017fa6

+ 4 - 3
app/src/main/java/com/vpn/fastestvpnservice/screensTV/NotificationScreenTV.kt

@@ -1,5 +1,6 @@
 package com.vpn.fastestvpnservice.screensTV
 
+import android.content.Context
 import androidx.compose.foundation.background
 import androidx.compose.foundation.layout.Box
 import androidx.compose.foundation.layout.BoxScope
@@ -41,7 +42,7 @@ fun NotificationsTV(navHostController: NavHostController) {
         LaunchedEffect(key1 = Unit) {
             notificationViewModel.getNotifications()
         }
-        HeaderRowNSTV(navHostController = navHostController)
+        HeaderRowNSTV(navHostController = navHostController, context)
 
         Column(
             modifier = Modifier
@@ -64,7 +65,7 @@ fun NotificationsTV(navHostController: NavHostController) {
 }
 
 @Composable
-fun BoxScope.HeaderRowNSTV(navHostController: NavHostController) {
+fun BoxScope.HeaderRowNSTV(navHostController: NavHostController, context: Context) {
 //    IconButton(
 //        onClick = {
 //            navHostController.popBackStack()
@@ -90,7 +91,7 @@ fun BoxScope.HeaderRowNSTV(navHostController: NavHostController) {
             .align(Alignment.TopStart),
         color = colorResource(id = R.color.transparent)
     ) {
-        Text(text = "Notifications",
+        Text(text = context.getString(R.string.notifcation),
             color = MaterialTheme.colorScheme.primary,
             style = MaterialTheme.typography.bodyMedium,
             modifier = Modifier.fillMaxHeight()

+ 52 - 22
app/src/main/java/com/vpn/fastestvpnservice/screensTV/SettingsScreenTV.kt

@@ -134,15 +134,13 @@ fun SettingsTV(navHostController: NavHostController) {
     val focusRequester1 = remember { FocusRequester() }
     val focusRequester2 = remember { FocusRequester() }
     val focusRequester3 = remember { FocusRequester() }
-    val focusRequester4 = remember { FocusRequester() }
-    val focusRequester5 = remember { FocusRequester() }
     val focusRequesterProtocol = remember { FocusRequester() }
     val scope = rememberCoroutineScope()
     val homeViewModel: HomeViewModel = viewModel{
         HomeViewModel(context, scope)
     }
     val vpnConnectionsUtil = VPNConnectionsUtil(context, activityGlobal, homeViewModel)
-
+    var settingsString by remember { mutableStateOf(context.getString(R.string.settings)) }
 
     if (isSettingsScreenPressed.value) {
         LaunchedEffect(Unit) {
@@ -153,9 +151,6 @@ fun SettingsTV(navHostController: NavHostController) {
     val navBackStackEntry = navHostController.currentBackStackEntryAsState()
 
     BackHandler {
-//        Toast.makeText(
-//            context, "BackHandler Settings TV - ${isSecondItemFocused.value}", Toast.LENGTH_SHORT
-//        ).show()
         if (isSecondItemFocused.value) {
             navHostController.popBackStack()
             isFirstItemPressed.value = true
@@ -200,8 +195,14 @@ fun SettingsTV(navHostController: NavHostController) {
 //                }
 
 //                Spacer(modifier = Modifier.height(16.dp))
+
+                val settingsStr = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
+                    context.getString(R.string.settings)
+                } else {
+                    settingsString
+                }
                 AddTextSettingsTV(
-                    text = "Settings",
+                    text = settingsStr,
                     size = 28.sp,
                     color = MaterialTheme.colorScheme.primary,
                     style = MaterialTheme.typography.headlineLarge,
@@ -211,7 +212,7 @@ fun SettingsTV(navHostController: NavHostController) {
 
                 AddRowSettingsColumnTV(
                     icon = R.drawable.vpn_protocols3x,
-                    text = "VPN Protocols",
+                    text = context.getString(R.string.vpn_protocols),
                     focusRequester1,
                     focusRequester2,
                     navHostController,
@@ -219,7 +220,7 @@ fun SettingsTV(navHostController: NavHostController) {
                 )
                 AddRowSettingsSmartTV(
                     icon = R.drawable.smart_connect3x,
-                    text = "Smart Connect",
+                    text = context.getString(R.string.smart_connect),
                     isRowShown = true,
                     isSheetShown = false,
                     navHostController,
@@ -228,7 +229,7 @@ fun SettingsTV(navHostController: NavHostController) {
                 )
                 AddRowSwitchTV(
                     icon = R.drawable.adblock3x,
-                    text = "AdBlock",
+                    text = context.getString(R.string.adblock),
                     focusRequester3,
                     vpnConnectionsUtil
                 )
@@ -244,22 +245,24 @@ fun SettingsTV(navHostController: NavHostController) {
 //                )
                 AddRowSettingsTV(
                     icon = R.drawable.split_tunneling3x,
-                    text = "Split Tunneling",
+                    text = context.getString(R.string.split_tunneling),
                     onClick = { navHostController.navigate(ScreenTV.SplitTunnelingTV.route) }
                 )
                 AddRowSettingsTV(
                     icon = R.drawable.notification3x,
-                    text = "Notifications",
+                    text = context.getString(R.string.notifcation),
                     onClick = { navHostController.navigate(ScreenTV.NotificationTV.route) },
                 )
                 AddRowDarkLightThemeTV(
                     icon = Icons.Default.DarkMode,
-                    text = "Appearance"
+                    text = context.getString(R.string.appearance)
                 )
                 AddLanguageTV(
                     icon = Icons.Default.Language,
-                    text = "Language"
-                )
+                    text = context.getString(R.string.language)
+                ) {
+                    settingsString = it
+                }
             }
         }
     }
@@ -685,7 +688,7 @@ fun ColumnScope.AddRowSettingsColumnTV(
                         horizontalAlignment = Alignment.Start
                     ) {
                         AddTextSettings(
-                            text = "VPN Protocols",
+                            text = context.getString(R.string.vpn_protocols),
                             size = 18.sp,
                             color = MaterialTheme.colorScheme.primary,
                             bottomPadding = 15.dp,
@@ -943,7 +946,7 @@ fun ColumnScope.AddRowSettingsSmartTV(
                     horizontalAlignment = Alignment.Start
                 ) {
                     AddTextSettings(
-                        text = "Smart Connect",
+                        text = context.getString(R.string.smart_connect),
                         size = 18.sp,
                         color = MaterialTheme.colorScheme.primary,
                         bottomPadding = 20.dp,
@@ -951,6 +954,20 @@ fun ColumnScope.AddRowSettingsSmartTV(
                         style = MaterialTheme.typography.titleMedium
                     )
                     smartConnect.forEach { smart ->
+                        var smartLingual: String = ""
+                        when (smart) {
+                            smartConnect[0] -> {
+                                smartLingual = context.getString(R.string.recommended)
+                            }
+
+                            smartConnect[1] -> {
+                                smartLingual = context.getString(R.string.recently)
+                            }
+
+                            smartConnect[2] -> {
+                                smartLingual = context.getString(R.string.any_specific)
+                            }
+                        }
                         isButtonFocused = isSmartFocused == smart
                         Row(
                             modifier = Modifier
@@ -1009,7 +1026,7 @@ fun ColumnScope.AddRowSettingsSmartTV(
                                     unselectedColor = colorResource(id = R.color.gray_icon),)
                             )
                             Column {
-                                Text(text = smart,
+                                Text(text = smartLingual,
                                     modifier = Modifier.padding(start = 12.dp),
                                     color = MaterialTheme.colorScheme.primary,
                                     style = MaterialTheme.typography.bodySmall
@@ -1280,7 +1297,7 @@ fun AddRowDarkLightThemeTV(
                     horizontalAlignment = Alignment.Start
                 ) {
                     AddTextSettings(
-                        text = "Appearance",
+                        text = context.getString(R.string.appearance),
                         size = 18.sp,
                         color = MaterialTheme.colorScheme.primary,
                         bottomPadding = 20.dp,
@@ -1288,6 +1305,18 @@ fun AddRowDarkLightThemeTV(
                         style = MaterialTheme.typography.titleSmall
                     )
                     themesList.forEach { theme ->
+                        var themeLingual: String = ""
+                        when (theme) {
+                            themesList[0] -> {
+                                themeLingual = context.getString(R.string.system_default)
+                            }
+                            themesList[1] -> {
+                                themeLingual = context.getString(R.string.light_mode)
+                            }
+                            themesList[2] -> {
+                                themeLingual = context.getString(R.string.dark_mode)
+                            }
+                        }
                         isButtonFocused = isSelectedTheme == theme
                         Row(
                             modifier = Modifier
@@ -1350,7 +1379,7 @@ fun AddRowDarkLightThemeTV(
                                     selectedColor = colorResource(id = R.color.radio_button_blue),
                                     unselectedColor = colorResource(id = R.color.gray_icon),)
                             )
-                            Text(text = theme,
+                            Text(text = themeLingual,
                                 modifier = Modifier.padding(start = 12.dp),
                                 style = MaterialTheme.typography.bodySmall,
                                 color = MaterialTheme.colorScheme.primary
@@ -1368,6 +1397,7 @@ fun AddRowDarkLightThemeTV(
 fun AddLanguageTV(
     icon: ImageVector,
     text: String,
+    changeLanguage: (String) -> Unit
 ) {
     var isRowFocused by remember { mutableStateOf(false) }
     var isButtonFocused by remember { mutableStateOf(false) }
@@ -1532,7 +1562,7 @@ fun AddLanguageTV(
                                                 },
                                                 context.resources.displayMetrics
                                             )
-//                                            changeLanguage(context.getString(R.string.settings))
+                                            changeLanguage(context.getString(R.string.settings))
                                         }
                                         isLanguageSheetOpen = false
                                     },
@@ -1570,7 +1600,7 @@ fun AddLanguageTV(
                                             },
                                             context.resources.displayMetrics
                                         )
-//                                        changeLanguage(context.getString(R.string.settings))
+                                        changeLanguage(context.getString(R.string.settings))
                                     }
                                     isLanguageSheetOpen = false
                                 },

+ 18 - 5
app/src/main/java/com/vpn/fastestvpnservice/screensTV/SplitTunnelingTV.kt

@@ -71,12 +71,13 @@ fun SplitTunnelingTV(navHostController: NavHostController) {
             .fillMaxSize()
             .background(MaterialTheme.colorScheme.background)
     ) {
+        val context = LocalContext.current
         val view = LocalView.current
         val window = (view.context as Activity).window
         window.statusBarColor = Color.Transparent.toArgb()
         window.navigationBarColor = Color.Transparent.toArgb()
 
-        HeaderRowSTTV(navHostController = navHostController)
+        HeaderRowSTTV(navHostController = navHostController, context)
 
         Column(
             verticalArrangement = Arrangement.Top,
@@ -100,7 +101,7 @@ fun SplitTunnelingTV(navHostController: NavHostController) {
                     .padding(start = 16.dp, end = 28.dp)
                     .fillMaxWidth()
             ) {
-                Text(text = "While VPN is Connected",
+                Text(text = context.getString(R.string.while_vpn_connected),
                     style = MaterialTheme.typography.titleSmall,
                     color = MaterialTheme.colorScheme.primary
                 )
@@ -130,7 +131,7 @@ fun SplitTunnelingTV(navHostController: NavHostController) {
 }
 
 @Composable
-fun BoxScope.HeaderRowSTTV(navHostController: NavHostController) {
+fun BoxScope.HeaderRowSTTV(navHostController: NavHostController, context: Context) {
     val focusRequester1 = remember { FocusRequester() }
     var isButtonFocused by remember { mutableStateOf(false) }
 //    LaunchedEffect(key1 = Unit) {
@@ -172,7 +173,7 @@ fun BoxScope.HeaderRowSTTV(navHostController: NavHostController) {
                 ,
         color = colorResource(id = R.color.transparent)
     ) {
-        Text(text = "Split Tunneling",
+        Text(text = context.getString(R.string.split_tunneling),
             color = MaterialTheme.colorScheme.primary,
             style = MaterialTheme.typography.titleMedium,
             modifier = Modifier.fillMaxHeight()
@@ -212,6 +213,18 @@ fun ColumnScope.ShowRadioButtonsTV() {
     Spacer(modifier = Modifier.height(10.dp))
 
     splitList.forEachIndexed { index, list ->
+        var splitListLingual: String = ""
+        when (list) {
+            splitList[0] -> {
+                splitListLingual = context.getString(R.string.all_apps_use_vpn)
+            }
+            splitList[1] -> {
+                splitListLingual = context.getString(R.string.only_selected_apps_use_vpn)
+            }
+            splitList[2] -> {
+                splitListLingual = context.getString(R.string.only_selected_apps_not_use_vpn)
+            }
+        }
         isButtonFocused = focusedList == list
         Row(
             modifier = Modifier
@@ -258,7 +271,7 @@ fun ColumnScope.ShowRadioButtonsTV() {
                                 )
                             )
                             Text(
-                                text = list,
+                                text = splitListLingual,
                                 modifier = Modifier.padding(start = 12.dp),
                                 style = MaterialTheme.typography.bodySmall,
                                 color = MaterialTheme.colorScheme.primary