Add starting state to temp hotspot
This commit is contained in:
@@ -10,11 +10,13 @@ import androidx.annotation.RequiresApi
|
||||
import androidx.core.content.ContextCompat
|
||||
import be.mygod.vpnhotspot.LocalOnlyHotspotService
|
||||
import be.mygod.vpnhotspot.R
|
||||
import be.mygod.vpnhotspot.util.KillableTileService
|
||||
import be.mygod.vpnhotspot.util.stopAndUnbind
|
||||
|
||||
@RequiresApi(26)
|
||||
class LocalOnlyHotspotTileService : TetherListeningTileService() {
|
||||
class LocalOnlyHotspotTileService : KillableTileService() {
|
||||
private val tile by lazy { Icon.createWithResource(application, R.drawable.ic_device_wifi_tethering) }
|
||||
|
||||
private var binder: LocalOnlyHotspotService.Binder? = null
|
||||
|
||||
override fun onStartListening() {
|
||||
@@ -29,29 +31,41 @@ class LocalOnlyHotspotTileService : TetherListeningTileService() {
|
||||
|
||||
override fun onClick() {
|
||||
val binder = binder
|
||||
when {
|
||||
binder == null -> tapPending = true
|
||||
binder.iface != null -> binder.stop()
|
||||
else -> ContextCompat.startForegroundService(this, Intent(this, LocalOnlyHotspotService::class.java))
|
||||
if (binder == null) tapPending = true
|
||||
else when (binder.iface) {
|
||||
null -> ContextCompat.startForegroundService(this, Intent(this, LocalOnlyHotspotService::class.java))
|
||||
"" -> { } // STARTING, ignored
|
||||
else -> binder.stop()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
|
||||
binder = service as LocalOnlyHotspotService.Binder
|
||||
updateTile()
|
||||
service.ifaceChanged[this] = {
|
||||
qsTile?.run {
|
||||
icon = tile
|
||||
when (it) {
|
||||
null -> {
|
||||
state = Tile.STATE_INACTIVE
|
||||
label = getText(R.string.tethering_temp_hotspot)
|
||||
}
|
||||
"" -> {
|
||||
state = Tile.STATE_UNAVAILABLE
|
||||
label = getText(R.string.tethering_temp_hotspot)
|
||||
}
|
||||
else -> {
|
||||
state = Tile.STATE_ACTIVE
|
||||
label = service.configuration!!.SSID
|
||||
}
|
||||
}
|
||||
updateTile()
|
||||
}
|
||||
}
|
||||
super.onServiceConnected(name, service)
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(name: ComponentName?) {
|
||||
binder?.ifaceChanged?.remove(this)
|
||||
binder = null
|
||||
}
|
||||
|
||||
override fun updateTile() {
|
||||
qsTile?.run {
|
||||
state = if ((binder ?: return).iface == null) Tile.STATE_INACTIVE else Tile.STATE_ACTIVE
|
||||
icon = tile
|
||||
label = getText(R.string.tethering_temp_hotspot)
|
||||
updateTile()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user