From 4b498d7dc7da8b8c7c2f208d43a6c80e1390bd1d Mon Sep 17 00:00:00 2001 From: Kr328 <39107975+Kr328@users.noreply.github.com> Date: Tue, 10 Dec 2019 14:59:19 +0800 Subject: [PATCH] update tile on clash reload --- .../java/com/github/kr328/clash/TileService.kt | 17 +++++++++++------ .../github/kr328/clash/service/ClashService.kt | 5 ++++- .../com/github/kr328/clash/service/Constants.kt | 1 + 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/github/kr328/clash/TileService.kt b/app/src/main/java/com/github/kr328/clash/TileService.kt index f8e1d00..02cec2f 100644 --- a/app/src/main/java/com/github/kr328/clash/TileService.kt +++ b/app/src/main/java/com/github/kr328/clash/TileService.kt @@ -7,8 +7,10 @@ import android.content.IntentFilter import android.service.quicksettings.Tile import android.service.quicksettings.TileService import com.github.kr328.clash.core.event.ProcessEvent +import com.github.kr328.clash.core.event.ProfileReloadEvent import com.github.kr328.clash.service.ClashService import com.github.kr328.clash.service.Constants +import com.github.kr328.clash.service.IClashEventObserver import com.github.kr328.clash.service.IClashService import com.github.kr328.clash.service.data.ClashProfileEntity import com.github.kr328.clash.utils.ServiceUtils @@ -35,29 +37,29 @@ class TileService : TileService() { } override fun onStartListening() { - refreshTileStatus() + refreshStatus() } - private fun refreshTileStatus() { + private fun refreshStatus() { val current = getCurrentStatus() when (current.first) { ProcessEvent.STARTED -> { qsTile.state = Tile.STATE_ACTIVE + qsTile.label = current.second?.name ?: getString(R.string.launch_name) } ProcessEvent.STOPPED -> { qsTile.state = Tile.STATE_INACTIVE + qsTile.label = getString(R.string.launch_name) } } - qsTile.label = current.second?.name ?: getString(R.string.launch_name) - qsTile.updateTile() } private val clashStatusReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { - refreshTileStatus() + refreshStatus() } } @@ -66,7 +68,10 @@ class TileService : TileService() { registerReceiver( clashStatusReceiver, - IntentFilter(Constants.CLASH_PROCESS_BROADCAST_ACTION) + IntentFilter().apply { + addAction(Constants.CLASH_PROCESS_BROADCAST_ACTION) + addAction(Constants.CLASH_RELOAD_BROADCAST_ACTION) + } ) } diff --git a/service/src/main/java/com/github/kr328/clash/service/ClashService.kt b/service/src/main/java/com/github/kr328/clash/service/ClashService.kt index 3a3cb28..5ab9387 100644 --- a/service/src/main/java/com/github/kr328/clash/service/ClashService.kt +++ b/service/src/main/java/com/github/kr328/clash/service/ClashService.kt @@ -290,6 +290,10 @@ class ClashService : Service(), IClashEventObserver, ClashEventService.Master, } } + override fun onProfileReloaded(event: ProfileReloadEvent?) { + sendBroadcast(Intent(Constants.CLASH_RELOAD_BROADCAST_ACTION).setPackage(packageName)) + } + override fun onSpeedEvent(event: SpeedEvent?) { notification.setSpeed(event?.up ?: 0, event?.down ?: 0) } @@ -313,7 +317,6 @@ class ClashService : Service(), IClashEventObserver, ClashEventService.Master, override fun onBandwidthEvent(event: BandwidthEvent?) {} override fun onLogEvent(event: LogEvent?) {} override fun onErrorEvent(event: ErrorEvent?) {} - override fun onProfileReloaded(event: ProfileReloadEvent?) {} override fun asBinder(): IBinder = object : Binder() { override fun queryLocalInterface(descriptor: String): IInterface? { return this@ClashService diff --git a/service/src/main/java/com/github/kr328/clash/service/Constants.kt b/service/src/main/java/com/github/kr328/clash/service/Constants.kt index 1416826..925e530 100644 --- a/service/src/main/java/com/github/kr328/clash/service/Constants.kt +++ b/service/src/main/java/com/github/kr328/clash/service/Constants.kt @@ -2,4 +2,5 @@ package com.github.kr328.clash.service object Constants { const val CLASH_PROCESS_BROADCAST_ACTION = "com.github.kr328.clash.ClashService.ClashProcessEvent" + const val CLASH_RELOAD_BROADCAST_ACTION = "com.github.kr328.clash.ClashService.ProfileReloadEvent" } \ No newline at end of file