aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/SimpleConfirmDialog.java
blob: 04e60caa87967d6f64b9429f60400c77181a4289 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package de.thedevstack.conversationsplus.ui.dialogs;

import android.content.Context;
import android.content.DialogInterface;

import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.ui.listeners.SimpleUserDecisionCallback;

/**
 * A dialog to give the user the choice to decide whether to do something or not.
 * A UserDecisionListener is used to provide the functionality to be performed by clicking on yes, or no.
 */
public class SimpleConfirmDialog extends AbstractAlertDialog {
    protected final SimpleUserDecisionCallback callback;

    public SimpleConfirmDialog(Context context, String title, SimpleUserDecisionCallback userDecisionCallback) {
        super(context, title);
        this.callback = userDecisionCallback;
        this.setPositiveButton(R.string.cplus_ok, new ConfirmOnClickListener());
        this.setNegativeButton(R.string.cancel, null);
    }

    public SimpleConfirmDialog(Context context, int titleTextId, SimpleUserDecisionCallback userDecisionCallback) {
        super(context, titleTextId);
        this.callback = userDecisionCallback;
        this.setPositiveButton(R.string.cplus_ok, new ConfirmOnClickListener());
        this.setNegativeButton(R.string.cancel, null);
    }

    private class ConfirmOnClickListener implements DialogInterface.OnClickListener {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            callback.onYes();
        }
    }
}