Refactor snippet formatting

This commit is contained in:
andrew 2023-08-07 10:46:38 +09:30
parent f70aa9155b
commit 50fd3292c8
1 changed files with 10 additions and 14 deletions

View File

@ -103,7 +103,7 @@ class ConversationView : LinearLayout {
R.drawable.ic_notifications_mentions R.drawable.ic_notifications_mentions
} }
binding.muteIndicatorImageView.setImageResource(drawableRes) binding.muteIndicatorImageView.setImageResource(drawableRes)
binding.snippetTextView.text = highlightMentions(getSnippet(thread), thread.threadId, context) binding.snippetTextView.text = highlightMentions(thread.getSnippet(), thread.threadId, context)
binding.snippetTextView.typeface = if (unreadCount > 0 && !thread.isRead) Typeface.DEFAULT_BOLD else Typeface.DEFAULT binding.snippetTextView.typeface = if (unreadCount > 0 && !thread.isRead) Typeface.DEFAULT_BOLD else Typeface.DEFAULT
binding.snippetTextView.visibility = if (isTyping) View.GONE else View.VISIBLE binding.snippetTextView.visibility = if (isTyping) View.GONE else View.VISIBLE
if (isTyping) { if (isTyping) {
@ -136,20 +136,16 @@ class ConversationView : LinearLayout {
else -> recipient.toShortString() // Internally uses the Contact API else -> recipient.toShortString() // Internally uses the Contact API
} }
private fun getSnippet(thread: ThreadRecord): CharSequence = thread.run { private fun ThreadRecord.getSnippet(): CharSequence =
val body = getDisplayBody(context) concatSnippet(getSnippetPrefix(), getDisplayBody(context))
when { private fun concatSnippet(prefix: CharSequence?, body: CharSequence): CharSequence =
recipient.isLocalNumber || lastMessage?.isControlMessage == true -> body // Note to self prefix?.let { TextUtils.concat(it, ": ", body) } ?: body
lastMessage?.isOutgoing == true -> {
TextUtils.concat(resources.getString(R.string.MessageRecord_you), ": ", body) private fun ThreadRecord.getSnippetPrefix(): CharSequence? = when {
} recipient.isLocalNumber || lastMessage?.isControlMessage == true -> null
else -> lastMessage lastMessage?.isOutgoing == true -> resources.getString(R.string.MessageRecord_you)
?.individualRecipient else -> lastMessage?.individualRecipient?.toShortString()
?.toShortString()
?.let { TextUtils.concat(it, ": ", body) }
?: body
}
} }
// endregion // endregion
} }