diff --git a/src/com/fsck/k9/activity/ChooseFolder.java b/src/com/fsck/k9/activity/ChooseFolder.java index a5b8568fe..a5aa71849 100644 --- a/src/com/fsck/k9/activity/ChooseFolder.java +++ b/src/com/fsck/k9/activity/ChooseFolder.java @@ -296,7 +296,9 @@ public class ChooseFolder extends K9ListActivity { } Account.FolderMode aMode = mMode; Preferences prefs = Preferences.getPreferences(getApplication().getApplicationContext()); - ArrayList localFolders = new ArrayList(); + + List newFolders = new ArrayList(); + List topFolders = new ArrayList(); for (Folder folder : folders) { String name = folder.getName(); @@ -325,33 +327,34 @@ public class ChooseFolder extends K9ListActivity { folder.getName(), me); } - localFolders.add(folder.getName()); - + if (folder.isInTopGroup()) { + topFolders.add(name); + } else { + newFolders.add(name); + } } + final Comparator comparator = new Comparator() { + @Override + public int compare(String s1, String s2) { + int ret = s1.compareToIgnoreCase(s2); + return (ret != 0) ? ret : s1.compareTo(s2); + } + }; + + Collections.sort(topFolders, comparator); + Collections.sort(newFolders, comparator); + + List localFolders = new ArrayList(newFolders.size() + + topFolders.size() + ((mShowOptionNone) ? 1 : 0)); + if (mShowOptionNone) { localFolders.add(K9.FOLDER_NONE); } - Collections.sort(localFolders, new Comparator() { - @Override - public int compare(String aName, String bName) { - if (K9.FOLDER_NONE.equalsIgnoreCase(aName)) { - return -1; - } - if (K9.FOLDER_NONE.equalsIgnoreCase(bName)) { - return 1; - } - if (mAccount.getInboxFolderName().equalsIgnoreCase(aName)) { - return -1; - } - if (mAccount.getInboxFolderName().equalsIgnoreCase(bName)) { - return 1; - } + localFolders.addAll(topFolders); + localFolders.addAll(newFolders); - return aName.compareToIgnoreCase(bName); - } - }); int selectedFolder = -1; /*