Skip to content

Commit 620e48a

Browse files
wmontweWolf Montwe
authored andcommitted
Fix MessageList colors for better contrast
This removes the custom color attributes and replaces them by Material 3 colors.
1 parent 827c224 commit 620e48a

File tree

10 files changed

+33
-81
lines changed

10 files changed

+33
-81
lines changed

app-k9mail/src/main/res/values/themes.xml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@
1515
<item name="textColorPrimaryRecipientDropdown">@android:color/primary_text_light</item>
1616
<item name="textColorSecondaryRecipientDropdown">@android:color/secondary_text_light</item>
1717

18-
<item name="messageListRegularItemBackgroundColor">?android:attr/windowBackground</item>
19-
<item name="messageListReadItemBackgroundColor">#ffd8d8d8</item>
20-
<item name="messageListUnreadItemBackgroundColor">?attr/messageListRegularItemBackgroundColor</item>
21-
<item name="messageListActiveItemBackgroundColor">?attr/colorSecondaryVariant</item>
22-
<item name="messageListActiveItemBackgroundAlphaFraction">60%</item>
23-
<item name="messageListActiveItemBackgroundAlphaBackground">?attr/colorSurface</item>
24-
2518
<item name="messageListSwipeSelectColor">@color/material_blue_600</item>
2619
<item name="messageListSwipeToggleReadColor">@color/material_blue_600</item>
2720
<item name="messageListSwipeToggleStarColor">@color/material_orange_600</item>
@@ -59,13 +52,6 @@
5952
<item name="textColorPrimaryRecipientDropdown">@android:color/primary_text_dark</item>
6053
<item name="textColorSecondaryRecipientDropdown">@android:color/secondary_text_dark</item>
6154

62-
<item name="messageListRegularItemBackgroundColor">?android:attr/windowBackground</item>
63-
<item name="messageListReadItemBackgroundColor">?attr/messageListRegularItemBackgroundColor</item>
64-
<item name="messageListUnreadItemBackgroundColor">#ff505050</item>
65-
<item name="messageListActiveItemBackgroundColor">?attr/colorSecondaryVariant</item>
66-
<item name="messageListActiveItemBackgroundAlphaFraction">50%</item>
67-
<item name="messageListActiveItemBackgroundAlphaBackground">?attr/colorSurface</item>
68-
6955
<item name="messageListSwipeSelectColor">@color/material_blue_700</item>
7056
<item name="messageListSwipeToggleReadColor">@color/material_blue_700</item>
7157
<item name="messageListSwipeToggleStarColor">@color/material_orange_700</item>

app-thunderbird/src/main/res/values/themes.xml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@
1515
<item name="textColorPrimaryRecipientDropdown">@android:color/primary_text_light</item>
1616
<item name="textColorSecondaryRecipientDropdown">@android:color/secondary_text_light</item>
1717

18-
<item name="messageListRegularItemBackgroundColor">?android:attr/windowBackground</item>
19-
<item name="messageListReadItemBackgroundColor">#ffd8d8d8</item>
20-
<item name="messageListUnreadItemBackgroundColor">?attr/messageListRegularItemBackgroundColor</item>
21-
<item name="messageListActiveItemBackgroundColor">?attr/colorSecondaryVariant</item>
22-
<item name="messageListActiveItemBackgroundAlphaFraction">60%</item>
23-
<item name="messageListActiveItemBackgroundAlphaBackground">?attr/colorSurface</item>
24-
2518
<item name="messageListSwipeSelectColor">@color/material_blue_600</item>
2619
<item name="messageListSwipeToggleReadColor">@color/material_blue_600</item>
2720
<item name="messageListSwipeToggleStarColor">@color/material_orange_600</item>
@@ -59,13 +52,6 @@
5952
<item name="textColorPrimaryRecipientDropdown">@android:color/primary_text_dark</item>
6053
<item name="textColorSecondaryRecipientDropdown">@android:color/secondary_text_dark</item>
6154

62-
<item name="messageListRegularItemBackgroundColor">?android:attr/windowBackground</item>
63-
<item name="messageListReadItemBackgroundColor">?attr/messageListRegularItemBackgroundColor</item>
64-
<item name="messageListUnreadItemBackgroundColor">#ff505050</item>
65-
<item name="messageListActiveItemBackgroundColor">?attr/colorSecondaryVariant</item>
66-
<item name="messageListActiveItemBackgroundAlphaFraction">50%</item>
67-
<item name="messageListActiveItemBackgroundAlphaBackground">?attr/colorSurface</item>
68-
6955
<item name="messageListSwipeSelectColor">@color/material_blue_700</item>
7056
<item name="messageListSwipeToggleReadColor">@color/material_blue_700</item>
7157
<item name="messageListSwipeToggleStarColor">@color/material_orange_700</item>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package app.k9mail.core.ui.theme.api
2+
3+
import androidx.annotation.ColorInt
4+
import androidx.core.graphics.ColorUtils
5+
6+
const val SELECTED_COLOR_ALPHA = 0.1f
7+
const val ACTIVE_COLOR_ALPHA = 0.15f
8+
9+
const val MAX_ALPHA = 255
10+
11+
object ThemeColorHelper {
12+
13+
fun getSelectedColor(@ColorInt color: Int): Int {
14+
return ColorUtils.setAlphaComponent(color, (SELECTED_COLOR_ALPHA * MAX_ALPHA).toInt())
15+
}
16+
17+
fun getActiveColor(@ColorInt color: Int): Int {
18+
return ColorUtils.setAlphaComponent(color, (ACTIVE_COLOR_ALPHA * MAX_ALPHA).toInt())
19+
}
20+
}

legacy/ui/legacy/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies {
1414
implementation(projects.uiUtils.toolbarBottomSheet)
1515

1616
implementation(projects.core.featureflags)
17+
implementation(projects.core.ui.theme.api)
1718
implementation(projects.feature.launcher)
1819
implementation(projects.feature.navigation.drawer)
1920
// TODO: Remove AccountOauth dependency

legacy/ui/legacy/src/main/java/com/fsck/k9/ui/ThemeExtensions.kt

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.fsck.k9.ui
22

33
import android.content.res.Resources.Theme
4-
import android.graphics.Color
54
import android.util.TypedValue
65

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

18-
fun Theme.resolveColorAttribute(colorAttrId: Int, alphaFractionAttrId: Int, backgroundColorAttrId: Int): Int {
19-
val typedValue = TypedValue()
20-
21-
if (!resolveAttribute(colorAttrId, typedValue, true)) {
22-
error("Couldn't resolve attribute ($colorAttrId)")
23-
}
24-
val color = typedValue.data
25-
26-
if (!resolveAttribute(alphaFractionAttrId, typedValue, true)) {
27-
error("Couldn't resolve attribute ($alphaFractionAttrId)")
28-
}
29-
val colorPercentage = TypedValue.complexToFloat(typedValue.data)
30-
val backgroundPercentage = 1 - colorPercentage
31-
32-
if (!resolveAttribute(backgroundColorAttrId, typedValue, true)) {
33-
error("Couldn't resolve attribute ($colorAttrId)")
34-
}
35-
val backgroundColor = typedValue.data
36-
37-
val red = colorPercentage * Color.red(color) + backgroundPercentage * Color.red(backgroundColor)
38-
val green = colorPercentage * Color.green(color) + backgroundPercentage * Color.green(backgroundColor)
39-
val blue = colorPercentage * Color.blue(color) + backgroundPercentage * Color.blue(backgroundColor)
40-
41-
return Color.rgb(red.toInt(), green.toInt(), blue.toInt())
42-
}
43-
4417
fun Theme.getIntArray(attrId: Int): IntArray {
4518
val typedValue = TypedValue()
4619

legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListAdapter.kt

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import androidx.recyclerview.widget.DiffUtil
2626
import androidx.recyclerview.widget.RecyclerView
2727
import androidx.recyclerview.widget.RecyclerView.NO_POSITION
2828
import app.k9mail.core.ui.legacy.designsystem.atom.icon.Icons
29+
import app.k9mail.core.ui.theme.api.ThemeColorHelper
2930
import app.k9mail.legacy.message.controller.MessageReference
3031
import com.fsck.k9.FontSizes
3132
import com.fsck.k9.UiDensity
@@ -57,21 +58,18 @@ class MessageListAdapter internal constructor(
5758
private val answeredIcon: Drawable = ResourcesCompat.getDrawable(res, Icons.Outlined.Reply, theme)!!
5859
private val forwardedAnsweredIcon: Drawable =
5960
ResourcesCompat.getDrawable(res, Icons.Outlined.CompareArrows, theme)!!
60-
private val activeItemBackgroundColor: Int = theme.resolveColorAttribute(
61-
colorAttrId = R.attr.messageListActiveItemBackgroundColor,
62-
alphaFractionAttrId = R.attr.messageListActiveItemBackgroundAlphaFraction,
63-
backgroundColorAttrId = R.attr.messageListActiveItemBackgroundAlphaBackground,
64-
)
65-
private val selectedItemBackgroundColor: Int =
66-
theme.resolveColorAttribute(com.google.android.material.R.attr.colorSurfaceContainerHigh)
61+
private val activeItemBackgroundColor: Int = ThemeColorHelper.getActiveColor(MaterialR.attr.colorPrimary)
62+
private val selectedItemBackgroundColor: Int = ThemeColorHelper.getSelectedColor(MaterialR.attr.colorPrimary)
63+
6764
private val regularItemBackgroundColor: Int =
68-
theme.resolveColorAttribute(R.attr.messageListRegularItemBackgroundColor)
69-
private val readItemBackgroundColor: Int = theme.resolveColorAttribute(R.attr.messageListReadItemBackgroundColor)
65+
theme.resolveColorAttribute(MaterialR.attr.colorSurface)
66+
private val readItemBackgroundColor: Int =
67+
theme.resolveColorAttribute(MaterialR.attr.colorSurfaceContainerHigh)
7068
private val unreadItemBackgroundColor: Int =
71-
theme.resolveColorAttribute(R.attr.messageListUnreadItemBackgroundColor)
69+
theme.resolveColorAttribute(MaterialR.attr.colorSurface)
7270

7371
private val unreadTextColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorOnSurface)
74-
private val readTextColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorOnSurfaceVariant)
72+
private val readTextColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorOnSurface)
7573
private val previewTextColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorOnSurfaceVariant)
7674

