Skip to content
Snippets Groups Projects
Commit 157074b0 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Videos grouping: pass context from fragments

(cherry picked from commit bb3b18ab)
parent 99de86a8
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,7 @@ package org.videolan.vlc.gui.video; ...@@ -22,6 +22,7 @@ package org.videolan.vlc.gui.video;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
...@@ -341,6 +342,7 @@ public class VideoGridFragment extends SortableFragment<VideoListAdapter> implem ...@@ -341,6 +342,7 @@ public class VideoGridFragment extends SortableFragment<VideoListAdapter> implem
@MainThread @MainThread
public void updateList() { public void updateList() {
mHandler.sendEmptyMessageDelayed(SET_REFRESHING, 300); mHandler.sendEmptyMessageDelayed(SET_REFRESHING, 300);
final Context ctx = getActivity();
VLCApplication.runBackground(new Runnable() { VLCApplication.runBackground(new Runnable() {
@Override @Override
...@@ -354,8 +356,9 @@ public class VideoGridFragment extends SortableFragment<VideoListAdapter> implem ...@@ -354,8 +356,9 @@ public class VideoGridFragment extends SortableFragment<VideoListAdapter> implem
displayList.add(item); displayList.add(item);
} }
} else { } else {
for (MediaGroup item : MediaGroup.group(itemList)) final SharedPreferences preferences = ctx != null ? PreferenceManager.getDefaultSharedPreferences(ctx) : null;
displayList.add(item.getMedia()); 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() { VLCApplication.runOnMainThread(new Runnable() {
@Override @Override
......
...@@ -20,11 +20,7 @@ ...@@ -20,11 +20,7 @@
package org.videolan.vlc.media; package org.videolan.vlc.media;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import org.videolan.medialibrary.media.MediaWrapper; import org.videolan.medialibrary.media.MediaWrapper;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.helpers.BitmapUtil; import org.videolan.vlc.gui.helpers.BitmapUtil;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -88,25 +84,19 @@ public class MediaGroup extends MediaWrapper { ...@@ -88,25 +84,19 @@ public class MediaGroup extends MediaWrapper {
this.mTitle = title; 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<>(); final ArrayList<MediaGroup> groups = new ArrayList<>();
for (MediaWrapper media : mediaList) for (MediaWrapper media : mediaList) if (media != null) insertInto(groups, media, minGroupLengthValue);
if (media != null)
insertInto(groups, media);
return groups; 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<>(); final ArrayList<MediaGroup> groups = new ArrayList<>();
for (MediaWrapper media : mediaList) for (MediaWrapper media : mediaList) if (media != null) insertInto(groups, media, minGroupLengthValue);
if (media != null)
insertInto(groups, media);
return groups; return groups;
} }
private static void insertInto(ArrayList<MediaGroup> groups, MediaWrapper media) { private static void insertInto(ArrayList<MediaGroup> groups, MediaWrapper media, int minGroupLengthValue) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
final int minGroupLengthValue = Integer.valueOf(preferences.getString("video_min_group_length", "6"));
for (MediaGroup mediaGroup : groups) { for (MediaGroup mediaGroup : groups) {
final String group = mediaGroup.getTitle().toLowerCase(); final String group = mediaGroup.getTitle().toLowerCase();
String title = media.getTitle().toLowerCase(); String title = media.getTitle().toLowerCase();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment