[Android] Audio browser: add a new class to factorize the media comparators

Adrien Maglo git at videolan.org
Tue Nov 19 16:03:34 CET 2013


vlc-ports/android | branch: master | Adrien Maglo <magsoft at videolan.org> | Tue Nov 19 15:59:16 2013 +0100| [aca345dd7a58bb83cb7bc1a8c4ed447e0dbf6b0e] | committer: Adrien Maglo

Audio browser: add a new class to factorize the media comparators

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=aca345dd7a58bb83cb7bc1a8c4ed447e0dbf6b0e
---

 .../videolan/vlc/gui/audio/MediaComparators.java   |   61 ++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/MediaComparators.java b/vlc-android/src/org/videolan/vlc/gui/audio/MediaComparators.java
new file mode 100644
index 0000000..2a4fe1c
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/MediaComparators.java
@@ -0,0 +1,61 @@
+package org.videolan.vlc.gui.audio;
+
+import java.util.Comparator;
+
+import org.videolan.libvlc.Media;
+
+public class MediaComparators {
+
+    public final Comparator<Media> byName = new Comparator<Media>() {
+        @Override
+        public int compare(Media m1, Media m2) {
+            return String.CASE_INSENSITIVE_ORDER.compare(m1.getTitle(), m2.getTitle());
+        };
+    };
+
+    public final Comparator<Media> byMRL = new Comparator<Media>() {
+        @Override
+        public int compare(Media m1, Media m2) {
+            return String.CASE_INSENSITIVE_ORDER.compare(m1.getLocation(), m2.getLocation());
+        };
+    };
+
+    public final Comparator<Media> byLength = new Comparator<Media>() {
+        @Override
+        public int compare(Media m1, Media m2) {
+            if(m1.getLength() > m2.getLength()) return -1;
+            if(m1.getLength() < m2.getLength()) return 1;
+            else return 0;
+        };
+    };
+
+    public final Comparator<Media> byAlbum = new Comparator<Media>() {
+        @Override
+        public int compare(Media m1, Media m2) {
+            int res = String.CASE_INSENSITIVE_ORDER.compare(m1.getAlbum(), m2.getAlbum());
+            if (res == 0)
+                res = byMRL.compare(m1, m2);
+            return res;
+        };
+    };
+
+    public final Comparator<Media> byArtist = new Comparator<Media>() {
+        @Override
+        public int compare(Media m1, Media m2) {
+            int res = String.CASE_INSENSITIVE_ORDER.compare(m1.getArtist(), m2.getArtist());
+            if (res == 0)
+                res = byAlbum.compare(m1, m2);
+            return res;
+        };
+    };
+
+    public final Comparator<Media> byGenre = new Comparator<Media>() {
+        @Override
+        public int compare(Media m1, Media m2) {
+            int res = String.CASE_INSENSITIVE_ORDER.compare(m1.getGenre(), m2.getGenre());
+            if (res == 0)
+                res = byArtist.compare(m1, m2);
+            return res;
+        };
+    };
+}



More information about the Android mailing list