From a6844a566ee431b7fcdbd691a0b2585423e47fad Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Tue, 26 Sep 2017 17:47:33 -0400 Subject: [PATCH] Show sender's name in notification --- .../com/moez/QKSMS/util/NotificationManager.kt | 17 ++++++++++------- .../java/com/moez/QKSMS/util/ThemeManager.kt | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/qksms/src/main/java/com/moez/QKSMS/util/NotificationManager.kt b/qksms/src/main/java/com/moez/QKSMS/util/NotificationManager.kt index 4b0a7a2c..197e8dd9 100644 --- a/qksms/src/main/java/com/moez/QKSMS/util/NotificationManager.kt +++ b/qksms/src/main/java/com/moez/QKSMS/util/NotificationManager.kt @@ -42,16 +42,19 @@ class NotificationManager(private val context: Context, private val themeManager fun update(messageRepo: MessageRepository) { messageRepo.getUnreadUnseenMessages() .groupBy { message -> message.threadId } - .forEach { conversation -> + .forEach { group -> + val threadId = group.key + val messages = group.value + val conversation = messageRepo.getConversation(threadId) - val style = NotificationCompat.MessagingStyle("Me") - conversation.value.forEach { message -> - val name = if (message.isMe()) null else "Person" + val style = NotificationCompat.MessagingStyle("Me")f + messages.forEach { message -> + val name = if (message.isMe()) null else conversation?.getTitle() ?: "" style.addMessage(message.body, message.date, name) } - val seenIntent = Intent(context, MarkSeenReceiver::class.java).putExtra("threadId", conversation.key) - val seenPI = PendingIntent.getBroadcast(context, conversation.key.toInt(), seenIntent, PendingIntent.FLAG_UPDATE_CURRENT) + val seenIntent = Intent(context, MarkSeenReceiver::class.java).putExtra("threadId", threadId) + val seenPI = PendingIntent.getBroadcast(context, threadId.toInt(), seenIntent, PendingIntent.FLAG_UPDATE_CURRENT) val notification = NotificationCompat.Builder(context, "channel_1") .setColor(themeManager.color) @@ -59,7 +62,7 @@ class NotificationManager(private val context: Context, private val themeManager .setDeleteIntent(seenPI) .setStyle(style) - notificationManager.notify(conversation.key.toInt(), notification.build()) + notificationManager.notify(threadId.toInt(), notification.build()) } } diff --git a/qksms/src/main/java/com/moez/QKSMS/util/ThemeManager.kt b/qksms/src/main/java/com/moez/QKSMS/util/ThemeManager.kt index 682984d3..c232c1de 100644 --- a/qksms/src/main/java/com/moez/QKSMS/util/ThemeManager.kt +++ b/qksms/src/main/java/com/moez/QKSMS/util/ThemeManager.kt @@ -2,7 +2,7 @@ package com.moez.QKSMS.util class ThemeManager { - val color = 0xFF0BAE9F.toInt() + val color = 0xFF008389.toInt() val bubbleColor = 0xFFF4F4F4.toInt() } \ No newline at end of file