From ad096f4bfd220a106aab670105275397bfcbfd0e Mon Sep 17 00:00:00 2001 From: steckbrief Date: Tue, 23 Aug 2016 11:23:40 +0200 Subject: Confirmation dialog added before sending delete command for remote file --- .../ui/dialogs/SimpleConfirmDialog.java | 36 ++++++++++++++++++++++ .../ui/dialogs/UserDecisionDialog.java | 18 +++++------ 2 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 src/main/java/de/thedevstack/conversationsplus/ui/dialogs/SimpleConfirmDialog.java (limited to 'src/main/java/de/thedevstack/conversationsplus/ui/dialogs') diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/SimpleConfirmDialog.java b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/SimpleConfirmDialog.java new file mode 100644 index 00000000..04e60caa --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/SimpleConfirmDialog.java @@ -0,0 +1,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(); + } + } +} diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java index 25349b2d..e0834390 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/UserDecisionDialog.java @@ -15,13 +15,11 @@ import de.thedevstack.conversationsplus.R; * 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 AbstractAlertDialog { - protected final UserDecisionListener listener; +public class UserDecisionDialog extends SimpleConfirmDialog { protected final CheckBox rememberCheckBox; public UserDecisionDialog(Activity context, int questionResourceId, UserDecisionListener userDecisionListener) { - super(context, questionResourceId); - this.listener = userDecisionListener; + super(context, questionResourceId, userDecisionListener); int viewId = R.layout.dialog_userdecision; View view = context.getLayoutInflater().inflate(viewId, null); @@ -36,10 +34,10 @@ public class UserDecisionDialog extends AbstractAlertDialog { public void decide(UserDecision baseDecision) { switch (baseDecision) { case ALWAYS: - this.listener.onYes(); + this.callback.onYes(); break; case NEVER: - this.listener.onNo(); + this.callback.onNo(); break; case ASK: this.show(); @@ -51,9 +49,9 @@ public class UserDecisionDialog extends AbstractAlertDialog { @Override public void onClick(DialogInterface dialog, int which) { - listener.onYes(); + callback.onYes(); if (rememberCheckBox.isChecked()) { - listener.onRemember(UserDecision.ALWAYS); + ((UserDecisionListener)callback).onRemember(UserDecision.ALWAYS); } } } @@ -62,9 +60,9 @@ public class UserDecisionDialog extends AbstractAlertDialog { @Override public void onClick(DialogInterface dialog, int which) { - listener.onNo(); + callback.onNo(); if (rememberCheckBox.isChecked()) { - listener.onRemember(UserDecision.NEVER); + ((UserDecisionListener)callback).onRemember(UserDecision.NEVER); } } } -- cgit v1.2.3