[Android] Partial update instead of Observable field

Geoffrey Métais git at videolan.org
Mon Dec 5 15:32:13 CET 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Dec  5 15:31:37 2016 +0100| [b8beaf8211ea7cecfaec74c700ddfbf1b6e869a2] | committer: Geoffrey Métais

Partial update instead of Observable field

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

 .../org/videolan/medialibrary/media/MediaLibraryItem.java   |  2 --
 vlc-android/res/layout/directory_view_item.xml              |  4 ++--
 .../org/videolan/vlc/gui/browser/BaseBrowserAdapter.java    | 13 ++++++++++---
 .../org/videolan/vlc/gui/browser/BaseBrowserFragment.java   |  7 ++-----
 4 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java b/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java
index 815682c..c2a214a 100644
--- a/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java
+++ b/medialibrary/src/org/videolan/medialibrary/media/MediaLibraryItem.java
@@ -1,6 +1,5 @@
 package org.videolan.medialibrary.media;
 
-import android.databinding.ObservableField;
 import android.os.Parcel;
 import android.os.Parcelable;
 
@@ -23,7 +22,6 @@ public abstract class MediaLibraryItem implements Parcelable {
 
     long mId;
     protected String mTitle, mDescription;
-    public ObservableField<String> observableDescription = null;
 
     protected MediaLibraryItem() {}
 
diff --git a/vlc-android/res/layout/directory_view_item.xml b/vlc-android/res/layout/directory_view_item.xml
index e301bd9..b9b4ce4 100644
--- a/vlc-android/res/layout/directory_view_item.xml
+++ b/vlc-android/res/layout/directory_view_item.xml
@@ -94,9 +94,9 @@
                 android:layout_height="wrap_content"
                 android:ellipsize="marquee"
                 android:maxLines="1"
-                android:text="@{item.observableDescription}"
+                android:text="@{item.description}"
                 android:fontFamily="sans-serif-light"
-                android:visibility="@{item.observableDescription != null ? View.VISIBLE : View.GONE}"
+                android:visibility="@{item.description != null ? View.VISIBLE : View.GONE}"
                 android:textColor="?attr/list_subtitle"/>
         </LinearLayout>
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
index c19c213..b18594b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.java
@@ -23,7 +23,6 @@
 package org.videolan.vlc.gui.browser;
 
 import android.databinding.DataBindingUtil;
-import android.databinding.ObservableField;
 import android.databinding.ViewDataBinding;
 import android.graphics.BitmapFactory;
 import android.graphics.drawable.BitmapDrawable;
@@ -106,10 +105,18 @@ public class BaseBrowserAdapter extends RecyclerView.Adapter<BaseBrowserAdapter.
         }
     }
 
+    @Override
+    public void onBindViewHolder(ViewHolder holder, int position, List<Object> payloads) {
+        if (payloads.isEmpty())
+            onBindViewHolder(holder, position);
+        else {
+            ((MediaViewHolder) holder).binding.text.setVisibility(View.VISIBLE);
+            ((MediaViewHolder) holder).binding.text.setText((CharSequence) payloads.get(0));
+        }
+    }
+
     private void onBindMediaViewHolder(final MediaViewHolder vh, int position) {
         final MediaWrapper media = (MediaWrapper) getItem(position);
-        if (media.observableDescription == null)
-            media.observableDescription = new ObservableField<>();
         vh.binding.setItem(media);
         vh.binding.setHasContextMenu(true);
         if (fragment instanceof NetworkBrowserFragment && fragment.isRootDirectory())
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
index 8966779..8d3e714 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -23,7 +23,6 @@
 package org.videolan.vlc.gui.browser;
 
 import android.annotation.TargetApi;
-import android.databinding.ObservableField;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
@@ -614,10 +613,8 @@ public abstract class BaseBrowserFragment extends MediaBrowserFragment implement
 
             if (!TextUtils.equals(holderText, "")) {
                 MediaLibraryItem item = mAdapter.getItem(mCurrentParsedPosition);
-                if (item.observableDescription == null)
-                    item.observableDescription = new ObservableField<>(holderText);
-                else
-                    item.observableDescription.set(holderText);
+                item.setDescription(holderText);
+                mAdapter.notifyItemChanged(mCurrentParsedPosition, holderText);
                 directories.addAll(files);
                 mFoldersContentLists.put(mCurrentParsedPosition, new ArrayList<>(directories));
             }



More information about the Android mailing list