Commit 7ec2b08d authored by Janne Koschinski's avatar Janne Koschinski

Implement colorful nicknames/idents/hosts

parent 8c49923d
Pipeline #496 passed with stages
in 43 minutes and 59 seconds
......@@ -304,11 +304,11 @@ class QuasselNotificationBackend @Inject constructor(
.firstOrNull() ?: nickName.firstOrNull()
val initial = rawInitial?.toUpperCase().toString()
val senderColor = when (messageSettings.colorizeNicknames) {
MessageSettings.ColorizeNicknamesMode.ALL -> senderColors[senderColorIndex]
MessageSettings.ColorizeNicknamesMode.ALL_BUT_MINE ->
MessageSettings.SenderColorMode.ALL -> senderColors[senderColorIndex]
MessageSettings.SenderColorMode.ALL_BUT_MINE ->
if (self) selfColor
else senderColors[senderColorIndex]
MessageSettings.ColorizeNicknamesMode.NONE -> selfColor
MessageSettings.SenderColorMode.NONE -> selfColor
}
val avatarList = AvatarHelper.avatar(messageSettings, ident, realName, avatarUrl, size)
......
......@@ -21,7 +21,7 @@ package de.kuschku.quasseldroid.settings
data class MessageSettings(
val showPrefix: ShowPrefixMode = ShowPrefixMode.HIGHEST,
val colorizeNicknames: ColorizeNicknamesMode = ColorizeNicknamesMode.ALL_BUT_MINE,
val colorizeNicknames: SenderColorMode = SenderColorMode.ALL_BUT_MINE,
val colorizeMirc: Boolean = true,
val useMonospace: Boolean = false,
val textSize: Int = 14,
......@@ -41,7 +41,7 @@ data class MessageSettings(
val replaceEmoji: Boolean = true
) {
enum class ColorizeNicknamesMode {
enum class SenderColorMode {
ALL,
ALL_BUT_MINE,
NONE;
......
......@@ -79,7 +79,7 @@ object Settings {
""
) ?: ""
) ?: MessageSettings.DEFAULT.showPrefix,
colorizeNicknames = MessageSettings.ColorizeNicknamesMode.of(
colorizeNicknames = MessageSettings.SenderColorMode.of(
getString(
context.getString(R.string.preference_colorize_nicknames_key),
""
......
......@@ -114,10 +114,10 @@ class ToolbarFragment : ServiceBoundFragment() {
val nickName = user.nick()
val useSelfColor = when (messageSettings.colorizeNicknames) {
MessageSettings.ColorizeNicknamesMode.ALL -> false
MessageSettings.ColorizeNicknamesMode.ALL_BUT_MINE ->
MessageSettings.SenderColorMode.ALL -> false
MessageSettings.SenderColorMode.ALL_BUT_MINE ->
user.network().isMyNick(nickName)
MessageSettings.ColorizeNicknamesMode.NONE -> true
MessageSettings.SenderColorMode.NONE -> true
}
val fallbackDrawable = colorContext.buildTextDrawable(user.nick(), useSelfColor)
......
......@@ -19,13 +19,9 @@
package de.kuschku.quasseldroid.ui.chat.add.query
import android.graphics.Typeface
import android.os.Bundle
import android.text.Editable
import android.text.SpannableString
import android.text.TextWatcher
import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
......@@ -65,6 +61,7 @@ import de.kuschku.quasseldroid.util.avatars.AvatarHelper
import de.kuschku.quasseldroid.util.helper.loadWithFallbacks
import de.kuschku.quasseldroid.util.helper.styledAttributes
import de.kuschku.quasseldroid.util.helper.toLiveData
import de.kuschku.quasseldroid.util.irc.format.ContentFormatter
import de.kuschku.quasseldroid.util.irc.format.IrcFormatDeserializer
import de.kuschku.quasseldroid.util.service.ServiceBoundFragment
import de.kuschku.quasseldroid.viewmodel.data.Avatar
......@@ -98,6 +95,9 @@ class QueryCreateFragment : ServiceBoundFragment() {
@Inject
lateinit var modelHelper: QueryCreateViewModelHelper
@Inject
lateinit var contentFormatter: ContentFormatter
private var hasSelectedNetwork = false
private var networkId = NetworkId(0)
......@@ -260,30 +260,13 @@ class QueryCreateFragment : ServiceBoundFragment() {
.firstOrNull() ?: nickName.firstOrNull()
val initial = rawInitial?.toUpperCase().toString()
val useSelfColor = when (messageSettings.colorizeNicknames) {
MessageSettings.ColorizeNicknamesMode.ALL -> false
MessageSettings.ColorizeNicknamesMode.ALL_BUT_MINE -> it.self
MessageSettings.ColorizeNicknamesMode.NONE -> true
MessageSettings.SenderColorMode.ALL -> false
MessageSettings.SenderColorMode.ALL_BUT_MINE -> it.self
MessageSettings.SenderColorMode.NONE -> true
}
val senderColor = if (useSelfColor) selfColor else senderColors[senderColorIndex]
fun formatNick(nick: CharSequence): CharSequence {
val spannableString = SpannableString(nick)
spannableString.setSpan(
ForegroundColorSpan(senderColor),
0,
nick.length,
SpannableString.SPAN_INCLUSIVE_EXCLUSIVE
)
spannableString.setSpan(
StyleSpan(Typeface.BOLD),
0,
nick.length,
SpannableString.SPAN_INCLUSIVE_EXCLUSIVE
)
return spannableString
}
it.copy(
displayNick = formatNick(it.nick),
displayNick = contentFormatter.formatNick(it.nick),
fallbackDrawable = colorContext.buildTextDrawable(initial, senderColor),
initial = initial,
modes = when (messageSettings.showPrefix) {
......
......@@ -297,7 +297,7 @@ class ArchiveListAdapter(
}
override fun bind(item: BufferListItem, messageSettings: MessageSettings) {
name.text = item.props.network.networkName
name.text = item.props.name
bufferId = item.props.info.bufferId
networkId = item.props.info.networkId
......@@ -396,7 +396,7 @@ class ArchiveListAdapter(
override fun bind(item: BufferListItem, messageSettings: MessageSettings) {
bufferId = item.props.info.bufferId
name.text = item.props.info.bufferName
name.text = item.props.name
description.text = item.props.description
name.setTextColor(
......@@ -487,7 +487,7 @@ class ArchiveListAdapter(
override fun bind(item: BufferListItem, messageSettings: MessageSettings) {
bufferId = item.props.info.bufferId
name.text = item.props.info.bufferName
name.text = item.props.name
description.text = item.props.description
name.setTextColor(
......@@ -573,7 +573,7 @@ class ArchiveListAdapter(
override fun bind(item: BufferListItem, messageSettings: MessageSettings) {
bufferId = item.props.info.bufferId
name.text = item.props.info.bufferName
name.text = item.props.name
description.text = item.props.description
name.setTextColor(
......
......@@ -218,7 +218,7 @@ class BufferListAdapter(
}
override fun bind(item: BufferListItem, messageSettings: MessageSettings) {
name.text = item.props.network.networkName
name.text = item.props.name
bufferId = item.props.info.bufferId
networkId = item.props.info.networkId
......@@ -317,7 +317,7 @@ class BufferListAdapter(
override fun bind(item: BufferListItem, messageSettings: MessageSettings) {
bufferId = item.props.info.bufferId
name.text = item.props.info.bufferName
name.text = item.props.name
description.text = item.props.description
name.setTextColor(
......@@ -408,7 +408,7 @@ class BufferListAdapter(
override fun bind(item: BufferListItem, messageSettings: MessageSettings) {
bufferId = item.props.info.bufferId
name.text = item.props.info.bufferName
name.text = item.props.name
description.text = item.props.description
name.setTextColor(
......
......@@ -19,10 +19,6 @@
package de.kuschku.quasseldroid.ui.chat.input
import android.graphics.Typeface
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.Observer
import de.kuschku.libquassel.protocol.BufferId
......@@ -45,6 +41,7 @@ import de.kuschku.quasseldroid.util.avatars.AvatarHelper
import de.kuschku.quasseldroid.util.emoji.EmojiData
import de.kuschku.quasseldroid.util.helper.styledAttributes
import de.kuschku.quasseldroid.util.helper.toLiveData
import de.kuschku.quasseldroid.util.irc.format.ContentFormatter
import de.kuschku.quasseldroid.util.irc.format.IrcFormatDeserializer
import de.kuschku.quasseldroid.viewmodel.data.AutoCompleteItem
import de.kuschku.quasseldroid.viewmodel.data.BufferStatus
......@@ -56,6 +53,7 @@ class AutoCompleteHelper(
private val autoCompleteSettings: AutoCompleteSettings,
private val messageSettings: MessageSettings,
private val ircFormatDeserializer: IrcFormatDeserializer,
private val contentFormatter: ContentFormatter,
private val helper: EditorViewModelHelper
) {
private var autocompleteListener: ((AutoCompletionState) -> Unit)? = null
......@@ -110,31 +108,13 @@ class AutoCompleteHelper(
?: nickName.firstOrNull()
val initial = rawInitial?.toUpperCase().toString()
val useSelfColor = when (messageSettings.colorizeNicknames) {
MessageSettings.ColorizeNicknamesMode.ALL -> false
MessageSettings.ColorizeNicknamesMode.ALL_BUT_MINE -> it.self
MessageSettings.ColorizeNicknamesMode.NONE -> true
MessageSettings.SenderColorMode.ALL -> false
MessageSettings.SenderColorMode.ALL_BUT_MINE -> it.self
MessageSettings.SenderColorMode.NONE -> true
}
val senderColor = if (useSelfColor) selfColor else senderColors[senderColorIndex]
fun formatNick(nick: CharSequence): CharSequence {
val spannableString = SpannableString(nick)
spannableString.setSpan(
ForegroundColorSpan(senderColor),
0,
nick.length,
SpannableString.SPAN_INCLUSIVE_EXCLUSIVE
)
spannableString.setSpan(
StyleSpan(Typeface.BOLD),
0,
nick.length,
SpannableString.SPAN_INCLUSIVE_EXCLUSIVE
)
return spannableString
}
it.copy(
displayNick = formatNick(it.nick),
displayNick = contentFormatter.formatNick(it.nick),
fallbackDrawable = colorContext.buildTextDrawable(initial, senderColor),
modes = when (messageSettings.showPrefix) {
MessageSettings.ShowPrefixMode.ALL ->
......
......@@ -41,6 +41,7 @@ import de.kuschku.quasseldroid.settings.AutoCompleteSettings
import de.kuschku.quasseldroid.settings.MessageSettings
import de.kuschku.quasseldroid.util.emoji.EmojiData
import de.kuschku.quasseldroid.util.helper.*
import de.kuschku.quasseldroid.util.irc.format.ContentFormatter
import de.kuschku.quasseldroid.util.irc.format.IrcFormatDeserializer
import de.kuschku.quasseldroid.util.irc.format.IrcFormatSerializer
import de.kuschku.quasseldroid.util.service.ServiceBoundFragment
......@@ -87,6 +88,9 @@ class ChatlineFragment : ServiceBoundFragment() {
@Inject
lateinit var ircFormatDeserializer: IrcFormatDeserializer
@Inject
lateinit var contentFormatter: ContentFormatter
@Inject
lateinit var ircFormatSerializer: IrcFormatSerializer
......@@ -120,6 +124,7 @@ class ChatlineFragment : ServiceBoundFragment() {
autoCompleteSettings,
messageSettings,
ircFormatDeserializer,
contentFormatter,
modelHelper
)
......
......@@ -266,10 +266,10 @@ class QuasselMessageRenderer @Inject constructor(
.firstOrNull() ?: nickName.firstOrNull()
val initial = rawInitial?.toUpperCase().toString()
val useSelfColor = when (messageSettings.colorizeNicknames) {
MessageSettings.ColorizeNicknamesMode.ALL -> false
MessageSettings.ColorizeNicknamesMode.ALL_BUT_MINE ->
MessageSettings.SenderColorMode.ALL -> false
MessageSettings.SenderColorMode.ALL_BUT_MINE ->
message.content.flag.hasFlag(Message_Flag.Self)
MessageSettings.ColorizeNicknamesMode.NONE -> true
MessageSettings.SenderColorMode.NONE -> true
}
val senderColor = if (useSelfColor) selfColor else senderColors[senderColorIndex]
......@@ -301,10 +301,10 @@ class QuasselMessageRenderer @Inject constructor(
.firstOrNull() ?: nickName.firstOrNull()
val initial = rawInitial?.toUpperCase().toString()
val useSelfColor = when (messageSettings.colorizeNicknames) {
MessageSettings.ColorizeNicknamesMode.ALL -> false
MessageSettings.ColorizeNicknamesMode.ALL_BUT_MINE ->
MessageSettings.SenderColorMode.ALL -> false
MessageSettings.SenderColorMode.ALL_BUT_MINE ->
message.content.flag.hasFlag(Message_Flag.Self)
MessageSettings.ColorizeNicknamesMode.NONE -> true
MessageSettings.SenderColorMode.NONE -> true
}
val senderColor = if (useSelfColor) selfColor else senderColors[senderColorIndex]
......
......@@ -19,11 +19,7 @@
package de.kuschku.quasseldroid.ui.chat.nicks
import android.graphics.Typeface
import android.os.Bundle
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
......@@ -53,6 +49,7 @@ import de.kuschku.quasseldroid.util.avatars.AvatarHelper
import de.kuschku.quasseldroid.util.helper.loadWithFallbacks
import de.kuschku.quasseldroid.util.helper.styledAttributes
import de.kuschku.quasseldroid.util.helper.toLiveData
import de.kuschku.quasseldroid.util.irc.format.ContentFormatter
import de.kuschku.quasseldroid.util.irc.format.IrcFormatDeserializer
import de.kuschku.quasseldroid.util.service.ServiceBoundFragment
import de.kuschku.quasseldroid.viewmodel.data.Avatar
......@@ -73,6 +70,9 @@ class NickListFragment : ServiceBoundFragment() {
@Inject
lateinit var ircFormatDeserializer: IrcFormatDeserializer
@Inject
lateinit var contentFormatter: ContentFormatter
@Inject
lateinit var modelHelper: ChatViewModelHelper
......@@ -115,30 +115,14 @@ class NickListFragment : ServiceBoundFragment() {
.firstOrNull() ?: nickName.firstOrNull()
val initial = rawInitial?.toUpperCase().toString()
val useSelfColor = when (messageSettings.colorizeNicknames) {
MessageSettings.ColorizeNicknamesMode.ALL -> false
MessageSettings.ColorizeNicknamesMode.ALL_BUT_MINE -> it.self
MessageSettings.ColorizeNicknamesMode.NONE -> true
MessageSettings.SenderColorMode.ALL -> false
MessageSettings.SenderColorMode.ALL_BUT_MINE -> it.self
MessageSettings.SenderColorMode.NONE -> true
}
val senderColor = if (useSelfColor) selfColor else senderColors[senderColorIndex]
fun formatNick(nick: CharSequence): CharSequence {
val spannableString = SpannableString(nick)
spannableString.setSpan(
ForegroundColorSpan(senderColor),
0,
nick.length,
SpannableString.SPAN_INCLUSIVE_EXCLUSIVE
)
spannableString.setSpan(
StyleSpan(Typeface.BOLD),
0,
nick.length,
SpannableString.SPAN_INCLUSIVE_EXCLUSIVE
)
return spannableString
}
it.copy(
displayNick = formatNick(it.nick),
displayNick = contentFormatter.formatNick(it.nick),
fallbackDrawable = colorContext.buildTextDrawable(initial, senderColor),
initial = initial,
modes = when (messageSettings.showPrefix) {
......
......@@ -38,6 +38,7 @@ import de.kuschku.quasseldroid.settings.AutoCompleteSettings
import de.kuschku.quasseldroid.settings.MessageSettings
import de.kuschku.quasseldroid.ui.chat.input.*
import de.kuschku.quasseldroid.util.helper.toLiveData
import de.kuschku.quasseldroid.util.irc.format.ContentFormatter
import de.kuschku.quasseldroid.util.irc.format.IrcFormatDeserializer
import de.kuschku.quasseldroid.util.irc.format.IrcFormatSerializer
import de.kuschku.quasseldroid.util.ui.settings.fragment.Savable
......@@ -67,6 +68,9 @@ class TopicFragment : ServiceBoundSettingsFragment(), Savable {
@Inject
lateinit var formatDeserializer: IrcFormatDeserializer
@Inject
lateinit var contentFormatter: ContentFormatter
@Inject
lateinit var formatSerializer: IrcFormatSerializer
......@@ -88,6 +92,7 @@ class TopicFragment : ServiceBoundSettingsFragment(), Savable {
autoCompleteSettings,
messageSettings,
formatDeserializer,
contentFormatter,
modelHelper
)
......
......@@ -38,6 +38,7 @@ import de.kuschku.quasseldroid.settings.AppearanceSettings
import de.kuschku.quasseldroid.settings.AutoCompleteSettings
import de.kuschku.quasseldroid.settings.MessageSettings
import de.kuschku.quasseldroid.ui.chat.input.*
import de.kuschku.quasseldroid.util.irc.format.ContentFormatter
import de.kuschku.quasseldroid.util.irc.format.IrcFormatDeserializer
import de.kuschku.quasseldroid.util.irc.format.IrcFormatSerializer
import de.kuschku.quasseldroid.util.ui.settings.fragment.Changeable
......@@ -71,6 +72,9 @@ class AliasItemFragment : ServiceBoundSettingsFragment(), Savable, Changeable {
@Inject
lateinit var formatDeserializer: IrcFormatDeserializer
@Inject
lateinit var contentFormatter: ContentFormatter
@Inject
lateinit var formatSerializer: IrcFormatSerializer
......@@ -99,6 +103,7 @@ class AliasItemFragment : ServiceBoundSettingsFragment(), Savable, Changeable {
autoCompleteSettings,
messageSettings,
formatDeserializer,
contentFormatter,
modelHelper
)
......
......@@ -61,6 +61,7 @@ import de.kuschku.quasseldroid.util.avatars.MatrixApi
import de.kuschku.quasseldroid.util.avatars.MatrixAvatarInfo
import de.kuschku.quasseldroid.util.helper.*
import de.kuschku.quasseldroid.util.irc.format.ContentFormatter
import de.kuschku.quasseldroid.util.irc.format.IrcFormatDeserializer
import de.kuschku.quasseldroid.util.irc.format.spans.IrcItalicSpan
import de.kuschku.quasseldroid.util.service.ServiceBoundFragment
import de.kuschku.quasseldroid.util.ui.BetterLinkMovementMethod
......@@ -133,6 +134,9 @@ class UserInfoFragment : ServiceBoundFragment() {
@Inject
lateinit var contentFormatter: ContentFormatter
@Inject
lateinit var ircFormatDeserializer: IrcFormatDeserializer
@Inject
lateinit var messageSettings: MessageSettings
......@@ -318,8 +322,7 @@ class UserInfoFragment : ServiceBoundFragment() {
}
}
}
nick.text = user.nick
nick.text = ircFormatDeserializer.formatString(user.nick, messageSettings.colorizeMirc)
val (content, _) = contentFormatter.formatContent(
user.realName ?: "",
networkId = user.networkId
......@@ -337,11 +340,19 @@ class UserInfoFragment : ServiceBoundFragment() {
account.text = user.account
accountContainer.visibleIf(!user.account.isNullOrBlank())
ident.text = user.user
identContainer.visibleIf(!user.user.isNullOrBlank())
val (userIdent, _) = contentFormatter.formatContent(
user.user ?: "",
networkId = user.networkId
)
ident.text = userIdent
identContainer.visibleIf(userIdent.isNotBlank())
host.text = user.host
hostContainer.visibleIf(!user.host.isNullOrBlank())
val (userHost, _) = contentFormatter.formatContent(
user.host ?: "",
networkId = user.networkId
)
host.text = userHost
hostContainer.visibleIf(userHost.isNotBlank())
server.text = user.server
serverContainer.visibleIf(!user.server.isNullOrBlank())
......
......@@ -183,11 +183,11 @@ class ContentFormatter @Inject constructor(
showHostmask: Boolean = false, senderColors: IntArray = this.senderColors,
@ColorInt selfColor: Int = this.selfColor) =
when (messageSettings.colorizeNicknames) {
MessageSettings.ColorizeNicknamesMode.ALL ->
MessageSettings.SenderColorMode.ALL ->
formatNickImpl(sender, false, !highlight, showHostmask, senderColors, selfColor)
MessageSettings.ColorizeNicknamesMode.ALL_BUT_MINE ->
MessageSettings.SenderColorMode.ALL_BUT_MINE ->
formatNickImpl(sender, self, !highlight, showHostmask, senderColors, selfColor)
MessageSettings.ColorizeNicknamesMode.NONE ->
MessageSettings.SenderColorMode.NONE ->
formatNickImpl(sender, false, false, showHostmask, senderColors, selfColor)
}
......
......@@ -25,6 +25,7 @@ import de.kuschku.quasseldroid.settings.AppearanceSettings
import de.kuschku.quasseldroid.settings.MessageSettings
import de.kuschku.quasseldroid.util.ColorContext
import de.kuschku.quasseldroid.util.avatars.AvatarHelper
import de.kuschku.quasseldroid.util.irc.format.ContentFormatter
import de.kuschku.quasseldroid.util.irc.format.IrcFormatDeserializer
import de.kuschku.quasseldroid.viewmodel.data.BufferListItem
import de.kuschku.quasseldroid.viewmodel.data.BufferProps
......@@ -35,10 +36,19 @@ class BufferPresenter @Inject constructor(
val appearanceSettings: AppearanceSettings,
val messageSettings: MessageSettings,
val ircFormatDeserializer: IrcFormatDeserializer,
val contentFormatter: ContentFormatter,
val colorContext: ColorContext
) {
fun render(props: BufferProps): BufferProps {
return props.copy(
name = when {
props.info.type.hasFlag(Buffer_Type.QueryBuffer) ->
ircFormatDeserializer.formatString(props.info.bufferName, messageSettings.colorizeMirc)
props.info.type.hasFlag(Buffer_Type.StatusBuffer) ->
props.network.networkName
else ->
props.info.bufferName ?: ""
},
description = ircFormatDeserializer.formatString(
props.description.toString(),
colorize = messageSettings.colorizeMirc
......@@ -47,10 +57,10 @@ class BufferPresenter @Inject constructor(
props.ircUser?.let {
val nickName = it.nick()
val useSelfColor = when (messageSettings.colorizeNicknames) {
MessageSettings.ColorizeNicknamesMode.ALL -> false
MessageSettings.ColorizeNicknamesMode.ALL_BUT_MINE ->
MessageSettings.SenderColorMode.ALL -> false
MessageSettings.SenderColorMode.ALL_BUT_MINE ->
props.ircUser?.network()?.isMyNick(nickName) == true
MessageSettings.ColorizeNicknamesMode.NONE -> true
MessageSettings.SenderColorMode.NONE -> true
}
colorContext.buildTextDrawable(it.nick(), useSelfColor)
......
......@@ -37,6 +37,7 @@ data class BufferProps(
val bufferActivity: Buffer_Activities = BufferInfo.Activity.of(
BufferInfo.Activity.NoActivity
),
val name: CharSequence = "",
val ircUser: IrcUser? = null,
val avatarUrls: List<Avatar> = emptyList(),
val fallbackDrawable: Drawable? = null,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment