Converted some more confirmation dialogs to use ConfirmationDialog

This commit is contained in:
cketti 2011-04-01 03:40:08 +02:00
parent ac148a1ef7
commit ea9213cd4d
2 changed files with 76 additions and 122 deletions

View File

@ -456,11 +456,67 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
public Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_REMOVE_ACCOUNT:
return createRemoveAccountDialog();
return ConfirmationDialog.create(this, id,
R.string.account_delete_dlg_title,
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 createClearAccountDialog();
return ConfirmationDialog.create(this, id,
R.string.account_clear_dlg_title,
getString(R.string.account_clear_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;
mHandler.workingAccount(realAccount, R.string.clearing_account);
MessagingController.getInstance(getApplication()).clear(realAccount, null);
}
}
});
case DIALOG_RECREATE_ACCOUNT:
return createRecreateAccountDialog();
return ConfirmationDialog.create(this, id,
R.string.account_recreate_dlg_title,
getString(R.string.account_recreate_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;
mHandler.workingAccount(realAccount, R.string.recreating_account);
MessagingController.getInstance(getApplication()).recreate(realAccount, null);
}
}
});
}
return super.onCreateDialog(id);
}
@ -487,89 +543,6 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
super.onPrepareDialog(id, d);
}
private Dialog createRemoveAccountDialog() {
return new AlertDialog.Builder(this)
.setTitle(R.string.account_delete_dlg_title)
.setMessage(getString(R.string.account_delete_dlg_instructions_fmt, mSelectedContextAccount.getDescription()))
.setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dismissDialog(DIALOG_REMOVE_ACCOUNT);
removeDialog(DIALOG_REMOVE_ACCOUNT);
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();
}
}
})
.setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dismissDialog(DIALOG_REMOVE_ACCOUNT);
removeDialog(DIALOG_REMOVE_ACCOUNT);
}
})
.create();
}
private Dialog createClearAccountDialog() {
return new AlertDialog.Builder(this)
.setTitle(R.string.account_clear_dlg_title)
.setMessage(getString(R.string.account_clear_dlg_instructions_fmt, mSelectedContextAccount.getDescription()))
.setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dismissDialog(DIALOG_CLEAR_ACCOUNT);
removeDialog(DIALOG_CLEAR_ACCOUNT);
if (mSelectedContextAccount instanceof Account) {
Account realAccount = (Account)mSelectedContextAccount;
mHandler.workingAccount(realAccount, R.string.clearing_account);
MessagingController.getInstance(getApplication()).clear(realAccount, null);
}
}
})
.setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dismissDialog(DIALOG_CLEAR_ACCOUNT);
removeDialog(DIALOG_CLEAR_ACCOUNT);
}
})
.create();
}
private Dialog createRecreateAccountDialog() {
return new AlertDialog.Builder(this)
.setTitle(R.string.account_recreate_dlg_title)
.setMessage(getString(R.string.account_recreate_dlg_instructions_fmt, mSelectedContextAccount.getDescription()))
.setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dismissDialog(DIALOG_RECREATE_ACCOUNT);
removeDialog(DIALOG_RECREATE_ACCOUNT);
if (mSelectedContextAccount instanceof Account) {
Account realAccount = (Account)mSelectedContextAccount;
mHandler.workingAccount(realAccount, R.string.recreating_account);
MessagingController.getInstance(getApplication()).recreate(realAccount, null);
}
}
})
.setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dismissDialog(DIALOG_RECREATE_ACCOUNT);
removeDialog(DIALOG_RECREATE_ACCOUNT);
}
})
.create();
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo)item.getMenuInfo();

View File

@ -3,7 +3,6 @@ package com.fsck.k9.activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
@ -640,7 +639,23 @@ public class FolderList extends K9ListActivity {
public Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_MARK_ALL_AS_READ:
return createMarkAllAsReadDialog();
return ConfirmationDialog.create(this, id,
R.string.mark_all_as_read_dlg_title,
getString(R.string.mark_all_as_read_dlg_instructions_fmt,
mSelectedContextFolder.displayName),
R.string.okay_action,
R.string.cancel_action,
new Runnable() {
@Override
public void run() {
try {
MessagingController.getInstance(getApplication())
.markAllMessagesRead(mAccount, mSelectedContextFolder.name);
mSelectedContextFolder.unreadMessageCount = 0;
mHandler.dataChanged();
} catch (Exception e) { /* Ignore */ }
}
});
}
return super.onCreateDialog(id);
@ -660,40 +675,6 @@ public class FolderList extends K9ListActivity {
}
}
private Dialog createMarkAllAsReadDialog() {
return new AlertDialog.Builder(this)
.setTitle(R.string.mark_all_as_read_dlg_title)
.setMessage(getString(R.string.mark_all_as_read_dlg_instructions_fmt,
mSelectedContextFolder.displayName))
.setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dismissDialog(DIALOG_MARK_ALL_AS_READ);
try {
MessagingController.getInstance(getApplication()).markAllMessagesRead(mAccount, mSelectedContextFolder.name);
mSelectedContextFolder.unreadMessageCount = 0;
mHandler.dataChanged();
} catch (Exception e) {
// Ignore
}
}
})
.setNegativeButton(R.string.cancel_action, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dismissDialog(DIALOG_MARK_ALL_AS_READ);
}
})
.create();
}
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;