Commit 2f59e9e2 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Merge branch 'markdown-support' into message-actions

parents df9f1480 0749391e
...@@ -7,7 +7,7 @@ import chat.rocket.core.TokenRepository ...@@ -7,7 +7,7 @@ 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.CommonPool
import kotlinx.coroutines.experimental.launch import kotlinx.coroutines.experimental.withContext
import javax.inject.Inject import javax.inject.Inject
class MessageViewModelMapper @Inject constructor(private val context: Context, class MessageViewModelMapper @Inject constructor(private val context: Context,
...@@ -15,8 +15,15 @@ class MessageViewModelMapper @Inject constructor(private val context: Context, ...@@ -15,8 +15,15 @@ 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>>) = launch(CommonPool) { suspend fun mapToViewModel(message: Message, settings: Map<String, Value<Any>>): MessageViewModel = withContext(CommonPool) {
MessageViewModel(this@MessageViewModelMapper.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> {
......
...@@ -4,8 +4,8 @@ import android.app.Application ...@@ -4,8 +4,8 @@ import android.app.Application
import android.arch.persistence.room.Room import android.arch.persistence.room.Room
import android.content.Context import android.content.Context
import android.content.SharedPreferences import android.content.SharedPreferences
import android.graphics.Color
import chat.rocket.android.BuildConfig import chat.rocket.android.BuildConfig
import chat.rocket.android.R
import chat.rocket.android.app.RocketChatDatabase import chat.rocket.android.app.RocketChatDatabase
import chat.rocket.android.app.utils.CustomImageFormatConfigurator import chat.rocket.android.app.utils.CustomImageFormatConfigurator
import chat.rocket.android.authentication.infraestructure.MemoryTokenRepository import chat.rocket.android.authentication.infraestructure.MemoryTokenRepository
...@@ -206,14 +206,15 @@ class AppModule { ...@@ -206,14 +206,15 @@ class AppModule {
@Provides @Provides
@Singleton @Singleton
fun provideConfiguration(context: Application, client: OkHttpClient): SpannableConfiguration { fun provideConfiguration(context: Application, client: OkHttpClient): SpannableConfiguration {
val res = context.resources
return SpannableConfiguration.builder(context) return SpannableConfiguration.builder(context)
.asyncDrawableLoader(AsyncDrawableLoader.builder() .asyncDrawableLoader(AsyncDrawableLoader.builder()
.client(client) .client(client)
.executorService(Executors.newCachedThreadPool()) .executorService(Executors.newCachedThreadPool())
.resources(context.resources) .resources(res)
.build()) .build())
.theme(SpannableTheme.builder() .theme(SpannableTheme.builder()
.linkColor(Color.BLUE) .linkColor(res.getColor(R.color.colorAccent))
.build()) .build())
.build() .build()
} }
......
...@@ -129,7 +129,7 @@ class MessageParser @Inject constructor(val context: Application, private val co ...@@ -129,7 +129,7 @@ class MessageParser @Inject constructor(val context: Application, private val co
} }
class QuoteMarginSpan(quoteDrawable: Drawable, private var pad: Int) : LeadingMarginSpan, LineHeightSpan { class QuoteMarginSpan(quoteDrawable: Drawable, private var pad: Int) : LeadingMarginSpan, LineHeightSpan {
private var drawable: Drawable = quoteDrawable private val drawable: Drawable = quoteDrawable
override fun getLeadingMargin(first: Boolean): Int { override fun getLeadingMargin(first: Boolean): Int {
return drawable.intrinsicWidth + pad return drawable.intrinsicWidth + pad
...@@ -150,14 +150,14 @@ class MessageParser @Inject constructor(val context: Application, private val co ...@@ -150,14 +150,14 @@ class MessageParser @Inject constructor(val context: Application, private val co
} }
override fun chooseHeight(text: CharSequence, start: Int, end: Int, override fun chooseHeight(text: CharSequence, start: Int, end: Int,
istartv: Int, v: Int, spanstartv: 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 = drawable.intrinsicHeight val ht = drawable.intrinsicHeight
var need = ht - (v + fm.descent - fm.ascent - istartv) var need = ht - (v + fm.descent - fm.ascent - spanstartv)
if (need > 0) if (need > 0)
fm.descent += need fm.descent += need
need = ht - (v + fm.bottom - fm.top - istartv) need = ht - (v + fm.bottom - fm.top - spanstartv)
if (need > 0) if (need > 0)
fm.bottom += need fm.bottom += 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