[Android] Use constants for partial updates
Geoffrey Métais
git at videolan.org
Sat Feb 4 16:19:51 CET 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Sat Feb 4 15:01:26 2017 +0100| [a7bca5c3f4529ea21a292eb9e7c1d7f22817c66d] | committer: Geoffrey Métais
Use constants for partial updates
> https://code.videolan.org/videolan/vlc-android/commit/a7bca5c3f4529ea21a292eb9e7c1d7f22817c66d
---
.../videolan/vlc/gui/video/VideoGridFragment.java | 6 ++--
.../videolan/vlc/gui/video/VideoListAdapter.java | 34 ++++++++++++----------
2 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
index 4ebad9b..0d5704b 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -568,7 +568,7 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda
if (mw.hasStateFlags(MediaLibraryItem.FLAG_SELECTED)) {
mw.removeStateFlags(MediaLibraryItem.FLAG_SELECTED);
mVideoAdapter.resetSelectionCount();
- mVideoAdapter.notifyItemChanged(i, mw);
+ mVideoAdapter.notifyItemChanged(i, VideoListAdapter.UPDATE_SELECTION);
}
}
}
@@ -603,7 +603,7 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda
if (mActionMode != null) {
item.toggleStateFlag(MediaLibraryItem.FLAG_SELECTED);
mVideoAdapter.updateSelectionCount(item.hasStateFlags(MediaLibraryItem.FLAG_SELECTED));
- mVideoAdapter.notifyItemChanged(position, item);
+ mVideoAdapter.notifyItemChanged(position, VideoListAdapter.UPDATE_SELECTION);
invalidateActionMode();
return;
}
@@ -629,7 +629,7 @@ public class VideoGridFragment extends MediaBrowserFragment implements MediaUpda
return false;
item.toggleStateFlag(MediaLibraryItem.FLAG_SELECTED);
mVideoAdapter.updateSelectionCount(item.hasStateFlags(MediaLibraryItem.FLAG_SELECTED));
- mVideoAdapter.notifyItemChanged(position, item);
+ mVideoAdapter.notifyItemChanged(position, VideoListAdapter.UPDATE_SELECTION);
startActionMode();
return true;
}
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 79b4f68..f617c28 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -41,7 +41,6 @@ import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
-import org.videolan.libvlc.util.AndroidUtil;
import org.videolan.medialibrary.Tools;
import org.videolan.medialibrary.media.MediaLibraryItem;
import org.videolan.medialibrary.media.MediaWrapper;
@@ -68,6 +67,11 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
public final static int SORT_BY_LENGTH = 1;
public final static int SORT_BY_DATE = 2;
+
+ public final static int UPDATE_SELECTION = 0;
+ public final static int UPDATE_THUMB = 1;
+ public final static int UPDATE_TIME = 2;
+
private boolean mListMode = false;
private IEventsHandler mEventsHandler;
private VideoComparator mVideoComparator = new VideoComparator();
@@ -119,17 +123,18 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
else {
MediaWrapper media = mVideos.get(position);
for (Object data : payloads) {
- if (data instanceof String) {
- media.setArtworkURL((String) payloads.get(0));
- AsyncImageLoader.loadPicture(holder.thumbView, media);
- } else if (data instanceof MediaWrapper) {
- media = (MediaWrapper) data;
- boolean isSelected = media.hasStateFlags(MediaLibraryItem.FLAG_SELECTED);
- holder.setOverlay(isSelected);
- holder.binding.setVariable(BR.bgColor, ContextCompat.getColor(holder.itemView.getContext(), mListMode && isSelected ? R.color.orange200transparent : R.color.transparent));
- } else {
- media.setTime((Long) data);
- fillView(holder, media);
+ switch ((int) data) {
+ case UPDATE_THUMB:
+ AsyncImageLoader.loadPicture(holder.thumbView, media);
+ break;
+ case UPDATE_TIME:
+ fillView(holder, media);
+ break;
+ case UPDATE_SELECTION:
+ boolean isSelected = media.hasStateFlags(MediaLibraryItem.FLAG_SELECTED);
+ holder.setOverlay(isSelected);
+ holder.binding.setVariable(BR.bgColor, ContextCompat.getColor(holder.itemView.getContext(), mListMode && isSelected ? R.color.orange200transparent : R.color.transparent));
+ break;
}
}
}
@@ -553,10 +558,9 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
MediaWrapper oldItem = oldList.get(oldItemPosition);
MediaWrapper newItem = newList.get(newItemPosition);
if (oldItem.getTime() != newItem.getTime())
- return newItem.getTime();
+ return UPDATE_TIME;
else
- return newItem.getArtworkMrl();
-
+ return UPDATE_THUMB;
}
}
}
More information about the Android
mailing list