From 6ae4207e320d8e914f9cd6a7901f13013f3648f2 Mon Sep 17 00:00:00 2001 From: Mygod Date: Tue, 16 Jun 2020 09:51:50 +0800 Subject: [PATCH] Support showing connected device in repeater tile --- .../be/mygod/vpnhotspot/manage/RepeaterTileService.kt | 9 +++++++-- .../java/be/mygod/vpnhotspot/util/KillableTileService.kt | 9 +++++++++ mobile/src/main/res/values/strings.xml | 6 ++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterTileService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterTileService.kt index cea8fe5c..28d82cd5 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterTileService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/RepeaterTileService.kt @@ -22,8 +22,9 @@ class RepeaterTileService : KillableTileService() { override fun onStartListening() { super.onStartListening() - if (!RepeaterService.supported) updateTile() - else bindService(Intent(this, RepeaterService::class.java), this, Context.BIND_AUTO_CREATE) + if (RepeaterService.supported) { + bindService(Intent(this, RepeaterService::class.java), this, Context.BIND_AUTO_CREATE) + } else updateTile() } override fun onStopListening() { @@ -57,6 +58,7 @@ class RepeaterTileService : KillableTileService() { private fun updateTile(group: WifiP2pGroup? = binder?.group) { qsTile?.run { + subtitle(null) when ((binder ?: return).service.status) { RepeaterService.Status.IDLE -> { state = Tile.STATE_INACTIVE @@ -65,6 +67,9 @@ class RepeaterTileService : KillableTileService() { RepeaterService.Status.ACTIVE -> { state = Tile.STATE_ACTIVE label = group?.networkName + val size = group?.clientList?.size ?: 0 + if (size > 0) subtitle(resources.getQuantityString( + R.plurals.quick_settings_hotspot_secondary_label_num_devices, size, size)) } else -> { // STARTING or DESTROYED, which should never occur state = Tile.STATE_UNAVAILABLE diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/util/KillableTileService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/util/KillableTileService.kt index 507f1c2c..78224b21 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/util/KillableTileService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/util/KillableTileService.kt @@ -2,7 +2,9 @@ package be.mygod.vpnhotspot.util import android.content.ComponentName import android.content.ServiceConnection +import android.os.Build import android.os.IBinder +import android.service.quicksettings.Tile import android.service.quicksettings.TileService import androidx.annotation.RequiresApi @@ -10,6 +12,13 @@ import androidx.annotation.RequiresApi abstract class KillableTileService : TileService(), ServiceConnection { protected var tapPending = false + /** + * Compat helper for setSubtitle. + */ + protected fun Tile.subtitle(value: CharSequence?) { + if (Build.VERSION.SDK_INT >= 29) subtitle = value + } + override fun onServiceConnected(name: ComponentName?, service: IBinder?) { if (tapPending) { tapPending = false diff --git a/mobile/src/main/res/values/strings.xml b/mobile/src/main/res/values/strings.xml index b2f73d88..630da154 100644 --- a/mobile/src/main/res/values/strings.xml +++ b/mobile/src/main/res/values/strings.xml @@ -11,6 +11,8 @@ * @string/wifi_ap_choose_2G * @string/wifi_ap_choose_5G * @string/wifi_hidden_network + * https://android.googlesource.com/platform/frameworks/base/+/f41fdc9/packages/SystemUI/res/values/strings.xml#874 + * @plurals/quick_settings_hotspot_secondary_label_num_devices --> VPN Hotspot @@ -150,6 +152,10 @@ %d interfaces Inactive: %s + + %d device + %d devices + unknown #%d Fatal: Downstream interface not found