Skip to content

Commit

Permalink
Merge pull request #8387 from cketti/message-list-ui-tweaks
Browse files Browse the repository at this point in the history
Message list text color tweaks
  • Loading branch information
cketti authored Oct 23, 2024
2 parents 6d19a99 + 8f806ca commit fda4070
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.graphics.drawable.Drawable
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.AbsoluteSizeSpan
import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan
import android.view.LayoutInflater
import android.view.View
Expand Down Expand Up @@ -35,6 +36,7 @@ import com.fsck.k9.ui.helper.RelativeDateTimeFormatter
import com.fsck.k9.ui.resolveColorAttribute
import com.google.android.material.textview.MaterialTextView
import kotlin.math.max
import com.google.android.material.R as MaterialR

private const val FOOTER_ID = 1L

Expand Down Expand Up @@ -68,6 +70,10 @@ class MessageListAdapter internal constructor(
private val unreadItemBackgroundColor: Int =
theme.resolveColorAttribute(R.attr.messageListUnreadItemBackgroundColor)

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 compactVerticalPadding = res.getDimensionPixelSize(R.dimen.messageListCompactVerticalPadding)
private val compactTextViewMarginTop = res.getDimensionPixelSize(R.dimen.messageListCompactTextViewMargin)
private val compactLineSpacingMultiplier = res.getFloatCompat(R.dimen.messageListCompactLineSpacingMultiplier)
Expand Down Expand Up @@ -372,6 +378,7 @@ class MessageListAdapter internal constructor(
}

with(messageListItem) {
val textColor = if (isRead) readTextColor else unreadTextColor
val maybeBoldTypeface = if (isRead) Typeface.NORMAL else Typeface.BOLD
val displayDate = relativeDateTimeFormatter.formatDate(messageDate)
val displayThreadCount = if (appearance.showingThreadedList) threadCount else 0
Expand Down Expand Up @@ -405,11 +412,13 @@ class MessageListAdapter internal constructor(
messageStringBuilder.append("").append(preview)
}
}
holder.preview.setTextColor(textColor)
holder.preview.setText(messageStringBuilder, TextView.BufferType.SPANNABLE)

formatPreviewText(holder.preview, beforePreviewText, isRead)

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

val firstLineText = if (appearance.senderAboveSubject) displayName else subject
holder.subject.text = firstLineText
Expand All @@ -421,6 +430,7 @@ class MessageListAdapter internal constructor(
}

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

Expand All @@ -443,6 +453,13 @@ class MessageListAdapter internal constructor(

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

previewText.setSpan(
ForegroundColorSpan(previewTextColor),
beforePreviewLength,
previewText.length,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
)
}

private fun addBeforePreviewSpan(text: Spannable, length: Int, messageRead: Boolean) {
Expand Down
6 changes: 3 additions & 3 deletions legacy/ui/legacy/src/main/res/layout/message_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
android:layout_marginEnd="4dp"
android:focusable="false"
android:textAppearance="?attr/textAppearanceBodyMedium"
android:textColor="?attr/colorSecondary"
android:textColor="?attr/colorOnSurfaceVariant"
app:layout_constraintBaseline_toBaselineOf="@+id/subject"
app:layout_constraintEnd_toStartOf="@+id/attachment"
app:layout_constraintHorizontal_bias="0.0"
Expand All @@ -143,7 +143,7 @@
android:layout_marginEnd="@dimen/messageListHorizontalPadding"
android:singleLine="true"
android:textAppearance="?attr/textAppearanceBodyMedium"
android:textColor="?attr/colorSecondary"
android:textColor="?attr/colorOnSurfaceVariant"
app:layout_constraintBaseline_toBaselineOf="@+id/subject"
app:layout_constraintEnd_toEndOf="parent"
tools:text="Oct 27"
Expand All @@ -156,7 +156,7 @@
android:layout_marginTop="@dimen/fakeAlignImageTopToTextTopPadding"
android:layout_marginEnd="@dimen/messageListHorizontalPadding"
android:src="@drawable/btn_select_star"
android:contentDescription="@string/star_button_description"
android:contentDescription="@string/star_button_description"
app:layout_constraintBottom_toBottomOf="@+id/bottom_guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/preview"
Expand Down

0 comments on commit fda4070

Please sign in to comment.