Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/src/main/kotlin/com/flxrs/dankchat/chat/ChatAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class ChatAdapter(
val firstHighlightType = message.highlights.firstOrNull()?.type
val shouldHighlight = firstHighlightType == HighlightType.Subscription || firstHighlightType == HighlightType.Announcement
val background = when {
shouldHighlight -> ContextCompat.getColor(context, R.color.color_sub_highlight)
shouldHighlight -> message.highlights.toBackgroundColor(context)
appearanceSettings.checkeredMessages && holder.isAlternateBackground -> MaterialColors.layer(
this,
android.R.attr.colorBackground,
Expand Down Expand Up @@ -358,7 +358,7 @@ class ChatAdapter(
private fun TextView.handlePointRedemptionMessage(message: PointRedemptionMessage, holder: ViewHolder) {
val appearanceSettings = appearanceSettingsDataStore.current()
val chatSettings = chatSettingsDataStore.current()
val background = ContextCompat.getColor(context, R.color.color_redemption_highlight)
val background = message.highlights.toBackgroundColor(context)
holder.binding.itemLayout.setBackgroundColor(background)
setRippleBackground(background, enableRipple = false)

Expand Down Expand Up @@ -894,6 +894,9 @@ class ChatAdapter(
@ColorInt
private fun Set<Highlight>.toBackgroundColor(context: Context): Int {
val highlight = highestPriorityHighlight() ?: return ContextCompat.getColor(context, android.R.color.transparent)
if (highlight.customColor != null) {
return highlight.customColor
}
return when (highlight.type) {
HighlightType.Subscription, HighlightType.Announcement -> ContextCompat.getColor(context, R.color.color_sub_highlight)
HighlightType.ChannelPointRedemption -> ContextCompat.getColor(context, R.color.color_redemption_highlight)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,14 @@ class HighlightsRepository(
val messageHighlights = validMessageHighlights.value

val highlights = buildSet {
if (isSub && messageHighlights.areSubsEnabled) {
add(Highlight(HighlightType.Subscription))
val subsHighlight = messageHighlights.subsHighlight
if (isSub && subsHighlight != null) {
add(Highlight(HighlightType.Subscription, subsHighlight.customColor))
}

if (isAnnouncement && messageHighlights.areAnnouncementsEnabled) {
add(Highlight(HighlightType.Announcement))
val announcementsHighlight = messageHighlights.announcementsHighlight
if (isAnnouncement && announcementsHighlight != null) {
add(Highlight(HighlightType.Announcement, announcementsHighlight.customColor))
}
}

Expand All @@ -222,15 +224,11 @@ class HighlightsRepository(
}

private fun PointRedemptionMessage.calculateHighlightState(): PointRedemptionMessage {
val redemptionsEnabled = validMessageHighlights.value
.any { it.type == MessageHighlightEntityType.ChannelPointRedemption }

val highlights = when {
redemptionsEnabled -> setOf(Highlight(HighlightType.ChannelPointRedemption))
else -> emptySet()
val rewardsHighlight = validMessageHighlights.value.rewardsHighlight
if (rewardsHighlight != null) {
return copy(highlights = setOf(Highlight(HighlightType.ChannelPointRedemption, rewardsHighlight.customColor)))
}

return copy(highlights = highlights)
return copy(highlights = emptySet())
}

private fun PrivMessage.calculateHighlightState(): PrivMessage {
Expand All @@ -247,38 +245,43 @@ class HighlightsRepository(
val badgeHighlights = validBadgeHighlights.value
val messageHighlights = validMessageHighlights.value
val highlights = buildSet {
if (isSub && messageHighlights.areSubsEnabled) {
add(Highlight(HighlightType.Subscription))
val subsHighlight = messageHighlights.subsHighlight
if (isSub && subsHighlight != null) {
add(Highlight(HighlightType.Subscription, subsHighlight.customColor))
}

if (isAnnouncement && messageHighlights.areAnnouncementsEnabled) {
add(Highlight(HighlightType.Announcement))
val announcementsHighlight = messageHighlights.announcementsHighlight
if (isAnnouncement && announcementsHighlight != null) {
add(Highlight(HighlightType.Announcement, announcementsHighlight.customColor))
}

if (isReward && messageHighlights.areRewardsEnabled) {
add(Highlight(HighlightType.ChannelPointRedemption))
val rewardsHighlight = messageHighlights.rewardsHighlight
if (isReward && rewardsHighlight != null) {
add(Highlight(HighlightType.ChannelPointRedemption, rewardsHighlight.customColor))
}

if (isFirstMessage && messageHighlights.areFirstMessagesEnabled) {
add(Highlight(HighlightType.FirstMessage))
val firstMessageHighlight = messageHighlights.firstMessageHighlight
if (isFirstMessage && firstMessageHighlight != null) {
add(Highlight(HighlightType.FirstMessage, firstMessageHighlight.customColor))
}

if (isElevatedMessage && messageHighlights.areElevatedMessagesEnabled) {
add(Highlight(HighlightType.ElevatedMessage))
val elevatedMessageHighlight = messageHighlights.elevatedMessageHighlight
if (isElevatedMessage && elevatedMessageHighlight != null) {
add(Highlight(HighlightType.ElevatedMessage, elevatedMessageHighlight.customColor))
}

if (containsCurrentUserName) {
val highlight = messageHighlights.userNameHighlight
if (highlight?.enabled == true) {
add(Highlight(HighlightType.Username))
add(Highlight(HighlightType.Username, highlight.customColor))
addNotificationHighlightIfEnabled(highlight)
}
}

if (containsParticipatedReply) {
val highlight = messageHighlights.repliesHighlight
if (highlight?.enabled == true) {
add(Highlight(HighlightType.Reply))
add(Highlight(HighlightType.Reply, highlight.customColor))
addNotificationHighlightIfEnabled(highlight)
}
}
Expand All @@ -289,14 +292,14 @@ class HighlightsRepository(
val regex = it.regex ?: return@forEach

if (message.contains(regex)) {
add(Highlight(HighlightType.Custom))
add(Highlight(HighlightType.Custom, it.customColor))
addNotificationHighlightIfEnabled(it)
}
}

userHighlights.forEach {
if (name.matches(it.username)) {
add(Highlight(HighlightType.Custom))
add(Highlight(HighlightType.Custom, it.customColor))
addNotificationHighlightIfEnabled(it)
}
}
Expand Down Expand Up @@ -326,31 +329,27 @@ class HighlightsRepository(
else -> this
}

private val List<MessageHighlightEntity>.areSubsEnabled: Boolean
get() = isMessageHighlightTypeEnabled(MessageHighlightEntityType.Subscription)
private val List<MessageHighlightEntity>.subsHighlight: MessageHighlightEntity?
get() = find { it.type == MessageHighlightEntityType.Subscription }

private val List<MessageHighlightEntity>.areAnnouncementsEnabled: Boolean
get() = isMessageHighlightTypeEnabled(MessageHighlightEntityType.Announcement)
private val List<MessageHighlightEntity>.announcementsHighlight : MessageHighlightEntity?
get() = find { it.type == MessageHighlightEntityType.Announcement }

private val List<MessageHighlightEntity>.areRewardsEnabled: Boolean
get() = isMessageHighlightTypeEnabled(MessageHighlightEntityType.ChannelPointRedemption)
private val List<MessageHighlightEntity>.rewardsHighlight: MessageHighlightEntity?
get() = find { it.type == MessageHighlightEntityType.ChannelPointRedemption }

private val List<MessageHighlightEntity>.areFirstMessagesEnabled: Boolean
get() = isMessageHighlightTypeEnabled(MessageHighlightEntityType.FirstMessage)
private val List<MessageHighlightEntity>.firstMessageHighlight: MessageHighlightEntity?
get() = find { it.type == MessageHighlightEntityType.FirstMessage }

private val List<MessageHighlightEntity>.areElevatedMessagesEnabled: Boolean
get() = isMessageHighlightTypeEnabled(MessageHighlightEntityType.ElevatedMessage)
private val List<MessageHighlightEntity>.elevatedMessageHighlight: MessageHighlightEntity?
get() = find { it.type == MessageHighlightEntityType.ElevatedMessage }

private val List<MessageHighlightEntity>.repliesHighlight: MessageHighlightEntity?
get() = find { it.type == MessageHighlightEntityType.Reply }

private val List<MessageHighlightEntity>.userNameHighlight: MessageHighlightEntity?
get() = find { it.type == MessageHighlightEntityType.Username }

private fun List<MessageHighlightEntity>.isMessageHighlightTypeEnabled(type: MessageHighlightEntityType): Boolean {
return any { it.type == type }
}

private fun MutableCollection<Highlight>.addNotificationHighlightIfEnabled(highlightEntity: MessageHighlightEntity) {
if (highlightEntity.createNotification) {
add(Highlight(HighlightType.Notification))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ class ChatRepository(
}

reward?.let {
listOf(ChatItem(PointRedemptionMessage.parsePointReward(it.timestamp, it.data)))
listOf(ChatItem(PointRedemptionMessage.parsePointReward(it.timestamp, it.data).calculateHighlightState()))
}.orEmpty()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ data class MessageHighlightItem(
val createNotification: Boolean,
val loggedIn: Boolean,
val notificationsEnabled: Boolean,
val customColor: Int?,
) : HighlightItem {
enum class Type {
Username,
Expand All @@ -46,6 +47,7 @@ data class UserHighlightItem(
val username: String,
val createNotification: Boolean,
val notificationsEnabled: Boolean,
val customColor: Int?,
) : HighlightItem

data class BadgeHighlightItem(
Expand Down Expand Up @@ -75,6 +77,7 @@ fun MessageHighlightEntity.toItem(loggedIn: Boolean, notificationsEnabled: Boole
createNotification = createNotification,
loggedIn = loggedIn,
notificationsEnabled = notificationsEnabled,
customColor = customColor,
)

fun MessageHighlightItem.toEntity() = MessageHighlightEntity(
Expand All @@ -85,6 +88,7 @@ fun MessageHighlightItem.toEntity() = MessageHighlightEntity(
isRegex = isRegex,
isCaseSensitive = isCaseSensitive,
createNotification = createNotification,
customColor = customColor,
)

fun MessageHighlightItem.Type.toEntityType(): MessageHighlightEntityType = when (this) {
Expand Down Expand Up @@ -115,13 +119,15 @@ fun UserHighlightEntity.toItem(notificationsEnabled: Boolean) = UserHighlightIte
username = username,
createNotification = createNotification,
notificationsEnabled = notificationsEnabled,
customColor = customColor,
)

fun UserHighlightItem.toEntity() = UserHighlightEntity(
id = id,
enabled = enabled,
username = username,
createNotification = createNotification,
customColor = customColor,
)

fun BadgeHighlightEntity.toItem(notificationsEnabled: Boolean) = BadgeHighlightItem(
Expand Down
Loading