[Android] Support videos grouping by filename
Geoffrey Métais
git at videolan.org
Thu Dec 20 11:00:55 CET 2018
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Dec 20 11:00:07 2018 +0100| [c308a284619a98caa04b25638bd9b28976773b83] | committer: Geoffrey Métais
Support videos grouping by filename
Fix #698
> https://code.videolan.org/videolan/vlc-android/commit/c308a284619a98caa04b25638bd9b28976773b83
---
.../src/org/videolan/vlc/media/MediaGroup.java | 28 +++++++++++-----------
.../src/org/videolan/vlc/viewmodels/VideosModel.kt | 2 +-
2 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/media/MediaGroup.java b/vlc-android/src/org/videolan/vlc/media/MediaGroup.java
index f65c025bd..b09517019 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaGroup.java
+++ b/vlc-android/src/org/videolan/vlc/media/MediaGroup.java
@@ -32,13 +32,13 @@ public class MediaGroup extends MediaWrapper {
private List<MediaWrapper> mMedias;
- private MediaGroup(MediaWrapper media) {
+ private MediaGroup(MediaWrapper media, boolean filename) {
super(media.getUri(),
media.getTime(),
media.getLength(),
MediaWrapper.TYPE_GROUP,
BitmapUtil.getPicture(media),
- media.getTitle(),
+ filename ? media.getFileName() : media.getTitle(),
media.getArtist(),
media.getGenre(),
media.getAlbum(),
@@ -52,13 +52,19 @@ public class MediaGroup extends MediaWrapper {
media.getDiscNumber(),
media.getLastModified(),
media.getSeen());
- mMedias = new ArrayList<MediaWrapper>();
+ mMedias = new ArrayList<>();
mMedias.add(media);
}
public String getDisplayTitle() {
return getTitle() + "\u2026";
}
+
+ @Override
+ public String getFileName() {
+ return mTitle;
+ }
+
public void add(MediaWrapper media) {
mMedias.add(media);
}
@@ -84,22 +90,16 @@ public class MediaGroup extends MediaWrapper {
this.mTitle = title;
}
- 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, minGroupLengthValue);
- return groups;
- }
-
- public static List<MediaGroup> group(List<MediaWrapper> mediaList, int minGroupLengthValue) {
+ public static List<MediaGroup> group(MediaWrapper[] mediaList, int minGroupLengthValue, boolean filename) {
final ArrayList<MediaGroup> groups = new ArrayList<>();
- for (MediaWrapper media : mediaList) if (media != null) insertInto(groups, media, minGroupLengthValue);
+ for (MediaWrapper media : mediaList) if (media != null) insertInto(groups, media, minGroupLengthValue, filename);
return groups;
}
- private static void insertInto(ArrayList<MediaGroup> groups, MediaWrapper media, int minGroupLengthValue) {
+ private static void insertInto(ArrayList<MediaGroup> groups, MediaWrapper media, int minGroupLengthValue, boolean filename) {
for (MediaGroup mediaGroup : groups) {
final String group = mediaGroup.getTitle().toLowerCase();
- String title = media.getTitle().toLowerCase();
+ String title = (filename ? media.getFileName() : media.getTitle()).toLowerCase();
//Handle titles starting with "The"
int groupOffset = group.startsWith("the") ? 4 : 0;
@@ -127,6 +127,6 @@ public class MediaGroup extends MediaWrapper {
}
// does not match any group, so add one
- groups.add(new MediaGroup(media));
+ groups.add(new MediaGroup(media, filename));
}
}
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/VideosModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/VideosModel.kt
index 0a7e25365..c08928902 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/VideosModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/VideosModel.kt
@@ -76,7 +76,7 @@ open class VideosModel(context: Context, private val group: String?, private val
if (title.startsWith(loGroup)) displayList.add(item)
}
}
- minGroupLen > 0 -> MediaGroup.group(list, minGroupLen).mapTo(displayList) {
+ minGroupLen > 0 -> MediaGroup.group(list, minGroupLen, sort == Medialibrary.SORT_FILENAME).mapTo(displayList) {
if (it.size() > 1) { it.description = context.resources.getQuantityString(R.plurals.videos_quantity, it.size(), it.size()) }
it.media
}
More information about the Android
mailing list