From 4b3c8177db74695c3f4a20642e5aa9f5d9a1b125 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sun, 16 Aug 2026 15:32:35 +0800 Subject: [PATCH] Add Duration-based delay extension helpers --- .../com/v2ray/ang/core/CoreServiceManager.kt | 2 +- .../main/java/com/v2ray/ang/extension/_Ext.kt | 17 +++++++++++++++++ .../v2ray/ang/handler/NotificationManager.kt | 2 +- .../v2ray/ang/service/DialerNativeService.kt | 2 +- .../com/v2ray/ang/service/NetworkMonitor.kt | 2 +- .../java/com/v2ray/ang/ui/compose/Scrollbar.kt | 2 +- .../java/com/v2ray/ang/ui/compose/SnackBar.kt | 4 ++-- .../java/com/v2ray/ang/ui/main/MainScreen.kt | 6 +++--- .../java/com/v2ray/ang/ui/main/MainViewModel.kt | 10 +++++----- 9 files changed, 32 insertions(+), 15 deletions(-) diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/core/CoreServiceManager.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/core/CoreServiceManager.kt index 8d1eb567..f1c7c1e3 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/core/CoreServiceManager.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/core/CoreServiceManager.kt @@ -31,7 +31,7 @@ import com.v2ray.ang.util.LogUtil import com.v2ray.ang.util.Utils import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.delay +import com.v2ray.ang.extension.delay import kotlinx.coroutines.launch import libv2ray.CoreCallbackHandler import libv2ray.CoreController diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/extension/_Ext.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/extension/_Ext.kt index 907f4e5c..7afd403a 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/extension/_Ext.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/extension/_Ext.kt @@ -7,6 +7,7 @@ import com.v2ray.ang.enums.EConfigType import java.io.Serializable import java.net.URI import java.util.Locale +import kotlin.time.Duration.Companion.milliseconds const val THRESHOLD = 1000L const val DIVISOR = 1024.0 @@ -76,3 +77,19 @@ fun EConfigType.isGroupType(): Boolean { fun EConfigType.isComplexType(): Boolean { return this == EConfigType.CUSTOM || this == EConfigType.POLICYGROUP || this == EConfigType.PROXYCHAIN } + +/** + * Shorthand for delay with Int milliseconds using Duration to avoid legacy Long overload warning. + */ +suspend fun delay(millis: Int) { + kotlinx.coroutines.delay(millis.toLong().milliseconds) +} + +/** + * Shorthand for delay with Long milliseconds using Duration to avoid legacy Long overload warning. + */ +suspend fun delay(millis: Long) { + kotlinx.coroutines.delay(millis.milliseconds) +} + + diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/NotificationManager.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/NotificationManager.kt index e775903b..29636fe5 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/NotificationManager.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/NotificationManager.kt @@ -21,7 +21,7 @@ import com.v2ray.ang.util.LogUtil import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job -import kotlinx.coroutines.delay +import com.v2ray.ang.extension.delay import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import kotlin.math.min diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/service/DialerNativeService.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/service/DialerNativeService.kt index 237852fb..b4fa8c45 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/service/DialerNativeService.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/service/DialerNativeService.kt @@ -8,7 +8,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.SupervisorJob -import kotlinx.coroutines.delay +import com.v2ray.ang.extension.delay import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import okhttp3.Call diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/service/NetworkMonitor.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/service/NetworkMonitor.kt index 0340ae17..d0a899b4 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/service/NetworkMonitor.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/service/NetworkMonitor.kt @@ -10,7 +10,7 @@ import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job -import kotlinx.coroutines.delay +import com.v2ray.ang.extension.delay import kotlinx.coroutines.launch /** diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/compose/Scrollbar.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/compose/Scrollbar.kt index 5a4efc84..3c3cdb22 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/compose/Scrollbar.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/compose/Scrollbar.kt @@ -26,7 +26,7 @@ import androidx.compose.ui.unit.dp import androidx.lifecycle.Lifecycle import androidx.lifecycle.compose.LocalLifecycleOwner import androidx.lifecycle.compose.currentStateAsState -import kotlinx.coroutines.delay +import com.v2ray.ang.extension.delay import kotlinx.coroutines.flow.collectLatest data class ScrollbarConfig( diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/compose/SnackBar.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/compose/SnackBar.kt index 571afbbd..0b7c7cb5 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/compose/SnackBar.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/compose/SnackBar.kt @@ -33,7 +33,7 @@ import androidx.lifecycle.compose.LocalLifecycleOwner import androidx.lifecycle.repeatOnLifecycle import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.BufferOverflow -import kotlinx.coroutines.delay +import com.v2ray.ang.extension.delay import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.launch @@ -88,7 +88,7 @@ class AppSnackbarController( if (currentShowTime != 0L) { val elapsed = System.currentTimeMillis() - currentShowTime if (elapsed < SnackbarThrottleMs) { - delay((SnackbarThrottleMs - elapsed).milliseconds) + delay((SnackbarThrottleMs - elapsed)) } } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/main/MainScreen.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/main/MainScreen.kt index ee2b149d..d7c9678e 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/main/MainScreen.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/main/MainScreen.kt @@ -30,7 +30,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.v2ray.ang.dto.entities.ProfileItem import com.v2ray.ang.ui.compose.LocalDarkTheme import com.v2ray.ang.ui.compose.QRCodeDialog -import kotlinx.coroutines.delay +import com.v2ray.ang.extension.delay import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.launch @@ -130,7 +130,7 @@ fun MainScreen( lazyListStates[target.groupId] != null } if (ready) return@repeat - delay(16L) + delay(16) } if (latestDoubleColumnDisplay) { @@ -149,7 +149,7 @@ fun MainScreen( } } } finally { - delay(32L) + delay(32) locateInProgress = false mainViewModel.onAction(MainAction.LocateHandled(target)) } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/main/MainViewModel.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/main/MainViewModel.kt index 83f0814d..89b0cf0e 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/main/MainViewModel.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/main/MainViewModel.kt @@ -24,7 +24,7 @@ import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.currentCoroutineContext -import kotlinx.coroutines.delay +import com.v2ray.ang.extension.delay import kotlinx.coroutines.ensureActive import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow @@ -222,7 +222,7 @@ class MainViewModel( viewModelScope.launch(preloadDispatcher) { try { initialPageReady.await() - delay(32L) + delay(32) dataSource.initAssets() dataSource.syncSubscriptions() } catch (cancelled: CancellationException) { @@ -364,7 +364,7 @@ class MainViewModel( preloadJob = viewModelScope.launch(preloadDispatcher) { preloadOrder.forEach { groupId -> ensureActive() - delay(32L) + delay(32) val servers = loadGroup(groupId, forceRefresh) updateGroupUi(groupId, servers) } @@ -617,7 +617,7 @@ class MainViewModel( } order.forEachIndexed { index, groupId -> ensureActive() - if (index > 0) delay(32L) + if (index > 0) delay(32) updateGroupUi(groupId, loadGroup(groupId, forceRefresh = true)) } } @@ -628,7 +628,7 @@ class MainViewModel( keywordFilter = keyword filterJob?.cancel() filterJob = viewModelScope.launch(defaultDispatcher) { - delay(300L) + delay(300) val snapshot = cacheMutex.withLock { groupDataCache.toMap() } ensureActive() snapshot.forEach { (groupId, servers) ->