Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 759e5220 authored by Wolf-Martell Montwé's avatar Wolf-Martell Montwé Committed by GitHub
Browse files

Merge pull request #8596 from wmontwe/fix-message-list-colors

Fix MessageList colors for better contrast
parents 8d1f53d2 2bf3006d
Loading
Loading
Loading
Loading
+0 −14
Original line number Diff line number Diff line
@@ -15,13 +15,6 @@
        <item name="textColorPrimaryRecipientDropdown">@android:color/primary_text_light</item>
        <item name="textColorSecondaryRecipientDropdown">@android:color/secondary_text_light</item>

        <item name="messageListRegularItemBackgroundColor">?android:attr/windowBackground</item>
        <item name="messageListReadItemBackgroundColor">#ffd8d8d8</item>
        <item name="messageListUnreadItemBackgroundColor">?attr/messageListRegularItemBackgroundColor</item>
        <item name="messageListActiveItemBackgroundColor">?attr/colorSecondaryVariant</item>
        <item name="messageListActiveItemBackgroundAlphaFraction">60%</item>
        <item name="messageListActiveItemBackgroundAlphaBackground">?attr/colorSurface</item>

        <item name="messageListSwipeSelectColor">@color/material_blue_600</item>
        <item name="messageListSwipeToggleReadColor">@color/material_blue_600</item>
        <item name="messageListSwipeToggleStarColor">@color/material_orange_600</item>
@@ -59,13 +52,6 @@
        <item name="textColorPrimaryRecipientDropdown">@android:color/primary_text_dark</item>
        <item name="textColorSecondaryRecipientDropdown">@android:color/secondary_text_dark</item>

        <item name="messageListRegularItemBackgroundColor">?android:attr/windowBackground</item>
        <item name="messageListReadItemBackgroundColor">?attr/messageListRegularItemBackgroundColor</item>
        <item name="messageListUnreadItemBackgroundColor">#ff505050</item>
        <item name="messageListActiveItemBackgroundColor">?attr/colorSecondaryVariant</item>
        <item name="messageListActiveItemBackgroundAlphaFraction">50%</item>
        <item name="messageListActiveItemBackgroundAlphaBackground">?attr/colorSurface</item>

        <item name="messageListSwipeSelectColor">@color/material_blue_700</item>
        <item name="messageListSwipeToggleReadColor">@color/material_blue_700</item>
        <item name="messageListSwipeToggleStarColor">@color/material_orange_700</item>
+0 −14
Original line number Diff line number Diff line
@@ -15,13 +15,6 @@
        <item name="textColorPrimaryRecipientDropdown">@android:color/primary_text_light</item>
        <item name="textColorSecondaryRecipientDropdown">@android:color/secondary_text_light</item>

        <item name="messageListRegularItemBackgroundColor">?android:attr/windowBackground</item>
        <item name="messageListReadItemBackgroundColor">#ffd8d8d8</item>
        <item name="messageListUnreadItemBackgroundColor">?attr/messageListRegularItemBackgroundColor</item>
        <item name="messageListActiveItemBackgroundColor">?attr/colorSecondaryVariant</item>
        <item name="messageListActiveItemBackgroundAlphaFraction">60%</item>
        <item name="messageListActiveItemBackgroundAlphaBackground">?attr/colorSurface</item>

        <item name="messageListSwipeSelectColor">@color/material_blue_600</item>
        <item name="messageListSwipeToggleReadColor">@color/material_blue_600</item>
        <item name="messageListSwipeToggleStarColor">@color/material_orange_600</item>
@@ -59,13 +52,6 @@
        <item name="textColorPrimaryRecipientDropdown">@android:color/primary_text_dark</item>
        <item name="textColorSecondaryRecipientDropdown">@android:color/secondary_text_dark</item>

        <item name="messageListRegularItemBackgroundColor">?android:attr/windowBackground</item>
        <item name="messageListReadItemBackgroundColor">?attr/messageListRegularItemBackgroundColor</item>
        <item name="messageListUnreadItemBackgroundColor">#ff505050</item>
        <item name="messageListActiveItemBackgroundColor">?attr/colorSecondaryVariant</item>
        <item name="messageListActiveItemBackgroundAlphaFraction">50%</item>
        <item name="messageListActiveItemBackgroundAlphaBackground">?attr/colorSurface</item>

        <item name="messageListSwipeSelectColor">@color/material_blue_700</item>
        <item name="messageListSwipeToggleReadColor">@color/material_blue_700</item>
        <item name="messageListSwipeToggleStarColor">@color/material_orange_700</item>
