forked from GitHub-Mirror/riotX-android
Notification: better code
This commit is contained in:
parent
5a1242109d
commit
b388be93c8
@ -216,22 +216,23 @@ class NotificationDrawerManager(val context: Context,
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
val roomGroup = RoomEventGroupInfo(roomId)
|
|
||||||
roomGroup.hasNewEvent = false
|
|
||||||
roomGroup.shouldBing = false
|
|
||||||
roomGroup.isDirect = events[0].roomIsDirect
|
|
||||||
val roomName = events[0].roomName ?: events[0].senderName ?: ""
|
val roomName = events[0].roomName ?: events[0].senderName ?: ""
|
||||||
|
|
||||||
|
val roomEventGroupInfo = RoomEventGroupInfo(
|
||||||
|
roomId = roomId,
|
||||||
|
isDirect = events[0].roomIsDirect,
|
||||||
|
roomDisplayName = roomName)
|
||||||
|
|
||||||
val style = NotificationCompat.MessagingStyle(Person.Builder()
|
val style = NotificationCompat.MessagingStyle(Person.Builder()
|
||||||
.setName(myUserDisplayName)
|
.setName(myUserDisplayName)
|
||||||
.setIcon(iconLoader.getUserIcon(myUserAvatarUrl))
|
.setIcon(iconLoader.getUserIcon(myUserAvatarUrl))
|
||||||
.setKey(events[0].matrixID)
|
.setKey(events[0].matrixID)
|
||||||
.build())
|
.build())
|
||||||
roomGroup.roomDisplayName = roomName
|
|
||||||
|
|
||||||
style.isGroupConversation = !roomGroup.isDirect
|
style.isGroupConversation = !roomEventGroupInfo.isDirect
|
||||||
|
|
||||||
if (!roomGroup.isDirect) {
|
if (!roomEventGroupInfo.isDirect) {
|
||||||
style.conversationTitle = roomName
|
style.conversationTitle = roomEventGroupInfo.roomDisplayName
|
||||||
}
|
}
|
||||||
|
|
||||||
val largeBitmap = getRoomBitmap(events)
|
val largeBitmap = getRoomBitmap(events)
|
||||||
@ -240,10 +241,10 @@ class NotificationDrawerManager(val context: Context,
|
|||||||
for (event in events) {
|
for (event in events) {
|
||||||
//if all events in this room have already been displayed there is no need to update it
|
//if all events in this room have already been displayed there is no need to update it
|
||||||
if (!event.hasBeenDisplayed) {
|
if (!event.hasBeenDisplayed) {
|
||||||
roomGroup.shouldBing = roomGroup.shouldBing || event.noisy
|
roomEventGroupInfo.shouldBing = roomEventGroupInfo.shouldBing || event.noisy
|
||||||
roomGroup.customSound = event.soundName
|
roomEventGroupInfo.customSound = event.soundName
|
||||||
}
|
}
|
||||||
roomGroup.hasNewEvent = roomGroup.hasNewEvent || !event.hasBeenDisplayed
|
roomEventGroupInfo.hasNewEvent = roomEventGroupInfo.hasNewEvent || !event.hasBeenDisplayed
|
||||||
|
|
||||||
val senderPerson = Person.Builder()
|
val senderPerson = Person.Builder()
|
||||||
.setName(event.senderName)
|
.setName(event.senderName)
|
||||||
@ -253,7 +254,7 @@ class NotificationDrawerManager(val context: Context,
|
|||||||
|
|
||||||
if (event.outGoingMessage && event.outGoingMessageFailed) {
|
if (event.outGoingMessage && event.outGoingMessageFailed) {
|
||||||
style.addMessage(context.getString(R.string.notification_inline_reply_failed), event.timestamp, senderPerson)
|
style.addMessage(context.getString(R.string.notification_inline_reply_failed), event.timestamp, senderPerson)
|
||||||
roomGroup.hasSmartReplyError = true
|
roomEventGroupInfo.hasSmartReplyError = true
|
||||||
} else {
|
} else {
|
||||||
style.addMessage(event.body, event.timestamp, senderPerson)
|
style.addMessage(event.body, event.timestamp, senderPerson)
|
||||||
}
|
}
|
||||||
@ -274,7 +275,7 @@ class NotificationDrawerManager(val context: Context,
|
|||||||
summaryInboxStyle.addLine(roomName)
|
summaryInboxStyle.addLine(roomName)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstTime || roomGroup.hasNewEvent) {
|
if (firstTime || roomEventGroupInfo.hasNewEvent) {
|
||||||
//Should update displayed notification
|
//Should update displayed notification
|
||||||
Timber.v("%%%%%%%% REFRESH NOTIFICATION DRAWER $roomId need refresh")
|
Timber.v("%%%%%%%% REFRESH NOTIFICATION DRAWER $roomId need refresh")
|
||||||
val lastMessageTimestamp = events.last().timestamp
|
val lastMessageTimestamp = events.last().timestamp
|
||||||
@ -283,14 +284,14 @@ class NotificationDrawerManager(val context: Context,
|
|||||||
globalLastMessageTimestamp = lastMessageTimestamp
|
globalLastMessageTimestamp = lastMessageTimestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
NotificationUtils.buildMessagesListNotification(context, style, roomGroup, largeBitmap, lastMessageTimestamp, myUserDisplayName)
|
NotificationUtils.buildMessagesListNotification(context, style, roomEventGroupInfo, largeBitmap, lastMessageTimestamp, myUserDisplayName)
|
||||||
?.let {
|
?.let {
|
||||||
//is there an id for this room?
|
//is there an id for this room?
|
||||||
notifications.add(it)
|
notifications.add(it)
|
||||||
NotificationUtils.showNotificationMessage(context, roomId, ROOM_MESSAGES_NOTIFICATION_ID, it)
|
NotificationUtils.showNotificationMessage(context, roomId, ROOM_MESSAGES_NOTIFICATION_ID, it)
|
||||||
}
|
}
|
||||||
hasNewEvent = true
|
hasNewEvent = true
|
||||||
summaryIsNoisy = summaryIsNoisy || roomGroup.shouldBing
|
summaryIsNoisy = summaryIsNoisy || roomEventGroupInfo.shouldBing
|
||||||
} else {
|
} else {
|
||||||
Timber.v("%%%%%%%% REFRESH NOTIFICATION DRAWER $roomId is up to date")
|
Timber.v("%%%%%%%% REFRESH NOTIFICATION DRAWER $roomId is up to date")
|
||||||
}
|
}
|
||||||
|
@ -20,15 +20,15 @@ package im.vector.riotredesign.features.notifications
|
|||||||
* Data class to hold information about a group of notifications for a room
|
* Data class to hold information about a group of notifications for a room
|
||||||
*/
|
*/
|
||||||
data class RoomEventGroupInfo(
|
data class RoomEventGroupInfo(
|
||||||
val roomId: String
|
val roomId: String,
|
||||||
|
val roomDisplayName: String = "",
|
||||||
|
val roomAvatarPath: String? = null,
|
||||||
|
val isDirect: Boolean = false
|
||||||
) {
|
) {
|
||||||
var roomDisplayName: String = ""
|
// An event in the list has not yet been display
|
||||||
var roomAvatarPath: String? = null
|
|
||||||
//An event in the list has not yet been display
|
|
||||||
var hasNewEvent: Boolean = false
|
var hasNewEvent: Boolean = false
|
||||||
//true if at least one on the not yet displayed event is noisy
|
// true if at least one on the not yet displayed event is noisy
|
||||||
var shouldBing: Boolean = false
|
var shouldBing: Boolean = false
|
||||||
var customSound: String? = null
|
var customSound: String? = null
|
||||||
var hasSmartReplyError = false
|
var hasSmartReplyError: Boolean = false
|
||||||
var isDirect = false
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user