aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/domain/MusicFolder.java49
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/CachedMusicService.java4
2 files changed, 40 insertions, 13 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/domain/MusicFolder.java b/app/src/main/java/github/daneren2005/dsub/domain/MusicFolder.java
index 12ca5909..37f76249 100644
--- a/app/src/main/java/github/daneren2005/dsub/domain/MusicFolder.java
+++ b/app/src/main/java/github/daneren2005/dsub/domain/MusicFolder.java
@@ -18,7 +18,12 @@
*/
package github.daneren2005.dsub.domain;
+import android.util.Log;
+
import java.io.Serializable;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
/**
* Represents a top level directory in which music or other media is stored.
@@ -27,26 +32,26 @@ import java.io.Serializable;
* @version $Id$
*/
public class MusicFolder implements Serializable {
-
- private String id;
- private String name;
+ private static final String TAG = MusicFolder.class.getSimpleName();
+ private String id;
+ private String name;
private boolean enabled;
public MusicFolder() {
}
- public MusicFolder(String id, String name) {
- this.id = id;
- this.name = name;
- }
+ public MusicFolder(String id, String name) {
+ this.id = id;
+ this.name = name;
+ }
- public String getId() {
- return id;
- }
+ public String getId() {
+ return id;
+ }
- public String getName() {
- return name;
- }
+ public String getName() {
+ return name;
+ }
public void setEnabled(boolean enabled) {
this.enabled = enabled;
@@ -54,4 +59,22 @@ public class MusicFolder implements Serializable {
public boolean getEnabled() {
return enabled;
}
+
+ public static class MusicFolderComparator implements Comparator<MusicFolder> {
+ public int compare(MusicFolder lhsMusicFolder, MusicFolder rhsMusicFolder) {
+ if(lhsMusicFolder == rhsMusicFolder || lhsMusicFolder.getName().equals(rhsMusicFolder.getName())) {
+ return 0;
+ } else {
+ return lhsMusicFolder.getName().compareToIgnoreCase(rhsMusicFolder.getName());
+ }
+ }
+ }
+
+ public static void sort(List<MusicFolder> musicFolders) {
+ try {
+ Collections.sort(musicFolders, new MusicFolderComparator());
+ } catch (Exception e) {
+ Log.w(TAG, "Failed to sort music folders", e);
+ }
+ }
}
diff --git a/app/src/main/java/github/daneren2005/dsub/service/CachedMusicService.java b/app/src/main/java/github/daneren2005/dsub/service/CachedMusicService.java
index 52268d82..3be04cff 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/CachedMusicService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/CachedMusicService.java
@@ -22,6 +22,8 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
@@ -130,6 +132,8 @@ public class CachedMusicService implements MusicService {
result = musicService.getMusicFolders(refresh, context, progressListener);
FileUtil.serialize(context, new ArrayList<MusicFolder>(result), getCacheName(context, "musicFolders"));
}
+
+ MusicFolder.sort(result);
cachedMusicFolders.set(result);
}
return result;