Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set notification icon background color #591

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -27,6 +27,7 @@ import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import androidx.core.app.Person
import androidx.core.app.RemoteInput
import androidx.core.content.ContextCompat
import androidx.core.content.LocusIdCompat
import androidx.core.content.edit
import androidx.fragment.app.DialogFragment
Expand Down Expand Up @@ -72,6 +73,13 @@ private var myself = Person.Builder().setName("Me").build()
private val manager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager


// In dark mode, the icon color might be of the same hue but lighter than the original color.
// Note that even though the documentation says that setColor sets the background color of the icon,
// in some cases the foreground will be colored instead,
// particularly on stock Android, when coloring the small icon attached to the conversation icon.
val notificationIconBackgroundColor = ContextCompat.getColor(applicationContext, R.color.launcherIconKittyBackgroundColor)


fun initializeNotificator(context: Context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return

Expand Down Expand Up @@ -122,12 +130,12 @@ private val disconnectActionPendingIntent = PendingIntent.getService(
PendingIntent.FLAG_IMMUTABLE
)


@AnyThread fun showMainNotification(relay: RelayService, content: String) {
val builder = NotificationCompat.Builder(
applicationContext, CHANNEL_CONNECTION_STATUS)
.setContentIntent(connectionStatusTapPendingIntent)
.setSmallIcon(R.drawable.ic_notification_main)
.setColor(notificationIconBackgroundColor)
.setCategory(NotificationCompat.CATEGORY_SERVICE)
.setWhen(System.currentTimeMillis())
.setPriority(Notification.PRIORITY_MIN)
Expand Down Expand Up @@ -353,6 +361,7 @@ private fun makeSummaryNotification(hotBuffers: Collection<HotlistBuffer>): Noti
val builder = NotificationCompat.Builder(applicationContext, CHANNEL_HOTLIST)
.setContentIntent(summaryNotificationIntent)
.setSmallIcon(R.drawable.ic_notification_hot)
.setColor(notificationIconBackgroundColor)
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setGroup(GROUP_KEY)
.setGroupSummary(true)
Expand Down Expand Up @@ -408,6 +417,7 @@ private fun makeBufferNotification(hotBuffer: HotlistBuffer, addReplyAction: Boo
.setContentIntent(makeActivityIntent<WeechatActivity>(hotBuffer.pointer))
.setDeleteIntent(makeBroadcastIntent<NotificationDismissedReceiver>(hotBuffer.pointer))
.setSmallIcon(R.drawable.ic_notification_hot)
.setColor(notificationIconBackgroundColor)
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setGroup(GROUP_KEY)
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN)
Expand Down Expand Up @@ -458,6 +468,7 @@ private fun makeEmptyBufferNotification(fullName: String): NotificationCompat.Bu

return NotificationCompat.Builder(applicationContext, CHANNEL_HOTLIST)
.setSmallIcon(R.drawable.ic_notification_hot)
.setColor(notificationIconBackgroundColor)
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setGroup(GROUP_KEY)
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN)
Expand Down
Loading