Commit 91fb79a4 authored by Joey's avatar Joey

ui: use setTextFuture in recyclerviews

To take advantage of prefetch phase to work with text
Signed-off-by: Joey's avatarJoey <bevilacquajoey@gmail.com>
Change-Id: I58800773b0f04b36dfed007a7933b7a600f8e8d7
parent 30ae4fdb
......@@ -10,17 +10,17 @@ package it.diab.holders
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.widget.AppCompatTextView
import it.diab.R
import it.diab.core.util.extensions.setPrecomputedText
import it.diab.data.entities.Glucose
import it.diab.ui.util.extensions.setPreText
class GlucoseHolder(
view: View,
private val callbacks: GlucoseHolderCallbacks
) : MainHolder(view) {
private val titleView = view.findViewById<TextView>(R.id.item_glucose_value)
private val summaryView = view.findViewById<TextView>(R.id.item_glucose_insulin)
private val titleView = view.findViewById<AppCompatTextView>(R.id.item_glucose_value)
private val summaryView = view.findViewById<AppCompatTextView>(R.id.item_glucose_insulin)
private val indicatorView = view.findViewById<ImageView>(R.id.item_glucose_status)
fun onBind(glucose: Glucose) {
......@@ -40,7 +40,7 @@ class GlucoseHolder(
val title = "${glucose.value} (%1\$s)"
callbacks.fetchHourText(glucose.date) { text ->
titleView.setPrecomputedText(title.format(text))
titleView.setPreText(title.format(text))
}
val indicatorDrawable = callbacks.getIndicator(glucose.value)
......@@ -79,7 +79,7 @@ class GlucoseHolder(
summaryView.visibility = View.GONE
} else {
summaryView.visibility = View.VISIBLE
summaryView.text = builder.toString()
summaryView.setPreText(builder.toString())
}
}
}
\ No newline at end of file
......@@ -29,7 +29,7 @@
app:layout_constraintTop_toTopOf="parent"
tools:ignore="RtlSymmetry">
<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/item_glucose_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
......@@ -38,7 +38,7 @@
android:textSize="18sp"
tools:text="123 (19:02)" />
<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/item_glucose_insulin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
......
/*
* Copyright (c) 2019 Bevilacqua Joey
*
* Licensed under the GNU GPLv3 license
*
* The text of the license can be found in the LICENSE file
* or at https://www.gnu.org/licenses/gpl.txt
*/
package it.diab.core.util.extensions
import android.widget.TextView
import androidx.core.text.PrecomputedTextCompat
import androidx.core.widget.TextViewCompat
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
fun TextView.setPrecomputedText(text: CharSequence) {
val params = TextViewCompat.getTextMetricsParams(this)
val scope = CoroutineScope(Dispatchers.Default)
scope.launch {
val textDef = async { PrecomputedTextCompat.getTextFuture(text, params, null).get() }
launch(Dispatchers.Main) { this@setPrecomputedText.text = textDef.await() }
}
}
......@@ -29,7 +29,6 @@ import it.diab.core.util.Activities
import it.diab.core.util.ComposableError
import it.diab.core.util.PreferencesUtil
import it.diab.core.util.SystemUtil
import it.diab.core.util.extensions.setPrecomputedText
import it.diab.data.entities.Glucose
import it.diab.data.entities.Insulin
import it.diab.data.plugin.PluginManager
......@@ -127,7 +126,7 @@ class EditorFragment : Fragment() {
eatView.setProgress(glucose.eatLevel)
eatView.lock()
valueView.text = glucose.value.toString()
timeView.setPrecomputedText(glucose.date.getDetailedString())
timeView.text = glucose.date.getDetailedString()
fabView.setOnClickListener { onFabClick() }
if (viewModel.isEditMode) {
......
......@@ -10,22 +10,23 @@ package it.diab.insulin.holders
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.widget.AppCompatTextView
import androidx.recyclerview.widget.RecyclerView
import it.diab.core.arch.EventBusFactory
import it.diab.insulin.R
import it.diab.insulin.components.status.ListItemStatus
import it.diab.insulin.events.ListEvent
import it.diab.ui.util.extensions.setPreText
class InsulinHolder(
view: View,
private val bus: EventBusFactory
) : RecyclerView.ViewHolder(view) {
private val titleView = view.findViewById<TextView>(R.id.item_insulin_name)
private val titleView = view.findViewById<AppCompatTextView>(R.id.item_insulin_name)
private val iconView = view.findViewById<ImageView>(R.id.item_insulin_icon)
fun onBind(status: ListItemStatus) {
titleView.text = status.name
titleView.setPreText(status.name)
iconView.setImageResource(status.icon)
itemView.setOnClickListener {
......@@ -35,7 +36,7 @@ class InsulinHolder(
fun onBind() {
val res = itemView.resources
titleView.text = res.getString(R.string.insulin_add_item)
titleView.setPreText(res.getString(R.string.insulin_add_item))
iconView.setImageResource(R.drawable.ic_add)
itemView.setOnClickListener {
......
......@@ -42,7 +42,7 @@
android:padding="8dp"
tools:src="@drawable/ic_time_dinner" />
<TextView
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/item_insulin_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
......
/*
* Copyright (c) 2019 Bevilacqua Joey
*
* Licensed under the GNU GPLv3 license
*
* The text of the license can be found in the LICENSE file
* or at https://www.gnu.org/licenses/gpl.txt
*/
package it.diab.ui.util.extensions
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.text.PrecomputedTextCompat
fun AppCompatTextView.setPreText(text: CharSequence) {
setTextFuture(
PrecomputedTextCompat.getTextFuture(
text,
textMetricsParamsCompat,
null
)
)
}
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