|
@@ -11,8 +11,10 @@ import com.google.gson.reflect.TypeToken
|
|
|
import com.stealthcopter.networktools.Ping
|
|
|
import com.stealthcopter.networktools.ping.PingResult
|
|
|
import com.stealthcopter.networktools.ping.PingStats
|
|
|
+import com.vpn.fastestvpnservice.beans.Protocol
|
|
|
import com.vpn.fastestvpnservice.beans.Server
|
|
|
import com.vpn.fastestvpnservice.beans.ServerData
|
|
|
+import com.vpn.fastestvpnservice.beans.ServerProtocol
|
|
|
import com.vpn.fastestvpnservice.beans.ServerResponse
|
|
|
import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
|
|
|
import com.vpn.fastestvpnservice.retrofit.RetrofitNetworkHandling
|
|
@@ -60,8 +62,6 @@ class ServerListViewModel(context: Context): ViewModel() {
|
|
|
android.os.Handler(Looper.getMainLooper()).post {
|
|
|
val ping = pingResult?.timeTaken?.toInt()!!
|
|
|
onPingResult(ping)
|
|
|
- Log.d("test_ping", "ping[0] = $ping")
|
|
|
- Log.d("test_ping_stream", "calculatePing: ${ping}")
|
|
|
}
|
|
|
}
|
|
|
override fun onError(e: java.lang.Exception?) {}
|
|
@@ -71,37 +71,20 @@ class ServerListViewModel(context: Context): ViewModel() {
|
|
|
}
|
|
|
|
|
|
fun filterServersByISO(serverlist: ArrayList<Server>, isAlphabetList: Boolean = false): ArrayList<Server> {
|
|
|
-// Log.d("test_compose_servers", "size = ${serverlist.size}")
|
|
|
-
|
|
|
- serverlist.forEachIndexed { index, server ->
|
|
|
- Log.d("serverlist_test", server.server_name + " , " + server.country)
|
|
|
- }
|
|
|
|
|
|
serverlist.sortWith(Comparator { s1, s2 ->
|
|
|
return@Comparator s1.country_sort.compareTo(s2.country_sort)
|
|
|
})
|
|
|
|
|
|
- serverlist.forEachIndexed { index, server ->
|
|
|
- Log.d("serverlist_test 2", server.server_name + " , " + server.country)
|
|
|
- }
|
|
|
-
|
|
|
var serverprotocol = serverlist.filter {
|
|
|
it.protocol.equals(preferencesHelper.getProtocol().title, ignoreCase = true)
|
|
|
}
|
|
|
|
|
|
- serverprotocol.forEachIndexed { index, server ->
|
|
|
- Log.d("serverlist_test p", server.server_name + " , " + server.country)
|
|
|
- }
|
|
|
-
|
|
|
var distinctBy: List<Server>
|
|
|
distinctBy = serverprotocol.distinctBy {
|
|
|
it.iso
|
|
|
}
|
|
|
|
|
|
- distinctBy.forEachIndexed { index, server ->
|
|
|
- Log.d("serverlist_test d", server.server_name + " , " + server.country)
|
|
|
- }
|
|
|
-
|
|
|
serverprotocol.groupBy(Server::country).mapValues { entry ->
|
|
|
|
|
|
for ((index, value) in distinctBy.withIndex()) {
|
|
@@ -121,13 +104,6 @@ class ServerListViewModel(context: Context): ViewModel() {
|
|
|
|
|
|
// distinctBy.get(index).countryServers = entry.value
|
|
|
|
|
|
-// value.countryServers?.forEachIndexed { indexs1, serverInfo ->
|
|
|
-// calculatePing(serverInfo) {
|
|
|
-// serverInfo.ping = it
|
|
|
-// Log.d("test_return_ping","ISO=> " + serverInfo.server_name + serverInfo.ping)
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
if (total_enables >= 1) {
|
|
|
distinctBy.get(index).enableServers = 1
|
|
|
} else {
|
|
@@ -146,47 +122,24 @@ class ServerListViewModel(context: Context): ViewModel() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// distinctBy.forEachIndexed { index, server ->
|
|
|
-// calculatePing(server) {
|
|
|
-// server.ping = it
|
|
|
-// }
|
|
|
-// Log.d("serverlist_test_d2", server.server_name + " , " + server.country + " , " + server.totalServers)
|
|
|
-// }
|
|
|
-
|
|
|
return (filterListCountries)
|
|
|
}
|
|
|
|
|
|
fun filterServersByISOTV(serverlist: ArrayList<Server>): ArrayList<Server> {
|
|
|
|
|
|
- serverlist.forEachIndexed { index, server ->
|
|
|
- Log.d("serverlist test", server.server_name + " , " + server.country)
|
|
|
- }
|
|
|
-
|
|
|
serverlist.sortWith(Comparator { s1, s2 ->
|
|
|
return@Comparator s1.country_sort.compareTo(s2.country_sort)
|
|
|
})
|
|
|
|
|
|
- serverlist.forEachIndexed { index, server ->
|
|
|
- Log.d("serverlist 2 test 2", server.server_name + " , " + server.country)
|
|
|
- }
|
|
|
-
|
|
|
var serverprotocol = serverlist.filter {
|
|
|
it.protocol.equals(preferencesHelper.getProtocol().title, ignoreCase = true)
|
|
|
}
|
|
|
|
|
|
- serverprotocol.forEachIndexed { index, server ->
|
|
|
- Log.d("serverprotocol test", server.server_name + " , " + server.country)
|
|
|
- }
|
|
|
-
|
|
|
var distinctBy: List<Server>
|
|
|
distinctBy = serverprotocol.distinctBy {
|
|
|
it.iso
|
|
|
}
|
|
|
|
|
|
- distinctBy.forEachIndexed { index, server ->
|
|
|
- Log.d("distinctBy test", server.server_name + " , " + server.country)
|
|
|
- }
|
|
|
-
|
|
|
serverprotocol.groupBy(Server::country).mapValues { entry ->
|
|
|
|
|
|
for ((index, value) in distinctBy.withIndex()) {
|
|
@@ -208,10 +161,6 @@ class ServerListViewModel(context: Context): ViewModel() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- distinctBy.forEachIndexed { index, server ->
|
|
|
- Log.d("distinctBy_test_enable", server.server_name + " , " + server.enable)
|
|
|
- }
|
|
|
-
|
|
|
val enabledServer = distinctBy.filter {
|
|
|
it.enable == 1
|
|
|
}
|
|
@@ -263,9 +212,7 @@ class ServerListViewModel(context: Context): ViewModel() {
|
|
|
serverDataList.servers?.let {serverList ->
|
|
|
serverList.forEachIndexed { index, server ->
|
|
|
calculatePing(server) {
|
|
|
- Log.d("test_ping_servers", "${server.server_name} $it")
|
|
|
server.ping = it
|
|
|
- Log.d("test_ping_data", "${server.server_name} ${server.ping}")
|
|
|
serverList.set(index, server)
|
|
|
}
|
|
|
}
|
|
@@ -402,10 +349,6 @@ class ServerListViewModel(context: Context): ViewModel() {
|
|
|
it.iso
|
|
|
}
|
|
|
|
|
|
- distinctBy.forEachIndexed { index, server ->
|
|
|
- Log.d("test server cc", server.server_name.toString() + server.country)
|
|
|
- }
|
|
|
-
|
|
|
return distinctBy[0]
|
|
|
}
|
|
|
|
|
@@ -450,6 +393,35 @@ class ServerListViewModel(context: Context): ViewModel() {
|
|
|
return tempList2[0]
|
|
|
}
|
|
|
|
|
|
+ fun getFilteredServerByProtocolChanged(
|
|
|
+ serverList: ArrayList<ServerData>,
|
|
|
+ serverObj: Server,
|
|
|
+ protocol: Protocol
|
|
|
+ ): ServerProtocol {
|
|
|
+// val protocol = preferencesHelper.getProtocol().title
|
|
|
+ val tempList = ArrayList<Server>()
|
|
|
+ var server = Server()
|
|
|
+ var isServerFound: Boolean = false
|
|
|
+
|
|
|
+ serverList.let {
|
|
|
+ it.forEach {
|
|
|
+ it.servers?.forEach { server ->
|
|
|
+ tempList.add(server)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (i in tempList.indices) {
|
|
|
+ val obj = tempList[i]
|
|
|
+ if (obj.server_name == serverObj.server_name && protocol.title.equals(obj.protocol, ignoreCase = true)) {
|
|
|
+ server = obj
|
|
|
+ isServerFound = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return ServerProtocol(server, isServerFound)
|
|
|
+ }
|
|
|
+
|
|
|
fun favAndUnFav(server: Server) {
|
|
|
updateFavServer(server)
|
|
|
WebServiceFactory.getInstance().setFavUnfav("${server.id}")
|