From 490a07d75b968a15715b303b7a1a7cbb8e4bbc8d Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 31 Jul 2026 20:27:08 +0800 Subject: [PATCH] Move message/notification utils to helper package --- .../com/v2ray/ang/core/CoreServiceManager.kt | 16 ++++++++-------- .../java/com/v2ray/ang/core/LauncherManager.kt | 4 ++-- .../com/v2ray/ang/handler/SubscriptionUpdater.kt | 4 ++-- .../MessageUtil.kt => helper/MessageHelper.kt} | 7 ++++--- .../ang/{util => helper}/NotificationHelper.kt | 5 ++--- .../com/v2ray/ang/service/CoreTestService.kt | 10 +++++----- .../java/com/v2ray/ang/service/QSTileService.kt | 4 ++-- .../ang/service/SubscriptionUpdateService.kt | 2 +- .../java/com/v2ray/ang/ui/main/MainRepository.kt | 10 +++++----- .../ui/subscription/SubscriptionsViewModel.kt | 4 ++-- 10 files changed, 33 insertions(+), 33 deletions(-) rename V2rayNG/app/src/main/java/com/v2ray/ang/{util/MessageUtil.kt => helper/MessageHelper.kt} (97%) rename V2rayNG/app/src/main/java/com/v2ray/ang/{util => helper}/NotificationHelper.kt (99%) 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 9c66e4074..172f08e16 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 @@ -25,7 +25,7 @@ import com.v2ray.ang.service.DialerNativeService import com.v2ray.ang.service.DialerWebviewService import com.v2ray.ang.contracts.IDialerService import com.v2ray.ang.util.LogUtil -import com.v2ray.ang.util.MessageUtil +import com.v2ray.ang.helper.MessageHelper import com.v2ray.ang.util.Utils import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -90,7 +90,7 @@ object CoreServiceManager { } catch (e: Exception) { val message = e.message?.takeUnless { it.isBlank() } ?: e.javaClass.simpleName LogUtil.e(AppConfig.TAG, "StartCore-Manager: $message", e) - MessageUtil.sendMsg2UI(service, AppConfig.MSG_STATE_START_FAILURE, message) + MessageHelper.sendMsg2UI(service, AppConfig.MSG_STATE_START_FAILURE, message) NotificationManager.cancelNotification() return false } @@ -154,7 +154,7 @@ object CoreServiceManager { else -> {} } - MessageUtil.sendMsg2UI(service, AppConfig.MSG_STATE_START_SUCCESS, "") + MessageHelper.sendMsg2UI(service, AppConfig.MSG_STATE_START_SUCCESS, "") NotificationManager.startSpeedNotification() LogUtil.i(AppConfig.TAG, "StartCore-Manager: Core started successfully") } @@ -184,7 +184,7 @@ object CoreServiceManager { browserDialer = null } - MessageUtil.sendMsg2UI(service, AppConfig.MSG_STATE_STOP_SUCCESS, "") + MessageHelper.sendMsg2UI(service, AppConfig.MSG_STATE_STOP_SUCCESS, "") NotificationManager.cancelNotification() try { @@ -260,12 +260,12 @@ object CoreServiceManager { } else { service.getString(R.string.connection_test_error, errorStr) } - MessageUtil.sendMsg2UI(service, AppConfig.MSG_MEASURE_DELAY_SUCCESS, result) + MessageHelper.sendMsg2UI(service, AppConfig.MSG_MEASURE_DELAY_SUCCESS, result) // Only fetch IP info if the delay test was successful if (time >= 0) { SpeedtestManager.getRemoteIPInfo()?.let { ip -> - MessageUtil.sendMsg2UI(service, AppConfig.MSG_MEASURE_DELAY_SUCCESS, "$result\n$ip") + MessageHelper.sendMsg2UI(service, AppConfig.MSG_MEASURE_DELAY_SUCCESS, "$result\n$ip") } } } @@ -371,9 +371,9 @@ object CoreServiceManager { when (intent?.getIntExtra("key", 0)) { AppConfig.MSG_REGISTER_CLIENT -> { if (isRunning()) { - MessageUtil.sendMsg2UI(serviceControl.getService(), AppConfig.MSG_STATE_RUNNING, "") + MessageHelper.sendMsg2UI(serviceControl.getService(), AppConfig.MSG_STATE_RUNNING, "") } else { - MessageUtil.sendMsg2UI(serviceControl.getService(), AppConfig.MSG_STATE_NOT_RUNNING, "") + MessageHelper.sendMsg2UI(serviceControl.getService(), AppConfig.MSG_STATE_NOT_RUNNING, "") } } diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/core/LauncherManager.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/core/LauncherManager.kt index 7da47d5b6..f143df197 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/core/LauncherManager.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/core/LauncherManager.kt @@ -16,7 +16,7 @@ import com.v2ray.ang.service.CoreProxyOnlyService import com.v2ray.ang.service.CoreRootService import com.v2ray.ang.service.CoreVpnService import com.v2ray.ang.util.LogUtil -import com.v2ray.ang.util.MessageUtil +import com.v2ray.ang.helper.MessageHelper import com.v2ray.ang.util.Utils object LauncherManager { @@ -53,7 +53,7 @@ object LauncherManager { fun stopService(context: Context) { //context.toast(R.string.toast_services_stop) - MessageUtil.sendMsg2Service(context, AppConfig.MSG_STATE_STOP, "") + MessageHelper.sendMsg2Service(context, AppConfig.MSG_STATE_STOP, "") } @Throws(Exception::class) diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/SubscriptionUpdater.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/SubscriptionUpdater.kt index 3dcbc1130..4251003be 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/handler/SubscriptionUpdater.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/handler/SubscriptionUpdater.kt @@ -14,7 +14,7 @@ import com.v2ray.ang.AngApplication import com.v2ray.ang.AppConfig import com.v2ray.ang.dto.SubscriptionUpdateMessage import com.v2ray.ang.util.LogUtil -import com.v2ray.ang.util.MessageUtil +import com.v2ray.ang.helper.MessageHelper import java.util.concurrent.TimeUnit object SubscriptionUpdater { @@ -178,7 +178,7 @@ object SubscriptionUpdater { updateLastUpdatedAndReschedule(applicationContext, subId) - MessageUtil.sendMsg2SubscriptionService( + MessageHelper.sendMsg2SubscriptionService( applicationContext, SubscriptionUpdateMessage(AppConfig.MSG_SUB_UPDATE_START, true, listOf(subId)) ) diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/util/MessageUtil.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/helper/MessageHelper.kt similarity index 97% rename from V2rayNG/app/src/main/java/com/v2ray/ang/util/MessageUtil.kt rename to V2rayNG/app/src/main/java/com/v2ray/ang/helper/MessageHelper.kt index ad5067cea..0c92ddf2e 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/util/MessageUtil.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/helper/MessageHelper.kt @@ -1,4 +1,4 @@ -package com.v2ray.ang.util +package com.v2ray.ang.helper import android.content.ComponentName import android.content.Context @@ -10,9 +10,10 @@ import com.v2ray.ang.dto.SubscriptionUpdateMessage import com.v2ray.ang.dto.TestServiceMessage import com.v2ray.ang.service.CoreTestService import com.v2ray.ang.service.SubscriptionUpdateService +import com.v2ray.ang.util.LogUtil import java.io.Serializable -object MessageUtil { +object MessageHelper { /** @@ -124,4 +125,4 @@ object MessageUtil { LogUtil.e(AppConfig.TAG, "Failed to send message with action: $action", e) } } -} +} \ No newline at end of file diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/util/NotificationHelper.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/helper/NotificationHelper.kt similarity index 99% rename from V2rayNG/app/src/main/java/com/v2ray/ang/util/NotificationHelper.kt rename to V2rayNG/app/src/main/java/com/v2ray/ang/helper/NotificationHelper.kt index 4c5788d7b..0b99b84df 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/util/NotificationHelper.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/helper/NotificationHelper.kt @@ -1,4 +1,4 @@ -package com.v2ray.ang.util +package com.v2ray.ang.helper import android.app.Notification import android.app.NotificationChannel @@ -159,5 +159,4 @@ object NotificationHelper { .setPriority(NotificationCompat.PRIORITY_LOW) .setCategory(NotificationCompat.CATEGORY_SERVICE) } -} - +} \ No newline at end of file diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/service/CoreTestService.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/service/CoreTestService.kt index 6acaf0362..63ef7bc4c 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/service/CoreTestService.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/service/CoreTestService.kt @@ -12,8 +12,8 @@ import com.v2ray.ang.enums.NotificationChannelType import com.v2ray.ang.extension.serializable import com.v2ray.ang.handler.MmkvManager import com.v2ray.ang.util.LogUtil -import com.v2ray.ang.util.MessageUtil -import com.v2ray.ang.util.NotificationHelper +import com.v2ray.ang.helper.MessageHelper +import com.v2ray.ang.helper.NotificationHelper import java.util.Collections class CoreTestService : Service() { @@ -116,16 +116,16 @@ class CoreTestService : Service() { title = getString(R.string.app_name), content = getString(R.string.connection_runing_task_left, event.text) ) - MessageUtil.sendMsg2UI(this, AppConfig.MSG_MEASURE_CONFIG_NOTIFY, event.text) + MessageHelper.sendMsg2UI(this, AppConfig.MSG_MEASURE_CONFIG_NOTIFY, event.text) } is RealPingEvent.Result -> { MmkvManager.encodeServerTestDelayMillis(event.guid, event.delayMillis) - MessageUtil.sendMsg2UI(this, AppConfig.MSG_MEASURE_CONFIG_SUCCESS, event.guid) + MessageHelper.sendMsg2UI(this, AppConfig.MSG_MEASURE_CONFIG_SUCCESS, event.guid) } is RealPingEvent.Finish -> { - MessageUtil.sendMsg2UI(this, AppConfig.MSG_MEASURE_CONFIG_FINISH, event.status) + MessageHelper.sendMsg2UI(this, AppConfig.MSG_MEASURE_CONFIG_FINISH, event.status) onWorkerDone() if (activeWorkers.isEmpty()) { NotificationHelper.stopForeground(this) diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/service/QSTileService.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/service/QSTileService.kt index e56880f6f..90447c8fc 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/service/QSTileService.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/service/QSTileService.kt @@ -13,7 +13,7 @@ import com.v2ray.ang.R import com.v2ray.ang.core.CoreServiceManager import com.v2ray.ang.core.LauncherManager import com.v2ray.ang.util.LogUtil -import com.v2ray.ang.util.MessageUtil +import com.v2ray.ang.helper.MessageHelper import com.v2ray.ang.util.Utils import java.lang.ref.SoftReference @@ -51,7 +51,7 @@ class QSTileService : TileService() { mMsgReceive = ReceiveMessageHandler(this) val mFilter = IntentFilter(AppConfig.BROADCAST_ACTION_ACTIVITY) ContextCompat.registerReceiver(applicationContext, mMsgReceive, mFilter, Utils.receiverFlags()) - MessageUtil.sendMsg2Service(this, AppConfig.MSG_REGISTER_CLIENT, "") + MessageHelper.sendMsg2Service(this, AppConfig.MSG_REGISTER_CLIENT, "") } /** diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/service/SubscriptionUpdateService.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/service/SubscriptionUpdateService.kt index 3198215f5..809d482b3 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/service/SubscriptionUpdateService.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/service/SubscriptionUpdateService.kt @@ -15,7 +15,7 @@ import com.v2ray.ang.extension.serializable import com.v2ray.ang.handler.AngConfigManager import com.v2ray.ang.handler.MmkvManager import com.v2ray.ang.util.LogUtil -import com.v2ray.ang.util.NotificationHelper +import com.v2ray.ang.helper.NotificationHelper import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/main/MainRepository.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/main/MainRepository.kt index ed91e4576..6c1a77bd0 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/main/MainRepository.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/main/MainRepository.kt @@ -19,7 +19,7 @@ import com.v2ray.ang.handler.MmkvManager import com.v2ray.ang.handler.SettingsManager import com.v2ray.ang.handler.SubscriptionUpdater import com.v2ray.ang.util.LogUtil -import com.v2ray.ang.util.MessageUtil +import com.v2ray.ang.helper.MessageHelper import com.v2ray.ang.util.Utils import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.flow.MutableSharedFlow @@ -79,13 +79,13 @@ class MainRepository( IntentFilter(AppConfig.BROADCAST_ACTION_ACTIVITY), Utils.receiverFlags() ) - MessageUtil.sendMsg2Service(app, AppConfig.MSG_REGISTER_CLIENT, "") + MessageHelper.sendMsg2Service(app, AppConfig.MSG_REGISTER_CLIENT, "") } override fun close() { if (!closed.compareAndSet(false, true)) return runCatching { - MessageUtil.sendMsg2Service(app, AppConfig.MSG_UNREGISTER_CLIENT, "") + MessageHelper.sendMsg2Service(app, AppConfig.MSG_UNREGISTER_CLIENT, "") }.onFailure { LogUtil.e(AppConfig.TAG, "Failed to unregister service client", it) } @@ -198,10 +198,10 @@ class MainRepository( AngConfigManager.share2Clipboard(app, guid) == 0 override fun sendMsg2Service(msgId: Int, content: String) = - MessageUtil.sendMsg2Service(app, msgId, content) + MessageHelper.sendMsg2Service(app, msgId, content) override fun sendMsg2TestService(msg: TestServiceMessage) = - MessageUtil.sendMsg2TestService(app, msg) + MessageHelper.sendMsg2TestService(app, msg) override fun cancelAllPing() { sendMsg2TestService( diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/subscription/SubscriptionsViewModel.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/subscription/SubscriptionsViewModel.kt index 4dbcc62ee..63a3f17bb 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/ui/subscription/SubscriptionsViewModel.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/ui/subscription/SubscriptionsViewModel.kt @@ -11,7 +11,7 @@ import com.v2ray.ang.handler.MmkvManager import com.v2ray.ang.handler.SettingsChangeManager import com.v2ray.ang.handler.SettingsManager import com.v2ray.ang.ui.base.BaseViewModel -import com.v2ray.ang.util.MessageUtil +import com.v2ray.ang.helper.MessageHelper import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow @@ -65,7 +65,7 @@ class SubscriptionsViewModel(application: Application) : BaseViewModel(applicati .map { it.guid } if (subIds.isNotEmpty()) { - MessageUtil.sendMsg2SubscriptionService(app, SubscriptionUpdateMessage(AppConfig.MSG_SUB_UPDATE_START, false, subIds)) + MessageHelper.sendMsg2SubscriptionService(app, SubscriptionUpdateMessage(AppConfig.MSG_SUB_UPDATE_START, false, subIds)) } toast(R.string.subscription_updater_job_tips)