git.iko.soy/opencode-android
on 0bc1eda help sign in
36 lines 1.5 kB history raw
1package soy.iko.opencode.notification
3import android.app.NotificationChannel
4import android.app.NotificationManager
5import android.content.Context
6import android.os.Build
7import soy.iko.opencode.R
9/**
10 * The app's notification channels. Created once at startup (idempotent — recreating an
11 * existing channel is a no-op). Two channels keep user control granular:
12 *
13 * - [STATUS]: low-importance, no sound. Used by the foreground service's persistent
14 * "agent running" indicator.
15 * - [COMPLETED]: default importance. Used when a background session finishes a run.
16 */
17object NotificationChannels {
18 const val STATUS = "run_status"
19 const val COMPLETED = "session_completed"
21 fun create(context: Context) {
22 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return
23 val nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
24 nm.createNotificationChannel(
25 NotificationChannel(STATUS, context.getString(R.string.notif_channel_status), NotificationManager.IMPORTANCE_LOW).apply {
26 description = context.getString(R.string.notif_channel_status_desc)
27 setShowBadge(false)
28 },
29 )
30 nm.createNotificationChannel(
31 NotificationChannel(COMPLETED, context.getString(R.string.notif_channel_completed), NotificationManager.IMPORTANCE_DEFAULT).apply {
32 description = context.getString(R.string.notif_channel_completed_desc)
33 },
34 )
35 }