|
@@ -2,6 +2,7 @@ package com.vpn.fastestvpnservice.screens
|
|
|
|
|
|
import android.content.res.Configuration
|
|
|
import android.location.Location
|
|
|
+import android.os.Looper
|
|
|
import android.util.Log
|
|
|
import android.view.animation.Animation
|
|
|
import android.view.animation.AnimationUtils
|
|
@@ -83,13 +84,15 @@ import androidx.compose.ui.platform.LocalFocusManager
|
|
|
import androidx.compose.ui.res.painterResource
|
|
|
import androidx.compose.ui.zIndex
|
|
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
|
+import com.stealthcopter.networktools.Ping
|
|
|
+import com.stealthcopter.networktools.ping.PingResult
|
|
|
+import com.stealthcopter.networktools.ping.PingStats
|
|
|
import com.vpn.fastestvpnservice.R
|
|
|
import com.vpn.fastestvpnservice.beans.Server
|
|
|
import com.vpn.fastestvpnservice.beans.filterList
|
|
|
import com.vpn.fastestvpnservice.customItems.CountryItem
|
|
|
import com.vpn.fastestvpnservice.customItems.ServerItem
|
|
|
import com.vpn.fastestvpnservice.customItems.ServerSearchItem
|
|
|
-import com.vpn.fastestvpnservice.customItems.calculatePing
|
|
|
import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
|
|
|
import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.AddTextSettings
|
|
|
import com.vpn.fastestvpnservice.screens.bottomNavBarScreens.onServer
|
|
@@ -394,7 +397,7 @@ fun ColumnScope.ShowRecommendedList(
|
|
|
// favFilterList = it
|
|
|
// }
|
|
|
items(items = favList) { server ->
|
|
|
- ServerItem(server, navHostController)
|
|
|
+ ServerItem(server, navHostController, server.ping)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -427,7 +430,7 @@ fun ColumnScope.ShowRecommendedList(
|
|
|
}
|
|
|
|
|
|
items(items = smartLocationList) { server ->
|
|
|
- ServerItem(server, navHostController)
|
|
|
+ ServerItem(server, navHostController, server.ping)
|
|
|
}
|
|
|
|
|
|
/* Recent List */
|
|
@@ -470,7 +473,7 @@ fun ColumnScope.ShowRecommendedList(
|
|
|
recentLocation.add(it)
|
|
|
}
|
|
|
items(items = recentLocation) { server ->
|
|
|
- ServerItem(server, navHostController)
|
|
|
+ ServerItem(server, navHostController, server.ping)
|
|
|
}
|
|
|
|
|
|
/* Recommended List */
|
|
@@ -510,7 +513,7 @@ fun ColumnScope.ShowRecommendedList(
|
|
|
// }
|
|
|
|
|
|
items(items = recommendedList) { server ->
|
|
|
- ServerItem(server, navHostController)
|
|
|
+ ServerItem(server, navHostController, server.ping)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -636,9 +639,13 @@ fun ColumnScope.ShowAllLocationsList(
|
|
|
}!!
|
|
|
}
|
|
|
|
|
|
- filterServersList.forEachIndexed { index, server ->
|
|
|
- Log.d("test_fav_server_logic", "${server.server_name} ${server.isFavourited}")
|
|
|
- }
|
|
|
+// filterServersList.forEachIndexed { index, server ->
|
|
|
+// calculatePing(server) {
|
|
|
+// server.ping = it
|
|
|
+// Log.d("test_fav_server_logic", "${server.server_name} ${server.ping}")
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
|
|
|
HorizontalPager(
|
|
|
state = pagerState,
|
|
@@ -658,6 +665,7 @@ fun ColumnScope.ShowAllLocationsList(
|
|
|
LocalOverscrollConfiguration provides null
|
|
|
)
|
|
|
{
|
|
|
+ var pingResult: Int = 0
|
|
|
|
|
|
Log.d("filterServersList", "filterServersList: ${filterServersList.size}")
|
|
|
when (selectedTabIndex) {
|
|
@@ -671,7 +679,13 @@ fun ColumnScope.ShowAllLocationsList(
|
|
|
else -> {
|
|
|
LazyColumn() {
|
|
|
items(items = filterServersList, itemContent = {country ->
|
|
|
- ServerItem(server = country, navHostController)
|
|
|
+ CalculatePing(country, onPingResult = {
|
|
|
+ Log.d("test_ping_stream", "SLS : ${country.server_name} ${it}")
|
|
|
+ pingResult = it
|
|
|
+ })
|
|
|
+ ServerItem(server = country, navHostController, pingResult)
|
|
|
+
|
|
|
+// Log.d("test_fav_server_logic", "${country.server_name} ${it}")
|
|
|
})
|
|
|
}
|
|
|
}
|
|
@@ -697,6 +711,23 @@ fun ColumnScope.ShowAllLocationsList(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+fun CalculatePing(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)
|
|
|
+ Log.d("test_ping", "ping[0] = $ping")
|
|
|
+ Log.d("test_ping_stream", "calculatePing: ${ping}")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ override fun onError(e: java.lang.Exception?) {}
|
|
|
+ override fun onFinished(pingStats: PingStats?) {}
|
|
|
+ }
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
@Composable
|
|
|
fun ColumnScope.ShowHeaderItem(
|
|
|
serverTitle: String,
|