Precompute TextView in I/O thread for performance
This commit is contained in:
parent
89e9e7c176
commit
a0b47f3ca3
@ -1,9 +1,14 @@
|
||||
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.extensions.subscribeK
|
||||
import io.reactivex.Single
|
||||
|
||||
@BindingAdapter("gone")
|
||||
fun setGone(view: View, gone: Boolean) {
|
||||
@ -24,3 +29,12 @@ fun setGoneUnless(view: View, goneUnless: Boolean) {
|
||||
fun setInvisibleUnless(view: View, invisibleUnless: Boolean) {
|
||||
setInvisible(view, invisibleUnless.not())
|
||||
}
|
||||
|
||||
@BindingAdapter("precomputedText")
|
||||
fun setPrecomputedText(tv: TextView, text: CharSequence) {
|
||||
Single.fromCallable {
|
||||
PrecomputedTextCompat.create(text, TextViewCompat.getTextMetricsParams(tv))
|
||||
}.subscribeK {
|
||||
TextViewCompat.setPrecomputedText(tv, it);
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="monospace"
|
||||
android:text="@{viewModel.consoleText}"
|
||||
precomputedText="@{viewModel.consoleText}"
|
||||
android:textAppearance="@style/AppearanceFoundation.Caption"
|
||||
android:textSize="10sp"
|
||||
android:paddingTop="@{viewModel.insets.top + (int) @dimen/internal_action_bar_size}"
|
||||
|
Loading…
Reference in New Issue
Block a user