|
@@ -44,12 +44,17 @@ import androidx.compose.ui.text.input.ImeAction
|
|
|
import androidx.compose.ui.text.input.KeyboardType
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
+import androidx.lifecycle.viewmodel.compose.viewModel
|
|
|
import androidx.navigation.NavHostController
|
|
|
import com.vpn.fastestvpnservice.R
|
|
|
import com.vpn.fastestvpnservice.customItems.ServerItemTV
|
|
|
+import com.vpn.fastestvpnservice.screens.isSearchModelInitialized
|
|
|
import com.vpn.fastestvpnservice.screens.searchListViewModelSplash
|
|
|
import com.vpn.fastestvpnservice.screens.serverListViewModelSplash
|
|
|
import com.vpn.fastestvpnservice.ui.theme.customTypography
|
|
|
+import com.vpn.fastestvpnservice.viewmodels.SearchListViewModel
|
|
|
+import com.vpn.fastestvpnservice.viewmodels.ServerListViewModel
|
|
|
+import com.vpn.fastestvpnservice.viewmodels.SplashViewModel
|
|
|
import kotlinx.coroutines.delay
|
|
|
|
|
|
@Composable
|
|
@@ -58,6 +63,18 @@ fun ServerListTV(navHostController: NavHostController) {
|
|
|
var textChanged by remember { mutableStateOf("") }
|
|
|
val keyboardController = LocalSoftwareKeyboardController.current
|
|
|
|
|
|
+ if (!isSearchModelInitialized) {
|
|
|
+ splashViewModelSplash = viewModel {
|
|
|
+ SplashViewModel(context)
|
|
|
+ }
|
|
|
+ serverListViewModelSplash = viewModel {
|
|
|
+ ServerListViewModel(context = context)
|
|
|
+ }
|
|
|
+ searchListViewModelSplash = viewModel {
|
|
|
+ SearchListViewModel(context, serverListViewModelSplash, splashViewModelSplash)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
Box(
|
|
|
modifier = Modifier
|
|
|
.fillMaxSize()
|
|
@@ -251,18 +268,18 @@ fun ServerListTV(navHostController: NavHostController) {
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- val searchListViewModel = searchListViewModelSplash
|
|
|
+// val searchListViewModel = searchListViewModelSplash
|
|
|
LaunchedEffect(key1 = textChanged) {
|
|
|
- Log.d("test_search_logic", "LaunchedEffect $textChanged")
|
|
|
+// Log.d("test_search_logic", "LaunchedEffect $textChanged")
|
|
|
val delay = if (textChanged.isEmpty()) 0L else 300L
|
|
|
delay(delay)
|
|
|
- searchListViewModel.getCountries(textChanged, true)
|
|
|
+ searchListViewModelSplash.getCountries(textChanged, true)
|
|
|
}
|
|
|
|
|
|
- val searchServersList = searchListViewModel.countriesList.observeAsState().value
|
|
|
- searchServersList?.forEachIndexed { index, server ->
|
|
|
- Log.d("test_search", "SLS_ ${server.server_name} ${server.ping}")
|
|
|
- }
|
|
|
+ val searchServersList = searchListViewModelSplash.countriesList.observeAsState().value
|
|
|
+// searchServersList?.forEachIndexed { index, server ->
|
|
|
+// Log.d("test_search", "SLS_ ${server.server_name} ${server.ping}")
|
|
|
+// }
|
|
|
|
|
|
if (searchServersList != null) {
|
|
|
val fraction = if (searchServersList.size > 0) 1f else if (textChanged.isNotEmpty()) 1f else 0f
|