Support showing connected device in repeater tile
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user