Browse Source

Calculating ping of recently connected and favorite servers

Khubaib 8 months ago
parent
commit
186be00164

+ 13 - 5
app/src/main/java/com/vpn/fastestvpnservice/helpers/BasePreferenceHelper.kt

@@ -2,14 +2,22 @@ package com.vpn.fastestvpnservice.helpers
 
 import android.app.Activity
 import android.content.Context
-import android.graphics.drawable.AdaptiveIconDrawable
-import android.graphics.drawable.Drawable
-import android.util.Log
 import com.google.gson.Gson
 import com.google.gson.GsonBuilder
 import com.google.gson.reflect.TypeToken
-import com.vpn.fastestvpnservice.R
-import com.vpn.fastestvpnservice.beans.*
+import com.vpn.fastestvpnservice.beans.IpInfo
+import com.vpn.fastestvpnservice.beans.Product
+import com.vpn.fastestvpnservice.beans.ProductFeatures
+import com.vpn.fastestvpnservice.beans.Protocol
+import com.vpn.fastestvpnservice.beans.Server
+import com.vpn.fastestvpnservice.beans.ServerData
+import com.vpn.fastestvpnservice.beans.TvDisableApps
+import com.vpn.fastestvpnservice.beans.TvEnableApps
+import com.vpn.fastestvpnservice.beans.TvSplitTunneling
+import com.vpn.fastestvpnservice.beans.UserResponse
+import com.vpn.fastestvpnservice.beans.WireGuard
+import com.vpn.fastestvpnservice.beans.languages
+import com.vpn.fastestvpnservice.beans.themesList
 import com.vpn.fastestvpnservice.constants.AppEnum
 import com.vpn.fastestvpnservice.constants.splitList
 

+ 0 - 1
app/src/main/java/com/vpn/fastestvpnservice/screens/ServerListScreen.kt

@@ -8,7 +8,6 @@ import androidx.compose.foundation.ExperimentalFoundationApi
 import androidx.compose.foundation.LocalOverscrollConfiguration
 import androidx.compose.foundation.background
 import androidx.compose.foundation.gestures.detectTapGestures
-import androidx.compose.foundation.interaction.MutableInteractionSource
 import androidx.compose.foundation.layout.Arrangement
 import androidx.compose.foundation.layout.Box
 import androidx.compose.foundation.layout.BoxScope

+ 1 - 1
app/src/main/java/com/vpn/fastestvpnservice/screens/bottomNavBarScreens/SettingsScreen.kt

@@ -1256,7 +1256,7 @@ fun SelectLanguage(
                         while (true) {
                             for (i in 1..100) {
                                 progress = i.toFloat()/100F
-                                delay(25)
+                                delay(50)
                             }
                             progress = 0.1F
                         }

+ 12 - 17
app/src/main/java/com/vpn/fastestvpnservice/viewmodels/ServerListViewModel.kt

@@ -7,9 +7,6 @@ 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
 import com.stealthcopter.networktools.ping.PingResult
 import com.stealthcopter.networktools.ping.PingStats
@@ -20,8 +17,6 @@ import com.vpn.fastestvpnservice.beans.ServerDataGlobal
 import com.vpn.fastestvpnservice.beans.ServerProtocol
 import com.vpn.fastestvpnservice.beans.ServerResponse
 import com.vpn.fastestvpnservice.helpers.BasePreferenceHelper
-import com.vpn.fastestvpnservice.retrofit.RetrofitNetworkHandling
-import com.vpn.fastestvpnservice.retrofit.WebServiceFactory
 import com.vpn.fastestvpnservice.screens.isAlphabetList
 import com.vpn.fastestvpnservice.screens.recommendedListFinalGlobal
 import com.vpn.fastestvpnservice.screens.recommendedListGlobal
@@ -30,14 +25,8 @@ 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
-import java.lang.reflect.Array
+import com.vpn.fastestvpnservice.screensTV.serversListGlobalTV
 
 class ServerListViewModel(context: Context): ViewModel() {
 
@@ -755,11 +744,11 @@ class ServerListViewModel(context: Context): ViewModel() {
         }
 
 
-//        tempList.forEachIndexed { index, server ->
-//            CalculatePing(server) {
-//                server.ping = it
-//            }
-//        }
+        tempList.forEachIndexed { index, server ->
+            calculatePing(server) {
+                server.ping = it
+            }
+        }
 //
 //        if (toReturn) {
 //            _mutableLiveDataGetFavList.value = tempList
@@ -903,6 +892,12 @@ class ServerListViewModel(context: Context): ViewModel() {
             }
         }
 
+        tempList.forEachIndexed { index, server ->
+            calculatePing(server) {
+                server.ping = it
+            }
+        }
+
         if (isAlphabetList.value) {
             tempList.sortBy {
                 it.server_name