1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-14 05:25:07 -05:00
k-9/src/com/fsck/k9/activity/NotificationDeleteConfirmation.java

104 lines
3.4 KiB
Java
Raw Normal View History

2013-01-04 02:24:03 -05:00
package com.fsck.k9.activity;
import java.util.ArrayList;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.Preferences;
import com.fsck.k9.R;
import com.fsck.k9.service.NotificationActionService;
public class NotificationDeleteConfirmation extends Activity {
private final static String EXTRA_ACCOUNT = "account";
private final static String EXTRA_MESSAGE_LIST = "messages";
private final static int DIALOG_CONFIRM = 1;
private Account mAccount;
private ArrayList<MessageReference> mMessageRefs;
public static PendingIntent getIntent(Context context, final Account account, final ArrayList<MessageReference> refs) {
Intent i = new Intent(context, NotificationDeleteConfirmation.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_MESSAGE_LIST, refs);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
return PendingIntent.getActivity(context, account.getAccountNumber(), i, PendingIntent.FLAG_UPDATE_CURRENT);
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setTheme(K9.getK9Theme() == K9.THEME_LIGHT ?
R.style.Theme_K9_Dialog_Translucent_Light : R.style.Theme_K9_Dialog_Translucent_Dark);
final Preferences preferences = Preferences.getPreferences(this);
final Intent intent = getIntent();
mAccount = preferences.getAccount(intent.getStringExtra(EXTRA_ACCOUNT));
mMessageRefs = (ArrayList<MessageReference>) intent.getSerializableExtra(EXTRA_MESSAGE_LIST);
if (mAccount == null || mMessageRefs == null || mMessageRefs.isEmpty()) {
finish();
} else if (!K9.confirmDeleteFromNotification()) {
triggerDelete();
finish();
} else {
showDialog(DIALOG_CONFIRM);
}
}
@Override
public Dialog onCreateDialog(int id) {
switch (id) {
case DIALOG_CONFIRM:
return ConfirmationDialog.create(this, id,
R.string.dialog_confirm_delete_title, "",
R.string.dialog_confirm_delete_confirm_button,
R.string.dialog_confirm_delete_cancel_button,
new Runnable() {
@Override
public void run() {
triggerDelete();
finish();
}
},
new Runnable() {
@Override
public void run() {
finish();
}
});
}
return super.onCreateDialog(id);
}
@Override
public void onPrepareDialog(int id, Dialog d) {
AlertDialog alert = (AlertDialog) d;
switch (id) {
case DIALOG_CONFIRM:
alert.setMessage(getResources().getQuantityString(
R.plurals.dialog_confirm_delete_message, mMessageRefs.size()));
break;
}
super.onPrepareDialog(id, d);
}
private void triggerDelete() {
Intent i = NotificationActionService.getDeleteAllMessagesIntent(this, mAccount, mMessageRefs);
startService(i);
}
}