[Android] Videos grouping: pass context from fragments
Geoffrey Métais
git at videolan.org
Mon Mar 5 17:02:40 CET 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Mar 5 15:19:42 2018 +0100| [bb3b18ab87e78f2e1a529b884a069d5b897aeb27] | committer: Geoffrey Métais
Videos grouping: pass context from fragments
> https://code.videolan.org/videolan/vlc-android/commit/bb3b18ab87e78f2e1a529b884a069d5b897aeb27
---
.../videolan/vlc/gui/video/VideoGridFragment.java | 7 +++++--
.../src/org/videolan/vlc/media/MediaGroup.java | 20 +++++---------------
2 files changed, 10 insertions(+), 17 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 4da309119..7e1781254 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -22,6 +22,7 @@ package org.videolan.vlc.gui.video;
import android.annotation.TargetApi;
import android.app.Activity;
+import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
@@ -341,6 +342,7 @@ public class VideoGridFragment extends SortableFragment<VideoListAdapter> implem
@MainThread
public void updateList() {
mHandler.sendEmptyMessageDelayed(SET_REFRESHING, 300);
+ final Context ctx = getActivity();
VLCApplication.runBackground(new Runnable() {
@Override
@@ -354,8 +356,9 @@ public class VideoGridFragment extends SortableFragment<VideoListAdapter> implem
displayList.add(item);
}
} else {
- for (MediaGroup item : MediaGroup.group(itemList))
- displayList.add(item.getMedia());
+ final SharedPreferences preferences = ctx != null ? PreferenceManager.getDefaultSharedPreferences(ctx) : null;
+ final int minGroupLengthValue = preferences != null ? Integer.valueOf(preferences.getString("video_min_group_length", "6")) : 6;
+ for (MediaGroup item : MediaGroup.group(itemList, minGroupLengthValue)) displayList.add(item.getMedia());
}
VLCApplication.runOnMainThread(new Runnable() {
@Override
diff --git a/vlc-android/src/org/videolan/vlc/media/MediaGroup.java b/vlc-android/src/org/videolan/vlc/media/MediaGroup.java
index 27a50a1b5..97631211b 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaGroup.java
+++ b/vlc-android/src/org/videolan/vlc/media/MediaGroup.java
@@ -20,11 +20,7 @@
package org.videolan.vlc.media;
-import android.content.SharedPreferences;
-import android.preference.PreferenceManager;
-
import org.videolan.medialibrary.media.MediaWrapper;
-import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.helpers.BitmapUtil;
import java.util.ArrayList;
@@ -88,25 +84,19 @@ public class MediaGroup extends MediaWrapper {
this.mTitle = title;
}
- public static List<MediaGroup> group(MediaWrapper[] mediaList) {
+ public static List<MediaGroup> group(MediaWrapper[] mediaList, int minGroupLengthValue) {
final ArrayList<MediaGroup> groups = new ArrayList<>();
- for (MediaWrapper media : mediaList)
- if (media != null)
- insertInto(groups, media);
+ for (MediaWrapper media : mediaList) if (media != null) insertInto(groups, media, minGroupLengthValue);
return groups;
}
- public static List<MediaGroup> group(List<MediaWrapper> mediaList) {
+ public static List<MediaGroup> group(List<MediaWrapper> mediaList, int minGroupLengthValue) {
final ArrayList<MediaGroup> groups = new ArrayList<>();
- for (MediaWrapper media : mediaList)
- if (media != null)
- insertInto(groups, media);
+ for (MediaWrapper media : mediaList) if (media != null) insertInto(groups, media, minGroupLengthValue);
return groups;
}
- private static void insertInto(ArrayList<MediaGroup> groups, MediaWrapper media) {
- final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
- final int minGroupLengthValue = Integer.valueOf(preferences.getString("video_min_group_length", "6"));
+ private static void insertInto(ArrayList<MediaGroup> groups, MediaWrapper media, int minGroupLengthValue) {
for (MediaGroup mediaGroup : groups) {
final String group = mediaGroup.getTitle().toLowerCase();
String title = media.getTitle().toLowerCase();
More information about the Android
mailing list