mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-06-05 21:49:22 +02:00
Added multiple messages in notification
This commit is contained in:
@ -12,6 +12,7 @@ import android.media.AudioAttributes
|
|||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
import android.media.RingtoneManager
|
import android.media.RingtoneManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.provider.ContactsContract.PhoneLookup
|
import android.provider.ContactsContract.PhoneLookup
|
||||||
@ -740,19 +741,18 @@ fun Context.showMessageNotification(address: String, body: String, threadId: Lon
|
|||||||
val builder = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL).apply {
|
val builder = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL).apply {
|
||||||
when (config.lockScreenVisibilitySetting) {
|
when (config.lockScreenVisibilitySetting) {
|
||||||
LOCK_SCREEN_SENDER_MESSAGE -> {
|
LOCK_SCREEN_SENDER_MESSAGE -> {
|
||||||
setContentTitle(sender)
|
|
||||||
setLargeIcon(largeIcon)
|
setLargeIcon(largeIcon)
|
||||||
setContentText(body)
|
setStyle(getMessagesStyle(notificationManager, threadId, sender, body))
|
||||||
}
|
}
|
||||||
LOCK_SCREEN_SENDER -> {
|
LOCK_SCREEN_SENDER -> {
|
||||||
setContentTitle(sender)
|
setContentTitle(sender)
|
||||||
setLargeIcon(largeIcon)
|
setLargeIcon(largeIcon)
|
||||||
|
setStyle(NotificationCompat.BigTextStyle().setSummaryText(summaryText).bigText(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
color = getAdjustedPrimaryColor()
|
color = getAdjustedPrimaryColor()
|
||||||
setSmallIcon(R.drawable.ic_messenger)
|
setSmallIcon(R.drawable.ic_messenger)
|
||||||
setStyle(NotificationCompat.BigTextStyle().setSummaryText(summaryText).bigText(body))
|
|
||||||
setContentIntent(pendingIntent)
|
setContentIntent(pendingIntent)
|
||||||
priority = NotificationCompat.PRIORITY_MAX
|
priority = NotificationCompat.PRIORITY_MAX
|
||||||
setDefaults(Notification.DEFAULT_LIGHTS)
|
setDefaults(Notification.DEFAULT_LIGHTS)
|
||||||
@ -771,6 +771,39 @@ fun Context.showMessageNotification(address: String, body: String, threadId: Lon
|
|||||||
notificationManager.notify(threadId.hashCode(), builder.build())
|
notificationManager.notify(threadId.hashCode(), builder.build())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getMessagesStyle(notificationManager: NotificationManager, threadId: Long, sender: String, body: String): NotificationCompat.MessagingStyle {
|
||||||
|
val oldMessages = getOldMessages(notificationManager, threadId)
|
||||||
|
val messages = NotificationCompat.MessagingStyle(sender)
|
||||||
|
oldMessages.forEach {
|
||||||
|
messages.addMessage(it)
|
||||||
|
}
|
||||||
|
val currentMessage = NotificationCompat.MessagingStyle.Message(body, System.currentTimeMillis(), sender)
|
||||||
|
messages.addMessage(currentMessage)
|
||||||
|
return messages
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getOldMessages(notificationManager: NotificationManager, threadId: Long): List<NotificationCompat.MessagingStyle.Message> {
|
||||||
|
if (!isNougatPlus()) {
|
||||||
|
return arrayListOf()
|
||||||
|
}
|
||||||
|
val currentNotification = notificationManager.activeNotifications.find { it.id == threadId.hashCode() }
|
||||||
|
return if (currentNotification != null) {
|
||||||
|
val messages = currentNotification.notification.extras.getParcelableArray(NotificationCompat.EXTRA_MESSAGES)
|
||||||
|
val result = arrayListOf<NotificationCompat.MessagingStyle.Message>()
|
||||||
|
messages?.forEach {
|
||||||
|
val bundle = it as Bundle
|
||||||
|
val sender = bundle.getCharSequence("sender")
|
||||||
|
val text = bundle.getCharSequence("text")
|
||||||
|
val time = bundle.getLong("time")
|
||||||
|
val message = NotificationCompat.MessagingStyle.Message(text, time, sender)
|
||||||
|
result.add(message)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
} else {
|
||||||
|
arrayListOf()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun Context.removeDiacriticsIfNeeded(text: String): String {
|
fun Context.removeDiacriticsIfNeeded(text: String): String {
|
||||||
return if (config.useSimpleCharacters) text.normalizeString() else text
|
return if (config.useSimpleCharacters) text.normalizeString() else text
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user