Skip to content
Snippets Groups Projects
Verified Commit b4e3f68c authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Only expand messages which have spoilers

parent d9976ecf
No related branches found
No related tags found
No related merge requests found
...@@ -352,7 +352,7 @@ class QuasselNotificationBackend @Inject constructor( ...@@ -352,7 +352,7 @@ class QuasselNotificationBackend @Inject constructor(
selfColor = selfColor selfColor = selfColor
)) ))
} }
val content = contentFormatter.formatContent(it.content, false, false, it.networkId) val (content, _) = contentFormatter.formatContent(it.content, false, false, it.networkId)
NotificationMessage( NotificationMessage(
messageId = it.messageId, messageId = it.messageId,
......
...@@ -253,7 +253,7 @@ class MessageListFragment : ServiceBoundFragment() { ...@@ -253,7 +253,7 @@ class MessageListFragment : ServiceBoundFragment() {
1 -> actionMode?.menu?.findItem(R.id.action_user_info)?.isVisible = true 1 -> actionMode?.menu?.findItem(R.id.action_user_info)?.isVisible = true
else -> actionMode?.menu?.findItem(R.id.action_user_info)?.isVisible = false else -> actionMode?.menu?.findItem(R.id.action_user_info)?.isVisible = false
} }
} else { } else if (msg.hasSpoilers) {
val value = viewModel.expandedMessages.value val value = viewModel.expandedMessages.value
viewModel.expandedMessages.onNext( viewModel.expandedMessages.onNext(
if (value.contains(msg.original.messageId)) value - msg.original.messageId if (value.contains(msg.original.messageId)) value - msg.original.messageId
......
...@@ -257,7 +257,7 @@ class QuasselMessageRenderer @Inject constructor( ...@@ -257,7 +257,7 @@ class QuasselMessageRenderer @Inject constructor(
false false
)) ))
} }
val content = contentFormatter.formatContent(message.content.content, val (content, hasSpoilers) = contentFormatter.formatContent(message.content.content,
monochromeForeground, monochromeForeground,
message.isExpanded, message.isExpanded,
message.content.networkId) message.content.networkId)
...@@ -291,7 +291,8 @@ class QuasselMessageRenderer @Inject constructor( ...@@ -291,7 +291,8 @@ class QuasselMessageRenderer @Inject constructor(
hasDayChange = message.hasDayChange, hasDayChange = message.hasDayChange,
isMarkerLine = message.isMarkerLine, isMarkerLine = message.isMarkerLine,
isExpanded = message.isExpanded, isExpanded = message.isExpanded,
isSelected = message.isSelected isSelected = message.isSelected,
hasSpoilers = hasSpoilers
) )
} }
Message_Type.Action -> { Message_Type.Action -> {
...@@ -308,6 +309,11 @@ class QuasselMessageRenderer @Inject constructor( ...@@ -308,6 +309,11 @@ class QuasselMessageRenderer @Inject constructor(
} }
val senderColor = if (useSelfColor) selfColor else senderColors[senderColorIndex] val senderColor = if (useSelfColor) selfColor else senderColors[senderColorIndex]
val (content, hasSpoilers) = contentFormatter.formatContent(message.content.content,
monochromeForeground,
message.isExpanded,
message.content.networkId)
FormattedMessage( FormattedMessage(
original = message.content, original = message.content,
time = timeFormatter.format(message.content.time.atZone(zoneId)), time = timeFormatter.format(message.content.time.atZone(zoneId)),
...@@ -316,20 +322,23 @@ class QuasselMessageRenderer @Inject constructor( ...@@ -316,20 +322,23 @@ class QuasselMessageRenderer @Inject constructor(
context.getString(R.string.message_format_action), context.getString(R.string.message_format_action),
contentFormatter.formatPrefix(message.content.senderPrefixes), contentFormatter.formatPrefix(message.content.senderPrefixes),
contentFormatter.formatNick(message.content.sender, self, monochromeForeground, false), contentFormatter.formatNick(message.content.sender, self, monochromeForeground, false),
contentFormatter.formatContent(message.content.content, content
monochromeForeground,
message.isExpanded,
message.content.networkId)
), ),
avatarUrls = AvatarHelper.avatar(messageSettings, message.content, avatarSize), avatarUrls = AvatarHelper.avatar(messageSettings, message.content, avatarSize),
fallbackDrawable = colorContext.buildTextDrawable(initial, senderColor), fallbackDrawable = colorContext.buildTextDrawable(initial, senderColor),
hasDayChange = message.hasDayChange, hasDayChange = message.hasDayChange,
isMarkerLine = message.isMarkerLine, isMarkerLine = message.isMarkerLine,
isExpanded = message.isExpanded, isExpanded = message.isExpanded,
isSelected = message.isSelected isSelected = message.isSelected,
hasSpoilers = hasSpoilers
) )
} }
Message_Type.Notice -> FormattedMessage( Message_Type.Notice -> {
val (content, hasSpoilers) = contentFormatter.formatContent(message.content.content,
monochromeForeground,
message.isExpanded,
message.content.networkId)
FormattedMessage(
original = message.content, original = message.content,
time = timeFormatter.format(message.content.time.atZone(zoneId)), time = timeFormatter.format(message.content.time.atZone(zoneId)),
dayChange = formatDayChange(message), dayChange = formatDayChange(message),
...@@ -337,16 +346,15 @@ class QuasselMessageRenderer @Inject constructor( ...@@ -337,16 +346,15 @@ class QuasselMessageRenderer @Inject constructor(
context.getString(R.string.message_format_notice), context.getString(R.string.message_format_notice),
contentFormatter.formatPrefix(message.content.senderPrefixes), contentFormatter.formatPrefix(message.content.senderPrefixes),
contentFormatter.formatNick(message.content.sender, self, monochromeForeground, false), contentFormatter.formatNick(message.content.sender, self, monochromeForeground, false),
contentFormatter.formatContent(message.content.content, content
monochromeForeground,
message.isExpanded,
message.content.networkId)
), ),
hasDayChange = message.hasDayChange, hasDayChange = message.hasDayChange,
isMarkerLine = message.isMarkerLine, isMarkerLine = message.isMarkerLine,
isExpanded = message.isExpanded, isExpanded = message.isExpanded,
isSelected = message.isSelected isSelected = message.isSelected,
hasSpoilers = hasSpoilers
) )
}
Message_Type.Nick -> { Message_Type.Nick -> {
val nickSelf = message.content.sender == message.content.content || self val nickSelf = message.content.sender == message.content.content || self
FormattedMessage( FormattedMessage(
...@@ -386,7 +394,8 @@ class QuasselMessageRenderer @Inject constructor( ...@@ -386,7 +394,8 @@ class QuasselMessageRenderer @Inject constructor(
hasDayChange = message.hasDayChange, hasDayChange = message.hasDayChange,
isMarkerLine = message.isMarkerLine, isMarkerLine = message.isMarkerLine,
isExpanded = message.isExpanded, isExpanded = message.isExpanded,
isSelected = message.isSelected isSelected = message.isSelected,
hasSpoilers = false
) )
} }
Message_Type.Mode -> FormattedMessage( Message_Type.Mode -> FormattedMessage(
...@@ -402,7 +411,8 @@ class QuasselMessageRenderer @Inject constructor( ...@@ -402,7 +411,8 @@ class QuasselMessageRenderer @Inject constructor(
hasDayChange = message.hasDayChange, hasDayChange = message.hasDayChange,
isMarkerLine = message.isMarkerLine, isMarkerLine = message.isMarkerLine,
isExpanded = message.isExpanded, isExpanded = message.isExpanded,
isSelected = message.isSelected isSelected = message.isSelected,
hasSpoilers = false
) )
Message_Type.Join -> FormattedMessage( Message_Type.Join -> FormattedMessage(
original = message.content, original = message.content,
...@@ -422,13 +432,12 @@ class QuasselMessageRenderer @Inject constructor( ...@@ -422,13 +432,12 @@ class QuasselMessageRenderer @Inject constructor(
hasDayChange = message.hasDayChange, hasDayChange = message.hasDayChange,
isMarkerLine = message.isMarkerLine, isMarkerLine = message.isMarkerLine,
isExpanded = message.isExpanded, isExpanded = message.isExpanded,
isSelected = message.isSelected isSelected = message.isSelected,
hasSpoilers = false
) )
Message_Type.Part -> FormattedMessage( Message_Type.Part -> {
original = message.content, val (content, hasSpoilers) = if (message.content.content.isBlank()) {
time = timeFormatter.format(message.content.time.atZone(zoneId)), Pair(
dayChange = formatDayChange(message),
combined = if (message.content.content.isBlank()) {
SpanFormatter.format( SpanFormatter.format(
context.getString(R.string.message_format_part_1), context.getString(R.string.message_format_part_1),
contentFormatter.formatPrefix(message.content.senderPrefixes), contentFormatter.formatPrefix(message.content.senderPrefixes),
...@@ -438,8 +447,15 @@ class QuasselMessageRenderer @Inject constructor( ...@@ -438,8 +447,15 @@ class QuasselMessageRenderer @Inject constructor(
monochromeForeground, monochromeForeground,
messageSettings.showHostmaskActions messageSettings.showHostmaskActions
) )
),
false
) )
} else { } else {
val (content, hasSpoilers) = contentFormatter.formatContent(message.content.content,
monochromeForeground,
message.isExpanded,
message.content.networkId)
Pair(
SpanFormatter.format( SpanFormatter.format(
context.getString(R.string.message_format_part_2), context.getString(R.string.message_format_part_2),
contentFormatter.formatPrefix(message.content.senderPrefixes), contentFormatter.formatPrefix(message.content.senderPrefixes),
...@@ -449,22 +465,27 @@ class QuasselMessageRenderer @Inject constructor( ...@@ -449,22 +465,27 @@ class QuasselMessageRenderer @Inject constructor(
monochromeForeground, monochromeForeground,
messageSettings.showHostmaskActions messageSettings.showHostmaskActions
), ),
contentFormatter.formatContent(message.content.content, content
monochromeForeground, ),
message.isExpanded, hasSpoilers
message.content.networkId)
) )
}, }
FormattedMessage(
original = message.content,
time = timeFormatter.format(message.content.time.atZone(zoneId)),
dayChange = formatDayChange(message),
combined = content,
hasDayChange = message.hasDayChange, hasDayChange = message.hasDayChange,
isMarkerLine = message.isMarkerLine, isMarkerLine = message.isMarkerLine,
isExpanded = message.isExpanded, isExpanded = message.isExpanded,
isSelected = message.isSelected isSelected = message.isSelected,
hasSpoilers = hasSpoilers
) )
Message_Type.Quit -> FormattedMessage( }
original = message.content, Message_Type.Quit -> {
time = timeFormatter.format(message.content.time.atZone(zoneId)), val (content, hasSpoilers) = if (message.content.content.isBlank()) {
dayChange = formatDayChange(message), Pair(
combined = if (message.content.content.isBlank()) {
SpanFormatter.format( SpanFormatter.format(
context.getString(R.string.message_format_quit_1), context.getString(R.string.message_format_quit_1),
contentFormatter.formatPrefix(message.content.senderPrefixes), contentFormatter.formatPrefix(message.content.senderPrefixes),
...@@ -474,8 +495,15 @@ class QuasselMessageRenderer @Inject constructor( ...@@ -474,8 +495,15 @@ class QuasselMessageRenderer @Inject constructor(
monochromeForeground, monochromeForeground,
messageSettings.showHostmaskActions messageSettings.showHostmaskActions
) )
),
false
) )
} else { } else {
val (content, hasSpoilers) = contentFormatter.formatContent(message.content.content,
monochromeForeground,
message.isExpanded,
message.content.networkId)
Pair(
SpanFormatter.format( SpanFormatter.format(
context.getString(R.string.message_format_quit_2), context.getString(R.string.message_format_quit_2),
contentFormatter.formatPrefix(message.content.senderPrefixes), contentFormatter.formatPrefix(message.content.senderPrefixes),
...@@ -485,24 +513,28 @@ class QuasselMessageRenderer @Inject constructor( ...@@ -485,24 +513,28 @@ class QuasselMessageRenderer @Inject constructor(
monochromeForeground, monochromeForeground,
messageSettings.showHostmaskActions messageSettings.showHostmaskActions
), ),
contentFormatter.formatContent(message.content.content, content
monochromeForeground, ),
message.isExpanded, hasSpoilers
message.content.networkId)
) )
}, }
FormattedMessage(
original = message.content,
time = timeFormatter.format(message.content.time.atZone(zoneId)),
dayChange = formatDayChange(message),
combined = content,
hasDayChange = message.hasDayChange, hasDayChange = message.hasDayChange,
isMarkerLine = message.isMarkerLine, isMarkerLine = message.isMarkerLine,
isExpanded = message.isExpanded, isExpanded = message.isExpanded,
isSelected = message.isSelected isSelected = message.isSelected,
hasSpoilers = hasSpoilers
) )
}
Message_Type.Kick -> { Message_Type.Kick -> {
val (user, reason) = message.content.content.split(' ', limit = 2) + listOf("", "") val (user, reason) = message.content.content.split(' ', limit = 2) + listOf("", "")
FormattedMessage( val (content, hasSpoilers) = if (reason.isBlank()) {
original = message.content, Pair(
time = timeFormatter.format(message.content.time.atZone(zoneId)),
dayChange = formatDayChange(message),
combined = if (reason.isBlank()) {
SpanFormatter.format( SpanFormatter.format(
context.getString(R.string.message_format_kick_1), context.getString(R.string.message_format_kick_1),
contentFormatter.formatNick(user, false, monochromeForeground, false), contentFormatter.formatNick(user, false, monochromeForeground, false),
...@@ -511,8 +543,15 @@ class QuasselMessageRenderer @Inject constructor( ...@@ -511,8 +543,15 @@ class QuasselMessageRenderer @Inject constructor(
self, self,
monochromeForeground, monochromeForeground,
false) false)
),
false
) )
} else { } else {
val (content, hasSpoilers) = contentFormatter.formatContent(reason,
monochromeForeground,
message.isExpanded,
message.content.networkId)
Pair(
SpanFormatter.format( SpanFormatter.format(
context.getString(R.string.message_format_kick_2), context.getString(R.string.message_format_kick_2),
contentFormatter.formatNick(user, false, monochromeForeground, false), contentFormatter.formatNick(user, false, monochromeForeground, false),
...@@ -521,25 +560,28 @@ class QuasselMessageRenderer @Inject constructor( ...@@ -521,25 +560,28 @@ class QuasselMessageRenderer @Inject constructor(
self, self,
monochromeForeground, monochromeForeground,
false), false),
contentFormatter.formatContent(reason, content
monochromeForeground, ),
message.isExpanded, hasSpoilers
message.content.networkId)
) )
}, }
FormattedMessage(
original = message.content,
time = timeFormatter.format(message.content.time.atZone(zoneId)),
dayChange = formatDayChange(message),
combined = content,
hasDayChange = message.hasDayChange, hasDayChange = message.hasDayChange,
isMarkerLine = message.isMarkerLine, isMarkerLine = message.isMarkerLine,
isExpanded = message.isExpanded, isExpanded = message.isExpanded,
isSelected = message.isSelected isSelected = message.isSelected,
hasSpoilers = hasSpoilers
) )
} }
Message_Type.Kill -> { Message_Type.Kill -> {
val (user, reason) = message.content.content.split(' ', limit = 2) + listOf("", "") val (user, reason) = message.content.content.split(' ', limit = 2) + listOf("", "")
FormattedMessage( val (content, hasSpoilers) = if (reason.isBlank()) {
original = message.content, Pair(
time = timeFormatter.format(message.content.time.atZone(zoneId)),
dayChange = formatDayChange(message),
combined = if (reason.isBlank()) {
SpanFormatter.format( SpanFormatter.format(
context.getString(R.string.message_format_kill_1), context.getString(R.string.message_format_kill_1),
contentFormatter.formatNick(user, false, monochromeForeground, false), contentFormatter.formatNick(user, false, monochromeForeground, false),
...@@ -548,8 +590,15 @@ class QuasselMessageRenderer @Inject constructor( ...@@ -548,8 +590,15 @@ class QuasselMessageRenderer @Inject constructor(
self, self,
monochromeForeground, monochromeForeground,
false) false)
),
false
) )
} else { } else {
val (content, hasSpoilers) = contentFormatter.formatContent(reason,
monochromeForeground,
message.isExpanded,
message.content.networkId)
Pair(
SpanFormatter.format( SpanFormatter.format(
context.getString(R.string.message_format_kill_2), context.getString(R.string.message_format_kill_2),
contentFormatter.formatNick(user, false, monochromeForeground, false), contentFormatter.formatNick(user, false, monochromeForeground, false),
...@@ -558,16 +607,22 @@ class QuasselMessageRenderer @Inject constructor( ...@@ -558,16 +607,22 @@ class QuasselMessageRenderer @Inject constructor(
self, self,
monochromeForeground, monochromeForeground,
false), false),
contentFormatter.formatContent(reason, content
monochromeForeground, ),
message.isExpanded, hasSpoilers
message.content.networkId)
) )
}, }
FormattedMessage(
original = message.content,
time = timeFormatter.format(message.content.time.atZone(zoneId)),
dayChange = formatDayChange(message),
combined = content,
hasDayChange = message.hasDayChange, hasDayChange = message.hasDayChange,
isMarkerLine = message.isMarkerLine, isMarkerLine = message.isMarkerLine,
isExpanded = message.isExpanded, isExpanded = message.isExpanded,
isSelected = message.isSelected isSelected = message.isSelected,
hasSpoilers = hasSpoilers
) )
} }
Message_Type.NetsplitJoin -> { Message_Type.NetsplitJoin -> {
...@@ -593,7 +648,8 @@ class QuasselMessageRenderer @Inject constructor( ...@@ -593,7 +648,8 @@ class QuasselMessageRenderer @Inject constructor(
hasDayChange = message.hasDayChange, hasDayChange = message.hasDayChange,
isMarkerLine = message.isMarkerLine, isMarkerLine = message.isMarkerLine,
isExpanded = message.isExpanded, isExpanded = message.isExpanded,
isSelected = message.isSelected isSelected = message.isSelected,
hasSpoilers = false
) )
} }
Message_Type.NetsplitQuit -> { Message_Type.NetsplitQuit -> {
...@@ -619,37 +675,46 @@ class QuasselMessageRenderer @Inject constructor( ...@@ -619,37 +675,46 @@ class QuasselMessageRenderer @Inject constructor(
hasDayChange = message.hasDayChange, hasDayChange = message.hasDayChange,
isMarkerLine = message.isMarkerLine, isMarkerLine = message.isMarkerLine,
isExpanded = message.isExpanded, isExpanded = message.isExpanded,
isSelected = message.isSelected isSelected = message.isSelected,
hasSpoilers = false
) )
} }
Message_Type.Server, Message_Type.Server,
Message_Type.Info, Message_Type.Info,
Message_Type.Error -> FormattedMessage( Message_Type.Error -> {
val (content, hasSpoilers) = contentFormatter.formatContent(message.content.content,
monochromeForeground,
message.isExpanded,
message.content.networkId)
FormattedMessage(
original = message.content, original = message.content,
time = timeFormatter.format(message.content.time.atZone(zoneId)), time = timeFormatter.format(message.content.time.atZone(zoneId)),
dayChange = formatDayChange(message), dayChange = formatDayChange(message),
combined = contentFormatter.formatContent(message.content.content, combined = content,
monochromeForeground,
message.isExpanded,
message.content.networkId),
hasDayChange = message.hasDayChange, hasDayChange = message.hasDayChange,
isMarkerLine = message.isMarkerLine, isMarkerLine = message.isMarkerLine,
isExpanded = message.isExpanded, isExpanded = message.isExpanded,
isSelected = message.isSelected isSelected = message.isSelected,
hasSpoilers = hasSpoilers
) )
Message_Type.Topic -> FormattedMessage( }
Message_Type.Topic -> {
val (content, hasSpoilers) = contentFormatter.formatContent(message.content.content,
monochromeForeground,
message.isExpanded,
message.content.networkId)
FormattedMessage(
original = message.content, original = message.content,
time = timeFormatter.format(message.content.time.atZone(zoneId)), time = timeFormatter.format(message.content.time.atZone(zoneId)),
dayChange = formatDayChange(message), dayChange = formatDayChange(message),
combined = contentFormatter.formatContent(message.content.content, combined = content,
monochromeForeground,
message.isExpanded,
message.content.networkId),
hasDayChange = message.hasDayChange, hasDayChange = message.hasDayChange,
isMarkerLine = message.isMarkerLine, isMarkerLine = message.isMarkerLine,
isExpanded = message.isExpanded, isExpanded = message.isExpanded,
isSelected = message.isSelected isSelected = message.isSelected,
hasSpoilers = hasSpoilers
) )
}
Message_Type.DayChange -> FormattedMessage( Message_Type.DayChange -> FormattedMessage(
original = message.content, original = message.content,
time = "", time = "",
...@@ -658,21 +723,26 @@ class QuasselMessageRenderer @Inject constructor( ...@@ -658,21 +723,26 @@ class QuasselMessageRenderer @Inject constructor(
hasDayChange = message.hasDayChange, hasDayChange = message.hasDayChange,
isMarkerLine = false, isMarkerLine = false,
isExpanded = false, isExpanded = false,
isSelected = false isSelected = false,
hasSpoilers = false
) )
Message_Type.Invite -> FormattedMessage( Message_Type.Invite -> {
val (content, hasSpoilers) = contentFormatter.formatContent(message.content.content,
monochromeForeground,
message.isExpanded,
message.content.networkId)
FormattedMessage(
original = message.content, original = message.content,
time = timeFormatter.format(message.content.time.atZone(zoneId)), time = timeFormatter.format(message.content.time.atZone(zoneId)),
dayChange = formatDayChange(message), dayChange = formatDayChange(message),
combined = contentFormatter.formatContent(message.content.content, combined = content,
monochromeForeground,
message.isExpanded,
message.content.networkId),
hasDayChange = message.hasDayChange, hasDayChange = message.hasDayChange,
isMarkerLine = message.isMarkerLine, isMarkerLine = message.isMarkerLine,
isExpanded = message.isExpanded, isExpanded = message.isExpanded,
isSelected = message.isSelected isSelected = message.isSelected,
hasSpoilers = hasSpoilers
) )
}
else -> FormattedMessage( else -> FormattedMessage(
original = message.content, original = message.content,
time = timeFormatter.format(message.content.time.atZone(zoneId)), time = timeFormatter.format(message.content.time.atZone(zoneId)),
...@@ -692,7 +762,8 @@ class QuasselMessageRenderer @Inject constructor( ...@@ -692,7 +762,8 @@ class QuasselMessageRenderer @Inject constructor(
hasDayChange = message.hasDayChange, hasDayChange = message.hasDayChange,
isMarkerLine = message.isMarkerLine, isMarkerLine = message.isMarkerLine,
isExpanded = message.isExpanded, isExpanded = message.isExpanded,
isSelected = message.isSelected isSelected = message.isSelected,
hasSpoilers = false
) )
} }
} }
......
...@@ -109,8 +109,11 @@ class ChannelInfoFragment : ServiceBoundFragment() { ...@@ -109,8 +109,11 @@ class ChannelInfoFragment : ServiceBoundFragment() {
} }
}.toLiveData().observe(this, Observer { (info, channel) -> }.toLiveData().observe(this, Observer { (info, channel) ->
name.text = channel.name() name.text = channel.name()
topic.text = contentFormatter.formatContent(channel.topic(), val (content, hasSpoilers) = contentFormatter.formatContent(
networkId = channel.network().networkId()) channel.topic(),
networkId = channel.network().networkId()
)
topic.text = content
currentBufferInfo = info currentBufferInfo = info
actionShortcut.visibleIf(info != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) actionShortcut.visibleIf(info != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
......
...@@ -108,7 +108,11 @@ class ChannelListAdapter @Inject constructor( ...@@ -108,7 +108,11 @@ class ChannelListAdapter @Inject constructor(
fun bind(data: IrcListHelper.ChannelDescription) { fun bind(data: IrcListHelper.ChannelDescription) {
name.text = data.channelName name.text = data.channelName
topic.text = contentFormatter.formatContent(data.topic, networkId = data.netId) val (content, hasSpoilers) = contentFormatter.formatContent(
data.topic,
networkId = data.netId
)
topic.text = content
users.text = itemView.context.resources.getQuantityString(R.plurals.label_user_count, users.text = itemView.context.resources.getQuantityString(R.plurals.label_user_count,
data.userCount.toInt(), data.userCount.toInt(),
data.userCount.toInt()) data.userCount.toInt())
......
...@@ -225,8 +225,11 @@ class UserInfoFragment : ServiceBoundFragment() { ...@@ -225,8 +225,11 @@ class UserInfoFragment : ServiceBoundFragment() {
} }
nick.text = user.nick nick.text = user.nick
realName.text = contentFormatter.formatContent(user.realName ?: "", val (content, hasSpoilers) = contentFormatter.formatContent(
networkId = user.networkId) user.realName ?: "",
networkId = user.networkId
)
realName.text = content
realName.visibleIf(!user.realName.isNullOrBlank() && user.realName != user.nick) realName.visibleIf(!user.realName.isNullOrBlank() && user.realName != user.nick)
awayMessage.text = user.awayMessage.nullIf { it.isNullOrBlank() } ?: SpannableString( awayMessage.text = user.awayMessage.nullIf { it.isNullOrBlank() } ?: SpannableString(
......
...@@ -79,8 +79,8 @@ class ContentFormatter @Inject constructor( ...@@ -79,8 +79,8 @@ class ContentFormatter @Inject constructor(
fun formatContent(content: String, fun formatContent(content: String,
highlight: Boolean = false, highlight: Boolean = false,
showSpoilers: Boolean = false, unhideSpoilers: Boolean = false,
networkId: NetworkId?): CharSequence { networkId: NetworkId?): Pair<CharSequence, Boolean> {
val spans = mutableListOf<FormatInfo>() val spans = mutableListOf<FormatInfo>()
val formattedText = SpannableString( val formattedText = SpannableString(
ircFormatDeserializer.formatString( ircFormatDeserializer.formatString(
...@@ -90,7 +90,7 @@ class ContentFormatter @Inject constructor( ...@@ -90,7 +90,7 @@ class ContentFormatter @Inject constructor(
) )
) )
if (showSpoilers) { val hasSpoilers = if (unhideSpoilers) {
spans.removeAll { spans.removeAll {
when { when {
it.format is IrcFormat.Color -> it.format is IrcFormat.Color ->
...@@ -101,6 +101,17 @@ class ContentFormatter @Inject constructor( ...@@ -101,6 +101,17 @@ class ContentFormatter @Inject constructor(
false false
} }
} }
} else {
spans.any {
when {
it.format is IrcFormat.Color ->
it.format.foreground == it.format.background
it.format is IrcFormat.Hex ->
it.format.foreground == it.format.background
else ->
false
}
}
} }
for (result in urlPattern.findAll(formattedText)) { for (result in urlPattern.findAll(formattedText)) {
...@@ -131,7 +142,7 @@ class ContentFormatter @Inject constructor( ...@@ -131,7 +142,7 @@ class ContentFormatter @Inject constructor(
span.apply(formattedText) span.apply(formattedText)
} }
return formattedText return Pair(formattedText, hasSpoilers)
} }
private fun formatNickNickImpl(nick: String, self: Boolean, colorize: Boolean, private fun formatNickNickImpl(nick: String, self: Boolean, colorize: Boolean,
......
...@@ -36,7 +36,8 @@ class FormattedMessage( ...@@ -36,7 +36,8 @@ class FormattedMessage(
val hasDayChange: Boolean, val hasDayChange: Boolean,
val isSelected: Boolean, val isSelected: Boolean,
val isExpanded: Boolean, val isExpanded: Boolean,
val isMarkerLine: Boolean val isMarkerLine: Boolean,
val hasSpoilers: Boolean
) { ) {
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment