mirror of https://github.com/M66B/FairEmail.git
Simplify rule ordering
This commit is contained in:
parent
58b8c071be
commit
e10329c6ca
|
@ -34,12 +34,8 @@ import androidx.recyclerview.widget.DiffUtil;
|
||||||
import androidx.recyclerview.widget.ListUpdateCallback;
|
import androidx.recyclerview.widget.ListUpdateCallback;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import java.text.Collator;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
|
public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
|
||||||
private Context context;
|
private Context context;
|
||||||
|
@ -105,19 +101,6 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
|
||||||
public void set(@NonNull List<TupleRuleEx> rules) {
|
public void set(@NonNull List<TupleRuleEx> rules) {
|
||||||
Log.i("Set rules=" + rules.size());
|
Log.i("Set rules=" + rules.size());
|
||||||
|
|
||||||
final Collator collator = Collator.getInstance(Locale.getDefault());
|
|
||||||
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
|
|
||||||
|
|
||||||
Collections.sort(rules, new Comparator<TupleRuleEx>() {
|
|
||||||
@Override
|
|
||||||
public int compare(TupleRuleEx r1, TupleRuleEx r2) {
|
|
||||||
int o = ((Integer) r1.order).compareTo(r2.order);
|
|
||||||
if (o != 0)
|
|
||||||
return 0;
|
|
||||||
return collator.compare(r1.name, r2.name);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(items, rules), false);
|
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(items, rules), false);
|
||||||
|
|
||||||
items = rules;
|
items = rules;
|
||||||
|
|
|
@ -31,13 +31,13 @@ import java.util.List;
|
||||||
public interface DaoRule {
|
public interface DaoRule {
|
||||||
@Query("SELECT * FROM rule" +
|
@Query("SELECT * FROM rule" +
|
||||||
" WHERE folder = :folder" +
|
" WHERE folder = :folder" +
|
||||||
" ORDER BY `order`, name")
|
" ORDER BY `order`, name COLLATE NOCASE")
|
||||||
List<EntityRule> getRules(long folder);
|
List<EntityRule> getRules(long folder);
|
||||||
|
|
||||||
@Query("SELECT * FROM rule" +
|
@Query("SELECT * FROM rule" +
|
||||||
" WHERE folder = :folder" +
|
" WHERE folder = :folder" +
|
||||||
" AND enabled" +
|
" AND enabled" +
|
||||||
" ORDER BY `order`, name")
|
" ORDER BY `order`, name COLLATE NOCASE")
|
||||||
List<EntityRule> getEnabledRules(long folder);
|
List<EntityRule> getEnabledRules(long folder);
|
||||||
|
|
||||||
@Query("SELECT rule.*, folder.account, folder.name AS folderName, account.name AS accountName FROM rule" +
|
@Query("SELECT rule.*, folder.account, folder.name AS folderName, account.name AS accountName FROM rule" +
|
||||||
|
@ -50,7 +50,7 @@ public interface DaoRule {
|
||||||
" JOIN folder ON folder.id = rule.folder" +
|
" JOIN folder ON folder.id = rule.folder" +
|
||||||
" JOIN account ON account.id = folder.account" +
|
" JOIN account ON account.id = folder.account" +
|
||||||
" WHERE rule.folder = :folder" +
|
" WHERE rule.folder = :folder" +
|
||||||
" ORDER BY `order`, name")
|
" ORDER BY `order`, name COLLATE NOCASE")
|
||||||
LiveData<List<TupleRuleEx>> liveRules(long folder);
|
LiveData<List<TupleRuleEx>> liveRules(long folder);
|
||||||
|
|
||||||
@Insert
|
@Insert
|
||||||
|
|
Loading…
Reference in New Issue