AlwaysOnTileService.kt raw

   1  package io.github.domi04151309.alwayson.services
   2  
   3  import android.service.quicksettings.Tile
   4  import android.service.quicksettings.TileService
   5  import io.github.domi04151309.alwayson.helpers.Global
   6  
   7  class AlwaysOnTileService : TileService() {
   8      override fun onStartListening() {
   9          super.onStartListening()
  10          updateTile(Global.currentAlwaysOnState(this))
  11      }
  12  
  13      override fun onClick() {
  14          Global.changeAlwaysOnState(this)
  15      }
  16  
  17      private fun updateTile(isActive: Boolean) {
  18          qsTile.state =
  19              if (isActive) {
  20                  Tile.STATE_ACTIVE
  21              } else {
  22                  Tile.STATE_INACTIVE
  23              }
  24          qsTile.updateTile()
  25      }
  26  }
  27