[Android] Release cover on view recycled
Geoffrey Métais
git at videolan.org
Tue Nov 29 12:04:52 CET 2016
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Nov 29 12:04:04 2016 +0100| [7c4ee6effb2cbab8d9f3d80415959d61f29599b3] | committer: Geoffrey Métais
Release cover on view recycled
> https://code.videolan.org/videolan/vlc-android/commit/7c4ee6effb2cbab8d9f3d80415959d61f29599b3
---
.../videolan/vlc/gui/audio/AudioBrowserAdapter.java | 20 ++++++++++++--------
.../org/videolan/vlc/gui/video/VideoListAdapter.java | 1 +
2 files changed, 13 insertions(+), 8 deletions(-)
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 0effa5f..20b405a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
@@ -80,14 +80,21 @@ public class AudioBrowserAdapter extends RecyclerView.Adapter<AudioBrowserAdapte
}
@Override
+ public void onViewRecycled(ViewHolder holder) {
+ holder.vdb.setVariable(BR.cover, null);
+ }
+
+ @Override
public int getItemCount() {
return mDataList == null ? 0 : mDataList.size();
}
public MediaLibraryItem getItem(int position) {
- if (position < 0 || position >= mDataList.size())
- return null;
- return mDataList.get(position);
+ return isPositionValid(position) ? mDataList.get(position) : null;
+ }
+
+ private boolean isPositionValid(int position) {
+ return position >= 0 || position < mDataList.size();
}
public ArrayList<MediaLibraryItem> getAll() {
@@ -109,16 +116,13 @@ public class AudioBrowserAdapter extends RecyclerView.Adapter<AudioBrowserAdapte
if (i < position)
++offset;
} else
- list.add(mDataList.get(i));
+ list.add(mDataList.get(i));
return position-offset;
}
@Override
public long getItemId(int position) {
- if (position < 0 || position >= mDataList.size())
- return super.getItemId(position);
- else
- return mDataList.get(position).getId();
+ return isPositionValid(position) ? mDataList.get(position).getId() : -1;
}
@Override
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
index 2a2da2f..81bd788 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -120,6 +120,7 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
@Override
public void onViewRecycled(ViewHolder holder) {
mHolders.remove(holder.getAdapterPosition());
+ holder.binding.setVariable(BR.cover, null);
}
@MainThread
More information about the Android
mailing list