[Android] Fix grouping videos starting with "The"

Geoffrey Métais git at videolan.org
Fri May 27 11:48:34 CEST 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri May 27 11:48:00 2016 +0200| [0d0e2e8e0a01f2fd0f1b3d6fc7f2873a784f12e1] | committer: Geoffrey Métais

Fix grouping videos starting with "The"

> https://code.videolan.org/videolan/vlc-android/commit/0d0e2e8e0a01f2fd0f1b3d6fc7f2873a784f12e1
---

 vlc-android/src/org/videolan/vlc/media/MediaGroup.java | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/media/MediaGroup.java b/vlc-android/src/org/videolan/vlc/media/MediaGroup.java
index 38b9fbb..c4d41df 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaGroup.java
+++ b/vlc-android/src/org/videolan/vlc/media/MediaGroup.java
@@ -96,13 +96,16 @@ public class MediaGroup extends MediaWrapper {
             String group = mediaGroup.getTitle();
             String title = media.getTitle();
 
-            if (title.length() > 4 && (title.substring(0, 3).toLowerCase().startsWith("the")))
+            //Handle titles starting with "The"
+            int groupOffset = group.toLowerCase().startsWith("the") ? 4 : 0;
+            if (title.toLowerCase().startsWith("the"))
                 title = title.substring(4);
 
             // find common prefix
             int commonLength = 0;
-            int minLength = Math.min(group.length(), title.length());
-            while (commonLength < minLength && group.charAt(commonLength) == title.charAt(commonLength))
+            String groupTitle = group.substring(groupOffset);
+            int minLength = Math.min(groupTitle.length(), title.length());
+            while (commonLength < minLength && groupTitle.charAt(commonLength) == title.charAt(commonLength))
                 ++commonLength;
 
             if (commonLength >= MIN_GROUP_LENGTH) {
@@ -111,7 +114,7 @@ public class MediaGroup extends MediaWrapper {
                     mediaGroup.add(media);
                 } else {
                     // not the same prefix, but close : merge
-                    mediaGroup.merge(media, group.substring(0, commonLength));
+                    mediaGroup.merge(media, group.substring(0, commonLength+groupOffset));
                 }
                 return;
             }



More information about the Android mailing list