Browse Source

Resolved UninitializedPropertyAccessException of serverListViewModelSplash on settings screen

Khubaib 3 months ago
parent
commit
f3a7a3443e

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

@@ -115,6 +115,7 @@ import com.vpn.fastestvpnservice.constants.smartConnect
 import com.vpn.fastestvpnservice.customItems.ServerSpecificItem
 import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
 import com.vpn.fastestvpnservice.screens.isSearchModelInitialized
+import com.vpn.fastestvpnservice.screens.isServerModelInitialized
 import com.vpn.fastestvpnservice.screens.isSplashModelInitialized
 import com.vpn.fastestvpnservice.screens.searchListViewModelSplash
 import com.vpn.fastestvpnservice.screens.serverListViewModelSplash
@@ -668,10 +669,17 @@ fun ColumnScope.AddRowSettingsColumn(
         "Auto", "WireGuard", "IKEv2", "OpenVPN TCP", "OpenVPN UDP"
     )
     var selectedProtocol by remember { mutableStateOf(basePreferenceHelper.getProtocol().full_name) }
-    val serverListViewModel = serverListViewModelSplash
+//    val serverListViewModel = serverListViewModelSplash
 //    val serverListViewModel: ServerListViewModel = viewModel{
 //        ServerListViewModel(context)
 //    }
+
+    if (!isServerModelInitialized) {
+        serverListViewModelSplash = viewModel {
+            ServerListViewModel(context = context)
+        }
+    }
+
     val configuration = LocalConfiguration.current
     val isTablet = configuration.screenWidthDp > 840
 
@@ -802,7 +810,7 @@ fun ColumnScope.AddRowSettingsColumn(
                                             selectProtocolCallback(
                                                 protocol = protocol,
                                                 context,
-                                                serverListViewModel
+                                                serverListViewModelSplash
                                             )
                                         },
                                     )
@@ -819,7 +827,7 @@ fun ColumnScope.AddRowSettingsColumn(
                                     onClick = {
                                         selectedProtocol = protocol
                                         isSheetOpen = false
-                                        selectProtocolCallback(protocol = protocol, context, serverListViewModel)
+                                        selectProtocolCallback(protocol = protocol, context, serverListViewModelSplash)
                                     },
                                     colors = RadioButtonDefaults.colors(
                                         selectedColor = colorResource(id = R.color.radio_button_blue),

+ 7 - 0
app/src/main/java/com/vpn/fastestvpnservice/screensTV/SettingsScreenTV.kt

@@ -114,6 +114,7 @@ import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.AddTextSettingsLang
 import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.getAvailableProtocols
 import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.navHostController1
 import com.vpn.fastestvpnservice.screens.isSearchModelInitialized
+import com.vpn.fastestvpnservice.screens.isServerModelInitialized
 import com.vpn.fastestvpnservice.screens.searchListViewModelSplash
 import com.vpn.fastestvpnservice.screens.serverListViewModelSplash
 import com.vpn.fastestvpnservice.sealedClass.BottomBarScreen
@@ -538,6 +539,12 @@ fun ColumnScope.AddRowSettingsColumnTV(
     var isFocusedAnyItem by remember { mutableStateOf(false) }
     var isFirstRowFocused by remember { mutableStateOf(false) }
 
+    if (!isServerModelInitialized) {
+        serverListViewModelSplash = viewModel {
+            ServerListViewModel(context = context)
+        }
+    }
+
 //    val serverListViewModel = serverListViewModelSplash
 //    val serverListViewModel: ServerListViewModel = viewModel{
 //        ServerListViewModel(context)