Improve flash console screen

This commit is contained in:
topjohnwu
2020-02-16 19:04:26 -08:00
parent 40f971d18a
commit 8453282fa6
11 changed files with 63 additions and 59 deletions
@@ -6,7 +6,7 @@ import com.topjohnwu.magisk.databinding.ComparableRvItem
import com.topjohnwu.magisk.model.entity.recycler.LenientRvItem
import me.tatarka.bindingcollectionadapter2.BindingRecyclerViewAdapter
class BindingAdapter : BindingRecyclerViewAdapter<ComparableRvItem<*>>() {
class BindingAdapter <T : ComparableRvItem<*>> : BindingRecyclerViewAdapter<T>() {
private var recyclerView: RecyclerView? = null
@@ -15,12 +15,12 @@ class BindingAdapter : BindingRecyclerViewAdapter<ComparableRvItem<*>>() {
variableId: Int,
layoutRes: Int,
position: Int,
item: ComparableRvItem<*>
item: T
) {
super.onBindBinding(binding, variableId, layoutRes, position, item)
when (item) {
is LenientRvItem -> {
is LenientRvItem<*> -> {
val recycler = recyclerView ?: return
item.onBindingBound(binding)
item.onBindingBound(binding, recycler)
@@ -34,4 +34,4 @@ class BindingAdapter : BindingRecyclerViewAdapter<ComparableRvItem<*>>() {
this.recyclerView = recyclerView
}
}
}
@@ -1,18 +1,27 @@
package com.topjohnwu.magisk.model.entity.recycler
import android.view.View
import android.widget.TextView
import androidx.core.view.updateLayoutParams
import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
import com.topjohnwu.magisk.R
import kotlin.math.max
class ConsoleItem(val item: String) : LenientRvItem<ConsoleItem>() {
override val layoutRes = R.layout.item_console_md2
private var parentWidth = -1
override fun onBindingBound(binding: ViewDataBinding, recyclerView: RecyclerView) {
if (parentWidth < 0)
parentWidth = (recyclerView.parent as View).width
val view = binding.root as TextView
view.measure(0, 0)
val desiredWidth = view.measuredWidth
// We want our recyclerView at least as wide as screen
val desiredWidth = max(view.measuredWidth, parentWidth)
view.updateLayoutParams { width = desiredWidth }
@@ -23,4 +32,4 @@ class ConsoleItem(val item: String) : LenientRvItem<ConsoleItem>() {
override fun contentSameAs(other: ConsoleItem) = itemSameAs(other)
override fun itemSameAs(other: ConsoleItem) = item == other.item
}
}