فهرست منبع

Completed favorite server work across app through server id logic for multi lingual

Khubaib 7 ماه پیش
والد
کامیت
ebbd1bdbcd

+ 2 - 1
app/src/main/java/com/vpn/fastestvpnservice/customItems/ServerItem.kt

@@ -178,7 +178,8 @@ fun ServerItem(server: Server, navHostController: NavHostController, serverPing:
                     .background(Color.Transparent),
                 color = Color.Transparent
             ) {
-                Text(text = "${server.server_name}",
+                Text(
+                    text = "${server.server_name} ${server.id}",
                     style = MaterialTheme.typography.labelMedium,
                     color = MaterialTheme.colorScheme.primary,
                     maxLines = 1,

+ 21 - 15
app/src/main/java/com/vpn/fastestvpnservice/viewmodels/ServerListViewModel.kt

@@ -713,6 +713,7 @@ class ServerListViewModel(context: Context): ViewModel() {
     fun getFavList(toReturn: Boolean = false): ArrayList<Server> {
         val tempList = ArrayList<Server>()
         val getServersIdList = preferencesHelper.getServersId()
+        val serverList = ArrayList<Server>()
 
 //        preferencesHelper.getServerData().let {
 //            it.forEach {
@@ -724,14 +725,24 @@ class ServerListViewModel(context: Context): ViewModel() {
 
         preferencesHelper.getServerData().let {
             it.forEach {
-                tempList.addAll(it.servers?.filter { server ->
-                    getServersIdList?.any { id ->
-                        server.id == id
-                    } == true
-                }!!)
+                it.servers?.let { it1 -> serverList.addAll(it1) }
             }
         }
 
+//        val serverProtocol = serverList.filter {
+//            it.protocol.equals(preferencesHelper.getProtocol().title, ignoreCase = true)
+//        }
+
+        Log.d("test_fav_lang", "SLVM -> serverList = ${serverList.size}")
+//        Log.d("test_fav_lang", "SLVM -> serverProtocol = ${serverProtocol.size}")
+//        Log.d("test_fav_lang", "SLVM -> distinctBy = ${distinctBy.size}")
+
+        tempList.addAll(serverList.filter { server ->
+            getServersIdList?.any { id ->
+                server.id == id
+            } == true
+        })
+
         if (isAlphabetList.value) {
             tempList.sortBy {
                 it.server_name
@@ -740,21 +751,16 @@ class ServerListViewModel(context: Context): ViewModel() {
 
         tempList.forEachIndexed { index, server ->
             server.isFavourited = true
-            Log.d("test_fav_lang", "SLVM -> ${server.server_name} ${server.id}")
-        }
-
-
-        tempList.forEachIndexed { index, server ->
             calculatePing(server) {
                 server.ping = it
             }
         }
-//
-//        if (toReturn) {
-//            _mutableLiveDataGetFavList.value = tempList
-//        }
 
-        return tempList
+        val distinctBy: List<Server> = tempList.distinctBy {
+            it.id
+        }
+
+        return distinctBy as ArrayList
     }
 
     fun getServerData(): ArrayList<ServerData> {