Jelajahi Sumber

set round border of server item radius(4.dp)

Khubaib 11 bulan lalu
induk
melakukan
864becc449

+ 2 - 2
.idea/deploymentTargetSelector.xml

@@ -4,10 +4,10 @@
     <selectionStates>
       <SelectionState runConfigName="app">
         <option name="selectionMode" value="DROPDOWN" />
-        <DropdownSelection timestamp="2024-07-10T13:43:28.290813007Z">
+        <DropdownSelection timestamp="2024-07-11T09:38:37.275793585Z">
           <Target type="DEFAULT_BOOT">
             <handle>
-              <DeviceId pluginId="Default" identifier="serial=192.168.110.84:5555;connection=9dc6ebf4" />
+              <DeviceId pluginId="Default" identifier="serial=192.168.108.76:5555;connection=3676d456" />
             </handle>
           </Target>
         </DropdownSelection>

+ 9 - 3
app/src/main/java/com/vpn/fastestvpnservice/customItems/ServerItemTV.kt

@@ -86,8 +86,6 @@ fun ServerItemTV(
     )
     {
 
-
-
 //        if (isServerClicked) {
 //            Log.d("ServerCallbacks", "isServerClicked $isServerClicked")
 //            onServer.onServerSelected(
@@ -114,7 +112,15 @@ fun ServerItemTV(
                 modifier = Modifier
                     .size(150.dp)
                     .padding(start = 0.dp, end = 0.dp, top = 0.dp)
-                    .background(if (isItemFocused) Color.LightGray else Color.White)
+                    .border(
+                        border = BorderStroke(0.dp, if (isItemFocused) Color.LightGray else Color.White),
+                        shape = RoundedCornerShape(4.dp)
+                    )
+                    .background(
+                        shape = RoundedCornerShape(4.dp),
+                        color = if (isItemFocused) Color.LightGray else Color.White
+                    )
+//                    .background(if (isItemFocused) Color.LightGray else Color.White)
                     .onFocusChanged {
                         isItemFocused = it.isFocused
                     }

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

@@ -507,9 +507,9 @@ fun ColumnScope.LoginButtonTV(
                     serverListViewModelSplash = viewModel {
                         ServerListViewModel(context = context)
                     }
-                    searchListViewModelSplash = viewModel {
-                        SearchListViewModel(context, serverListViewModelSplash, splashViewModelSplash)
-                    }
+//                    searchListViewModelSplash = viewModel {
+//                        SearchListViewModel(context, serverListViewModelSplash, splashViewModelSplash)
+//                    }
 
                     serverListViewModelSplash.setRecommendedSmartServers()
                     serverListViewModelSplash.setCountryDataTV()

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

@@ -207,16 +207,16 @@ fun SettingsTV(navHostController: NavHostController) {
                     text = "AdBlock",
                     focusRequester3
                 )
-                AddRowSettingsTV(
-                    icon = R.drawable.kill_switch3x,
-                    text = "Kill Switch",
-                    topPadding = 40.dp,
-                    onClick = {
-                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
-                            gotoVPNSettingsTV(context)
-                        }
-                    }
-                )
+//                AddRowSettingsTV(
+//                    icon = R.drawable.kill_switch3x,
+//                    text = "Kill Switch",
+//                    topPadding = 40.dp,
+//                    onClick = {
+//                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+//                            gotoVPNSettingsTV(context)
+//                        }
+//                    }
+//                )
                 AddRowSettingsTV(
                     icon = R.drawable.split_tunneling3x,
                     text = "Split Tunneling",

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

@@ -1,6 +1,5 @@
 package com.vpn.fastestvpnservice.screensTV
 
-import android.widget.Toast
 import androidx.compose.foundation.Image
 import androidx.compose.foundation.layout.Box
 import androidx.compose.foundation.layout.Row
@@ -10,6 +9,11 @@ import androidx.compose.foundation.layout.padding
 import androidx.compose.foundation.layout.width
 import androidx.compose.runtime.Composable
 import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateListOf
+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.draw.paint
@@ -26,7 +30,6 @@ import com.vpn.fastestvpnservice.beans.isDarkTheme
 import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
 import com.vpn.fastestvpnservice.screens.serverListViewModelSplash
 import com.vpn.fastestvpnservice.sealedClass.ScreenTV
-import com.vpn.fastestvpnservice.viewmodels.SearchListViewModel
 import com.vpn.fastestvpnservice.viewmodels.ServerListViewModel
 import com.vpn.fastestvpnservice.viewmodels.SplashViewModel
 import kotlinx.coroutines.delay
@@ -36,12 +39,12 @@ import kotlinx.coroutines.delay
 //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 serversListGlobalTV: ArrayList<ServerDataGlobal?> = ArrayList<ServerDataGlobal?>()
 //var serversListFinalGlobal: List<ServerDataGlobal?> = ArrayList()
 
 lateinit var splashViewModelSplash: SplashViewModel
 //lateinit var serverListViewModelSplash: ServerListViewModel
-lateinit var searchListViewModelSplash: SearchListViewModel
+//lateinit var searchListViewModelSplash: SearchListViewModel   // No Need for Now
 @Composable
 fun SplashTV(navHostController: NavHostController) {
     val context = LocalContext.current
@@ -92,18 +95,16 @@ fun SplashTV(navHostController: NavHostController) {
             serverListViewModelSplash = viewModel {
                 ServerListViewModel(context = context)
             }
-            searchListViewModelSplash = viewModel {
-                SearchListViewModel(context, serverListViewModelSplash, splashViewModelSplash)
-            }
+//            searchListViewModelSplash = viewModel {
+//                SearchListViewModel(context, serverListViewModelSplash, splashViewModelSplash)
+//            }
         }
 
         val delay: Long = if (isLoggedIn) 1000 else 2000
-
         LaunchedEffect(key1 = true) {
             delay(delay)
-
             if (isLoggedIn) {
-                serverListViewModelSplash.setRecommendedSmartServers()
+//                serverListViewModelSplash.setRecommendedSmartServers()
                 serverListViewModelSplash.setCountryDataTV()
                 splashViewModelSplash.serverDataApi()
                 navHostController.popBackStack()
@@ -112,7 +113,6 @@ fun SplashTV(navHostController: NavHostController) {
                 navHostController.popBackStack()
                 navHostController.navigate(ScreenTV.LoginTV.route)
             }
-
         }
     }
 }

+ 45 - 26
app/src/main/java/com/vpn/fastestvpnservice/viewmodels/ServerListViewModel.kt

@@ -7,6 +7,7 @@ import android.util.Log
 import androidx.lifecycle.LiveData
 import androidx.lifecycle.MutableLiveData
 import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
 import com.google.gson.Gson
 import com.google.gson.reflect.TypeToken
 import com.stealthcopter.networktools.Ping
@@ -29,7 +30,12 @@ import com.vpn.fastestvpnservice.screens.serversGroupListGlobal
 import com.vpn.fastestvpnservice.screens.serversListAllGlobal
 import com.vpn.fastestvpnservice.screens.serversListFinalGlobal
 import com.vpn.fastestvpnservice.screens.serversListGlobal
+import com.vpn.fastestvpnservice.screensTV.serversListGlobalTV
 import com.vpn.fastestvpnservice.screens.smartLocationListGlobal
+import com.vpn.fastestvpnservice.sealedClass.ScreenTV
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
 import retrofit2.Call
 
 class ServerListViewModel(context: Context): ViewModel() {
@@ -205,41 +211,39 @@ class ServerListViewModel(context: Context): ViewModel() {
     fun setCountryDataTV() {
         val data = preferencesHelper.getServerData()
 
-        serversListGlobal.clear()
-        serversListAllGlobal.clear()
-        serversGroupListGlobal.clear()
-        var filterServersList = ArrayList<Server>()
+        serversListGlobalTV.clear()
+//        serversListAllGlobal.clear()
+//        serversGroupListGlobal.clear()
 
         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))
+                    serversListGlobalTV.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))
+                    serversListGlobalTV.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) }
-        }
+//        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
+        _mutableLiveDataGetServersGlobal.value = serversListGlobalTV
+//        mutableLiveDataAllServers.value = serversListAllGlobal
     }
 
     fun calculatePing(server: Server, onPingResult: (Int) -> Unit) {
@@ -256,6 +260,21 @@ class ServerListViewModel(context: Context): ViewModel() {
             }
         )
     }