+1 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ dependencies {
    implementation(projects.uiUtils.toolbarBottomSheet)

    implementation(projects.core.featureflags)
    implementation(projects.core.ui.theme.api)
    implementation(projects.feature.launcher)
    implementation(projects.feature.navigation.drawer)
    // TODO: Remove AccountOauth dependency
+0 −27
Original line number Diff line number Diff line
package com.fsck.k9.ui

import android.content.res.Resources.Theme
import android.graphics.Color
import android.util.TypedValue

fun Theme.resolveColorAttribute(attrId: Int): Int {
@@ -15,32 +14,6 @@ fun Theme.resolveColorAttribute(attrId: Int): Int {
    return typedValue.data
}

fun Theme.resolveColorAttribute(colorAttrId: Int, alphaFractionAttrId: Int, backgroundColorAttrId: Int): Int {
    val typedValue = TypedValue()

    if (!resolveAttribute(colorAttrId, typedValue, true)) {
        error("Couldn't resolve attribute ($colorAttrId)")
    }
    val color = typedValue.data

    if (!resolveAttribute(alphaFractionAttrId, typedValue, true)) {
        error("Couldn't resolve attribute ($alphaFractionAttrId)")
    }
    val colorPercentage = TypedValue.complexToFloat(typedValue.data)
    val backgroundPercentage = 1 - colorPercentage

    if (!resolveAttribute(backgroundColorAttrId, typedValue, true)) {
        error("Couldn't resolve attribute ($colorAttrId)")
    }
    val backgroundColor = typedValue.data

    val red = colorPercentage * Color.red(color) + backgroundPercentage * Color.red(backgroundColor)
    val green = colorPercentage * Color.green(color) + backgroundPercentage * Color.green(backgroundColor)
    val blue = colorPercentage * Color.blue(color) + backgroundPercentage * Color.blue(backgroundColor)

    return Color.rgb(red.toInt(), green.toInt(), blue.toInt())
}

fun Theme.getIntArray(attrId: Int): IntArray {
    val typedValue = TypedValue()

+57 −24
Original line number Diff line number Diff line
@@ -57,22 +57,25 @@ class MessageListAdapter internal constructor(
    private val answeredIcon: Drawable = ResourcesCompat.getDrawable(res, Icons.Outlined.Reply, theme)!!
    private val forwardedAnsweredIcon: Drawable =
        ResourcesCompat.getDrawable(res, Icons.Outlined.CompareArrows, theme)!!
    private val activeItemBackgroundColor: Int = theme.resolveColorAttribute(
        colorAttrId = R.attr.messageListActiveItemBackgroundColor,
        alphaFractionAttrId = R.attr.messageListActiveItemBackgroundAlphaFraction,
        backgroundColorAttrId = R.attr.messageListActiveItemBackgroundAlphaBackground,
    )
    private val selectedItemBackgroundColor: Int =
        theme.resolveColorAttribute(com.google.android.material.R.attr.colorSurfaceContainerHigh)

    private val activeItemBackgroundColor: Int =
        theme.resolveColorAttribute(MaterialR.attr.colorSecondaryContainer)
    private val selectedItemBackgroundColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorSurfaceVariant)
    private val regularItemBackgroundColor: Int =
        theme.resolveColorAttribute(R.attr.messageListRegularItemBackgroundColor)
    private val readItemBackgroundColor: Int = theme.resolveColorAttribute(R.attr.messageListReadItemBackgroundColor)
        theme.resolveColorAttribute(MaterialR.attr.colorSurface)
    private val readItemBackgroundColor: Int =
        theme.resolveColorAttribute(MaterialR.attr.colorSurfaceContainer)
    private val unreadItemBackgroundColor: Int =
        theme.resolveColorAttribute(R.attr.messageListUnreadItemBackgroundColor)
        theme.resolveColorAttribute(MaterialR.attr.colorSurface)

    private val activeItemColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorOnSecondaryContainer)
    private val selectedItemColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorOnSurfaceVariant)
    private val regularItemColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorOnSurface)
    private val readItemColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorOnSurface)
    private val unreadItemColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorOnSurface)

    private val unreadTextColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorOnSurface)
    private val readTextColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorOnSurfaceVariant)
    private val previewTextColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorOnSurfaceVariant)
    private val previewActiveTextColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorOnSecondary)

    private val compactVerticalPadding = res.getDimensionPixelSize(R.dimen.messageListCompactVerticalPadding)
    private val compactTextViewMarginTop = res.getDimensionPixelSize(R.dimen.messageListCompactTextViewMargin)
