From cd2e9b7d6a961f92907fcf7353210718b928dc1b Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Sat, 26 Nov 2022 13:52:52 -0500 Subject: [PATCH] Dark mode color --- .../main/java/io/heckel/ntfy/msg/NotificationService.kt | 4 +--- .../main/java/io/heckel/ntfy/service/SubscriberService.kt | 8 +++----- app/src/main/java/io/heckel/ntfy/ui/Colors.kt | 5 ++++- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/heckel/ntfy/msg/NotificationService.kt b/app/src/main/java/io/heckel/ntfy/msg/NotificationService.kt index 1b45588..8f5a7aa 100644 --- a/app/src/main/java/io/heckel/ntfy/msg/NotificationService.kt +++ b/app/src/main/java/io/heckel/ntfy/msg/NotificationService.kt @@ -65,12 +65,10 @@ class NotificationService(val context: Context) { val channelId = toChannelId(notification.priority) val builder = NotificationCompat.Builder(context, channelId) .setSmallIcon(R.drawable.ic_notification) + .setColor(ContextCompat.getColor(context, Colors.notificationIcon(context))) .setContentTitle(title) .setOnlyAlertOnce(true) // Do not vibrate or play sound if already showing (updates!) .setAutoCancel(true) // Cancel when notification is clicked - if (!isDarkThemeOn(context)) { - builder.setColor(ContextCompat.getColor(context, Colors.notificationIcon)) - } setStyleAndText(builder, subscription, notification) // Preview picture or big text style setClickAction(builder, subscription, notification) maybeSetSound(builder, update) diff --git a/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt b/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt index afb88f0..c3db8f4 100644 --- a/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt +++ b/app/src/main/java/io/heckel/ntfy/service/SubscriberService.kt @@ -290,18 +290,16 @@ class SubscriberService : Service() { val pendingIntent: PendingIntent = Intent(this, MainActivity::class.java).let { notificationIntent -> PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE) } - val builder = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID) + return NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID) .setSmallIcon(R.drawable.ic_notification_instant) + .setColor(ContextCompat.getColor(this, Colors.notificationIcon(this))) .setContentTitle(title) .setContentText(text) .setContentIntent(pendingIntent) .setSound(null) .setShowWhen(false) // Don't show date/time .setGroup(NOTIFICATION_GROUP_ID) // Do not group with other notifications - if (!isDarkThemeOn(this)) { - builder.setColor(ContextCompat.getColor(this, Colors.notificationIcon)) - } - return builder.build() + .build() } override fun onBind(intent: Intent): IBinder? { diff --git a/app/src/main/java/io/heckel/ntfy/ui/Colors.kt b/app/src/main/java/io/heckel/ntfy/ui/Colors.kt index 816d4b4..ada14cb 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/Colors.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/Colors.kt @@ -8,7 +8,10 @@ import io.heckel.ntfy.util.isDarkThemeOn class Colors { companion object { const val refreshProgressIndicator = R.color.teal - const val notificationIcon = R.color.teal + + fun notificationIcon(context: Context): Int { + return if (isDarkThemeOn(context)) R.color.teal_light else R.color.teal + } fun itemSelectedBackground(context: Context): Int { return if (isDarkThemeOn(context)) R.color.black_800b else R.color.gray_400