|
@@ -84,71 +84,73 @@ class ServerListViewModel(context: Context): ViewModel() {
|
|
|
recommendedListGlobal.clear()
|
|
|
smartLocationListGlobal.clear()
|
|
|
|
|
|
- preferencesHelper.getServerData().get(0).servers?.let {
|
|
|
- val serverDataLocation = it
|
|
|
+ val serverData = preferencesHelper.getServerData()
|
|
|
+ if (serverData.size > 0) {
|
|
|
+ serverData.get(0).servers?.let {
|
|
|
+ val serverDataLocation = it
|
|
|
|
|
|
- val distinctdatanotnull =
|
|
|
- serverDataLocation.filter { // servers's lt and lt not be null
|
|
|
- it.lt != null && it.lg != null
|
|
|
- }
|
|
|
+ val distinctdatanotnull =
|
|
|
+ serverDataLocation.filter { // servers's lt and lt not be null
|
|
|
+ it.lt != null && it.lg != null
|
|
|
+ }
|
|
|
|
|
|
- val distinctdata =
|
|
|
- distinctdatanotnull.distinctBy { // servers's lt filter, no same lt of a server
|
|
|
- it.lt
|
|
|
- }
|
|
|
+ val distinctdata =
|
|
|
+ distinctdatanotnull.distinctBy { // servers's lt filter, no same lt of a server
|
|
|
+ it.lt
|
|
|
+ }
|
|
|
|
|
|
- val result = FloatArray(1)
|
|
|
- val ipinfo = preferencesHelper.getIpinfo()
|
|
|
+ val result = FloatArray(1)
|
|
|
+ val ipinfo = preferencesHelper.getIpinfo()
|
|
|
|
|
|
- distinctdata.forEachIndexed { index, server ->
|
|
|
- val lat1 = ipinfo?.latitute
|
|
|
- val lon1 = ipinfo?.longitude
|
|
|
- val lat2 = server.lt
|
|
|
- val lon2 = server.lg
|
|
|
+ distinctdata.forEachIndexed { index, server ->
|
|
|
+ val lat1 = ipinfo?.latitute
|
|
|
+ val lon1 = ipinfo?.longitude
|
|
|
+ val lat2 = server.lt
|
|
|
+ val lon2 = server.lg
|
|
|
|
|
|
- if (lat1 != null && lat2 != null && lon1 != null && lon2 != null) {
|
|
|
- Location.distanceBetween(lat1, lon1, lat2, lon2, result)
|
|
|
- }
|
|
|
+ if (lat1 != null && lat2 != null && lon1 != null && lon2 != null) {
|
|
|
+ Location.distanceBetween(lat1, lon1, lat2, lon2, result)
|
|
|
+ }
|
|
|
|
|
|
- val distance: Float = result[0]
|
|
|
- distinctdata.get(index).distance = distance
|
|
|
+ val distance: Float = result[0]
|
|
|
+ distinctdata.get(index).distance = distance
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- val sortedDistance = distinctdata.sortedBy {
|
|
|
- it.distance
|
|
|
- }
|
|
|
+ val sortedDistance = distinctdata.sortedBy {
|
|
|
+ it.distance
|
|
|
+ }
|
|
|
|
|
|
- if (sortedDistance.isNotEmpty()) {
|
|
|
- var intRange: IntRange = 0..0
|
|
|
- intRange = when (sortedDistance.size) {
|
|
|
- 1 -> {
|
|
|
- 0..0
|
|
|
- }
|
|
|
+ if (sortedDistance.isNotEmpty()) {
|
|
|
+ var intRange: IntRange = 0..0
|
|
|
+ intRange = when (sortedDistance.size) {
|
|
|
+ 1 -> {
|
|
|
+ 0..0
|
|
|
+ }
|
|
|
|
|
|
- 2 -> {
|
|
|
- 0..1
|
|
|
- }
|
|
|
+ 2 -> {
|
|
|
+ 0..1
|
|
|
+ }
|
|
|
|
|
|
- 3 -> {
|
|
|
- 0..2
|
|
|
- }
|
|
|
- else -> {
|
|
|
- 0..2
|
|
|
- }
|
|
|
- }
|
|
|
- if (sortedDistance.isNotEmpty()) {
|
|
|
- for (i in intRange) {
|
|
|
- calculatePing(sortedDistance.get(i)) {
|
|
|
- sortedDistance.get(i).ping = it
|
|
|
+ 3 -> {
|
|
|
+ 0..2
|
|
|
+ }
|
|
|
+ else -> {
|
|
|
+ 0..2
|
|
|
}
|
|
|
- recommendedListGlobal.add(sortedDistance.get(i))
|
|
|
+ }
|
|
|
+ if (sortedDistance.isNotEmpty()) {
|
|
|
+ for (i in intRange) {
|
|
|
+ calculatePing(sortedDistance.get(i)) {
|
|
|
+ sortedDistance.get(i).ping = it
|
|
|
+ }
|
|
|
+ recommendedListGlobal.add(sortedDistance.get(i))
|
|
|
// Log.d("recommendedListGlobal", "SS:: server = ${sortedDistance.get(i).server_name} ${sortedDistance.get(i).ping}")
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- recommendedListFinalGlobal = recommendedListGlobal
|
|
|
+ recommendedListFinalGlobal = recommendedListGlobal
|
|
|
|
|
|
// recommendedListFinalGlobal.forEachIndexed { index, server ->
|
|
|
// Log.d("recommendedListGlobal F", "SS:: server = ${server.server_name} ${server.ping}")
|
|
@@ -162,18 +164,18 @@ class ServerListViewModel(context: Context): ViewModel() {
|
|
|
// }
|
|
|
|
|
|
// Log.d("test_filter_list", "setRecommendedSmartServers")
|
|
|
- _mutableLiveDataGetRecommendedServers.value = recommendedListGlobal
|
|
|
- preferencesHelper.setRecommendedList(recommendedListGlobal)
|
|
|
+ _mutableLiveDataGetRecommendedServers.value = recommendedListGlobal
|
|
|
+ preferencesHelper.setRecommendedList(recommendedListGlobal)
|
|
|
|
|
|
- if (sortedDistance.isNotEmpty()) {
|
|
|
- for (i in 0..0) {
|
|
|
+ if (sortedDistance.isNotEmpty()) {
|
|
|
+ for (i in 0..0) {
|
|
|
// smartLocationList.add(sortedDistance.get(i))
|
|
|
- calculatePing(sortedDistance.get(i)) {
|
|
|
- sortedDistance.get(i).ping = it
|
|
|
+ calculatePing(sortedDistance.get(i)) {
|
|
|
+ sortedDistance.get(i).ping = it
|
|
|
+ }
|
|
|
+ smartLocationListGlobal.add(sortedDistance.get(i))
|
|
|
}
|
|
|
- smartLocationListGlobal.add(sortedDistance.get(i))
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
// smartLocationList.forEach {
|
|
|
//// preferencesHelper.setSmartServerObject(it)
|
|
@@ -181,8 +183,8 @@ class ServerListViewModel(context: Context): ViewModel() {
|
|
|
// Log.d("smartLocationList", "SS:: server = ${it.server_name}")
|
|
|
// }
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
fun setCountryData() {
|