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:
parent
ef01dc906b
commit
69ee6a4818
@ -918,107 +918,128 @@ 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: {
|
||||||
return ConfirmationDialog.create(this, id,
|
if (mSelectedContextAccount == null) {
|
||||||
R.string.account_delete_dlg_title,
|
return null;
|
||||||
getString(R.string.account_delete_dlg_instructions_fmt,
|
|
||||||
mSelectedContextAccount.getDescription()),
|
|
||||||
R.string.okay_action,
|
|
||||||
R.string.cancel_action,
|
|
||||||
new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (mSelectedContextAccount instanceof Account) {
|
|
||||||
Account realAccount = (Account)mSelectedContextAccount;
|
|
||||||
try {
|
|
||||||
realAccount.getLocalStore().delete();
|
|
||||||
} catch (Exception e) {
|
|
||||||
// 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);
|
|
||||||
K9.setServicesEnabled(Accounts.this);
|
|
||||||
refresh();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
case DIALOG_CLEAR_ACCOUNT:
|
return ConfirmationDialog.create(this, id,
|
||||||
return ConfirmationDialog.create(this, id,
|
R.string.account_delete_dlg_title,
|
||||||
R.string.account_clear_dlg_title,
|
getString(R.string.account_delete_dlg_instructions_fmt,
|
||||||
getString(R.string.account_clear_dlg_instructions_fmt,
|
mSelectedContextAccount.getDescription()),
|
||||||
mSelectedContextAccount.getDescription()),
|
R.string.okay_action,
|
||||||
R.string.okay_action,
|
R.string.cancel_action,
|
||||||
R.string.cancel_action,
|
new Runnable() {
|
||||||
new Runnable() {
|
@Override
|
||||||
@Override
|
public void run() {
|
||||||
public void run() {
|
if (mSelectedContextAccount instanceof Account) {
|
||||||
if (mSelectedContextAccount instanceof Account) {
|
Account realAccount = (Account) mSelectedContextAccount;
|
||||||
Account realAccount = (Account)mSelectedContextAccount;
|
try {
|
||||||
mHandler.workingAccount(realAccount, R.string.clearing_account);
|
realAccount.getLocalStore().delete();
|
||||||
MessagingController.getInstance(getApplication()).clear(realAccount, null);
|
} catch (Exception e) {
|
||||||
}
|
// 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);
|
||||||
|
K9.setServicesEnabled(Accounts.this);
|
||||||
|
refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
case DIALOG_CLEAR_ACCOUNT: {
|
||||||
|
if (mSelectedContextAccount == null) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
case DIALOG_RECREATE_ACCOUNT:
|
return ConfirmationDialog.create(this, id,
|
||||||
return ConfirmationDialog.create(this, id,
|
R.string.account_clear_dlg_title,
|
||||||
R.string.account_recreate_dlg_title,
|
getString(R.string.account_clear_dlg_instructions_fmt,
|
||||||
getString(R.string.account_recreate_dlg_instructions_fmt,
|
mSelectedContextAccount.getDescription()),
|
||||||
mSelectedContextAccount.getDescription()),
|
R.string.okay_action,
|
||||||
R.string.okay_action,
|
R.string.cancel_action,
|
||||||
R.string.cancel_action,
|
new Runnable() {
|
||||||
new Runnable() {
|
@Override
|
||||||
@Override
|
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,
|
||||||
mHandler.workingAccount(realAccount, R.string.recreating_account);
|
R.string.clearing_account);
|
||||||
MessagingController.getInstance(getApplication()).recreate(realAccount, null);
|
MessagingController.getInstance(getApplication())
|
||||||
}
|
.clear(realAccount, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
case DIALOG_RECREATE_ACCOUNT: {
|
||||||
|
if (mSelectedContextAccount == null) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
case DIALOG_NO_FILE_MANAGER:
|
return ConfirmationDialog.create(this, id,
|
||||||
return ConfirmationDialog.create(this, id,
|
R.string.account_recreate_dlg_title,
|
||||||
R.string.import_dialog_error_title,
|
getString(R.string.account_recreate_dlg_instructions_fmt,
|
||||||
getString(R.string.import_dialog_error_message),
|
mSelectedContextAccount.getDescription()),
|
||||||
R.string.open_market,
|
R.string.okay_action,
|
||||||
R.string.close,
|
R.string.cancel_action,
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Uri uri = Uri.parse(ANDROID_MARKET_URL);
|
if (mSelectedContextAccount instanceof Account) {
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
Account realAccount = (Account) mSelectedContextAccount;
|
||||||
startActivity(intent);
|
mHandler.workingAccount(realAccount,
|
||||||
}
|
R.string.recreating_account);
|
||||||
});
|
MessagingController.getInstance(getApplication())
|
||||||
|
.recreate(realAccount, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
case DIALOG_NO_FILE_MANAGER: {
|
||||||
|
return ConfirmationDialog.create(this, id,
|
||||||
|
R.string.import_dialog_error_title,
|
||||||
|
getString(R.string.import_dialog_error_message),
|
||||||
|
R.string.open_market,
|
||||||
|
R.string.close,
|
||||||
|
new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Uri uri = Uri.parse(ANDROID_MARKET_URL);
|
||||||
|
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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:
|
}
|
||||||
alert.setMessage(getString(R.string.account_clear_dlg_instructions_fmt,
|
case DIALOG_CLEAR_ACCOUNT: {
|
||||||
mSelectedContextAccount.getDescription()));
|
alert.setMessage(getString(R.string.account_clear_dlg_instructions_fmt,
|
||||||
break;
|
mSelectedContextAccount.getDescription()));
|
||||||
case DIALOG_RECREATE_ACCOUNT:
|
break;
|
||||||
alert.setMessage(getString(R.string.account_recreate_dlg_instructions_fmt,
|
}
|
||||||
mSelectedContextAccount.getDescription()));
|
case DIALOG_RECREATE_ACCOUNT: {
|
||||||
break;
|
alert.setMessage(getString(R.string.account_recreate_dlg_instructions_fmt,
|
||||||
case DIALOG_NO_FILE_MANAGER:
|
mSelectedContextAccount.getDescription()));
|
||||||
alert.setMessage(getString(R.string.import_dialog_error_message));
|
break;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
super.onPrepareDialog(id, d);
|
super.onPrepareDialog(id, d);
|
||||||
|
Loading…
Reference in New Issue
Block a user