@@ -378,7 +381,7 @@ class MessageListAdapter internal constructor(
        }

        with(messageListItem) {
            val textColor = if (isRead) readTextColor else unreadTextColor
            val foregroundColor = selectForegroundColor(isSelected, isRead, isActive)
            val maybeBoldTypeface = if (isRead) Typeface.NORMAL else Typeface.BOLD
            val displayDate = relativeDateTimeFormatter.formatDate(messageDate)
            val displayThreadCount = if (appearance.showingThreadedList) threadCount else 0
@@ -392,6 +395,11 @@ class MessageListAdapter internal constructor(

            if (appearance.stars) {
                holder.star.isSelected = isStarred
                if (isStarred) {
                    holder.star.clearColorFilter()
                } else {
                    holder.star.setColorFilter(foregroundColor)
                }
                holder.starClickArea.contentDescription = if (isStarred) {
                    res.getString(R.string.unflag_action)
                } else {
@@ -402,7 +410,7 @@ class MessageListAdapter internal constructor(
            if (appearance.showContactPicture && holder.contactPicture.isVisible) {
                setContactPicture(holder.contactPicture, displayAddress)
            }
            setBackgroundColor(holder.itemView, isSelected, isRead, isActive)
            holder.itemView.setBackgroundColor(selectBackgroundColor(isSelected, isRead, isActive))
            updateWithThreadCount(holder, displayThreadCount)
            val beforePreviewText = if (appearance.senderAboveSubject) subject else displayName
            val messageStringBuilder = SpannableStringBuilder(beforePreviewText)
@@ -412,13 +420,13 @@ class MessageListAdapter internal constructor(
                    messageStringBuilder.append(" – ").append(preview)
                }
            }
            holder.preview.setTextColor(textColor)
            holder.preview.setTextColor(foregroundColor)
            holder.preview.setText(messageStringBuilder, TextView.BufferType.SPANNABLE)

            formatPreviewText(holder.preview, beforePreviewText, isRead)
            formatPreviewText(holder.preview, beforePreviewText, isRead, isActive, isSelected)

            holder.subject.typeface = Typeface.create(holder.subject.typeface, maybeBoldTypeface)
            holder.subject.setTextColor(textColor)
            holder.subject.setTextColor(foregroundColor)

            val firstLineText = if (appearance.senderAboveSubject) displayName else subject
            holder.subject.text = firstLineText
@@ -430,9 +438,10 @@ class MessageListAdapter internal constructor(
            }

            holder.date.typeface = Typeface.create(holder.date.typeface, maybeBoldTypeface)
            holder.date.setTextColor(textColor)
            holder.date.setTextColor(foregroundColor)
            holder.date.text = displayDate
            holder.attachment.isVisible = hasAttachments
            holder.attachment.setColorFilter(foregroundColor)

            val statusHolder = buildStatusHolder(isForwarded, isAnswered)
            if (statusHolder != null) {
@@ -448,14 +457,21 @@ class MessageListAdapter internal constructor(
        holder.text.text = footerText
    }

    private fun formatPreviewText(preview: MaterialTextView, beforePreviewText: CharSequence, messageRead: Boolean) {
    private fun formatPreviewText(
        preview: MaterialTextView,
        beforePreviewText: CharSequence,
        messageRead: Boolean,
        active: Boolean,
        selected: Boolean,
    ) {
        val previewText = preview.text as Spannable
        val textColor = selectPreviewTextColor(active, selected)

        val beforePreviewLength = beforePreviewText.length
        addBeforePreviewSpan(previewText, beforePreviewLength, messageRead)

        previewText.setSpan(
            ForegroundColorSpan(previewTextColor),
            ForegroundColorSpan(textColor),
            beforePreviewLength,
            previewText.length,
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
@@ -499,17 +515,34 @@ class MessageListAdapter internal constructor(
        return null
    }

    private fun setBackgroundColor(view: View, selected: Boolean, read: Boolean, active: Boolean) {
    private fun selectBackgroundColor(selected: Boolean, read: Boolean, active: Boolean): Int {
        val backGroundAsReadIndicator = appearance.backGroundAsReadIndicator
        val backgroundColor = when {
            active -> activeItemBackgroundColor
        return when {
            selected -> selectedItemBackgroundColor
            active -> activeItemBackgroundColor
            backGroundAsReadIndicator && read -> readItemBackgroundColor
            backGroundAsReadIndicator && !read -> unreadItemBackgroundColor
            else -> regularItemBackgroundColor
        }
    }

    private fun selectForegroundColor(selected: Boolean, read: Boolean, active: Boolean): Int {
        val backGroundAsReadIndicator = appearance.backGroundAsReadIndicator
        return when {
            selected -> selectedItemColor
            active -> activeItemColor
            backGroundAsReadIndicator && read -> readItemColor
            backGroundAsReadIndicator && !read -> unreadItemColor
            else -> regularItemColor
        }
    }

        view.setBackgroundColor(backgroundColor)
    private fun selectPreviewTextColor(active: Boolean, selected: Boolean): Int {
        return when {
            selected -> previewTextColor
            active -> previewActiveTextColor
            else -> previewTextColor
        }
    }

    private fun updateWithThreadCount(holder: MessageViewHolder, threadCount: Int) {
Loading