Some order

This commit is contained in:
M66B
2019-05-06 22:34:18 +02:00
parent 1f8a472131
commit 567aeffe46
20 changed files with 278 additions and 152 deletions

View File

@@ -34,6 +34,9 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
import java.text.Collator;
import java.util.Comparator;
import java.util.Locale;
import java.util.Objects;
@Entity(
@@ -123,11 +126,6 @@ public class EntityAccount extends EntityOrder implements Serializable {
return id;
}
@Override
String getSortKey(Context context) {
return name;
}
@Override
String[] getSortTitle(Context context) {
return new String[]{name, null};
@@ -238,6 +236,30 @@ public class EntityAccount extends EntityOrder implements Serializable {
return false;
}
@Override
Comparator getComparator(final Context context) {
final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
return new Comparator() {
@Override
public int compare(Object o1, Object o2) {
EntityAccount a1 = (EntityAccount) o1;
EntityAccount a2 = (EntityAccount) o2;
int o = Integer.compare(
a1.order == null ? -1 : a1.order,
a2.order == null ? -1 : a2.order);
if (o != 0)
return o;
String name1 = (a1.name == null ? "" : a1.name);
String name2 = (a2.name == null ? "" : a2.name);
return collator.compare(name1, name2);
}
};
}
@NonNull
@Override
public String toString() {