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.R; import de.thedevstack.conversationsplus.enums.UserDecision; import de.thedevstack.conversationsplus.ui.listeners.UserDecisionListener; /** * Created by tzur on 31.10.2015. */ public class UserDecisionDialog extends AbstractAlertDialog { protected final UserDecisionListener listener; protected final CheckBox rememberCheckBox; public UserDecisionDialog(Activity context, int questionResourceId, UserDecisionListener userDecisionListener) { super(context, "User Decision"); this.listener = userDecisionListener; int viewId = R.layout.dialog_userdecision; View view = context.getLayoutInflater().inflate(viewId, null); ((TextView)view.findViewById(R.id.dlgUserDecQuestion)).setText(questionResourceId); 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.listener.onYes(); break; case NEVER: this.listener.onNo(); break; case ASK: this.show(); break; } } class PositiveOnClickListener implements DialogInterface.OnClickListener { @Override public void onClick(DialogInterface dialog, int which) { listener.onYes(); if (rememberCheckBox.isChecked()) { listener.onRemember(UserDecision.ALWAYS); } } } class NegativeOnClickListener implements DialogInterface.OnClickListener { @Override public void onClick(DialogInterface dialog, int which) { listener.onNo(); if (rememberCheckBox.isChecked()) { listener.onRemember(UserDecision.NEVER); } } } }