ソースを参照

expand list also pre loaded showing

Khubaib 11 ヶ月 前
コミット
95aceb09d5

+ 33 - 0
app/src/main/java/com/vpn/fastestvpnservice/beans/Server.kt

@@ -35,6 +35,39 @@ class Server(
     var ping: Int = 0
 )
 
+class Server2(
+    var id: Int? = null,
+    @SerializedName("continent") val continent: String? = null,
+    @SerializedName("country") val country: String? = null,
+    @SerializedName("state") val state: String? = null,
+    @SerializedName("city") val city: Any? = null,
+    @SerializedName("name") val name: String? = null,
+    @SerializedName("dns") val dns: String? = null,
+    @SerializedName("iso") val iso: String? = null,
+    @SerializedName("lt") val lt: Double? = null,
+    @SerializedName("lg") var lg: Double? = null,
+    @SerializedName("ip") val ip: Any? = null,
+    @SerializedName("port") val port: Int? = null,
+    @SerializedName("protocol") val protocol: String? = null,
+    @SerializedName("ipsec") val ipsec: Any? = null,
+    @SerializedName("remote_id") val remoteId: Any? = null,
+    @SerializedName("is_trial") val isTrial: Boolean? = null,
+    @SerializedName("active") val active: Boolean? = null,
+    @SerializedName("flag") val flag: String? = null,
+    @SerializedName("server_name") val server_name: String? = null,
+    @SerializedName("is_favourited") var isFavourited: Boolean? = null,
+    val country_sort: Int = 0,
+    @SerializedName("connection_count") val connection_count: Int = 0,
+    @SerializedName("wg_key") val wg_key: String? = null,
+    @SerializedName("enable") var enable: Int = 1,
+    var countryServers: List<Server>? = null,
+    var totalServers: Int = 1,
+    var enableServers: Int = 1,
+    var distance: Float = 0.0f,
+    var ping: Int = 0
+)
+
+
 class ServerProtocol(
     val server: Server,
     val isFound: Boolean

+ 9 - 5
app/src/main/java/com/vpn/fastestvpnservice/customItems/CountryItem.kt

@@ -1,6 +1,7 @@
 package com.vpn.fastestvpnservice.customItems
 
 import android.util.Log
+import android.widget.Toast
 import androidx.compose.foundation.background
 import androidx.compose.foundation.border
 import androidx.compose.foundation.clickable
@@ -71,7 +72,8 @@ fun CountryItem(
     server: Server,
     category: String,
     countryTotalServers: Int,
-    navHostController: NavHostController
+    navHostController: NavHostController,
+    index: Int
 ) {
     Box(
         modifier = Modifier
@@ -135,6 +137,7 @@ fun CountryItem(
                         interactionSource = remember { MutableInteractionSource() }
                     ) {
                         isServerExpanded = !isServerExpanded
+//                        Toast.makeText(context, index.toString(), Toast.LENGTH_SHORT).show()
 
                         // commenting, open server list, not connecting by tap on tab
 //                            if (server.enable == 1) {
@@ -207,8 +210,9 @@ fun CountryItem(
                 if (isServerExpanded) {
                     val countriesServersData1 = basePreferenceHelper.getServerData().get(0).servers
                     countriesServersData1?.let {
-                        val serversGroup = serverListViewModelSplash.getServerGroupList(server, it)
-                        ExpandableRow(server = serversGroup, navHostController)
+//                        serverListViewModelSplash.getServerGroupList(server, it)
+                        val serversGroup = serverListViewModelSplash.liveDataGroupServers.observeAsState().value
+                        serversGroup?.get(index)?.servers?.let { it1 -> ExpandableRow(server = it1, navHostController) }
                     }
 
                 }
@@ -256,7 +260,7 @@ fun ColumnScope.ExpandableRow(
 
                 var isFavorite by rememberSaveable { mutableStateOf(serverInfo.isFavourited) }
                 val isServerFavourited: Boolean = serverInfo.isFavourited == true
-                Log.d("test-server_fav_d", "$isFavorite")
+                Log.d("test-server_fav_d", "${serverInfo.server_name} ${serverInfo.ping} $isFavorite")
 
                 if (isExpServerClicked) {
                     onServer.onServerSelected(
@@ -382,5 +386,5 @@ fun ColumnScope.ExpandableRow(
 @Preview
 @Composable
 fun CountryItemPreview() {
-    CountryItem(server = favListServer[0], "servers", 1, rememberNavController())
+    CountryItem(server = favListServer[0], "servers", 1, rememberNavController(), 0)
 }

+ 3 - 2
app/src/main/java/com/vpn/fastestvpnservice/screens/ServerListScreen.kt

@@ -25,6 +25,7 @@ import androidx.compose.foundation.layout.size
 import androidx.compose.foundation.layout.width
 import androidx.compose.foundation.lazy.LazyColumn
 import androidx.compose.foundation.lazy.items
+import androidx.compose.foundation.lazy.itemsIndexed
 import androidx.compose.foundation.pager.HorizontalPager
 import androidx.compose.foundation.pager.rememberPagerState
 import androidx.compose.foundation.selection.selectable
@@ -635,8 +636,8 @@ fun ColumnScope.ShowAllLocationsList(
                         0 -> {
                             LazyColumn() {
                                 countries?.get(selectedTabIndex)?.servers?.let {
-                                    items(items = it, itemContent = { country ->
-                                        CountryItem(server = country, "servers", country.totalServers, navHostController)
+                                    itemsIndexed(items = it, itemContent = {index, country ->
+                                        CountryItem(server = country, "servers", country.totalServers, navHostController, index)
                                     })
                                 }
                             }

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

@@ -72,6 +72,7 @@ var recommendedListGlobal: ArrayList<Server> = ArrayList<Server>()
 val smartLocationListGlobal: ArrayList<Server> = ArrayList<Server>()
 val countryListTestGlobal: ArrayList<Server> = ArrayList<Server>()
 var countriesListGlobal: ArrayList<Server> = ArrayList<Server>()
+var serversGroupListGlobal: ArrayList<ServerDataGlobal> = ArrayList<ServerDataGlobal>()
 var serversListGlobal: ArrayList<ServerDataGlobal?> = ArrayList<ServerDataGlobal?>()
 
 lateinit var splashViewModelSplash: SplashViewModel

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

@@ -25,6 +25,7 @@ import com.vpn.fastestvpnservice.screens.countriesListGlobal
 import com.vpn.fastestvpnservice.screens.isAlphabetList
 import com.vpn.fastestvpnservice.screens.recommendedListGlobal
 import com.vpn.fastestvpnservice.screens.serverListViewModelSplash
+import com.vpn.fastestvpnservice.screens.serversGroupListGlobal
 import com.vpn.fastestvpnservice.screens.serversListGlobal
 import com.vpn.fastestvpnservice.screens.smartLocationListGlobal
 import retrofit2.Call
@@ -37,8 +38,8 @@ class ServerListViewModel(context: Context): ViewModel() {
     val mutableLiveDataFavourite = MutableLiveData<List<Server>>()
     val mutableLiveDataFavUnFav = MutableLiveData<ServerResponse?>()
 
-    var mutableLiveDataGroupServers = MutableLiveData<ArrayList<Server>>()
-    var liveDataGroupServers: LiveData<ArrayList<Server>> = mutableLiveDataGroupServers
+    var mutableLiveDataGroupServers = MutableLiveData<ArrayList<ServerDataGlobal>>()
+    var liveDataGroupServers: LiveData<ArrayList<ServerDataGlobal>> = mutableLiveDataGroupServers
 
     var _mutableLiveDataTest = MutableLiveData<Int>(0)
     var liveDataTest: LiveData<Int> = _mutableLiveDataTest
@@ -141,11 +142,11 @@ class ServerListViewModel(context: Context): ViewModel() {
                 }
             }
 
-            smartLocationList.forEach {
-//                preferencesHelper.setSmartServerObject(it)
-                preferencesHelper.setRecommendedServerObject(it)
-                Log.d("smartLocationList", "SS:: server = ${it.server_name}")
-            }
+//            smartLocationList.forEach {
+////                preferencesHelper.setSmartServerObject(it)
+//                preferencesHelper.setRecommendedServerObject(it)
+//                Log.d("smartLocationList", "SS:: server = ${it.server_name}")
+//            }
 
         }
 
@@ -165,6 +166,12 @@ class ServerListViewModel(context: Context): ViewModel() {
                         it, isAlphabetList.value
                     )
                     serversListGlobal.add(index, ServerDataGlobal(serverData.name, servers))
+
+                    servers.forEachIndexed { index, server ->
+                        Log.d("test_filterList", "${server.server_name} ${server.country}")
+                        getServerGroupList(server, it, index)
+                    }
+
                 }
             } else {
                 data[index].servers?.let {
@@ -220,10 +227,9 @@ class ServerListViewModel(context: Context): ViewModel() {
                     distinctBy.get(index).totalServers = entry.value.sumBy { it.totalServers }
 //                    distinctBy.get(index).totalServers = 1
 
-
                     var total_enables = entry.value.sumBy { it.enable }
 
-                    println("--testing "+entry.value.size +" : "+total_enables+" : "+value.country)
+                    println("__testing"+entry.value.size +" : "+total_enables+" : "+value.country)
 
                     entry.value.forEachIndexed { indexs, server ->
                         Log.d("test_country_servers",server.country + " " + server.server_name.toString())
@@ -615,7 +621,7 @@ class ServerListViewModel(context: Context): ViewModel() {
     }
 
     fun getServerGroupList(
-        server: Server, serverList: ArrayList<Server>
+        server: Server, serverList: ArrayList<Server>, index: Int
     ): ArrayList<Server> {
 
         val tempList = ArrayList<Server>()
@@ -631,20 +637,18 @@ class ServerListViewModel(context: Context): ViewModel() {
             it.server_name
         }
 
-//        tempList.forEachIndexed { index, servers ->
-//            Log.d("tempList_servers", "${servers.server_name} , ${servers.country}")
-//        }
-
         val tempList2 = ArrayList<Server>()
-        tempList.forEachIndexed { index, server1 ->
+
+        tempList.forEachIndexed { index1, server1 ->
             calculatePing(server1){
-                Log.d("serverInfo_ping", "serverInfo $it")
+                Log.d("serverInfo_ping", "In: ${server1.server_name} $it")
                 server1.ping = it
             }
             tempList2.add(server1)
         }
 
-        mutableLiveDataGroupServers.value = tempList2
+        serversGroupListGlobal.add(index, ServerDataGlobal(server.country, tempList2))
+        mutableLiveDataGroupServers.value = serversGroupListGlobal
 
         return tempList2
     }