1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-16 06:25:06 -05:00

Use account sort settings when filtering messages of only one account

This will use the account settings when viewing e.g. only the unread
messages in a folder.
This commit is contained in:
cketti 2012-05-15 08:09:28 +02:00
parent 6d19d9c829
commit c64c14c4a6

View File

@ -827,15 +827,18 @@ public class MessageList
mController.addListener(mAdapter.mListener); mController.addListener(mAdapter.mListener);
Account[] accountsWithNotification; Account[] accountsWithNotification;
if (mAccount != null) {
accountsWithNotification = new Account[] { mAccount }; Preferences prefs = Preferences.getPreferences(getApplicationContext());
mSortType = mAccount.getSortType(); Account account = getCurrentAccount(prefs);
mSortAscending = mAccount.isSortAscending(mSortType);
mSortDateAscending = mAccount.isSortAscending(SortType.SORT_DATE); if (account != null) {
accountsWithNotification = new Account[] { account };
mSortType = account.getSortType();
mSortAscending = account.isSortAscending(mSortType);
mSortDateAscending = account.isSortAscending(SortType.SORT_DATE);
} else { } else {
Preferences preferences = Preferences.getPreferences(this); accountsWithNotification = prefs.getAccounts();
accountsWithNotification = preferences.getAccounts(); mSortType = K9.getSortType();
mSortType = K9.getSortType(); // ASH
mSortAscending = K9.isSortAscending(mSortType); mSortAscending = K9.isSortAscending(mSortType);
mSortDateAscending = K9.isSortAscending(SortType.SORT_DATE); mSortDateAscending = K9.isSortAscending(SortType.SORT_DATE);
} }
@ -1203,17 +1206,20 @@ public class MessageList
onToggleSortAscending(); onToggleSortAscending();
} else { } else {
mSortType = sortType; mSortType = sortType;
if (mAccount != null) {
mAccount.setSortType(mSortType); Preferences prefs = Preferences.getPreferences(getApplicationContext());
mSortAscending = mAccount.isSortAscending(mSortType); Account account = getCurrentAccount(prefs);
mSortDateAscending = mAccount.isSortAscending(SortType.SORT_DATE);
mAccount.save(Preferences.getPreferences(this)); if (account != null) {
account.setSortType(mSortType);
mSortAscending = account.isSortAscending(mSortType);
mSortDateAscending = account.isSortAscending(SortType.SORT_DATE);
account.save(prefs);
} else { } else {
K9.setSortType(mSortType); K9.setSortType(mSortType);
mSortAscending = K9.isSortAscending(mSortType); mSortAscending = K9.isSortAscending(mSortType);
mSortDateAscending = K9.isSortAscending(SortType.SORT_DATE); mSortDateAscending = K9.isSortAscending(SortType.SORT_DATE);
Preferences prefs = Preferences.getPreferences(getApplicationContext());
Editor editor = prefs.getPreferences().edit(); Editor editor = prefs.getPreferences().edit();
K9.save(editor); K9.save(editor);
editor.commit(); editor.commit();
@ -2981,4 +2987,25 @@ public class MessageList
Accounts.listAccounts(this); Accounts.listAccounts(this);
} }
/**
* Return the currently "open" account if available.
*
* @param prefs
* A {@link Preferences} instance that might be used to retrieve the current
* {@link Account}.
*
* @return The {@code Account} all displayed messages belong to.
*/
private Account getCurrentAccount(Preferences prefs) {
Account account = null;
if (mQueryString != null && !mIntegrate && mAccountUuids != null &&
mAccountUuids.length == 1) {
String uuid = mAccountUuids[0];
account = prefs.getAccount(uuid);
} else if (mAccount != null) {
account = mAccount;
}
return account;
}
} }