+    fun calculatePingNoDelay(server: Server, onPingResult: (Int) -> Unit) {
+        Ping.onAddress(server.ip as String).setTimeOutMillis(1000).doPing(
+            object : Ping.PingListener{
+                override fun onResult(pingResult: PingResult?) {
+                    android.os.Handler(Looper.getMainLooper()).post {
+                        val ping = pingResult?.timeTaken?.toInt()!!
+                        onPingResult(ping)
+                    }
+                }
+                override fun onError(e: java.lang.Exception?) {}
+                override fun onFinished(pingStats: PingStats?) {}
+            }
+        )
+    }
+
 
     fun filterServersByISO(serverlist: ArrayList<Server>,
                            isAlphabetList: Boolean = false): ArrayList<Server> {
@@ -416,10 +435,10 @@ class ServerListViewModel(context: Context): ViewModel() {
 
         serverprotocol.groupBy(Server::country).mapValues { entry ->
             for ((index, value) in distinctBy.withIndex()) {
-                if (entry.key == value.country) {
-                    distinctBy.get(index).totalServers = entry.value.sumBy { it.totalServers }
-                }
-                calculatePing(value) {
+//                if (entry.key == value.country) {
+//                    distinctBy.get(index).totalServers = entry.value.sumBy { it.totalServers }
+//                }
+                calculatePingNoDelay(value) {
                     distinctBy.get(index).ping = it
                 }
             }
@@ -508,11 +527,11 @@ class ServerListViewModel(context: Context): ViewModel() {
 
         serverprotocol.groupBy(Server::country).mapValues { entry ->
             for ((index, value) in distinctBy.withIndex()) {
-                if (entry.key == value.country) {
-                    distinctBy.get(index).totalServers = entry.value.sumBy { it.totalServers }
-                    calculatePing(value) {
-                        distinctBy.get(index).ping = it
-                    }
+//                if (entry.key == value.country) {
+////                    distinctBy.get(index).totalServers = entry.value.sumBy { it.totalServers }
+//                }
+                calculatePingNoDelay(value) {
+                    distinctBy.get(index).ping = it
                 }
             }
         }