Commit ba1a92ba authored by Eugene Shapovalov's avatar Eugene Shapovalov 💬

Take the decision for Markdown image size resolver from 2.0.0-SNAPSHOT.

parent fec9c209
package ru.terrakok.gitlabclient.toothpick.provider package ru.terrakok.gitlabclient.toothpick.provider
import android.content.Context import android.content.Context
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import ru.noties.markwon.SpannableConfiguration import ru.noties.markwon.SpannableConfiguration
import ru.noties.markwon.UrlProcessorRelativeToAbsolute import ru.noties.markwon.UrlProcessorRelativeToAbsolute
import import
import ru.noties.markwon.renderer.ImageSize
import ru.noties.markwon.renderer.ImageSizeResolver
import ru.noties.markwon.spans.SpannableTheme import ru.noties.markwon.spans.SpannableTheme
import ru.terrakok.gitlabclient.R import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.extension.color import ru.terrakok.gitlabclient.extension.color
...@@ -38,11 +41,39 @@ class MarkDownConverterProvider @Inject constructor( ...@@ -38,11 +41,39 @@ class MarkDownConverterProvider @Inject constructor(
private val urlProcessor = UrlProcessorRelativeToAbsolute("") private val urlProcessor = UrlProcessorRelativeToAbsolute("")
private val imageSizeResolver = object : ImageSizeResolver() {
override fun resolveImageSize(
imageSize: ImageSize?,
imageBounds: Rect,
canvasWidth: Int,
textSize: Float
): Rect {
// This implementation was taken from SNAPSHOT @2.0,0.
// Post process bounds to fit canvasWidth (previously was inside AsyncDrawable)
// must be applied only if imageSize is null.
val rect: Rect
val w = imageBounds.width()
rect = if (w > canvasWidth) {
val reduceRatio = w.toFloat() / canvasWidth
(imageBounds.height() / reduceRatio + .5f).toInt()
} else {
return rect
private val spannableConfig private val spannableConfig
get() = SpannableConfiguration.builder(context) get() = SpannableConfiguration.builder(context)
.asyncDrawableLoader(asyncDrawableLoader) .asyncDrawableLoader(asyncDrawableLoader)
.urlProcessor(urlProcessor) .urlProcessor(urlProcessor)
.theme(spannableTheme) .theme(spannableTheme)
.build() .build()
override fun get() = MarkDownConverter( override fun get() = MarkDownConverter(
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