Parcourir la source

Resolved crash on set recommended servers, array size out of bound issue

Khubaib il y a 6 mois
Parent
commit
46d8ce8503

+ 2 - 1
app/src/main/java/com/vpn/fastestvpnservice/beans/Dark_Light_Theme.kt

@@ -13,7 +13,8 @@ val languages = listOf<Language>(
     Language("French","fr"),
     Language("Spanish", "es"),
     Language("Italian", "it"),
-    Language("Polish", "pl")
+    Language("Polish", "pl"),
+    Language("Russian", "ru"),
 )
 
 var isDarkTheme: MutableState<Boolean> = mutableStateOf(false)

+ 3 - 3
app/src/main/java/com/vpn/fastestvpnservice/screens/bottomNavBarScreens/SettingsScreen.kt

@@ -247,9 +247,9 @@ fun Settings(navHostController: NavHostController, activity: ComponentActivity)
                     }
                 )
 
-                SelectLanguage(icon = Icons.Default.Language, text = context.getString(R.string.language)) {
-                    settingsString = it
-                }
+//                SelectLanguage(icon = Icons.Default.Language, text = context.getString(R.string.language)) {
+//                    settingsString = it
+//                }
 
                 if (isLaunched) {
                     AlertDialog(

+ 23 - 4
app/src/main/java/com/vpn/fastestvpnservice/viewmodels/ServerListViewModel.kt

@@ -119,12 +119,31 @@ class ServerListViewModel(context: Context): ViewModel() {
             }
 
             if (sortedDistance.isNotEmpty()) {
-                for (i in 0..2) {
-                    calculatePing(sortedDistance.get(i)) {
-                        sortedDistance.get(i).ping = it
+                var intRange: IntRange = 0..0
+                intRange = when (sortedDistance.size) {
+                    1 -> {
+                        0..0
                     }
-                    recommendedListGlobal.add(sortedDistance.get(i))
+
+                    2 -> {
+                        0..1
+                    }
+
+                    3 -> {
+                        0..2
+                    }
+                    else -> {
+                        0..2
+                    }
+                }
+                if (sortedDistance.isNotEmpty()) {
+                    for (i in intRange) {
+                        calculatePing(sortedDistance.get(i)) {
+                            sortedDistance.get(i).ping = it
+                        }
+                        recommendedListGlobal.add(sortedDistance.get(i))
 //                    Log.d("recommendedListGlobal", "SS:: server = ${sortedDistance.get(i).server_name} ${sortedDistance.get(i).ping}")
+                    }
                 }
             }
 

+ 10 - 0
app/src/main/res/values-ru/strings.xml

@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+    <!-- Multi Lingual - (Russian-ru) -->
+
+    <!-- Started Screen -->
+
+
+
+</resources>

+ 2 - 0
app/src/main/res/xml/locales_config.xml

@@ -6,4 +6,6 @@
     <locale android:name = "es" />
     <locale android:name = "it" />
     <locale android:name = "pl" />
+    <locale android:name = "ru" />
+
 </locale-config>