Parcourir la source

Servers list showing of all categories according to servers data

Khubaib il y a 9 mois
Parent
commit
2fe659ca39

+ 1 - 1
.idea/deploymentTargetSelector.xml

@@ -4,7 +4,7 @@
     <selectionStates>
       <SelectionState runConfigName="app">
         <option name="selectionMode" value="DROPDOWN" />
-        <DropdownSelection timestamp="2024-07-09T09:08:09.363424534Z">
+        <DropdownSelection timestamp="2024-07-10T12:28:25.511492595Z">
           <Target type="DEFAULT_BOOT">
             <handle>
               <DeviceId pluginId="LocalEmulator" identifier="path=/home/ubuntu/.android/avd/Television_1080p_API_31.avd" />

+ 217 - 0
app/src/main/java/com/vpn/fastestvpnservice/customItems/ServerItemTV.kt

@@ -0,0 +1,217 @@
+package com.vpn.fastestvpnservice.customItems
+
+import android.util.Log
+import androidx.compose.foundation.BorderStroke
+import androidx.compose.foundation.background
+import androidx.compose.foundation.border
+import androidx.compose.foundation.clickable
+import androidx.compose.foundation.focusable
+import androidx.compose.foundation.interaction.MutableInteractionSource
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxHeight
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.shape.CircleShape
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material3.Icon
+import androidx.compose.material3.IconButton
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Surface
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.alpha
+import androidx.compose.ui.draw.clip
+import androidx.compose.ui.draw.paint
+import androidx.compose.ui.focus.FocusRequester
+import androidx.compose.ui.focus.focusRequester
+import androidx.compose.ui.focus.onFocusChanged
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.layout.ContentScale
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.res.colorResource
+import androidx.compose.ui.res.painterResource
+import androidx.compose.ui.tooling.preview.Preview
+import androidx.compose.ui.unit.dp
+import androidx.lifecycle.viewmodel.compose.viewModel
+import androidx.navigation.NavHostController
+import com.vpn.fastestvpnservice.R
+import com.vpn.fastestvpnservice.beans.Server
+import com.vpn.fastestvpnservice.beans.toChangeServer
+import com.vpn.fastestvpnservice.constants.smartConnect
+import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
+import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.navHostController1
+import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.onServer
+import com.vpn.fastestvpnservice.screens.serverListViewModelSplash
+import com.vpn.fastestvpnservice.screensTV.ServerListTV
+import com.vpn.fastestvpnservice.sealedClass.Screen
+import com.vpn.fastestvpnservice.utils.Utils
+import com.vpn.fastestvpnservice.viewmodels.HomeViewModel
+
+@Composable
+fun ServerItemTV(
+    server: Server,
+    navHostController: NavHostController,
+    serverPing: Int = 0
+) {
+    val context = LocalContext.current
+    val scope = rememberCoroutineScope()
+    var isServerClicked by remember { mutableStateOf(false) }
+    val homeViewModel: HomeViewModel = viewModel{ HomeViewModel(context, scope) }
+    val basePreferenceHelper = BasePreferenceHelper(context)
+
+    var isFavorite by remember { mutableStateOf(server.isFavourited) }
+    val isServerFavourited: Boolean = server.isFavourited == true
+    Log.d("test-server_fav_d", "$isFavorite")
+    var isItemFocused by remember { mutableStateOf(false) }
+
+    Box(
+        modifier = Modifier
+            .size(width = 160.dp, height = 150.dp)
+            .padding(bottom = 0.dp)
+    )
+    {
+
+
+
+//        if (isServerClicked) {
+//            Log.d("ServerCallbacks", "isServerClicked $isServerClicked")
+//            onServer.onServerSelected(
+//                context,
+//                homeViewModel,
+//                onClick = { isServerClicked = false },
+//                true,
+//                server
+//            )
+//
+//            navHostController.popBackStack()
+//        }
+
+        Row(
+            modifier = Modifier
+                .size(width = 160.dp, height = 150.dp)
+            ,
+            verticalAlignment = Alignment.CenterVertically,
+            horizontalArrangement = Arrangement.Start
+        ) {
+            Column(
+                horizontalAlignment = Alignment.CenterHorizontally,
+            verticalArrangement = Arrangement.SpaceAround,
+                modifier = Modifier
+                    .size(150.dp)
+                    .padding(start = 0.dp, end = 0.dp, top = 0.dp)
+                    .background(if (isItemFocused) Color.LightGray else Color.White)
+                    .onFocusChanged {
+                        isItemFocused = it.isFocused
+                    }
+                    .focusable()
+
+//                .clickable(
+//                    indication = null,
+//                    interactionSource = remember { MutableInteractionSource() }
+//                ) {
+//                    if (server.enable == 1) {
+//                        if (toChangeServer.value) {
+//                            basePreferenceHelper.saveSmartList(smartConnect[2])
+//                            basePreferenceHelper.setSmartServerObject(server)
+//                            navHostController.popBackStack()
+//                        } else {
+//                            isServerClicked = true
+//                        }
+////                        basePreferenceHelper.setServerObject(server)
+//                    } else {
+//                        basePreferenceHelper.setSubscriptionServerObject(server)
+//                        Screen.Subscription.isTrue = true
+//                        navHostController.navigate(
+//                            Screen.Subscription.route
+//                        )
+//                    }
+//                }
+            ) {
+                val icon = if (server.enable == 1) Utils.getDrawable(context, server.iso)
+                else Utils.getDrawableGray(context, server.iso)
+
+                Icon(
+                    painter = painterResource(id = icon),
+                    contentDescription = "Server Logo",
+                    tint = Color.Unspecified,
+                    modifier = Modifier
+                        .padding(top = 20.dp)
+                        .size(44.dp)
+                        .clip(CircleShape)
+                        .border(1.dp, colorResource(id = R.color.gray_opac_04), CircleShape)
+                        .paint(
+                            painter = painterResource(id = icon),
+                            contentScale = ContentScale.FillBounds
+                        )
+                )
+                Text(text = "${server.server_name}",
+                    style = MaterialTheme.typography.labelMedium,
+                    color = colorResource(id = R.color.dark_blue_gray_text),
+                    modifier = Modifier
+                        .padding(start = 10.dp, top = 10.dp, end = 10.dp)
+                        .align(Alignment.CenterHorizontally)
+                )
+//            Spacer(modifier = Modifier.weight(1F))
+                Text(text = "$serverPing ms",
+                    style = MaterialTheme.typography.displayMedium,
+                    color = colorResource(id = R.color.dark_blue_gray_text),
+                    modifier = Modifier
+                        .padding(end = 0.dp, top = 8.dp)
+                        .align(Alignment.CenterHorizontally)
+                        .alpha(0.4f)
+                )
+//            Spacer(modifier = Modifier.weight(1F))
+
+//            IconButton(
+//                modifier = Modifier
+//                    .padding(bottom = 18.dp, end = 8.dp)
+//                    .size(25.dp),
+//                onClick = {
+//                    isFavorite = !isFavorite!!
+//                    serverListViewModelSplash.favAndUnFav(server)
+//                }
+//            ) {
+//                Icon(
+//                    painter = if (isServerFavourited) painterResource(
+//                        id = R.drawable.fav_server3x) else painterResource(
+//                        id = R.drawable.unfav_server3x),
+//                    contentDescription = "Server Logo",
+//                    tint = Color.Unspecified,
+//                    modifier = Modifier.size(22.dp, 21.dp)
+//                )
+//            }
+            }
+
+            Surface(
+                modifier = Modifier
+                    .padding(start = 0.dp, end = 0.dp)
+                    .height(150.dp)
+                    .width(10.dp)
+                    .alpha(1F)
+                    ,
+                color = colorResource(id = R.color.background_color_gray)
+            ) {}
+        }
+    }
+}
+
+@Preview
+@Composable
+fun ServerListTVPreview() {
+    ServerListTV(navHostController = navHostController1)
+}

