From 1b09947fb24aa133440a8712447a38e79d7cca19 Mon Sep 17 00:00:00 2001 From: Janne Koschinski <janne@kuschku.de> Date: Fri, 30 Mar 2018 14:51:34 +0200 Subject: [PATCH] Fixed a serialization bug --- .../util/irc/format/IrcFormatSerializer.kt | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/de/kuschku/quasseldroid/util/irc/format/IrcFormatSerializer.kt b/app/src/main/java/de/kuschku/quasseldroid/util/irc/format/IrcFormatSerializer.kt index f554edfcb..1116e4925 100644 --- a/app/src/main/java/de/kuschku/quasseldroid/util/irc/format/IrcFormatSerializer.kt +++ b/app/src/main/java/de/kuschku/quasseldroid/util/irc/format/IrcFormatSerializer.kt @@ -181,16 +181,28 @@ class IrcFormatSerializer @Inject constructor(private val context: Context) { val afterForegroundCode = mircColorMap[afterForeground] val afterBackgroundCode = mircColorMap[afterBackground] - if (afterForegroundCode != null || afterBackgroundCode != null) { + val hasForegroundBefore = foreground != null + val hasBackgroundBefore = background != null + val foregroundBeforeCodeValid = foregroundCode != null + val backgroundBeforeCodeValid = backgroundCode != null + + val hasForegroundAfter = afterForeground != null + val hasBackgroundAfter = afterBackground != null + val foregroundAfterCodeValid = afterForegroundCode != null + val backgroundAfterCodeValid = afterBackgroundCode != null + + if ((!hasBackgroundAfter || backgroundAfterCodeValid) && + (!hasForegroundAfter || foregroundAfterCodeValid)) { if (afterForegroundCode == backgroundCode && afterBackgroundCode == foregroundCode) { writeSwap(afterForegroundCode, afterBackgroundCode) } else { writeColor(afterForegroundCode, afterBackgroundCode) } - } else if (afterForeground != null || afterBackground != null) { + } else if (hasForegroundAfter || hasBackgroundAfter) { writeHexColor(afterForeground, afterBackground) } else { - if (foregroundCode != null || backgroundCode != null) { + if ((!hasBackgroundBefore || backgroundBeforeCodeValid) && + (!hasForegroundBefore || foregroundBeforeCodeValid)) { writeColor(afterForeground, afterBackground) } else { writeHexColor(afterForeground, afterBackground) -- GitLab