[Android] Audio lists: precompute texts

Geoffrey Métais git at videolan.org
Thu Feb 14 15:59:43 CET 2019


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Feb 14 15:35:28 2019 +0100| [2c8e7b52ab3a542da0f22f127b0a25a7b7602f97] | committer: Geoffrey Métais

Audio lists: precompute texts

> https://code.videolan.org/videolan/vlc-android/commit/2c8e7b52ab3a542da0f22f127b0a25a7b7602f97
---

 vlc-android/res/layout/audio_browser_item.xml                |  6 +++---
 .../src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java  |  9 ++++-----
 vlc-android/src/org/videolan/vlc/util/Kextensions.kt         | 12 ++++++++++++
 3 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/vlc-android/res/layout/audio_browser_item.xml b/vlc-android/res/layout/audio_browser_item.xml
index ce077b634..ffbf51758 100644
--- a/vlc-android/res/layout/audio_browser_item.xml
+++ b/vlc-android/res/layout/audio_browser_item.xml
@@ -46,7 +46,7 @@
             android:paddingBottom="@dimen/audio_item_header_padding"
             vlc:layout_constraintTop_toTopOf="parent"
             android:singleLine="true"
-            android:text="@{header}"
+            vlc:asyncText="@{header}"
             android:textColor="?attr/audio_browser_separator"
             android:textSize="20sp"
             android:background="?attr/background_default"
@@ -84,7 +84,7 @@
             android:layout_marginStart="@dimen/default_margin"
             android:gravity="center_vertical"
             vlc:alignMode="@{alignMode}"
-            android:text="@{item.title}"
+            vlc:asyncText="@{item.title}"
             style="@style/VLC.TextViewTitle" />
 
         <TextView
@@ -95,7 +95,7 @@
             vlc:layout_constraintStart_toStartOf="@+id/title"
             vlc:layout_constraintEnd_toEndOf="@+id/title"
             vlc:layout_constraintBottom_toBottomOf="parent"
-            android:text="@{item.description}"
+            vlc:asyncText="@{item.description}"
             style="@style/VLC.TextViewDescription"
             android:visibility="@{TextUtils.isEmpty(item.description) ? View.GONE : View.VISIBLE}"/>
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
index 886bdf143..8fb490e2b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
@@ -51,7 +51,6 @@ import java.util.List;
 
 import androidx.annotation.NonNull;
 import androidx.annotation.Nullable;
-import androidx.databinding.ViewDataBinding;
 import androidx.paging.PagedList;
 import androidx.paging.PagedListAdapter;
 import androidx.recyclerview.widget.DiffUtil;
@@ -69,8 +68,6 @@ public class AudioBrowserAdapter extends PagedListAdapter<MediaLibraryItem, Audi
     private int mSort;
     private final BitmapDrawable mDefaultCover;
 
-    private boolean mMakeSections = true;
-
     public AudioBrowserAdapter(int type, IEventsHandler eventsHandler, int sort) {
         super(DIFF_CALLBACK);
         multiSelectHelper = new MultiSelectHelper<>(this, Constants.UPDATE_SELECTION);
@@ -84,6 +81,7 @@ public class AudioBrowserAdapter extends PagedListAdapter<MediaLibraryItem, Audi
         mSort = sort;
     }
 
+    @NonNull
     @Override
     public MediaItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
         final LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@@ -101,6 +99,7 @@ public class AudioBrowserAdapter extends PagedListAdapter<MediaLibraryItem, Audi
         final boolean isSelected = multiSelectHelper.isSelected(position);
         holder.setCoverlay(isSelected);
         holder.selectView(isSelected);
+        holder.binding.executePendingBindings();
     }
 
     @Override
@@ -137,7 +136,7 @@ public class AudioBrowserAdapter extends PagedListAdapter<MediaLibraryItem, Audi
     }
 
     @Override
-    public void onViewRecycled(MediaItemViewHolder holder) {
+    public void onViewRecycled(@NonNull MediaItemViewHolder holder) {
         if (mDefaultCover != null) holder.binding.setCover(mDefaultCover);
     }
 
@@ -193,7 +192,7 @@ public class AudioBrowserAdapter extends PagedListAdapter<MediaLibraryItem, Audi
 
     @Override
     public boolean hasSections() {
-        return mMakeSections;
+        return true;
     }
 
     public class MediaItemViewHolder extends SelectorViewHolder<AudioBrowserItemBinding> implements View.OnFocusChangeListener {
diff --git a/vlc-android/src/org/videolan/vlc/util/Kextensions.kt b/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
index 5fe29d76f..26f096df6 100644
--- a/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
@@ -3,6 +3,11 @@ package org.videolan.vlc.util
 import android.content.Context
 import android.content.SharedPreferences
 import android.net.Uri
+import android.widget.TextView
+import androidx.appcompat.widget.AppCompatTextView
+import androidx.core.text.PrecomputedTextCompat
+import androidx.core.widget.TextViewCompat
+import androidx.databinding.BindingAdapter
 import androidx.fragment.app.Fragment
 import androidx.fragment.app.FragmentActivity
 import androidx.lifecycle.LiveData
@@ -139,3 +144,10 @@ fun <X, Y> CoroutineScope.map(
         }
     }
 }
+
+ at BindingAdapter("app:asyncText", requireAll = false)
+fun asyncText(view: TextView, text: CharSequence?) {
+    if (text === null) return
+    val params = TextViewCompat.getTextMetricsParams(view)
+    (view as AppCompatTextView).setTextFuture(PrecomputedTextCompat.getTextFuture(text, params, null))
+}



More information about the Android mailing list