[Android] Factorize videos sort code
Geoffrey Métais
git at videolan.org
Tue Dec 6 19:01:17 CET 2016
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Dec 6 17:12:14 2016 +0100| [b979b946d056cfc377b0cd6ca06a3df6d5d03b97] | committer: Geoffrey Métais
Factorize videos sort code
> https://code.videolan.org/videolan/vlc-android/commit/b979b946d056cfc377b0cd6ca06a3df6d5d03b97
---
.../org/videolan/vlc/gui/video/VideoListAdapter.java | 17 ++---------------
1 file changed, 2 insertions(+), 15 deletions(-)
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 cddd2bb..9383377 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -134,7 +134,7 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
public void sort() {
if (!isEmpty())
try {
- resetSorting();
+ dispatchUpdate(getAll());
} catch (ArrayIndexOutOfBoundsException e) {} //Exception happening on Android 2.x
}
@@ -359,19 +359,6 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
mVideoComparator.sortBy(sortby);
}
- private void resetSorting() {
- final ArrayList<MediaWrapper> oldList = getAll();
- mVideos.clear();
- mVideos.addAll(oldList);
- final DiffUtil.DiffResult result = DiffUtil.calculateDiff(new MediaItemDiffCallback(oldList, getAll()));
- mFragment.getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- result.dispatchUpdatesTo(VideoListAdapter.this);
- }
- });
- }
-
class VideoComparator extends SortedList.Callback<MediaWrapper> {
private static final String KEY_SORT_BY = "sort_by";
@@ -423,7 +410,7 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
mSortDirection = 1;
break;
}
- resetSorting();
+ dispatchUpdate(getAll());
SharedPreferences.Editor editor = mSettings.edit();
editor.putInt(KEY_SORT_BY, mSortBy);
More information about the Android
mailing list