Commit 2731b019 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Small refactoring

parent 80923948
...@@ -178,25 +178,29 @@ data class MessageViewModel(val context: Context, ...@@ -178,25 +178,29 @@ data class MessageViewModel(val context: Context,
spannableMsg.setSpan(StyleSpan(Typeface.BOLD_ITALIC), messageTextStartIndex, messageTextEndIndex, spannableMsg.setSpan(StyleSpan(Typeface.BOLD_ITALIC), messageTextStartIndex, messageTextEndIndex,
0) 0)
} }
} else { } else if (attachmentType == AttachmentType.Message) {
spannableMsg.apply { spannableMsg.append(quoteMessage(attachmentMessageAuthor!!, attachmentMessageText!!, attachmentTimestamp!!))
var header = "\n$attachmentMessageAuthor ${getTime(attachmentTimestamp!!)}\n" }
return spannableMsg
}
private fun quoteMessage(author: String, text: String, timestamp: Long): CharSequence {
return SpannableStringBuilder().apply {
val header = "\n$author ${getTime(timestamp)}\n"
append(SpannableString(header).apply { append(SpannableString(header).apply {
setSpan(StyleSpan(Typeface.BOLD), 1, attachmentMessageAuthor!!.length + 1, 0) setSpan(StyleSpan(Typeface.BOLD), 1, author.length + 1, 0)
setSpan(MessageParser.QuoteMarginSpan(context.getDrawable(R.drawable.quote), 10), 1, length, 0) setSpan(MessageParser.QuoteMarginSpan(context.getDrawable(R.drawable.quote), 10), 1, length, 0)
setSpan(AbsoluteSizeSpan(context.resources.getDimensionPixelSize(R.dimen.message_time_text_size)), setSpan(AbsoluteSizeSpan(context.resources.getDimensionPixelSize(R.dimen.message_time_text_size)),
attachmentMessageAuthor!!.length + 1, length, 0) author.length + 1, length, 0)
}) })
append(SpannableString(parser.renderMarkdown(attachmentMessageText!!)).apply { append(SpannableString(parser.renderMarkdown(text)).apply {
setSpan(MessageParser.QuoteMarginSpan(context.getDrawable(R.drawable.quote), 10), 0, length, 0) setSpan(MessageParser.QuoteMarginSpan(context.getDrawable(R.drawable.quote), 10), 0, length, 0)
}) })
} }
} }
return spannableMsg
}
private fun attachmentUrl(url: String): String { private fun attachmentUrl(url: String): String {
var response = url var response = url
val httpUrl = HttpUrl.parse(url) val httpUrl = HttpUrl.parse(url)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment