[Android] Set video group as an editable preference

Alexandre Perraud git at videolan.org
Thu Jun 30 14:53:02 CEST 2016


vlc-android | branch: master | Alexandre Perraud <4leyx4ndre at gmail.com> | Thu Jun 30 14:50:40 2016 +0200| [957c50f78de143446dd0b004a67bfa23194e78f8] | committer: Alexandre Perraud

Set video group as an editable preference

> https://code.videolan.org/videolan/vlc-android/commit/957c50f78de143446dd0b004a67bfa23194e78f8
---

 vlc-android/res/values/strings.xml                   | 20 ++++++++++++++++++++
 vlc-android/res/xml/preferences_ui.xml               |  8 ++++++++
 .../videolan/vlc/gui/preferences/PreferencesUi.java  |  3 +++
 .../videolan/vlc/gui/video/VideoGridFragment.java    |  3 ++-
 .../src/org/videolan/vlc/media/MediaGroup.java       | 13 +++++++++----
 5 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index afbd1cc..e7c20fc 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -386,6 +386,12 @@
     <string name="tv_ui_summary">Change UI to TV adapted theme</string>
     <string name="lockscreen_cover_title">Media cover on Lockscreen</string>
     <string name="lockscreen_cover_summary">When available, set the current media cover art as lockscreen wallpaper</string>
+    <string name="video_min_group_length_title">Group videos</string>
+    <string name="video_min_group_length_summary">Videos are grouped if their first letters are the same.</string>
+    <string name="video_min_group_length_disable">Disable</string>
+    <string name="video_min_group_length_first">First letter only</string>
+    <string name="video_min_group_length_short">Short number of letters (6)</string>
+    <string name="video_min_group_length_long">Long number of letters (9)</string>
 
     <!--Accessibility-->
     <string name="more_actions">More Actions</string>
@@ -486,6 +492,20 @@
         <item>3</item>
     </string-array>
 
+    <string-array name="video_min_group_length_list" translatable="false">
+        <item>@string/video_min_group_length_disable</item>
+        <item>@string/video_min_group_length_first</item>
+        <item>@string/video_min_group_length_short</item>
+        <item>@string/video_min_group_length_long</item>
+    </string-array>
+
+    <string-array name="video_min_group_length_values" translatable="false">
+        <item>0</item>
+        <item>1</item>
+        <item>6</item>
+        <item>9</item>
+    </string-array>
+
     <string-array name="subtitles_encoding_list" tools:ignore="TypographyDashes">
         <item>Default (Windows-1252)</item>
         <item>Universal (UTF-8)</item>
diff --git a/vlc-android/res/xml/preferences_ui.xml b/vlc-android/res/xml/preferences_ui.xml
index b9b73c7..f65e000 100644
--- a/vlc-android/res/xml/preferences_ui.xml
+++ b/vlc-android/res/xml/preferences_ui.xml
@@ -9,6 +9,14 @@
         android:key="enable_black_theme"
         android:summary="@string/enable_black_theme_summary"
         android:title="@string/enable_black_theme" />
+    <ListPreference
+        android:defaultValue="6"
+        android:entries="@array/video_min_group_length_list"
+        android:entryValues="@array/video_min_group_length_values"
+        android:key="video_min_group_length"
+        android:persistent="true"
+        android:summary="@string/video_min_group_length_summary"
+        android:title="@string/video_min_group_length_title" />
     <PreferenceCategory android:title="@string/interface_gui" >
         <CheckBoxPreference
             android:key="tv_ui"
diff --git a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.java b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.java
index d42cc7c..abeea83 100644
--- a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.java
+++ b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.java
@@ -58,6 +58,9 @@ public class PreferencesUi extends BasePreferenceFragment {
         if (preference.getKey() == null)
             return false;
         switch (preference.getKey()){
+            case "video_min_group_length":
+                getActivity().setResult(PreferencesActivity.RESULT_RESTART);
+                return true;
             case "enable_headset_detection":
                 ((PreferencesActivity)getActivity()).detectHeadset(((TwoStatePreference) preference).isChecked());
                 return true;
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 43242fa..63946b5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoGridFragment.java
@@ -398,7 +398,8 @@ public class VideoGridFragment extends MediaBrowserFragment implements ISortable
                     final ArrayList<MediaWrapper> jobsList = new ArrayList<>();
                     if (mGroup != null || itemList.size() <= 10) {
                         for (MediaWrapper item : itemList) {
-                            if (mGroup == null || item.getTitle().startsWith(mGroup))
+                            String title = item.getTitle().substring(item.getTitle().toLowerCase().startsWith("the") ? 4 : 0);
+                            if (mGroup == null || title.toLowerCase().startsWith(mGroup.toLowerCase()))
                                 displayList.add(item);
                                 jobsList.add(item);
                         }
diff --git a/vlc-android/src/org/videolan/vlc/media/MediaGroup.java b/vlc-android/src/org/videolan/vlc/media/MediaGroup.java
index c4d41df..7950bd6 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaGroup.java
+++ b/vlc-android/src/org/videolan/vlc/media/MediaGroup.java
@@ -20,6 +20,10 @@
 
 package org.videolan.vlc.media;
 
+import android.content.SharedPreferences;
+import android.preference.PreferenceManager;
+
+import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.helpers.BitmapUtil;
 
 import java.util.ArrayList;
@@ -29,8 +33,6 @@ public class MediaGroup extends MediaWrapper {
 
     public final static String TAG = "VLC/MediaGroup";
 
-    public final static int MIN_GROUP_LENGTH = 6;
-
     private ArrayList<MediaWrapper> mMedias;
 
     public MediaGroup(MediaWrapper media) {
@@ -92,6 +94,8 @@ public class MediaGroup extends MediaWrapper {
     }
 
     private static void insertInto(ArrayList<MediaGroup> groups, MediaWrapper media) {
+        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext());
+        int minGroupLengthValue = Integer.valueOf(preferences.getString("video_min_group_length", "6"));
         for (MediaGroup mediaGroup : groups) {
             String group = mediaGroup.getTitle();
             String title = media.getTitle();
@@ -105,10 +109,11 @@ public class MediaGroup extends MediaWrapper {
             int commonLength = 0;
             String groupTitle = group.substring(groupOffset);
             int minLength = Math.min(groupTitle.length(), title.length());
-            while (commonLength < minLength && groupTitle.charAt(commonLength) == title.charAt(commonLength))
+            while (commonLength < minLength
+                    && groupTitle.toLowerCase().charAt(commonLength) == title.toLowerCase().charAt(commonLength))
                 ++commonLength;
 
-            if (commonLength >= MIN_GROUP_LENGTH) {
+            if (commonLength >= minGroupLengthValue && minGroupLengthValue != 0) {
                 if (commonLength == group.length()) {
                     // same prefix name, just add
                     mediaGroup.add(media);



More information about the Android mailing list