Skip to content

Commit ed3092a

Browse files
committed
Fix MessageList colors for better contrast
1 parent 63d165c commit ed3092a

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

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

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,23 @@ class MessageListAdapter internal constructor(
5757
private val answeredIcon: Drawable = ResourcesCompat.getDrawable(res, Icons.Outlined.Reply, theme)!!
5858
private val forwardedAnsweredIcon: Drawable =
5959
ResourcesCompat.getDrawable(res, Icons.Outlined.CompareArrows, theme)!!
60-
private val activeItemBackgroundColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorPrimary)
61-
private val selectedItemBackgroundColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorPrimary)
6260

61+
private val activeItemBackgroundColor: Int =
62+
theme.resolveColorAttribute(MaterialR.attr.colorSecondaryContainer)
63+
private val selectedItemBackgroundColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorSurfaceVariant)
6364
private val regularItemBackgroundColor: Int =
6465
theme.resolveColorAttribute(MaterialR.attr.colorSurface)
6566
private val readItemBackgroundColor: Int =
6667
theme.resolveColorAttribute(MaterialR.attr.colorSurfaceContainerHigh)
6768
private val unreadItemBackgroundColor: Int =
6869
theme.resolveColorAttribute(MaterialR.attr.colorSurface)
6970

70-
private val unreadTextColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorOnSurface)
71-
private val readTextColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorOnSurfaceVariant)
71+
private val activeItemColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorOnSecondaryContainer)
72+
private val selectedItemColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorOnSurfaceVariant)
73+
private val regularItemColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorOnSurface)
74+
private val readItemColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorOnSurface)
75+
private val unreadItemColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorOnSurface)
76+
7277
private val previewTextColor: Int = theme.resolveColorAttribute(MaterialR.attr.colorOnSurfaceVariant)
7378

7479
private val compactVerticalPadding = res.getDimensionPixelSize(R.dimen.messageListCompactVerticalPadding)
@@ -375,7 +380,7 @@ class MessageListAdapter internal constructor(
375380
}
376381

377382
with(messageListItem) {
378-
val textColor = if (isRead) readTextColor else unreadTextColor
383+
val foregroundColor = selectForegroundColor(isSelected, isRead, isActive)
379384
val maybeBoldTypeface = if (isRead) Typeface.NORMAL else Typeface.BOLD
380385
val displayDate = relativeDateTimeFormatter.formatDate(messageDate)
381386
val displayThreadCount = if (appearance.showingThreadedList) threadCount else 0
@@ -399,7 +404,7 @@ class MessageListAdapter internal constructor(
399404
if (appearance.showContactPicture && holder.contactPicture.isVisible) {
400405
setContactPicture(holder.contactPicture, displayAddress)
401406
}
402-
setBackgroundColor(holder.itemView, isSelected, isRead, isActive)
407+
holder.itemView.setBackgroundColor(selectBackgroundColor(isSelected, isRead, isActive))
403408
updateWithThreadCount(holder, displayThreadCount)
404409
val beforePreviewText = if (appearance.senderAboveSubject) subject else displayName
405410
val messageStringBuilder = SpannableStringBuilder(beforePreviewText)
@@ -409,13 +414,13 @@ class MessageListAdapter internal constructor(
409414
messageStringBuilder.append("").append(preview)
410415
}
411416
}
412-
holder.preview.setTextColor(textColor)
417+
holder.preview.setTextColor(foregroundColor)
413418
holder.preview.setText(messageStringBuilder, TextView.BufferType.SPANNABLE)
414419

415420
formatPreviewText(holder.preview, beforePreviewText, isRead)
416421

417422
holder.subject.typeface = Typeface.create(holder.subject.typeface, maybeBoldTypeface)
418-
holder.subject.setTextColor(textColor)
423+
holder.subject.setTextColor(foregroundColor)
419424

420425
val firstLineText = if (appearance.senderAboveSubject) displayName else subject
421426
holder.subject.text = firstLineText
@@ -427,7 +432,7 @@ class MessageListAdapter internal constructor(
427432
}
428433

429434
holder.date.typeface = Typeface.create(holder.date.typeface, maybeBoldTypeface)
430-
holder.date.setTextColor(textColor)
435+
holder.date.setTextColor(foregroundColor)
431436
holder.date.text = displayDate
432437
holder.attachment.isVisible = hasAttachments
433438

@@ -496,17 +501,26 @@ class MessageListAdapter internal constructor(
496501
return null
497502
}
498503

499-
private fun setBackgroundColor(view: View, selected: Boolean, read: Boolean, active: Boolean) {
504+
private fun selectBackgroundColor(selected: Boolean, read: Boolean, active: Boolean): Int {
500505
val backGroundAsReadIndicator = appearance.backGroundAsReadIndicator
501-
val backgroundColor = when {
506+
return when {
502507
active -> activeItemBackgroundColor
503508
selected -> selectedItemBackgroundColor
504509
backGroundAsReadIndicator && read -> readItemBackgroundColor
505510
backGroundAsReadIndicator && !read -> unreadItemBackgroundColor
506511
else -> regularItemBackgroundColor
507512
}
513+
}
508514

509-
view.setBackgroundColor(backgroundColor)
515+
private fun selectForegroundColor(selected: Boolean, read: Boolean, active: Boolean): Int {
516+
val backGroundAsReadIndicator = appearance.backGroundAsReadIndicator
517+
return when {
518+
active -> activeItemColor
519+
selected -> selectedItemColor
520+
backGroundAsReadIndicator && read -> readItemColor
521+
backGroundAsReadIndicator && !read -> unreadItemColor
522+
else -> regularItemColor
523+
}
510524
}
511525

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

legacy/ui/legacy/src/main/res/drawable/message_list_item_selection_background.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
android:shape="oval"
55
>
66

7-
<solid android:color="?attr/colorPrimary" />
7+
<solid android:color="?attr/colorSecondary" />
88
</shape>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
android:background="@drawable/message_list_item_selection_background"
2626
android:padding="4dp"
2727
android:visibility="gone"
28-
app:tint="?attr/colorOnPrimary"
28+
app:tint="?attr/colorOnSecondary"
2929
app:layout_constraintBottom_toTopOf="@+id/bottom_guideline"
3030
app:layout_constraintStart_toStartOf="parent"
3131
app:layout_constraintTop_toTopOf="@+id/top_guideline"

0 commit comments

Comments
 (0)