Support showing connected device in repeater tile

This commit is contained in:
Mygod
2020-06-16 09:51:50 +08:00
parent 0430e76143
commit 6ae4207e32
3 changed files with 22 additions and 2 deletions

View File

@@ -22,8 +22,9 @@ class RepeaterTileService : KillableTileService() {
override fun onStartListening() { override fun onStartListening() {
super.onStartListening() super.onStartListening()
if (!RepeaterService.supported) updateTile() if (RepeaterService.supported) {
else bindService(Intent(this, RepeaterService::class.java), this, Context.BIND_AUTO_CREATE) bindService(Intent(this, RepeaterService::class.java), this, Context.BIND_AUTO_CREATE)
} else updateTile()
} }
override fun onStopListening() { override fun onStopListening() {
@@ -57,6 +58,7 @@ class RepeaterTileService : KillableTileService() {
private fun updateTile(group: WifiP2pGroup? = binder?.group) { private fun updateTile(group: WifiP2pGroup? = binder?.group) {
qsTile?.run { qsTile?.run {
subtitle(null)
when ((binder ?: return).service.status) { when ((binder ?: return).service.status) {
RepeaterService.Status.IDLE -> { RepeaterService.Status.IDLE -> {
state = Tile.STATE_INACTIVE state = Tile.STATE_INACTIVE
@@ -65,6 +67,9 @@ class RepeaterTileService : KillableTileService() {
RepeaterService.Status.ACTIVE -> { RepeaterService.Status.ACTIVE -> {
state = Tile.STATE_ACTIVE state = Tile.STATE_ACTIVE
label = group?.networkName 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 else -> { // STARTING or DESTROYED, which should never occur
state = Tile.STATE_UNAVAILABLE state = Tile.STATE_UNAVAILABLE

View File

@@ -2,7 +2,9 @@ package be.mygod.vpnhotspot.util
import android.content.ComponentName import android.content.ComponentName
import android.content.ServiceConnection import android.content.ServiceConnection
import android.os.Build
import android.os.IBinder import android.os.IBinder
import android.service.quicksettings.Tile
import android.service.quicksettings.TileService import android.service.quicksettings.TileService
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
@@ -10,6 +12,13 @@ import androidx.annotation.RequiresApi
abstract class KillableTileService : TileService(), ServiceConnection { abstract class KillableTileService : TileService(), ServiceConnection {
protected var tapPending = false 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?) { override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
if (tapPending) { if (tapPending) {
tapPending = false tapPending = false

View File

@@ -11,6 +11,8 @@
* @string/wifi_ap_choose_2G * @string/wifi_ap_choose_2G
* @string/wifi_ap_choose_5G * @string/wifi_ap_choose_5G
* @string/wifi_hidden_network * @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
--> -->
<resources> <resources>
<string name="app_name">VPN Hotspot</string> <string name="app_name">VPN Hotspot</string>
@@ -150,6 +152,10 @@
<item quantity="other">%d interfaces</item> <item quantity="other">%d interfaces</item>
</plurals> </plurals>
<string name="notification_interfaces_inactive">Inactive: %s</string> <string name="notification_interfaces_inactive">Inactive: %s</string>
<plurals name="quick_settings_hotspot_secondary_label_num_devices">
<item quantity="one">%d device</item>
<item quantity="other">%d devices</item>
</plurals>
<string name="failure_reason_unknown">unknown #%d</string> <string name="failure_reason_unknown">unknown #%d</string>
<string name="exception_interface_not_found">Fatal: Downstream interface not found</string> <string name="exception_interface_not_found">Fatal: Downstream interface not found</string>