Commit 6167018c authored by Konstantin Tskhovrebov's avatar Konstantin Tskhovrebov 🤖

Merge branch 'task/upgrade-markwon-and-remove-image-loading-crutch' into 'develop'

Upgrade Markwon to version 2.0.0. Replace ImageSizeResolver workaround with upstream one.

See merge request !131
parents fdb2e6c7 a548222d
......@@ -98,7 +98,7 @@ dependencies {
val moxyVersion = "1.4.6"
val toothpickVersion = "1.0.6"
val retrofitVersion = "2.2.0"
val markwonVersion = "1.1.1"
val markwonVersion = "2.0.0"
val glideVersion = "4.8.0"
//Support
......
package ru.terrakok.gitlabclient.toothpick.provider
import android.content.Context
import android.graphics.Rect
import okhttp3.OkHttpClient
import ru.noties.markwon.SpannableConfiguration
import ru.noties.markwon.UrlProcessorRelativeToAbsolute
import ru.noties.markwon.il.AsyncDrawableLoader
import ru.noties.markwon.renderer.ImageSize
import ru.noties.markwon.renderer.ImageSizeResolver
import ru.noties.markwon.spans.SpannableTheme
import ru.terrakok.gitlabclient.R
import ru.terrakok.gitlabclient.extension.color
......@@ -43,39 +40,11 @@ class MarkDownConverterProvider @Inject constructor(
private val urlProcessor = UrlProcessorRelativeToAbsolute(defaultServerPath)
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
Rect(
0,
0,
canvasWidth,
(imageBounds.height() / reduceRatio + .5f).toInt()
)
} else {
imageBounds
}
return rect
}
}
private val spannableConfig
get() = SpannableConfiguration.builder(context)
.asyncDrawableLoader(asyncDrawableLoader)
.urlProcessor(urlProcessor)
.theme(spannableTheme)
.imageSizeResolver(imageSizeResolver)
.build()
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