mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-17 06:55:03 -05:00
bbcc4988ba
The fragment should be fully functional. The only thing missing is the animation when showing the next/previous message.
96 lines
3.1 KiB
Java
96 lines
3.1 KiB
Java
package com.fsck.k9.fragment;
|
|
|
|
import android.app.AlertDialog;
|
|
import android.app.Dialog;
|
|
import android.content.DialogInterface;
|
|
import android.content.DialogInterface.OnCancelListener;
|
|
import android.content.DialogInterface.OnClickListener;
|
|
import android.os.Bundle;
|
|
|
|
import com.actionbarsherlock.app.SherlockDialogFragment;
|
|
|
|
|
|
public class ConfirmationDialogFragment extends SherlockDialogFragment implements OnClickListener,
|
|
OnCancelListener {
|
|
|
|
private static final String ARG_DIALOG_ID = "dialog_id";
|
|
private static final String ARG_TITLE = "title";
|
|
private static final String ARG_MESSAGE = "message";
|
|
private static final String ARG_CONFIRM_TEXT = "confirm";
|
|
private static final String ARG_CANCEL_TEXT = "cancel";
|
|
|
|
|
|
public static ConfirmationDialogFragment newInstance(int dialogId, String title, String message,
|
|
String confirmText, String cancelText) {
|
|
ConfirmationDialogFragment fragment = new ConfirmationDialogFragment();
|
|
|
|
Bundle args = new Bundle();
|
|
args.putInt(ARG_DIALOG_ID, dialogId);
|
|
args.putString(ARG_TITLE, title);
|
|
args.putString(ARG_MESSAGE, message);
|
|
args.putString(ARG_CONFIRM_TEXT, confirmText);
|
|
args.putString(ARG_CANCEL_TEXT, cancelText);
|
|
fragment.setArguments(args);
|
|
|
|
return fragment;
|
|
}
|
|
|
|
|
|
public interface ConfirmationDialogFragmentListener {
|
|
void doPositiveClick(int dialogId);
|
|
void doNegativeClick(int dialogId);
|
|
void dialogCancelled(int dialogId);
|
|
}
|
|
|
|
|
|
@Override
|
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
Bundle args = getArguments();
|
|
String title = args.getString(ARG_TITLE);
|
|
String message = args.getString(ARG_MESSAGE);
|
|
String confirmText = args.getString(ARG_CONFIRM_TEXT);
|
|
String cancelText = args.getString(ARG_CANCEL_TEXT);
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
|
builder.setTitle(title);
|
|
builder.setMessage(message);
|
|
builder.setPositiveButton(confirmText, this);
|
|
builder.setNegativeButton(cancelText, this);
|
|
|
|
return builder.create();
|
|
}
|
|
|
|
@Override
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
switch (which) {
|
|
case DialogInterface.BUTTON_POSITIVE: {
|
|
getListener().doPositiveClick(getDialogId());
|
|
break;
|
|
}
|
|
case DialogInterface.BUTTON_NEGATIVE: {
|
|
getListener().doNegativeClick(getDialogId());
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onCancel(DialogInterface dialog) {
|
|
super.onCancel(dialog);
|
|
getListener().dialogCancelled(getDialogId());
|
|
}
|
|
|
|
private int getDialogId() {
|
|
return getArguments().getInt(ARG_DIALOG_ID);
|
|
}
|
|
|
|
private ConfirmationDialogFragmentListener getListener() {
|
|
try {
|
|
return (ConfirmationDialogFragmentListener) getTargetFragment();
|
|
} catch (ClassCastException e) {
|
|
throw new ClassCastException(getTargetFragment().getClass() +
|
|
" must implement ConfirmationDialogFragmentListener");
|
|
}
|
|
}
|
|
}
|