diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/viewmodel/MainViewModel.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/viewmodel/MainViewModel.kt index fcd4bc8c..77ed13cb 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/viewmodel/MainViewModel.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/viewmodel/MainViewModel.kt @@ -88,11 +88,20 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { } else -> emptyList() } - val combined = mutableListOf() + + data class ServerWithDelay(val guid: String, val delay: Long) + val allServers = mutableListOf() + groupSubs.forEach { sub -> - combined.addAll(MmkvManager.decodeServerList(sub.guid)) + val subServers = MmkvManager.decodeServerList(sub.guid) + subServers.forEach { guid -> + val delay = MmkvManager.decodeServerAffiliationInfo(guid)?.testDelayMillis ?: 0L + allServers.add(ServerWithDelay(guid, if (delay <= 0L) 999999 else delay)) + } } - combined + + allServers.sortBy { it.delay } + allServers.map { it.guid }.toMutableList() } else { MmkvManager.decodeServerList(subscriptionId) }