Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import android.os.Build
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.toBitmap
import me.siddheshkothadi.codexdroid.R

object CodexDroidNotifications {
const val TURN_CHANNEL_ID = "turn_events"
// Use a versioned channel ID because Android preserves existing channel settings by ID.
const val TURN_CHANNEL_ID = "turn_events_v2"

fun canPostNotifications(context: Context): Boolean {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) return true
Expand All @@ -33,10 +35,12 @@ object CodexDroidNotifications {
NotificationChannel(
TURN_CHANNEL_ID,
"Turn updates",
NotificationManager.IMPORTANCE_DEFAULT
NotificationManager.IMPORTANCE_HIGH
).apply {
description = "Notifications when Codex finishes a turn."
setShowBadge(true)
enableVibration(true)
enableLights(true)
}
manager.createNotificationChannel(channel)
}
Expand All @@ -59,16 +63,25 @@ object CodexDroidNotifications {
}
ensureTurnChannel(context)

val appIcon =
runCatching {
context.packageManager
.getApplicationIcon(context.applicationInfo)
.toBitmap()
}.getOrNull()

val notification =
NotificationCompat.Builder(context, TURN_CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setLargeIcon(appIcon)
.setContentTitle(title)
.setContentText(text)
.setStyle(NotificationCompat.BigTextStyle().bigText(text))
.setAutoCancel(true)
.setContentIntent(contentIntent)
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setDefaults(NotificationCompat.DEFAULT_ALL)
.build()

try {
Expand All @@ -78,4 +91,3 @@ object CodexDroidNotifications {
}
}
}

Loading