Merge pull request #2293 from element-hq/feature/bma/notificationCount

Iterate on notification badges
This commit is contained in:
Benoit Marty 2024-01-30 10:33:17 +01:00 committed by GitHub
commit a7541be6bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
48 changed files with 138 additions and 150 deletions

View file

@ -35,6 +35,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.PreviewParameter
@ -141,7 +142,7 @@ private fun RowScope.NameAndTimestampRow(room: RoomListRoomSummary) {
Text(
text = room.timestamp ?: "",
style = ElementTheme.typography.fontBodySmMedium,
color = if (room.isTimestampHighlighted) {
color = if (room.isHighlighted) {
ElementTheme.colors.unreadIndicator
} else {
MaterialTheme.roomListRoomMessageDate()
@ -165,86 +166,61 @@ private fun RowScope.LastMessageAndIndicatorRow(room: RoomListRoomSummary) {
maxLines = 2,
overflow = TextOverflow.Ellipsis
)
// Unread
// Call and unread
Row(
modifier = Modifier.height(16.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically,
) {
// Video call
OnGoingCallIcon(
room.hasRoomCall,
)
// Other indicators
NotificationIcons(
room.userDefinedNotificationMode,
room.numberOfUnreadMessages,
room.numberOfUnreadMentions,
)
val tint = if (room.isHighlighted) ElementTheme.colors.unreadIndicator else ElementTheme.colors.iconQuaternary
if (room.hasRoomCall) {
OnGoingCallIcon(
color = tint,
)
}
if (room.userDefinedNotificationMode == RoomNotificationMode.MUTE) {
NotificationOffIndicatorAtom()
} else if (room.numberOfUnreadMentions > 0) {
MentionIndicatorAtom()
}
if (room.hasNewContent) {
UnreadIndicatorAtom(
color = tint
)
}
}
}
@Composable
private fun OnGoingCallIcon(
hasRoomCall: Boolean,
color: Color,
) {
if (hasRoomCall) {
Icon(
modifier = Modifier.size(16.dp),
imageVector = CompoundIcons.VideoCallSolid,
contentDescription = null,
tint = ElementTheme.colors.unreadIndicator,
)
}
Icon(
modifier = Modifier.size(16.dp),
imageVector = CompoundIcons.VideoCallSolid,
contentDescription = null,
tint = color,
)
}
@Composable
private fun RowScope.NotificationIcons(
userDefinedNotificationMode: RoomNotificationMode?,
numberOfUnreadMessages: Int,
numberOfUnreadMentions: Int,
) {
when (userDefinedNotificationMode) {
null,
RoomNotificationMode.ALL_MESSAGES -> {
if (numberOfUnreadMentions > 0) {
Icon(
modifier = Modifier.size(16.dp),
contentDescription = null,
imageVector = CompoundIcons.Mention,
tint = ElementTheme.colors.unreadIndicator,
)
UnreadIndicatorAtom()
} else if (numberOfUnreadMessages > 0) {
UnreadIndicatorAtom()
}
}
RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY -> {
if (numberOfUnreadMentions > 0) {
Icon(
modifier = Modifier.size(16.dp),
contentDescription = null,
imageVector = CompoundIcons.Mention,
tint = ElementTheme.colors.unreadIndicator,
)
UnreadIndicatorAtom()
} else if (numberOfUnreadMessages > 0) {
UnreadIndicatorAtom(color = ElementTheme.colors.iconQuaternary)
}
}
RoomNotificationMode.MUTE -> {
Icon(
modifier = Modifier.size(16.dp),
contentDescription = null,
imageVector = CompoundIcons.NotificationsSolidOff,
tint = ElementTheme.colors.iconQuaternary,
)
if (numberOfUnreadMessages > 0 || numberOfUnreadMentions > 0) {
UnreadIndicatorAtom(color = ElementTheme.colors.iconQuaternary)
}
}
}
private fun NotificationOffIndicatorAtom() {
Icon(
modifier = Modifier.size(16.dp),
contentDescription = null,
imageVector = CompoundIcons.NotificationsSolidOff,
tint = ElementTheme.colors.iconQuaternary,
)
}
@Composable
private fun MentionIndicatorAtom() {
Icon(
modifier = Modifier.size(16.dp),
contentDescription = null,
imageVector = CompoundIcons.Mention,
tint = ElementTheme.colors.unreadIndicator,
)
}
@PreviewsDayNight

View file

@ -43,6 +43,7 @@ class RoomListRoomSummaryFactory @Inject constructor(
avatarData = AvatarData(id, "S", size = AvatarSize.RoomListItem),
numberOfUnreadMessages = 0,
numberOfUnreadMentions = 0,
numberOfUnreadNotifications = 0,
userDefinedNotificationMode = null,
hasRoomCall = false,
isDm = false,
@ -69,6 +70,7 @@ class RoomListRoomSummaryFactory @Inject constructor(
name = roomSummary.details.name,
numberOfUnreadMessages = roomSummary.details.numUnreadMessages,
numberOfUnreadMentions = roomSummary.details.numUnreadMentions,
numberOfUnreadNotifications = roomSummary.details.numUnreadNotifications,
timestamp = lastMessageTimestampFormatter.format(roomSummary.details.lastMessageTimestamp),
lastMessage = roomSummary.details.lastMessage?.let { message ->
roomLastMessageFormatter.format(message.event, roomSummary.details.isDirect)

View file

@ -28,6 +28,7 @@ data class RoomListRoomSummary(
val name: String,
val numberOfUnreadMessages: Int,
val numberOfUnreadMentions: Int,
val numberOfUnreadNotifications: Int,
val timestamp: String?,
val lastMessage: CharSequence?,
val avatarData: AvatarData,
@ -36,11 +37,10 @@ data class RoomListRoomSummary(
val hasRoomCall: Boolean,
val isDm: Boolean,
) {
val isTimestampHighlighted = hasRoomCall ||
when (userDefinedNotificationMode) {
null,
RoomNotificationMode.ALL_MESSAGES -> numberOfUnreadMessages > 0 || numberOfUnreadMentions > 0
RoomNotificationMode.MENTIONS_AND_KEYWORDS_ONLY -> numberOfUnreadMentions > 0
RoomNotificationMode.MUTE -> false
}
val isHighlighted = userDefinedNotificationMode != RoomNotificationMode.MUTE &&
(numberOfUnreadNotifications > 0 || numberOfUnreadMentions > 0)
val hasNewContent = numberOfUnreadMessages > 0 ||
numberOfUnreadMentions > 0 ||
numberOfUnreadNotifications > 0
}

View file

@ -88,6 +88,7 @@ internal fun aRoomListRoomSummary(
name: String = "Room name",
numberOfUnreadMessages: Int = 0,
numberOfUnreadMentions: Int = 0,
numberOfUnreadNotifications: Int = 0,
lastMessage: String? = "Last message",
timestamp: String? = lastMessage?.let { "88:88" },
isPlaceholder: Boolean = false,
@ -101,6 +102,7 @@ internal fun aRoomListRoomSummary(
name = name,
numberOfUnreadMessages = numberOfUnreadMessages,
numberOfUnreadMentions = numberOfUnreadMentions,
numberOfUnreadNotifications = numberOfUnreadNotifications,
timestamp = timestamp,
lastMessage = lastMessage,
avatarData = avatarData,

View file

@ -442,6 +442,7 @@ private val aRoomListRoomSummary = RoomListRoomSummary(
name = A_ROOM_NAME,
numberOfUnreadMentions = 1,
numberOfUnreadMessages = 2,
numberOfUnreadNotifications = 0,
timestamp = A_FORMATTED_DATE,
lastMessage = "",
avatarData = AvatarData(id = A_ROOM_ID.value, name = A_ROOM_NAME, size = AvatarSize.RoomListItem),