Commit bb3b18ab authored by Geoffrey Métais's avatar Geoffrey Métais

Videos grouping: pass context from fragments

parent 85176224
......@@ -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
......
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment