Show sender name in bold for unread messages

This commit is contained in:
cketti 2019-09-06 16:22:11 +02:00
parent fde8c26268
commit 0985c5783b

View file

@ -12,6 +12,7 @@ import android.text.SpannableStringBuilder
import android.text.format.DateUtils import android.text.format.DateUtils
import android.text.style.AbsoluteSizeSpan import android.text.style.AbsoluteSizeSpan
import android.text.style.ForegroundColorSpan import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -221,7 +222,7 @@ class MessageListAdapter internal constructor(
} }
holder.preview.setText(messageStringBuilder, TextView.BufferType.SPANNABLE) holder.preview.setText(messageStringBuilder, TextView.BufferType.SPANNABLE)
formatPreviewText(holder.preview, beforePreviewText, sigil) formatPreviewText(holder.preview, beforePreviewText, sigil, read)
holder.subject.typeface = Typeface.create(holder.subject.typeface, maybeBoldTypeface) holder.subject.typeface = Typeface.create(holder.subject.typeface, maybeBoldTypeface)
if (appearance.senderAboveSubject) { if (appearance.senderAboveSubject) {
@ -250,12 +251,13 @@ class MessageListAdapter internal constructor(
private fun formatPreviewText( private fun formatPreviewText(
preview: TextView, preview: TextView,
beforePreviewText: CharSequence, beforePreviewText: CharSequence,
sigil: String sigil: String,
messageRead: Boolean
) { ) {
val previewText = preview.text as Spannable val previewText = preview.text as Spannable
val beforePreviewLength = beforePreviewText.length + sigil.length val beforePreviewLength = beforePreviewText.length + sigil.length
addBeforePreviewSpan(previewText, beforePreviewLength) addBeforePreviewSpan(previewText, beforePreviewLength, messageRead)
// Set span (color) for preview message // Set span (color) for preview message
previewText.setSpan( previewText.setSpan(
@ -266,7 +268,7 @@ class MessageListAdapter internal constructor(
) )
} }
private fun addBeforePreviewSpan(text: Spannable, length: Int) { private fun addBeforePreviewSpan(text: Spannable, length: Int, messageRead: Boolean) {
val fontSize = if (appearance.senderAboveSubject) { val fontSize = if (appearance.senderAboveSubject) {
appearance.fontSizes.messageListSubject appearance.fontSizes.messageListSubject
} else { } else {
@ -277,6 +279,11 @@ class MessageListAdapter internal constructor(
val span = AbsoluteSizeSpan(fontSize, true) val span = AbsoluteSizeSpan(fontSize, true)
text.setSpan(span, 0, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE) text.setSpan(span, 0, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
} }
if (!messageRead) {
val span = StyleSpan(Typeface.BOLD)
text.setSpan(span, 0, length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
}
} }
private fun fetchCounterPartyAddress( private fun fetchCounterPartyAddress(