package de.thedevstack.conversationsplus.ui.dialogs; import android.app.Activity; import android.content.DialogInterface; import android.view.View; import android.widget.CheckBox; import android.widget.TextView; import de.thedevstack.conversationsplus.enums.UserDecision; import de.thedevstack.conversationsplus.ui.listeners.UserDecisionListener; import eu.siacs.conversations.R; /** * A dialog to give the user the choice to decide whether to do something or not. * The user also has the choice to save his answer for the future. * A UserDecisionListener is used to provide the functionality to be performed by clicking on yes, or no. */ public class UserDecisionDialog extends SimpleConfirmDialog { protected final CheckBox rememberCheckBox; public UserDecisionDialog(Activity context, int questionResourceId, UserDecisionListener userDecisionListener) { super(context, questionResourceId, userDecisionListener); int viewId = R.layout.dialog_userdecision; View view = context.getLayoutInflater().inflate(viewId, null); this.rememberCheckBox = (CheckBox) view.findViewById(R.id.dlgUserDecRemember); this.setPositiveButton(R.string.cplus_yes, new PositiveOnClickListener()); this.setNegativeButton(R.string.cplus_no, new NegativeOnClickListener()); this.setView(view); } public void decide(UserDecision baseDecision) { switch (baseDecision) { case ALWAYS: this.callback.onYes(); break; case NEVER: this.callback.onNo(); break; case ASK: this.show(); break; } } class PositiveOnClickListener implements DialogInterface.OnClickListener { @Override public void onClick(DialogInterface dialog, int which) { callback.onYes(); if (rememberCheckBox.isChecked()) { ((UserDecisionListener)callback).onRemember(UserDecision.ALWAYS); } } } class NegativeOnClickListener implements DialogInterface.OnClickListener { @Override public void onClick(DialogInterface dialog, int which) { callback.onNo(); if (rememberCheckBox.isChecked()) { ((UserDecisionListener)callback).onRemember(UserDecision.NEVER); } } } }