+ 5 - 0
app/src/main/java/com/vpn/fastestvpnservice/navigation/BottomBarNavGraphTV.kt

@@ -15,8 +15,10 @@ import androidx.navigation.compose.composable
 import com.vpn.fastestvpnservice.screensTV.AccountTV
 import com.vpn.fastestvpnservice.screensTV.HelpTV
 import com.vpn.fastestvpnservice.screensTV.HomeTV
+import com.vpn.fastestvpnservice.screensTV.ServerListTV
 import com.vpn.fastestvpnservice.screensTV.SettingsTV
 import com.vpn.fastestvpnservice.sealedClass.BottomBarScreen
+import com.vpn.fastestvpnservice.sealedClass.ScreenTV
 
 @Composable
 fun BottomBarNavGraphTV(navHostController: NavHostController,
@@ -55,6 +57,9 @@ fun BottomBarNavGraphTV(navHostController: NavHostController,
         composable(route = BottomBarScreen.Account.route) {
             AccountTV(navHostController = navHostController, settingsNavHostController = settingsNavHostController)
         }
+        composable(route = ScreenTV.ServerListTV.route) {
+            ServerListTV(navHostController = navHostController)
+        }
 
         /* Again declare for login because of different -> navHostController */
 //        composable(route = Screen.Login.route) {

+ 6 - 2
app/src/main/java/com/vpn/fastestvpnservice/screensTV/HomeScreenTV.kt

@@ -83,6 +83,7 @@ import com.vpn.fastestvpnservice.constants.smartConnect
 import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
 import com.vpn.fastestvpnservice.navigation.isFirstItemPressed
 import com.vpn.fastestvpnservice.navigation.isHomeScreenPressed
+import com.vpn.fastestvpnservice.sealedClass.ScreenTV
 import com.vpn.fastestvpnservice.ui.theme.customTypography
 import com.vpn.fastestvpnservice.utils.Utils
 import com.vpn.fastestvpnservice.utils.VPNConnectionsUtil
@@ -639,6 +640,9 @@ fun HomeTV(navHostController: NavHostController) {
 //                            Toast
 //                                .makeText(context, "See All Pressed", Toast.LENGTH_SHORT)
 //                                .show()
+                            navHostController.navigate(
+                                ScreenTV.ServerListTV.route
+                            )
                         }
                         .border(
                             border = BorderStroke(2.dp, color),
@@ -875,11 +879,11 @@ fun BoxScope.AddRowSelectServerTV(navHostController: NavHostController, isTablet
             Image(
                 painter = painterResource(id = R.drawable.frontarrow3x),
                 contentDescription = "Front_Arrow",
-                colorFilter = ColorFilter.tint(colorResource(id = R.color.gray_icon)),
+                colorFilter = ColorFilter.tint(colorResource(id = R.color.dark_blue_gray_text)),
                 modifier = Modifier
                     .padding(start = 0.dp, end = 5.dp)
                     .size(10.dp, 18.dp)
-                    .weight(1f),
+                    .weight(1f)
             )
         }
 

+ 1 - 1
app/src/main/java/com/vpn/fastestvpnservice/screensTV/LoginScreenTV.kt

@@ -512,7 +512,7 @@ fun ColumnScope.LoginButtonTV(
                     }
 
                     serverListViewModelSplash.setRecommendedSmartServers()
-                    serverListViewModelSplash.setCountryData()
+                    serverListViewModelSplash.setCountryDataTV()
 
                     selectedItemIndex.value = 0
                     isHomeScreenPressed.value = true

+ 256 - 0
app/src/main/java/com/vpn/fastestvpnservice/screensTV/ServerListScreenTV.kt

@@ -0,0 +1,256 @@
+package com.vpn.fastestvpnservice.screensTV
+
+import android.util.Log
+import androidx.compose.foundation.background
+import androidx.compose.foundation.clickable
+import androidx.compose.foundation.focusable
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.BoxScope
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxHeight
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.lazy.LazyRow
+import androidx.compose.foundation.lazy.itemsIndexed
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.verticalScroll
+import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.automirrored.filled.ArrowBack
+import androidx.compose.material3.Icon
+import androidx.compose.material3.IconButton
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Surface
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.focus.FocusRequester
+import androidx.compose.ui.focus.focusRequester
+import androidx.compose.ui.focus.onFocusChanged
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.res.colorResource
+import androidx.compose.ui.unit.dp
+import androidx.navigation.NavHostController
+import com.vpn.fastestvpnservice.R
+import com.vpn.fastestvpnservice.beans.Server
+import com.vpn.fastestvpnservice.customItems.ServerItemTV
+import com.vpn.fastestvpnservice.screens.serverListViewModelSplash
+
+@Composable
+fun ServerListTV(navHostController: NavHostController) {
+    val context = LocalContext.current
+    Box(
+        modifier = Modifier
+            .fillMaxSize()
+            .background(
+                color = colorResource(id = R.color.background_color_gray)
+            )
+            .padding(bottom = 0.dp)
+
+    ) {
+        HeaderRowSL(navHostController = navHostController)
+
+        var locations = ArrayList<Server>()
+        var dedicatedIP = ArrayList<Server>()
+        var streaming = ArrayList<Server>()
+        var dvpn = ArrayList<Server>()
+        var p2p = ArrayList<Server>()
+
+        var isLocationsEnabled by remember { mutableStateOf(false) }
+        var isDedicatedIpEnabled by remember { mutableStateOf(false) }
+        var isStreamingEnabled by remember { mutableStateOf(false) }
+        var isDvpnEnabled by remember { mutableStateOf(false) }
+        var isP2pEnabled by remember { mutableStateOf(false) }
+
+
+        val countries = serverListViewModelSplash.liveDataGetServersGlobal.value
+        countries?.forEachIndexed { index, serverData ->
+            Log.d("test_serverlist_tv","$index ${serverData?.name} ${serverData?.servers?.size}")
+            if (serverData?.name?.equals("Servers") == true) {
+                serverData.servers?.let { locations = it }
+                if (locations.size > 0) isLocationsEnabled = true
+            }
+            else if (serverData?.name?.equals("Dedicated IP") == true) {
+                serverData.servers?.let { dedicatedIP = it }
+                if (dedicatedIP.size > 0) isDedicatedIpEnabled = true
+            }
+            else if (serverData?.name?.equals("Streaming") == true) {
+                serverData.servers?.let { streaming = it }
+                if (streaming.size > 0) isStreamingEnabled = true
+            }
+            else if (serverData?.name?.equals("D-VPN") == true) {
+                serverData.servers?.let { dvpn = it }
+                if (dvpn.size > 0) isDvpnEnabled = true
+            }
+            else if (serverData?.name?.equals("P2P") == true) {
+                serverData.servers?.let { p2p = it }
+                if (p2p.size > 0) isP2pEnabled = true
+            }
+        }
+
+        Column(
+            modifier = Modifier
+                .fillMaxSize()
+                .padding(top = 80.dp, start = 24.dp, end = 24.dp, bottom = 24.dp)
+                .verticalScroll(rememberScrollState())
+                .background(Color.Transparent)
+        ) {
+            val topPadding = 25.dp
+            Spacer(modifier = Modifier.height(0.dp))
+
+            if (isLocationsEnabled) {
+                Text(
+                    text = "Top Locations",
+                    style = MaterialTheme.typography.labelLarge,
+                    color = colorResource(id = R.color.dark_blue_gray_text),
+                    modifier = Modifier
+                        .padding(top = topPadding, start = 0.dp)
+                        .focusable()
+                )
+                LazyRow(
+                    modifier = Modifier
+                        .padding(top = 10.dp, start = 0.dp, end = 0.dp)
+                        .background(Color.Transparent)
+                ) {
+                    itemsIndexed(items = locations, itemContent = { index, server ->
+                        ServerItemTV(server = server, navHostController = navHostController, serverPing = server.ping)
+                    })
+                }
+            }
+            if (isDedicatedIpEnabled) {
+                Text(
+                    text = "Dedicated IP",
+                    style = MaterialTheme.typography.labelLarge,
+                    color = colorResource(id = R.color.dark_blue_gray_text),
+                    modifier = Modifier
+                        .padding(top = topPadding, start = 0.dp)
+                )
+                LazyRow(
+                    modifier = Modifier
+                        .padding(top = 10.dp, start = 0.dp, end = 0.dp)
+                        .background(Color.Transparent)
+                ) {
+                    itemsIndexed(items = dedicatedIP, itemContent = { index, server ->
+                        ServerItemTV(server = server, navHostController = navHostController, serverPing = server.ping)
+                    })
+                }
+            }
+            if (isStreamingEnabled) {
+                Text(
+                    text = "Streaming",
+                    style = MaterialTheme.typography.labelLarge,
+                    color = colorResource(id = R.color.dark_blue_gray_text),
+                    modifier = Modifier
+                        .padding(top = topPadding, start = 0.dp)
+                )
+                LazyRow(
+                    modifier = Modifier
+                        .padding(top = 10.dp, start = 0.dp, end = 0.dp)
+                        .background(Color.Transparent)
+                ) {
+                    itemsIndexed(items = streaming, itemContent = { index, server ->
+                        ServerItemTV(server = server, navHostController = navHostController, serverPing = server.ping)
+                    })
+                }
+            }
+            if (isDvpnEnabled) {
+                Text(
+                    text = "D-VPN",
+                    style = MaterialTheme.typography.labelLarge,
+                    color = colorResource(id = R.color.dark_blue_gray_text),
+                    modifier = Modifier
+                        .padding(top = topPadding, start = 0.dp)
+                )
+                LazyRow(
+                    modifier = Modifier
+                        .padding(top = 10.dp, start = 0.dp, end = 0.dp)
+                        .background(Color.Transparent)
+                ) {
+                    itemsIndexed(items = dvpn, itemContent = { index, server ->
+                        ServerItemTV(server = server, navHostController = navHostController, serverPing = server.ping)
+                    })
+                }
+            }
+            if (isP2pEnabled) {
+                Text(
+                    text = "P2P",
+                    style = MaterialTheme.typography.labelLarge,
+                    color = colorResource(id = R.color.dark_blue_gray_text),
+                    modifier = Modifier
+                        .padding(top = topPadding, start = 0.dp)
+                )
+                LazyRow(
+                    modifier = Modifier
+                        .padding(top = 10.dp, start = 0.dp, end = 0.dp)
+                        .background(Color.Transparent)
+                ) {
+                    itemsIndexed(items = p2p, itemContent = { index, server ->
+                        ServerItemTV(server = server, navHostController = navHostController, serverPing = server.ping)
+                    })
+                }
+            }
+        }
+    }
+}
+
+@Composable
+fun BoxScope.HeaderRowSL(
+    navHostController: NavHostController) {
+    val focusRequester1 = remember { FocusRequester() }
+    var isButtonFocused by remember { mutableStateOf(false) }
+    LaunchedEffect(key1 = Unit) {
+        focusRequester1.requestFocus()
+    }
+
+    IconButton(
+        onClick = {
+            navHostController.popBackStack()
+        },
+        modifier = Modifier
+            .align(Alignment.TopStart)
+            .padding(top = 25.dp)
+            .padding(start = 16.dp)
+            .size(30.dp, 32.dp)
+            .background(if (isButtonFocused) Color.LightGray else Color.Transparent)
+            .focusRequester(focusRequester1)
+            .onFocusChanged {
+                isButtonFocused = it.isFocused
+            }
+            .focusable()
+            .clickable {
+                navHostController.popBackStack()
+            }
+    ) {
+        Icon(
+            imageVector = Icons.AutoMirrored.Filled.ArrowBack,
+            contentDescription = "Arrow-Back",
+            tint = colorResource(id = R.color.dark_blue_gray_text),
+//            tint = MaterialTheme.colorScheme.primary,
+            modifier = Modifier.size(30.dp, 32.dp)
+        )
+    }
+    Surface(
+        modifier = Modifier
+            .padding(top = 25.dp)
+            .height(32.dp)
+            .align(Alignment.TopCenter)
+            .padding(5.dp),
+        color = colorResource(id = R.color.transparent)
+    ) {
+        Text(text = "Locations",
+            style = MaterialTheme.typography.bodyMedium,
+//            color = MaterialTheme.colorScheme.primary,
+            color = colorResource(id = R.color.dark_blue_gray_text),
+            modifier = Modifier.fillMaxHeight()
+        )
+    }
+}

+ 8 - 8
app/src/main/java/com/vpn/fastestvpnservice/screensTV/SplashScreenTV.kt

@@ -31,13 +31,13 @@ import com.vpn.fastestvpnservice.viewmodels.ServerListViewModel
 import com.vpn.fastestvpnservice.viewmodels.SplashViewModel
 import kotlinx.coroutines.delay
 
-var recommendedListGlobal: ArrayList<Server> = ArrayList<Server>()
-var recommendedListFinalGlobal: List<Server> = emptyList()
-val smartLocationListGlobal: ArrayList<Server> = ArrayList<Server>()
-var serversListAllGlobal: ArrayList<Server> = ArrayList<Server>()
-var serversGroupListGlobal: ArrayList<ServerDataGlobal?> = ArrayList<ServerDataGlobal?>()
-var serversListGlobal: ArrayList<ServerDataGlobal?> = ArrayList<ServerDataGlobal?>()
-var serversListFinalGlobal: List<ServerDataGlobal?> = ArrayList()
+//var recommendedListGlobal: ArrayList<Server> = ArrayList<Server>()
+//var recommendedListFinalGlobal: List<Server> = emptyList()
+//val smartLocationListGlobal: ArrayList<Server> = ArrayList<Server>()
+//var serversListAllGlobal: ArrayList<Server> = ArrayList<Server>()
+//var serversGroupListGlobal: ArrayList<ServerDataGlobal?> = ArrayList<ServerDataGlobal?>()
+//var serversListGlobal: ArrayList<ServerDataGlobal?> = ArrayList<ServerDataGlobal?>()
+//var serversListFinalGlobal: List<ServerDataGlobal?> = ArrayList()
 
 lateinit var splashViewModelSplash: SplashViewModel
 //lateinit var serverListViewModelSplash: ServerListViewModel
@@ -104,7 +104,7 @@ fun SplashTV(navHostController: NavHostController) {
 
             if (isLoggedIn) {
                 serverListViewModelSplash.setRecommendedSmartServers()
-                serverListViewModelSplash.setCountryData()
+                serverListViewModelSplash.setCountryDataTV()
                 splashViewModelSplash.serverDataApi()
                 navHostController.popBackStack()
                 navHostController.navigate(ScreenTV.BottomBarTV.route)

+ 1 - 0
app/src/main/java/com/vpn/fastestvpnservice/sealedClass/ScreenTV.kt

@@ -5,4 +5,5 @@ sealed class ScreenTV(val route: String) {
     data object LoginTV : ScreenTV("login_screen_tv")
     data object HomeTV : ScreenTV("home_screen_tv")
     data object BottomBarTV : ScreenTV("bottom_bar_tv")
+    data object ServerListTV : ScreenTV("server_list_route")
 }

+ 40 - 0
app/src/main/java/com/vpn/fastestvpnservice/viewmodels/ServerListViewModel.kt

@@ -202,6 +202,46 @@ class ServerListViewModel(context: Context): ViewModel() {
         _mutableLiveDataGetServersGlobal.value = serversListGlobal
         mutableLiveDataAllServers.value = serversListAllGlobal
     }
+    fun setCountryDataTV() {
+        val data = preferencesHelper.getServerData()
+
+        serversListGlobal.clear()
+        serversListAllGlobal.clear()
+        serversGroupListGlobal.clear()
+        var filterServersList = ArrayList<Server>()
+
+        data.forEachIndexed { index, serverData ->
+            if (data[index].name?.lowercase().toString() == "servers") {
+                data[index].servers?.let {
+                    val servers = serverListViewModelSplash.filterServersWithTvCountries(it)
+                    serversListGlobal.add(index, ServerDataGlobal(serverData.name, servers))
+
+                    servers.forEachIndexed { index, server ->
+                        getServerGroupList(server, it, index)
+                    }
+
+                }
+            } else {
+                data[index].servers?.let {
+                    val servers = serverListViewModelSplash.filterServersByStreamingServersTV(it)
+                    serversListGlobal.add(index, ServerDataGlobal(serverData.name, servers))
+                }
+            }
+        }
+
+        serversListFinalGlobal = serversListGlobal
+        serversListGlobal.forEachIndexed { index, serverData ->
+            serverData?.servers?.let { serversListAllGlobal.addAll(it) }
+        }
+
+        serversGroupListGlobal.forEachIndexed { index, serverDataGlobal ->
+            serverDataGlobal?.servers?.let { serversListAllGlobal.addAll(it) }
+        }
+
+        _mutableLiveDataGetServersGlobal.value = serversListGlobal
+        mutableLiveDataAllServers.value = serversListAllGlobal
+    }
+
     fun calculatePing(server: Server, onPingResult: (Int) -> Unit) {
         Ping.onAddress(server.ip as String).setTimeOutMillis(1000).doPing(
             object : Ping.PingListener{