git.iko.soy/opencode-android
on 9f0326a help sign in
33 lines 1.3 kB history raw
1package soy.iko.opencode.platform
3import android.app.PendingIntent
4import android.content.Intent
5import android.os.Build
6import android.service.quicksettings.TileService
7import soy.iko.opencode.MainActivity
9/**
10 * Quick-settings tile that starts a new opencode session. Tapping launches [MainActivity]
11 * with [MainActivity.ACTION_NEW_SESSION]; the app creates and opens a fresh session once
12 * connected. On Android 14+ [startActivityAndCollapse] requires a PendingIntent.
13 */
14class NewSessionTileService : TileService() {
16 override fun onClick() {
17 super.onClick()
18 val intent = Intent(this, MainActivity::class.java).apply {
19 action = MainActivity.ACTION_NEW_SESSION
20 addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP)
21 }
22 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
23 val pending = PendingIntent.getActivity(
24 this, 0, intent,
25 PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
26 )
27 startActivityAndCollapse(pending)
28 } else {
29 @Suppress("DEPRECATION", "StartActivityAndCollapseDeprecated")
30 startActivityAndCollapse(intent)
31 }
32 }