1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-25 00:58:50 -05:00

Avoid NullPointerException in Accounts.onCreateDialog()

Also cleaned up code formatting of onCreateDialog() and
onPrepareDialog().
This commit is contained in:
cketti 2012-03-17 20:12:33 +01:00
parent ef01dc906b
commit 69ee6a4818

View File

@ -918,8 +918,14 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
@Override
public Dialog onCreateDialog(int id) {
// Android recreates our dialogs on configuration changes even when they have been
// dismissed. Make sure we have all information necessary before creating a new dialog.
switch (id) {
case DIALOG_REMOVE_ACCOUNT:
case DIALOG_REMOVE_ACCOUNT: {
if (mSelectedContextAccount == null) {
return null;
}
return ConfirmationDialog.create(this, id,
R.string.account_delete_dlg_title,
getString(R.string.account_delete_dlg_instructions_fmt,
@ -934,19 +940,24 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
try {
realAccount.getLocalStore().delete();
} catch (Exception e) {
// Ignore, this may lead to localStores on sd-cards that are
// currently not inserted to be left
// Ignore, this may lead to localStores on sd-cards that
// are currently not inserted to be left
}
MessagingController.getInstance(getApplication())
.notifyAccountCancel(Accounts.this, realAccount);
Preferences.getPreferences(Accounts.this).deleteAccount(realAccount);
Preferences.getPreferences(Accounts.this)
.deleteAccount(realAccount);
K9.setServicesEnabled(Accounts.this);
refresh();
}
}
});
}
case DIALOG_CLEAR_ACCOUNT: {
if (mSelectedContextAccount == null) {
return null;
}
case DIALOG_CLEAR_ACCOUNT:
return ConfirmationDialog.create(this, id,
R.string.account_clear_dlg_title,
getString(R.string.account_clear_dlg_instructions_fmt,
@ -958,13 +969,19 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
public void run() {
if (mSelectedContextAccount instanceof Account) {
Account realAccount = (Account) mSelectedContextAccount;
mHandler.workingAccount(realAccount, R.string.clearing_account);
MessagingController.getInstance(getApplication()).clear(realAccount, null);
mHandler.workingAccount(realAccount,
R.string.clearing_account);
MessagingController.getInstance(getApplication())
.clear(realAccount, null);
}
}
});
}
case DIALOG_RECREATE_ACCOUNT: {
if (mSelectedContextAccount == null) {
return null;
}
case DIALOG_RECREATE_ACCOUNT:
return ConfirmationDialog.create(this, id,
R.string.account_recreate_dlg_title,
getString(R.string.account_recreate_dlg_instructions_fmt,
@ -976,12 +993,15 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
public void run() {
if (mSelectedContextAccount instanceof Account) {
Account realAccount = (Account) mSelectedContextAccount;
mHandler.workingAccount(realAccount, R.string.recreating_account);
MessagingController.getInstance(getApplication()).recreate(realAccount, null);
mHandler.workingAccount(realAccount,
R.string.recreating_account);
MessagingController.getInstance(getApplication())
.recreate(realAccount, null);
}
}
});
case DIALOG_NO_FILE_MANAGER:
}
case DIALOG_NO_FILE_MANAGER: {
return ConfirmationDialog.create(this, id,
R.string.import_dialog_error_title,
getString(R.string.import_dialog_error_message),
@ -996,29 +1016,30 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
}
});
}
}
return super.onCreateDialog(id);
}
@Override
public void onPrepareDialog(int id, Dialog d) {
AlertDialog alert = (AlertDialog) d;
switch (id) {
case DIALOG_REMOVE_ACCOUNT:
case DIALOG_REMOVE_ACCOUNT: {
alert.setMessage(getString(R.string.account_delete_dlg_instructions_fmt,
mSelectedContextAccount.getDescription()));
break;
case DIALOG_CLEAR_ACCOUNT:
}
case DIALOG_CLEAR_ACCOUNT: {
alert.setMessage(getString(R.string.account_clear_dlg_instructions_fmt,
mSelectedContextAccount.getDescription()));
break;
case DIALOG_RECREATE_ACCOUNT:
}
case DIALOG_RECREATE_ACCOUNT: {
alert.setMessage(getString(R.string.account_recreate_dlg_instructions_fmt,
mSelectedContextAccount.getDescription()));
break;
case DIALOG_NO_FILE_MANAGER:
alert.setMessage(getString(R.string.import_dialog_error_message));
break;
}
}
super.onPrepareDialog(id, d);