[Android] Make MediaComparators a static class

Edward Wang git at videolan.org
Thu Nov 28 22:19:34 CET 2013


vlc-ports/android | branch: master | Edward Wang <edward.c.wang at compdigitec.com> | Thu Nov 28 16:07:14 2013 -0500| [d80f2c580b634617b4e029fc37983223fe387015] | committer: Edward Wang

Make MediaComparators a static class

Reduce one unneeded class initialization, all comparators are accessible via static

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

 .../vlc/gui/audio/AudioAlbumsSongsFragment.java        |    6 ++----
 .../videolan/vlc/gui/audio/AudioBrowserFragment.java   |   16 +++++-----------
 .../videolan/vlc/gui/audio/AudioPlayerFragment.java    |    6 ++----
 .../org/videolan/vlc/gui/audio/MediaComparators.java   |   12 ++++++------
 4 files changed, 15 insertions(+), 25 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
index 5dfefd3..0cc2c13 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
@@ -60,8 +60,6 @@ public class AudioAlbumsSongsFragment extends SherlockFragment {
 
     private ArrayList<Media> mediaList;
 
-    private static final MediaComparators mComparators = new MediaComparators();
-
     /* All subclasses of Fragment must include a public empty constructor. */
     public AudioAlbumsSongsFragment() { }
 
@@ -154,13 +152,13 @@ public class AudioAlbumsSongsFragment extends SherlockFragment {
         mAlbumsAdapter.clear();
         mSongsAdapter.clear();
 
-        Collections.sort(mediaList, mComparators.byAlbum);
+        Collections.sort(mediaList, MediaComparators.byAlbum);
         for (int i = 0; i < mediaList.size(); ++i) {
             Media media = mediaList.get(i);
             mAlbumsAdapter.add(media.getAlbum(), null, media);
         }
 
-        Collections.sort(mediaList, mComparators.byName);
+        Collections.sort(mediaList, MediaComparators.byName);
         for (int i = 0; i < mediaList.size(); ++i) {
             Media media = mediaList.get(i);
             mSongsAdapter.add(media.getTitle(), null, media);
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
index 04883ed..29b80e3 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -22,7 +22,6 @@ package org.videolan.vlc.gui.audio;
 
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.List;
 
 import org.videolan.libvlc.Media;
@@ -30,16 +29,13 @@ import org.videolan.vlc.AudioServiceController;
 import org.videolan.vlc.MediaLibrary;
 import org.videolan.vlc.R;
 import org.videolan.vlc.Util;
-import org.videolan.vlc.VlcRunnable;
 import org.videolan.vlc.WeakHandler;
-import org.videolan.vlc.gui.CommonDialogs;
 import org.videolan.vlc.gui.MainActivity;
 import org.videolan.vlc.interfaces.ISortable;
 import org.videolan.vlc.widget.FlingViewGroup;
 import org.videolan.vlc.widget.FlingViewGroup.ViewSwitchListener;
 import org.videolan.vlc.widget.HeaderScrollView;
 
-import android.app.AlertDialog;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Message;
@@ -346,8 +342,6 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
         }
     };
 
-    private static final MediaComparators mComparators = new MediaComparators();
-
     private void updateLists() {
         List<Media> audioList = MediaLibrary.getInstance(getActivity()).getAudioItems();
         mSongsAdapter.clear();
@@ -357,11 +351,11 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
 
         switch(mSortBy) {
         case SORT_BY_LENGTH:
-            Collections.sort(audioList, mComparators.byLength);
+            Collections.sort(audioList, MediaComparators.byLength);
             break;
         case SORT_BY_TITLE:
         default:
-            Collections.sort(audioList, mComparators.byName);
+            Collections.sort(audioList, MediaComparators.byName);
             break;
         }
         if(mSortReverse) {
@@ -374,21 +368,21 @@ public class AudioBrowserFragment extends SherlockFragment implements ISortable
         if (mSortBy != SORT_BY_LENGTH)
             mSongsAdapter.addSeparators();
 
-        Collections.sort(audioList, mComparators.byArtist);
+        Collections.sort(audioList, MediaComparators.byArtist);
         for (int i = 0; i < audioList.size(); i++) {
             Media media = audioList.get(i);
             mArtistsAdapter.add(media.getArtist(), null, media);
         }
         mArtistsAdapter.addSeparators();
 
-        Collections.sort(audioList, mComparators.byAlbum);
+        Collections.sort(audioList, MediaComparators.byAlbum);
         for (int i = 0; i < audioList.size(); i++) {
             Media media = audioList.get(i);
             mAlbumsAdapter.add(media.getAlbum(), null, media);
         }
         mAlbumsAdapter.addSeparators();
 
-        Collections.sort(audioList, mComparators.byGenre);
+        Collections.sort(audioList, MediaComparators.byGenre);
         for (int i = 0; i < audioList.size(); i++) {
             Media media = audioList.get(i);
             mGenresAdapter.add(media.getGenre(), null, media);
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayerFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayerFragment.java
index 04f558c..2538595 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayerFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayerFragment.java
@@ -320,8 +320,6 @@ public class AudioPlayerFragment extends SherlockFragment implements IAudioPlaye
         updateList();
     }
 
-    private static final MediaComparators mComparators = new MediaComparators();
-
     private void updateList() {
         List<Media> audioList;
         List<String> itemList;
@@ -335,11 +333,11 @@ public class AudioPlayerFragment extends SherlockFragment implements IAudioPlaye
         mSongsListAdapter.clear();
         switch (mSortBy) {
             case SORT_BY_LENGTH:
-                Collections.sort(audioList, mComparators.byLength);
+                Collections.sort(audioList, MediaComparators.byLength);
                 break;
             case SORT_BY_TITLE:
             default:
-                Collections.sort(audioList, mComparators.byMRL);
+                Collections.sort(audioList, MediaComparators.byMRL);
                 break;
         }
         if (mSortReverse) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/MediaComparators.java b/vlc-android/src/org/videolan/vlc/gui/audio/MediaComparators.java
index f5d9fd8..a49835d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/MediaComparators.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/MediaComparators.java
@@ -25,21 +25,21 @@ import org.videolan.libvlc.Media;
 
 public class MediaComparators {
 
-    public final Comparator<Media> byName = new Comparator<Media>() {
+    public static 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>() {
+    public static 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>() {
+    public static final Comparator<Media> byLength = new Comparator<Media>() {
         @Override
         public int compare(Media m1, Media m2) {
             if(m1.getLength() > m2.getLength()) return -1;
@@ -48,7 +48,7 @@ public class MediaComparators {
         };
     };
 
-    public final Comparator<Media> byAlbum = new Comparator<Media>() {
+    public static 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());
@@ -58,7 +58,7 @@ public class MediaComparators {
         };
     };
 
-    public final Comparator<Media> byArtist = new Comparator<Media>() {
+    public static 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());
@@ -68,7 +68,7 @@ public class MediaComparators {
         };
     };
 
-    public final Comparator<Media> byGenre = new Comparator<Media>() {
+    public static 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());



More information about the Android mailing list