7775
private val compactVerticalPadding = res.getDimensionPixelSize(R.dimen.messageListCompactVerticalPadding)
@@ -502,8 +500,8 @@ class MessageListAdapter internal constructor(
502500
private fun setBackgroundColor(view: View, selected: Boolean, read: Boolean, active: Boolean) {
503501
val backGroundAsReadIndicator = appearance.backGroundAsReadIndicator
504502
val backgroundColor = when {
505-
active -> activeItemBackgroundColor
506503
selected -> selectedItemBackgroundColor
504+
active -> activeItemBackgroundColor
507505
backGroundAsReadIndicator && read -> readItemBackgroundColor
508506
backGroundAsReadIndicator && !read -> unreadItemBackgroundColor
509507
else -> regularItemBackgroundColor

legacy/ui/legacy/src/main/res/layout/message_list_item_footer.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="fill_parent"
66
android:layout_height="?android:attr/listPreferredItemHeight"
7-
android:background="?attr/messageListRegularItemBackgroundColor"
7+
android:background="?attr/colorSurface"
88
android:foreground="?attr/selectableItemBackground"
99
android:gravity="center"
1010
android:orientation="horizontal"

legacy/ui/legacy/src/main/res/values/attrs.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
<declare-styleable name="K9Styles">
55
<attr name="textColorPrimaryRecipientDropdown" format="reference" />
66
<attr name="textColorSecondaryRecipientDropdown" format="reference" />
7-
<attr name="messageListRegularItemBackgroundColor" format="reference|color" />
8-
<attr name="messageListReadItemBackgroundColor" format="reference|color" />
9-
<attr name="messageListUnreadItemBackgroundColor" format="reference|color" />
10-
<attr name="messageListActiveItemBackgroundColor" format="reference|color" />
11-
<attr name="messageListActiveItemBackgroundAlphaFraction" format="fraction" />
12-
<attr name="messageListActiveItemBackgroundAlphaBackground" format="reference|color" />
137
<attr name="messageListSwipeSelectColor" format="reference|color" />
148
<attr name="messageListSwipeToggleReadColor" format="reference|color" />
159
<attr name="messageListSwipeToggleStarColor" format="reference|color" />

legacy/ui/legacy/src/main/res/values/themes.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33

44
<!-- TODO remove when properties have been replaced -->
55
<style name="Theme.Legacy.Test" parent="Theme.Material3.Light">
6-
<item name="messageListActiveItemBackgroundColor">?attr/colorSecondaryVariant</item>
7-
<item name="messageListActiveItemBackgroundAlphaFraction">50%</item>
8-
<item name="messageListActiveItemBackgroundAlphaBackground">?attr/colorSurface</item>
9-
<item name="messageListRegularItemBackgroundColor">?android:attr/windowBackground</item>
10-
<item name="messageListReadItemBackgroundColor">?attr/messageListRegularItemBackgroundColor</item>
11-
<item name="messageListUnreadItemBackgroundColor">?attr/messageListRegularItemBackgroundColor</item>
126
<item name="contactTokenBackgroundColor">#ccc</item>
137
<item name="openpgp_black">#000</item>
148
<item name="openpgp_orange">#FF8800</item>

legacy/ui/legacy/src/test/java/com/fsck/k9/ui/messagelist/MessageListAdapterTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private const val DATE_DEFAULT_FONT_SIZE = 14f
3838

3939
class MessageListAdapterTest : RobolectricTest() {
4040
val activity = Robolectric.buildActivity(AppCompatActivity::class.java).create().get()
41-
val context: Context = ContextThemeWrapper(activity, R.style.Theme_Legacy_Test)
41+
val context: Context = ContextThemeWrapper(activity, com.google.android.material.R.style.Theme_Material3_Light)
4242

4343
val contactsPictureLoader: ContactPictureLoader = mock()
4444
val listItemListener: MessageListItemActionListener = mock()

0 commit comments

Comments
 (0)