Label sort should be alphabetical and locale-sensitive (#74)

Doing ascii sort on natural language text will result in unexpected sorting. ie: Lowercase words being sorted after uppercase block or accents messing ordering.
This commit is contained in:
Carlos Melero 2017-11-30 07:10:08 +01:00 committed by Jakob Nixdorf
parent 467540e488
commit d671b99704

View file

@ -51,6 +51,7 @@ import org.shadowice.flocke.andotp.R;
import static org.shadowice.flocke.andotp.Utilities.Settings.SortMode; import static org.shadowice.flocke.andotp.Utilities.Settings.SortMode;
import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
@ -438,9 +439,16 @@ public class EntriesCardAdapter extends RecyclerView.Adapter<EntryViewHolder>
} }
public class LabelComparator implements Comparator<Entry> { public class LabelComparator implements Comparator<Entry> {
Collator collator;
LabelComparator(){
collator = Collator.getInstance();
collator.setStrength(Collator.PRIMARY);
}
@Override @Override
public int compare(Entry o1, Entry o2) { public int compare(Entry o1, Entry o2) {
return o1.getLabel().compareTo(o2.getLabel()); return collator.compare(o1.getLabel(), o2.getLabel());
} }
} }