package moe.yuuta.workmode.suspend import android.content.Intent import android.service.quicksettings.Tile import android.service.quicksettings.TileService import moe.yuuta.workmode.suspend.data.Status import moe.yuuta.workmode.suspend.data.SuspendedStorage class SuspendTile : TileService() { override fun onClick() { val storage = SuspendedStorage(this) storage.setStatus( when (storage.getStatus()) { Status.ON -> Status.OFF Status.OFF -> Status.ON } ) sendBroadcast(Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) Suspender(this).applyFromSettings() } override fun onStartListening() { val tile = qsTile tile.state = when (SuspendedStorage(this@SuspendTile).getStatus()) { Status.ON -> Tile.STATE_ACTIVE Status.OFF -> Tile.STATE_INACTIVE } tile.updateTile() } }