mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-25 09:08:49 -05:00
Creating and initializing special accounts in Accounts activity to avoid NullPointerException when it's resumed. Constant added to represent the number of special accounts.
This commit is contained in:
parent
02b07f34a1
commit
e766f75da2
@ -106,6 +106,11 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
|
|||||||
*/
|
*/
|
||||||
private static final Flag[] EMPTY_FLAG_ARRAY = new Flag[0];
|
private static final Flag[] EMPTY_FLAG_ARRAY = new Flag[0];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Number of special accounts ('Unified Inbox' and 'All Messages')
|
||||||
|
*/
|
||||||
|
private static final int SPECIAL_ACCOUNTS_COUNT = 2;
|
||||||
|
|
||||||
private static final int DIALOG_REMOVE_ACCOUNT = 1;
|
private static final int DIALOG_REMOVE_ACCOUNT = 1;
|
||||||
private static final int DIALOG_CLEAR_ACCOUNT = 2;
|
private static final int DIALOG_CLEAR_ACCOUNT = 2;
|
||||||
private static final int DIALOG_RECREATE_ACCOUNT = 3;
|
private static final int DIALOG_RECREATE_ACCOUNT = 3;
|
||||||
@ -325,13 +330,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
|
|||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
|
|
||||||
if (!K9.isHideSpecialAccounts()) {
|
if (!K9.isHideSpecialAccounts()) {
|
||||||
unreadAccount = new SearchAccount(this, false, null, null);
|
createSpecialAccounts();
|
||||||
unreadAccount.setDescription(getString(R.string.search_all_messages_title));
|
|
||||||
unreadAccount.setEmail(getString(R.string.search_all_messages_detail));
|
|
||||||
|
|
||||||
integratedInboxAccount = new SearchAccount(this, true, null, null);
|
|
||||||
integratedInboxAccount.setDescription(getString(R.string.integrated_inbox_title));
|
|
||||||
integratedInboxAccount.setEmail(getString(R.string.integrated_inbox_detail));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Account[] accounts = Preferences.getPreferences(this).getAccounts();
|
Account[] accounts = Preferences.getPreferences(this).getAccounts();
|
||||||
@ -374,6 +373,19 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates and initializes the special accounts ('Integrated Inbox' and 'All Messages')
|
||||||
|
*/
|
||||||
|
private void createSpecialAccounts() {
|
||||||
|
unreadAccount = new SearchAccount(this, false, null, null);
|
||||||
|
unreadAccount.setDescription(getString(R.string.search_all_messages_title));
|
||||||
|
unreadAccount.setEmail(getString(R.string.search_all_messages_detail));
|
||||||
|
|
||||||
|
integratedInboxAccount = new SearchAccount(this, true, null, null);
|
||||||
|
integratedInboxAccount.setDescription(getString(R.string.integrated_inbox_title));
|
||||||
|
integratedInboxAccount.setEmail(getString(R.string.integrated_inbox_detail));
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void restoreAccountStats(Bundle icicle) {
|
private void restoreAccountStats(Bundle icicle) {
|
||||||
if (icicle != null) {
|
if (icicle != null) {
|
||||||
@ -458,9 +470,13 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
|
|||||||
accounts = Preferences.getPreferences(this).getAccounts();
|
accounts = Preferences.getPreferences(this).getAccounts();
|
||||||
|
|
||||||
List<BaseAccount> newAccounts;
|
List<BaseAccount> newAccounts;
|
||||||
if (!K9.isHideSpecialAccounts()
|
if (!K9.isHideSpecialAccounts() && accounts.length > 0) {
|
||||||
&& accounts.length > 0) {
|
if (integratedInboxAccount == null || unreadAccount == null) {
|
||||||
newAccounts = new ArrayList<BaseAccount>(accounts.length + 2);
|
createSpecialAccounts();
|
||||||
|
}
|
||||||
|
|
||||||
|
newAccounts = new ArrayList<BaseAccount>(accounts.length +
|
||||||
|
SPECIAL_ACCOUNTS_COUNT);
|
||||||
newAccounts.add(integratedInboxAccount);
|
newAccounts.add(integratedInboxAccount);
|
||||||
newAccounts.add(unreadAccount);
|
newAccounts.add(unreadAccount);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user