Fix Markdown rendering

Close #3074
This commit is contained in:
topjohnwu
2020-08-14 02:00:06 -07:00
parent d8b1d79879
commit ac2a9da4c4
9 changed files with 371 additions and 84 deletions
@@ -2,15 +2,13 @@ package com.topjohnwu.magisk.databinding
import android.view.View
import android.widget.TextView
import androidx.core.text.PrecomputedTextCompat
import androidx.core.view.isGone
import androidx.core.view.isInvisible
import androidx.core.widget.TextViewCompat
import androidx.databinding.BindingAdapter
import com.topjohnwu.magisk.ktx.coroutineScope
import com.topjohnwu.magisk.ktx.get
import io.noties.markwon.Markwon
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
@BindingAdapter("gone")
@@ -33,18 +31,10 @@ fun setInvisibleUnless(view: View, invisibleUnless: Boolean) {
setInvisible(view, invisibleUnless.not())
}
@BindingAdapter("precomputedText")
fun setPrecomputedText(tv: TextView, text: CharSequence) {
GlobalScope.launch(Dispatchers.Default) {
val pre = PrecomputedTextCompat.create(text, TextViewCompat.getTextMetricsParams(tv))
tv.post {
TextViewCompat.setPrecomputedText(tv, pre);
}
}
}
@BindingAdapter("markdownText")
fun setMarkdownText(tv: TextView, text: CharSequence) {
val markwon = get<Markwon>()
markwon.setMarkdown(tv, text.toString())
tv.coroutineScope.launch(Dispatchers.IO) {
val markwon = get<Markwon>()
markwon.setMarkdown(tv, text.toString())
}
}