Commit df9f1480 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Merge branch 'markdown-support' into message-actions

parents f25e08a5 e0d9e0cf
...@@ -6,6 +6,8 @@ import chat.rocket.android.server.domain.MessagesRepository ...@@ -6,6 +6,8 @@ import chat.rocket.android.server.domain.MessagesRepository
import chat.rocket.core.TokenRepository import chat.rocket.core.TokenRepository
import chat.rocket.core.model.Message import chat.rocket.core.model.Message
import chat.rocket.core.model.Value import chat.rocket.core.model.Value
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.launch
import javax.inject.Inject import javax.inject.Inject
class MessageViewModelMapper @Inject constructor(private val context: Context, class MessageViewModelMapper @Inject constructor(private val context: Context,
...@@ -13,8 +15,9 @@ class MessageViewModelMapper @Inject constructor(private val context: Context, ...@@ -13,8 +15,9 @@ class MessageViewModelMapper @Inject constructor(private val context: Context,
private val messageParser: MessageParser, private val messageParser: MessageParser,
private val messagesRepository: MessagesRepository) { private val messagesRepository: MessagesRepository) {
suspend fun mapToViewModel(message: Message, settings: Map<String, Value<Any>>) = suspend fun mapToViewModel(message: Message, settings: Map<String, Value<Any>>) = launch(CommonPool) {
MessageViewModel(context, tokenRepository.get(), message, settings, messageParser, messagesRepository) MessageViewModel(this@MessageViewModelMapper.context, tokenRepository.get(), message, settings, messageParser, messagesRepository)
}
suspend fun mapToViewModelList(messageList: List<Message>, settings: Map<String, Value<Any>>): List<MessageViewModel> { suspend fun mapToViewModelList(messageList: List<Message>, settings: Map<String, Value<Any>>): List<MessageViewModel> {
return messageList.map { MessageViewModel(context, tokenRepository.get(), it, settings, messageParser, messagesRepository) } return messageList.map { MessageViewModel(context, tokenRepository.get(), it, settings, messageParser, messagesRepository) }
......
...@@ -128,12 +128,11 @@ class MessageParser @Inject constructor(val context: Application, private val co ...@@ -128,12 +128,11 @@ class MessageParser @Inject constructor(val context: Application, private val co
} }
} }
class QuoteMarginSpan(b: Drawable, pad: Int) : LeadingMarginSpan, LineHeightSpan { class QuoteMarginSpan(quoteDrawable: Drawable, private var pad: Int) : LeadingMarginSpan, LineHeightSpan {
private var mDrawable: Drawable? = b private var drawable: Drawable = quoteDrawable
private var mPad: Int = pad
override fun getLeadingMargin(first: Boolean): Int { override fun getLeadingMargin(first: Boolean): Int {
return mDrawable!!.intrinsicWidth + mPad return drawable.intrinsicWidth + pad
} }
override fun drawLeadingMargin(c: Canvas, p: Paint, x: Int, dir: Int, override fun drawLeadingMargin(c: Canvas, p: Paint, x: Int, dir: Int,
...@@ -143,18 +142,18 @@ class MessageParser @Inject constructor(val context: Application, private val co ...@@ -143,18 +142,18 @@ class MessageParser @Inject constructor(val context: Application, private val co
val st = (text as Spanned).getSpanStart(this) val st = (text as Spanned).getSpanStart(this)
val ix = x val ix = x
val itop = layout.getLineTop(layout.getLineForOffset(st)) val itop = layout.getLineTop(layout.getLineForOffset(st))
val dw = mDrawable!!.intrinsicWidth val dw = drawable.intrinsicWidth
val dh = mDrawable!!.intrinsicHeight val dh = drawable.intrinsicHeight
// XXX What to do about Paint? // XXX What to do about Paint?
mDrawable!!.setBounds(ix, itop, ix + dw, itop + layout.height) drawable.setBounds(ix, itop, ix + dw, itop + layout.height)
mDrawable!!.draw(c) drawable.draw(c)
} }
override fun chooseHeight(text: CharSequence, start: Int, end: Int, override fun chooseHeight(text: CharSequence, start: Int, end: Int,
istartv: Int, v: Int, istartv: Int, v: Int,
fm: Paint.FontMetricsInt) { fm: Paint.FontMetricsInt) {
if (end == (text as Spanned).getSpanEnd(this)) { if (end == (text as Spanned).getSpanEnd(this)) {
val ht = mDrawable!!.intrinsicHeight val ht = drawable.intrinsicHeight
var need = ht - (v + fm.descent - fm.ascent - istartv) var need = ht - (v + fm.descent - fm.ascent - istartv)
if (need > 0) if (need > 0)
fm.descent += need fm.descent += need
......
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