k-9/src/com/fsck/k9/activity/NotificationDeleteConfirmat...

108 lines
3.5 KiB
Java
Raw Normal View History

2013-01-04 02:24:03 -05:00
package com.fsck.k9.activity;
2014-10-12 03:54:44 -04:00
import java.io.Serializable;
2013-01-04 02:24:03 -05:00
import java.util.ArrayList;
2014-10-04 06:45:45 -04:00
import java.util.List;
2013-01-04 02:24:03 -05:00
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;
2014-10-04 06:45:45 -04:00
import com.fsck.k9.helper.Utility;
2013-01-04 02:24:03 -05:00
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;
2014-10-12 03:54:44 -04:00
private ArrayList<MessageReference> mMessageRefs;
2013-01-04 02:24:03 -05:00
2014-10-12 04:24:08 -04:00
public static PendingIntent getIntent(Context context, final Account account, final Serializable refs) {
2013-01-04 02:24:03 -05:00
Intent i = new Intent(context, NotificationDeleteConfirmation.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
2014-10-12 03:54:44 -04:00
i.putExtra(EXTRA_MESSAGE_LIST, refs);
2013-01-04 02:24:03 -05:00
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 ?
2013-01-04 02:24:03 -05:00
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));
2013-09-25 09:20:43 -04:00
mMessageRefs = intent.getParcelableArrayListExtra(EXTRA_MESSAGE_LIST);
2013-01-04 02:24:03 -05:00
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:
int messageCount = mMessageRefs.size();
2013-01-04 02:24:03 -05:00
alert.setMessage(getResources().getQuantityString(
2014-01-03 19:44:31 -05:00
R.plurals.dialog_confirm_delete_messages, messageCount, messageCount));
2013-01-04 02:24:03 -05:00
break;
}
super.onPrepareDialog(id, d);
}
private void triggerDelete() {
Intent i = NotificationActionService.getDeleteAllMessagesIntent(this, mAccount, mMessageRefs);
startService(i);
}
}