|
@@ -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
|
|
|
}
|
|
|
}
|
|
|
}
|