From 74b342f5c678bbc57f10289efddc0216795e8e3e Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 17 May 2024 14:04:15 +0800 Subject: [PATCH] Bug fix https://github.com/2dust/v2rayNG/issues/3126 --- .../com/v2ray/ang/ui/MainRecyclerAdapter.kt | 2 +- .../kotlin/com/v2ray/ang/util/MmkvManager.kt | 6 ++-- .../com/v2ray/ang/viewmodel/MainViewModel.kt | 29 ++++++++++++++----- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainRecyclerAdapter.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainRecyclerAdapter.kt index 8d58cdce..3662b8bd 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainRecyclerAdapter.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainRecyclerAdapter.kt @@ -67,7 +67,7 @@ class MainRecyclerAdapter(val activity: MainActivity) : RecyclerView.Adapter + fun clearAllTestDelayResults(keys: List?) { + keys?.forEach { key -> decodeServerAffiliationInfo(key)?.let { aff -> aff.testDelayMillis = 0 serverAffStorage?.encode(key, Gson().toJson(aff)) @@ -172,7 +172,7 @@ object MmkvManager { fun removeInvalidServer() { serverAffStorage?.allKeys()?.forEach { key -> decodeServerAffiliationInfo(key)?.let { aff -> - if (aff.testDelayMillis <= 0L) { + if (aff.testDelayMillis < 0L) { removeServer(key) } } diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/viewmodel/MainViewModel.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/viewmodel/MainViewModel.kt index a57f60d6..8af4a1bf 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/viewmodel/MainViewModel.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/viewmodel/MainViewModel.kt @@ -1,7 +1,11 @@ package com.v2ray.ang.viewmodel import android.app.Application -import android.content.* +import android.content.BroadcastReceiver +import android.content.Context +import android.content.DialogInterface +import android.content.Intent +import android.content.IntentFilter import android.os.Build import android.util.Log import android.view.LayoutInflater @@ -17,12 +21,23 @@ import com.v2ray.ang.AppConfig import com.v2ray.ang.AppConfig.ANG_PACKAGE import com.v2ray.ang.R import com.v2ray.ang.databinding.DialogConfigFilterBinding -import com.v2ray.ang.dto.* +import com.v2ray.ang.dto.EConfigType +import com.v2ray.ang.dto.ServerConfig +import com.v2ray.ang.dto.ServersCache +import com.v2ray.ang.dto.V2rayConfig import com.v2ray.ang.extension.toast -import com.v2ray.ang.util.* +import com.v2ray.ang.util.MessageUtil +import com.v2ray.ang.util.MmkvManager import com.v2ray.ang.util.MmkvManager.KEY_ANG_CONFIGS -import kotlinx.coroutines.* -import java.util.* +import com.v2ray.ang.util.SpeedtestUtil +import com.v2ray.ang.util.Utils +import com.v2ray.ang.util.V2rayConfigUtil +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlinx.coroutines.cancelChildren +import kotlinx.coroutines.launch +import java.util.Collections class MainViewModel(application: Application) : AndroidViewModel(application) { private val mainStorage by lazy { @@ -130,7 +145,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { fun testAllTcping() { tcpingTestScope.coroutineContext[Job]?.cancelChildren() SpeedtestUtil.closeAllTcpSockets() - MmkvManager.clearAllTestDelayResults() + MmkvManager.clearAllTestDelayResults(serversCache.map { it.guid }.toList()) updateListAction.value = -1 // update all getApplication().toast(R.string.connection_test_testing) @@ -153,7 +168,7 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { fun testAllRealPing() { MessageUtil.sendMsg2TestService(getApplication(), AppConfig.MSG_MEASURE_CONFIG_CANCEL, "") - MmkvManager.clearAllTestDelayResults() + MmkvManager.clearAllTestDelayResults(serversCache.map { it.guid }.toList()) updateListAction.value = -1 // update all val serversCopy = serversCache.toList() // Create a copy of the list