Show sender's name in notification

This commit is contained in:
Moez Bhatti
2017-09-26 17:47:33 -04:00
parent 2341834c6e
commit a6844a566e
2 changed files with 11 additions and 8 deletions
@@ -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())
}
}
@@ -2,7 +2,7 @@ package com.moez.QKSMS.util
class ThemeManager {
val color = 0xFF0BAE9F.toInt()
val color = 0xFF008389.toInt()
val bubbleColor = 0xFFF4F4F4.toInt()
}