mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-25 09:08:49 -05:00
Avoid NullPointerException in Accounts.onCreateDialog()
Also cleaned up code formatting of onCreateDialog() and onPrepareDialog().
This commit is contained in:
parent
ef01dc906b
commit
69ee6a4818
@ -918,8 +918,14 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Dialog onCreateDialog(int id) {
|
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) {
|
switch (id) {
|
||||||
case DIALOG_REMOVE_ACCOUNT:
|
case DIALOG_REMOVE_ACCOUNT: {
|
||||||
|
if (mSelectedContextAccount == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return ConfirmationDialog.create(this, id,
|
return ConfirmationDialog.create(this, id,
|
||||||
R.string.account_delete_dlg_title,
|
R.string.account_delete_dlg_title,
|
||||||
getString(R.string.account_delete_dlg_instructions_fmt,
|
getString(R.string.account_delete_dlg_instructions_fmt,
|
||||||
@ -934,19 +940,24 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
|
|||||||
try {
|
try {
|
||||||
realAccount.getLocalStore().delete();
|
realAccount.getLocalStore().delete();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Ignore, this may lead to localStores on sd-cards that are
|
// Ignore, this may lead to localStores on sd-cards that
|
||||||
// currently not inserted to be left
|
// are currently not inserted to be left
|
||||||
}
|
}
|
||||||
MessagingController.getInstance(getApplication())
|
MessagingController.getInstance(getApplication())
|
||||||
.notifyAccountCancel(Accounts.this, realAccount);
|
.notifyAccountCancel(Accounts.this, realAccount);
|
||||||
Preferences.getPreferences(Accounts.this).deleteAccount(realAccount);
|
Preferences.getPreferences(Accounts.this)
|
||||||
|
.deleteAccount(realAccount);
|
||||||
K9.setServicesEnabled(Accounts.this);
|
K9.setServicesEnabled(Accounts.this);
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
case DIALOG_CLEAR_ACCOUNT: {
|
||||||
|
if (mSelectedContextAccount == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
case DIALOG_CLEAR_ACCOUNT:
|
|
||||||
return ConfirmationDialog.create(this, id,
|
return ConfirmationDialog.create(this, id,
|
||||||
R.string.account_clear_dlg_title,
|
R.string.account_clear_dlg_title,
|
||||||
getString(R.string.account_clear_dlg_instructions_fmt,
|
getString(R.string.account_clear_dlg_instructions_fmt,
|
||||||
@ -958,13 +969,19 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
|
|||||||
public void run() {
|
public void run() {
|
||||||
if (mSelectedContextAccount instanceof Account) {
|
if (mSelectedContextAccount instanceof Account) {
|
||||||
Account realAccount = (Account) mSelectedContextAccount;
|
Account realAccount = (Account) mSelectedContextAccount;
|
||||||
mHandler.workingAccount(realAccount, R.string.clearing_account);
|
mHandler.workingAccount(realAccount,
|
||||||
MessagingController.getInstance(getApplication()).clear(realAccount, null);
|
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,
|
return ConfirmationDialog.create(this, id,
|
||||||
R.string.account_recreate_dlg_title,
|
R.string.account_recreate_dlg_title,
|
||||||
getString(R.string.account_recreate_dlg_instructions_fmt,
|
getString(R.string.account_recreate_dlg_instructions_fmt,
|
||||||
@ -976,12 +993,15 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
|
|||||||
public void run() {
|
public void run() {
|
||||||
if (mSelectedContextAccount instanceof Account) {
|
if (mSelectedContextAccount instanceof Account) {
|
||||||
Account realAccount = (Account) mSelectedContextAccount;
|
Account realAccount = (Account) mSelectedContextAccount;
|
||||||
mHandler.workingAccount(realAccount, R.string.recreating_account);
|
mHandler.workingAccount(realAccount,
|
||||||
MessagingController.getInstance(getApplication()).recreate(realAccount, null);
|
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,
|
return ConfirmationDialog.create(this, id,
|
||||||
R.string.import_dialog_error_title,
|
R.string.import_dialog_error_title,
|
||||||
getString(R.string.import_dialog_error_message),
|
getString(R.string.import_dialog_error_message),
|
||||||
@ -996,29 +1016,30 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return super.onCreateDialog(id);
|
return super.onCreateDialog(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPrepareDialog(int id, Dialog d) {
|
public void onPrepareDialog(int id, Dialog d) {
|
||||||
|
|
||||||
AlertDialog alert = (AlertDialog) d;
|
AlertDialog alert = (AlertDialog) d;
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case DIALOG_REMOVE_ACCOUNT:
|
case DIALOG_REMOVE_ACCOUNT: {
|
||||||
alert.setMessage(getString(R.string.account_delete_dlg_instructions_fmt,
|
alert.setMessage(getString(R.string.account_delete_dlg_instructions_fmt,
|
||||||
mSelectedContextAccount.getDescription()));
|
mSelectedContextAccount.getDescription()));
|
||||||
break;
|
break;
|
||||||
case DIALOG_CLEAR_ACCOUNT:
|
}
|
||||||
|
case DIALOG_CLEAR_ACCOUNT: {
|
||||||
alert.setMessage(getString(R.string.account_clear_dlg_instructions_fmt,
|
alert.setMessage(getString(R.string.account_clear_dlg_instructions_fmt,
|
||||||
mSelectedContextAccount.getDescription()));
|
mSelectedContextAccount.getDescription()));
|
||||||
break;
|
break;
|
||||||
case DIALOG_RECREATE_ACCOUNT:
|
}
|
||||||
|
case DIALOG_RECREATE_ACCOUNT: {
|
||||||
alert.setMessage(getString(R.string.account_recreate_dlg_instructions_fmt,
|
alert.setMessage(getString(R.string.account_recreate_dlg_instructions_fmt,
|
||||||
mSelectedContextAccount.getDescription()));
|
mSelectedContextAccount.getDescription()));
|
||||||
break;
|
break;
|
||||||
case DIALOG_NO_FILE_MANAGER:
|
}
|
||||||
alert.setMessage(getString(R.string.import_dialog_error_message));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
super.onPrepareDialog(id, d);
|
super.onPrepareDialog(id, d);
|
||||||
|
Loading…
Reference in New Issue
Block a user