[Android] Use IDs to set tags on views

Geoffrey Métais git at videolan.org
Fri Jun 24 15:43:21 CEST 2016


vlc-android | branch: 2.0.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jun 24 15:42:29 2016 +0200| [26ca33e4c3cd5a8c84e09ef0ed5e6b405ea7053e] | committer: Geoffrey Métais

Use IDs to set tags on views

(cherry picked from commit 168556b79c7ef723dc888dcc4433e535113bbc1b)

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

 .../org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java | 13 +++++++------
 .../src/org/videolan/vlc/gui/helpers/AsyncImageLoader.java  |  2 +-
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
index d6c610e..d850420 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserListAdapter.java
@@ -340,7 +340,7 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex
          * if it does not correspond to a media view. */
         boolean b_createView = true;
         if (v != null) {
-            holder = (ViewHolder) v.getTag();
+            holder = (ViewHolder) v.getTag(R.layout.audio_browser_item);
             if (holder.viewType == VIEW_MEDIA)
                 b_createView = false;
         }
@@ -352,7 +352,7 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex
             holder.binding = DataBindingUtil.inflate(inflater, R.layout.audio_browser_item, parent, false);
             v = holder.binding.getRoot();
             holder.viewType = VIEW_MEDIA;
-            v.setTag(holder);
+            v.setTag(R.layout.audio_browser_item, holder);
         }
 
         ListItem item = getItem(position);
@@ -361,9 +361,10 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex
         holder.binding.setVariable(BR.position, position);
 
         if (mItemType == ITEM_WITH_COVER) {
+            holder.binding.setVariable(BR.cover, null);
             //Tagging the binding to the ImageView will trigger async image loading with:
             // org.videolan.vlc.gui.helpers.AsyncImageLoader.loadPicture(ImageView , AudioBrowserListAdapter.ListItem)
-            holder.binding.getRoot().findViewById(R.id.media_cover).setTag(holder.binding);
+            holder.binding.getRoot().findViewById(R.id.media_cover).setTag(R.id.media_cover, holder.binding);
         } else
             holder.binding.setVariable(BR.cover, AudioUtil.DEFAULT_COVER);
 
@@ -382,7 +383,7 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex
          * if it does not correspond to a separator view. */
         boolean b_createView = true;
         if (v != null) {
-            holder = (ViewHolder) v.getTag();
+            holder = (ViewHolder) v.getTag(R.layout.audio_browser_item);
             if (holder.viewType == VIEW_SEPARATOR)
                 b_createView = false;
         }
@@ -393,12 +394,12 @@ public class AudioBrowserListAdapter extends BaseAdapter implements SectionIndex
             holder.binding = DataBindingUtil.inflate(inflater, R.layout.audio_browser_separator, parent, false);
             v = holder.binding.getRoot();
             holder.viewType = VIEW_SEPARATOR;
-            v.setTag(holder);
+            v.setTag(R.layout.audio_browser_item, holder);
         }
 
         ListItem item = getItem(position);
+        holder.binding.setVariable(BR.cover, null);
         holder.binding.setVariable(BR.item, item);
-        holder.binding.executePendingBindings();
 
         return v;
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/AsyncImageLoader.java b/vlc-android/src/org/videolan/vlc/gui/helpers/AsyncImageLoader.java
index 3987e60..ab46bdf 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/AsyncImageLoader.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/AsyncImageLoader.java
@@ -164,7 +164,7 @@ public class AsyncImageLoader {
 
     @BindingAdapter({"item"})
     public static void loadPicture(final ImageView v, final AudioBrowserListAdapter.ListItem item) {
-        final Object tag = v.getTag();
+        final Object tag = v.getTag(R.id.media_cover);
         if (tag == null || !(tag instanceof ViewDataBinding))
             return;
         Bitmap bitmap = AudioUtil.getCoverFromMemCache(VLCApplication.getAppContext(), item.mMediaList, 64);



More information about the Android mailing list