[Android] Set search updates processing in background
Geoffrey Métais
git at videolan.org
Tue Dec 6 19:01:21 CET 2016
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Dec 6 19:00:29 2016 +0100| [088d19e2bd5091748f1aa9f6ba6ae4bc284c740f] | committer: Geoffrey Métais
Set search updates processing in background
> https://code.videolan.org/videolan/vlc-android/commit/088d19e2bd5091748f1aa9f6ba6ae4bc284c740f
---
.../videolan/vlc/gui/audio/AudioBrowserAdapter.java | 12 +++++-------
.../org/videolan/vlc/gui/video/VideoListAdapter.java | 19 +++++--------------
2 files changed, 10 insertions(+), 21 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 70781ed..91f22f2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
@@ -161,7 +161,6 @@ public class AudioBrowserAdapter extends RecyclerView.Adapter<AudioBrowserAdapte
public void addAll(MediaLibraryItem[] items, boolean generateSections) {
if (mContext == null)
return;
- mOriginalDataSet = null;
mDataList = generateSections ? generateList(items) : items;
}
@@ -231,8 +230,10 @@ public class AudioBrowserAdapter extends RecyclerView.Adapter<AudioBrowserAdapte
}
public void restoreList() {
- if (mOriginalDataSet != null)
- dispatchUpdate(mOriginalDataSet);
+ if (mOriginalDataSet != null) {
+ dispatchUpdate(Arrays.copyOf(mOriginalDataSet, mOriginalDataSet.length));
+ mOriginalDataSet = null;
+ }
}
void dispatchUpdate(final MediaLibraryItem[] items) {
@@ -375,10 +376,7 @@ public class AudioBrowserAdapter extends RecyclerView.Adapter<AudioBrowserAdapte
@Override
protected void publishResults(CharSequence charSequence, FilterResults filterResults) {
- MediaLibraryItem[] oldlist = Arrays.copyOf(mDataList, mDataList.length);
- mDataList = ((ArrayList<MediaLibraryItem>) filterResults.values).toArray(new MediaLibraryItem[filterResults.count]);
- final DiffUtil.DiffResult result = DiffUtil.calculateDiff(new MediaItemDiffCallback(oldlist, mDataList));
- result.dispatchUpdatesTo(AudioBrowserAdapter.this);
+ dispatchUpdate(((ArrayList<MediaLibraryItem>) filterResults.values).toArray(new MediaLibraryItem[filterResults.count]));
}
}
}
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 aed946d..295753d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoListAdapter.java
@@ -474,8 +474,10 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
}
void restoreList() {
- if (mOriginalData != null)
- dispatchUpdate(mOriginalData);
+ if (mOriginalData != null) {
+ dispatchUpdate(new ArrayList<>(mOriginalData));
+ mOriginalData = null;
+ }
}
private class ItemFilter extends MediaItemFilter {
@@ -492,17 +494,7 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
@Override
protected void publishResults(CharSequence charSequence, FilterResults filterResults) {
- final ArrayList<MediaWrapper> oldList = getAll();
- final ArrayList<MediaWrapper> newList = (ArrayList<MediaWrapper>) filterResults.values;
- mVideos.clear();
- mVideos.addAll(newList);
- final DiffUtil.DiffResult result = DiffUtil.calculateDiff(new MediaItemDiffCallback(oldList, newList));
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- result.dispatchUpdatesTo(VideoListAdapter.this);
- }
- });
+ dispatchUpdate((ArrayList<MediaWrapper>) filterResults.values);
}
}
@BindingAdapter({"time", "resolution"})
@@ -530,7 +522,6 @@ public class VideoListAdapter extends RecyclerView.Adapter<VideoListAdapter.View
public void run() {
mVideos.clear();
mVideos = newSortedList;
- mOriginalData = null;
result.dispatchUpdatesTo(VideoListAdapter.this);
mFragment.updateEmptyView();
}
More information about the Android
mailing list