-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
183 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 0 additions & 72 deletions
72
app/src/main/java/com/github/muellerma/coffee/CoffeeTile.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/github/muellerma/coffee/tiles/AbstractTile.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.github.muellerma.coffee.tiles | ||
|
||
import android.os.Build | ||
import android.service.quicksettings.Tile | ||
import android.service.quicksettings.TileService | ||
import android.util.Log | ||
import androidx.annotation.RequiresApi | ||
import com.github.muellerma.coffee.R | ||
import com.github.muellerma.coffee.ServiceStatus | ||
import com.github.muellerma.coffee.coffeeApp | ||
import com.github.muellerma.coffee.toFormattedTime | ||
|
||
@RequiresApi(Build.VERSION_CODES.N) | ||
abstract class AbstractTile : TileService() { | ||
override fun onStartListening() { | ||
Log.d(TAG, "onStartListening()") | ||
setTileState() | ||
super.onStartListening() | ||
} | ||
|
||
override fun onTileAdded() { | ||
Log.d(TAG, "onTileAdded()") | ||
setTileState() | ||
super.onTileAdded() | ||
} | ||
|
||
private fun setTileState() { | ||
val currentStatus = coffeeApp().lastStatusUpdate | ||
Log.d(TAG, "setTileState(): running = $currentStatus") | ||
val tile = qsTile ?: return | ||
|
||
val (tileState, tileSubtitle) = when (currentStatus) { | ||
is ServiceStatus.Stopped -> Pair(Tile.STATE_INACTIVE, "") | ||
is ServiceStatus.Running -> { | ||
if (currentStatus.remainingSeconds == null) { | ||
Pair(Tile.STATE_ACTIVE, "") | ||
} else { | ||
Pair(Tile.STATE_ACTIVE, currentStatus.remainingSeconds.toFormattedTime()) | ||
} | ||
} | ||
} | ||
|
||
tile.apply { | ||
state = tileState | ||
label = getString(R.string.app_name) | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { | ||
subtitle = tileSubtitle | ||
} | ||
updateTile() | ||
} | ||
} | ||
|
||
companion object { | ||
private val TAG = AbstractTile::class.java.simpleName | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
app/src/main/java/com/github/muellerma/coffee/tiles/TimeoutTile.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.github.muellerma.coffee.tiles | ||
|
||
import android.content.ComponentName | ||
import android.content.Context | ||
import android.os.Build | ||
import android.util.Log | ||
import androidx.annotation.RequiresApi | ||
import com.github.muellerma.coffee.* | ||
|
||
@RequiresApi(Build.VERSION_CODES.N) | ||
class TimeoutTile : AbstractTile() { | ||
override fun onClick() { | ||
Log.d(TAG, "onClick()") | ||
val prefs = Prefs(applicationContext) | ||
when { | ||
coffeeApp().lastStatusUpdate is ServiceStatus.Stopped -> { | ||
prefs.timeout = prefs.firstTimeout | ||
ForegroundService.changeState(this, ForegroundService.Companion.STATE.START, false) | ||
} | ||
prefs.nextTimeout == 0 -> { | ||
prefs.timeout = 0 | ||
ForegroundService.changeState(this, ForegroundService.Companion.STATE.STOP, false) | ||
} | ||
else -> { | ||
prefs.timeout = prefs.nextTimeout | ||
} | ||
|
||
} | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.N) | ||
companion object { | ||
private val TAG = TimeoutTile::class.java.simpleName | ||
|
||
fun requestTileStateUpdate(context: Context) { | ||
Log.d(TAG, "requestTileStateUpdate()") | ||
requestListeningState(context, ComponentName(context, TimeoutTile::class.java)) | ||
} | ||
} | ||
|
||
class TileServiceStatusObserver(private val context: Context) : ServiceStatusObserver { | ||
override fun onServiceStatusUpdate(status: ServiceStatus) { | ||
requestTileStateUpdate(context) | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
app/src/main/java/com/github/muellerma/coffee/tiles/ToggleTile.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.github.muellerma.coffee.tiles | ||
|
||
import android.content.ComponentName | ||
import android.content.Context | ||
import android.os.Build | ||
import android.util.Log | ||
import androidx.annotation.RequiresApi | ||
import com.github.muellerma.coffee.* | ||
|
||
@RequiresApi(Build.VERSION_CODES.N) | ||
class ToggleTile : AbstractTile() { | ||
override fun onClick() { | ||
Log.d(TAG, "onClick()") | ||
ForegroundService.changeState(this, ForegroundService.Companion.STATE.TOGGLE, false) | ||
} | ||
|
||
@RequiresApi(Build.VERSION_CODES.N) | ||
companion object { | ||
private val TAG = ToggleTile::class.java.simpleName | ||
|
||
fun requestTileStateUpdate(context: Context) { | ||
Log.d(TAG, "requestTileStateUpdate()") | ||
requestListeningState(context, ComponentName(context, ToggleTile::class.java)) | ||
} | ||
} | ||
|
||
class TileServiceStatusObserver(private val context: Context) : ServiceStatusObserver { | ||
override fun onServiceStatusUpdate(status: ServiceStatus) { | ||
requestTileStateUpdate(context) | ||
} | ||
|
||
} | ||
} |