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() {
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