aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/github
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2016-03-15 17:20:00 -0700
committerScott Jackson <daneren2005@gmail.com>2016-03-15 17:20:00 -0700
commit1bd7596ce4a901aaba1e2cc28e90d518bfb43029 (patch)
tree56f40d9292bdc4fedfbdc7cd30feafb2135ca06f /app/src/main/java/github
parenta9fd0ce825e3b6e305c03400865021ba9a3e906a (diff)
downloaddsub-1bd7596ce4a901aaba1e2cc28e90d518bfb43029.tar.gz
dsub-1bd7596ce4a901aaba1e2cc28e90d518bfb43029.tar.bz2
dsub-1bd7596ce4a901aaba1e2cc28e90d518bfb43029.zip
Use Collators to make sure special characters are sorted correctly
Diffstat (limited to 'app/src/main/java/github')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/domain/Artist.java16
-rw-r--r--app/src/main/java/github/daneren2005/dsub/domain/MusicDirectory.java12
2 files changed, 15 insertions, 13 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/domain/Artist.java b/app/src/main/java/github/daneren2005/dsub/domain/Artist.java
index fddafd65..5809146d 100644
--- a/app/src/main/java/github/daneren2005/dsub/domain/Artist.java
+++ b/app/src/main/java/github/daneren2005/dsub/domain/Artist.java
@@ -21,9 +21,11 @@ package github.daneren2005.dsub.domain;
import android.util.Log;
import java.io.Serializable;
+import java.text.Collator;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
+import java.util.Locale;
/**
* @author Sindre Mehus
@@ -119,9 +121,12 @@ public class Artist implements Serializable {
public static class ArtistComparator implements Comparator<Artist> {
private String[] ignoredArticles;
+ private Collator collator;
public ArtistComparator(String[] ignoredArticles) {
this.ignoredArticles = ignoredArticles;
+ this.collator = Collator.getInstance(Locale.US);
+ this.collator.setStrength(Collator.PRIMARY);
}
public int compare(Artist lhsArtist, Artist rhsArtist) {
@@ -134,15 +139,6 @@ public class Artist implements Serializable {
String lhs = lhsArtist.getName().toLowerCase();
String rhs = rhsArtist.getName().toLowerCase();
- char lhs1 = lhs.charAt(0);
- char rhs1 = rhs.charAt(0);
-
- if (Character.isDigit(lhs1) && !Character.isDigit(rhs1)) {
- return -1;
- } else if (Character.isDigit(rhs1) && !Character.isDigit(lhs1)) {
- return 1;
- }
-
for (String article : ignoredArticles) {
int index = lhs.indexOf(article.toLowerCase() + " ");
if (index == 0) {
@@ -154,7 +150,7 @@ public class Artist implements Serializable {
}
}
- return lhs.compareTo(rhs);
+ return collator.compare(lhs, rhs);
}
}
diff --git a/app/src/main/java/github/daneren2005/dsub/domain/MusicDirectory.java b/app/src/main/java/github/daneren2005/dsub/domain/MusicDirectory.java
index cd84c0a3..4df56022 100644
--- a/app/src/main/java/github/daneren2005/dsub/domain/MusicDirectory.java
+++ b/app/src/main/java/github/daneren2005/dsub/domain/MusicDirectory.java
@@ -24,6 +24,8 @@ import android.content.SharedPreferences;
import android.media.MediaMetadataRetriever;
import android.os.Build;
import android.util.Log;
+
+import java.text.Collator;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -31,6 +33,7 @@ import java.io.File;
import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
+import java.util.Locale;
import github.daneren2005.dsub.service.DownloadService;
import github.daneren2005.dsub.util.Constants;
@@ -617,9 +620,12 @@ public class MusicDirectory implements Serializable {
public static class EntryComparator implements Comparator<Entry> {
private boolean byYear;
+ private Collator collator;
public EntryComparator(boolean byYear) {
this.byYear = byYear;
+ this.collator = Collator.getInstance(Locale.US);
+ this.collator.setStrength(Collator.PRIMARY);
}
public int compare(Entry lhs, Entry rhs) {
@@ -639,8 +645,8 @@ public class MusicDirectory implements Serializable {
return 1;
}
}
-
- return lhs.getAlbumDisplay().compareToIgnoreCase(rhs.getAlbumDisplay());
+
+ return collator.compare(lhs.getAlbumDisplay(), rhs.getAlbumDisplay());
}
Integer lhsDisc = lhs.getDiscNumber();
@@ -664,7 +670,7 @@ public class MusicDirectory implements Serializable {
return 1;
}
- return lhs.getTitle().compareToIgnoreCase(rhs.getTitle());
+ return collator.compare(lhs.getTitle(), rhs.getTitle());
}
public static void sort(List<Entry> entries) {