aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/SimpleConfirmDialog.java
blob: 6bf9c56350c8d2cedb1980690e808992b570a3c8 (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
37
package de.thedevstack.conversationsplus.ui.dialogs;

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

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

import eu.siacs.conversations.R;

/**
 * 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();
        }
    }
}