mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat: split message notifications into direct- and broadcast messages (#2217)
This commit is contained in:
parent
89ad4dc350
commit
20f5888380
3 changed files with 45 additions and 6 deletions
|
|
@ -340,7 +340,8 @@ class MeshService : Service(), Logging {
|
|||
serviceNotifications.updateMessageNotification(
|
||||
contactKey,
|
||||
getSenderName(dataPacket),
|
||||
message
|
||||
message,
|
||||
isBroadcast = dataPacket.to == DataPacket.ID_BROADCAST
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ class MeshServiceNotifications(
|
|||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
createNotificationChannel()
|
||||
createMessageNotificationChannel()
|
||||
createBroadcastNotificationChannel()
|
||||
createAlertNotificationChannel()
|
||||
createNewNodeNotificationChannel()
|
||||
createLowBatteryNotificationChannel()
|
||||
|
|
@ -118,6 +119,32 @@ class MeshServiceNotifications(
|
|||
return channelId
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
private fun createBroadcastNotificationChannel(): String {
|
||||
val channelId = "my_broadcasts"
|
||||
if (notificationManager.getNotificationChannel(channelId) == null) {
|
||||
val channelName = context.getString(R.string.meshtastic_broadcast_notifications)
|
||||
val channel = NotificationChannel(
|
||||
channelId,
|
||||
channelName,
|
||||
NotificationManager.IMPORTANCE_DEFAULT
|
||||
).apply {
|
||||
lightColor = notificationLightColor
|
||||
lockscreenVisibility = Notification.VISIBILITY_PUBLIC
|
||||
setShowBadge(true)
|
||||
setSound(
|
||||
RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION),
|
||||
AudioAttributes.Builder()
|
||||
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
notificationManager.createNotificationChannel(channel)
|
||||
}
|
||||
return channelId
|
||||
}
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
private fun createAlertNotificationChannel(): String {
|
||||
val channelId = "my_alerts"
|
||||
|
|
@ -274,6 +301,14 @@ class MeshServiceNotifications(
|
|||
}
|
||||
}
|
||||
|
||||
private val broadcastChannelId: String by lazy {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
createBroadcastNotificationChannel()
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
private val alertChannelId: String by lazy {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
createAlertNotificationChannel()
|
||||
|
|
@ -349,10 +384,10 @@ class MeshServiceNotifications(
|
|||
notificationManager.cancel(contactKey.hashCode())
|
||||
}
|
||||
|
||||
fun updateMessageNotification(contactKey: String, name: String, message: String) =
|
||||
fun updateMessageNotification(contactKey: String, name: String, message: String, isBroadcast: Boolean) =
|
||||
notificationManager.notify(
|
||||
contactKey.hashCode(), // show unique notifications,
|
||||
createMessageNotification(contactKey, name, message)
|
||||
createMessageNotification(contactKey, name, message, isBroadcast)
|
||||
)
|
||||
|
||||
fun showAlertNotification(contactKey: String, name: String, alert: String) {
|
||||
|
|
@ -486,10 +521,12 @@ class MeshServiceNotifications(
|
|||
private fun createMessageNotification(
|
||||
contactKey: String,
|
||||
name: String,
|
||||
message: String
|
||||
message: String,
|
||||
isBroadcast: Boolean,
|
||||
): Notification {
|
||||
val channelId = if (isBroadcast) broadcastChannelId else messageChannelId
|
||||
val messageNotificationBuilder: NotificationCompat.Builder =
|
||||
commonBuilder(messageChannelId, createOpenMessageIntent(contactKey))
|
||||
commonBuilder(channelId, createOpenMessageIntent(contactKey))
|
||||
|
||||
val person = Person.Builder().setName(name).build()
|
||||
// Key for the string that's delivered in the action's intent.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue