Refactoring

pull/146/head
M66B 6 years ago
parent f8150f18b5
commit 13d9eb6e4f

@ -1350,22 +1350,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
if (!f.id.equals(message.folder) && !EntityFolder.DRAFTS.equals(f.type))
targets.add(f);
final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
Collections.sort(targets, new Comparator<EntityFolder>() {
@Override
public int compare(EntityFolder f1, EntityFolder f2) {
int s = Integer.compare(
EntityFolder.FOLDER_SORT_ORDER.indexOf(f1.type),
EntityFolder.FOLDER_SORT_ORDER.indexOf(f2.type));
if (s != 0)
return s;
return collator.compare(
f1.name == null ? "" : f1.name,
f2.name == null ? "" : f2.name);
}
});
EntityFolder.sort(targets);
return targets;
}

@ -23,8 +23,12 @@ import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
import java.text.Collator;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import androidx.annotation.NonNull;
import androidx.room.Entity;
@ -194,4 +198,26 @@ public class EntityFolder implements Serializable {
folder.unified = json.getBoolean("unified");
return folder;
}
static void sort(List<EntityFolder> folders) {
final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
Collections.sort(folders, new Comparator<EntityFolder>() {
@Override
public int compare(EntityFolder f1, EntityFolder f2) {
int s = Integer.compare(
EntityFolder.FOLDER_SORT_ORDER.indexOf(f1.type),
EntityFolder.FOLDER_SORT_ORDER.indexOf(f2.type));
if (s != 0)
return s;
int c = -f1.synchronize.compareTo(f2.synchronize);
if (c != 0)
return c;
return collator.compare(
f1.name == null ? "" : f1.name,
f2.name == null ? "" : f2.name);
}
});
}
}

@ -68,13 +68,9 @@ import org.xbill.DNS.Record;
import org.xbill.DNS.SRVRecord;
import org.xbill.DNS.Type;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import javax.mail.AuthenticationFailedException;
@ -1082,25 +1078,7 @@ public class FragmentAccount extends FragmentEx {
}
private void setFolders(List<EntityFolder> folders) {
final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
Collections.sort(folders, new Comparator<EntityFolder>() {
@Override
public int compare(EntityFolder f1, EntityFolder f2) {
int s = Integer.compare(
EntityFolder.FOLDER_SORT_ORDER.indexOf(f1.type),
EntityFolder.FOLDER_SORT_ORDER.indexOf(f2.type));
if (s != 0)
return s;
int c = -f1.synchronize.compareTo(f2.synchronize);
if (c != 0)
return c;
return collator.compare(
f1.name == null ? "" : f1.name,
f2.name == null ? "" : f2.name);
}
});
EntityFolder.sort(folders);
EntityFolder none = new EntityFolder();
none.name = "";

@ -56,12 +56,8 @@ import org.xbill.DNS.Record;
import org.xbill.DNS.SRVRecord;
import org.xbill.DNS.Type;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import javax.mail.AuthenticationFailedException;
@ -771,25 +767,7 @@ public class FragmentIdentity extends FragmentEx {
result.identity = db.identity().getIdentity(iid);
result.folders = db.folder().getFolders(aid);
final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
Collections.sort(result.folders, new Comparator<EntityFolder>() {
@Override
public int compare(EntityFolder f1, EntityFolder f2) {
int s = Integer.compare(
EntityFolder.FOLDER_SORT_ORDER.indexOf(f1.type),
EntityFolder.FOLDER_SORT_ORDER.indexOf(f2.type));
if (s != 0)
return s;
int c = -f1.synchronize.compareTo(f2.synchronize);
if (c != 0)
return c;
return collator.compare(
f1.name == null ? "" : f1.name,
f2.name == null ? "" : f2.name);
}
});
EntityFolder.sort(result.folders);
return result;
}

@ -45,12 +45,8 @@ import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import java.io.Serializable;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -591,22 +587,7 @@ public class FragmentMessages extends FragmentEx {
if (!f.id.equals(folder) && !EntityFolder.DRAFTS.equals(f.type))
targets.add(f);
final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
Collections.sort(targets, new Comparator<EntityFolder>() {
@Override
public int compare(EntityFolder f1, EntityFolder f2) {
int s = Integer.compare(
EntityFolder.FOLDER_SORT_ORDER.indexOf(f1.type),
EntityFolder.FOLDER_SORT_ORDER.indexOf(f2.type));
if (s != 0)
return s;
return collator.compare(
f1.name == null ? "" : f1.name,
f2.name == null ? "" : f2.name);
}
});
EntityFolder.sort(targets);
return targets;
}

Loading…
Cancel
Save