Skip to content

Commit

Permalink
Showing 2 changed files with 46 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1834,39 +1834,11 @@ public void onClick(DialogInterface dialog, int i) {
* Creates a confirm/cancel dialog for deleting repeats.
*/
private void createDeleteRepeatConfirmDialog() {
FormController formController = getFormController();

alertDialog = new AlertDialog.Builder(this).create();
String name = formController.getLastRepeatedGroupName();
int repeatcount = formController.getLastRepeatedGroupRepeatCount();
if (repeatcount != -1) {
name += " (" + (repeatcount + 1) + ")";
}
alertDialog.setTitle(getString(R.string.delete_repeat_ask));
alertDialog
.setMessage(getString(R.string.delete_repeat_confirm, name));
DialogInterface.OnClickListener quitListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
FormController formController = getFormController();
switch (i) {
case BUTTON_POSITIVE: // yes
formController.getAuditEventLogger().logEvent(AuditEvent.AuditEventType.DELETE_REPEAT, null, true);
formController.deleteRepeat();
showNextView();
break;

case BUTTON_NEGATIVE: // no
refreshCurrentView();
break;
}
}
};
alertDialog.setCancelable(false);
alertDialog.setButton(BUTTON_POSITIVE, getString(R.string.discard_group), quitListener);
alertDialog.setButton(BUTTON_NEGATIVE, getString(R.string.delete_repeat_no),
quitListener);
alertDialog.show();
DialogUtils.createDeleteRepeatConfirmDialog(this, () -> {
showNextView();
}, () -> {
refreshCurrentView();
});
}

/**
Original file line number Diff line number Diff line change
@@ -28,8 +28,14 @@

import org.odk.collect.android.R;

import org.odk.collect.android.application.Collect;
import org.odk.collect.android.logic.AuditEvent;
import org.odk.collect.android.logic.FormController;
import timber.log.Timber;

import static android.content.DialogInterface.BUTTON_NEGATIVE;
import static android.content.DialogInterface.BUTTON_POSITIVE;

/**
* Reusable code between dialogs for keeping consistency
*/
@@ -78,6 +84,41 @@ public static void showDialog(Dialog dialog, Activity activity) {
}
}

/**
* Creates a confirm/cancel dialog for deleting repeats.
*/
public static void createDeleteRepeatConfirmDialog(Context context, Runnable onDeleted, Runnable onCanceled) {
FormController formController = Collect.getInstance().getFormController();
String name = formController.getLastRepeatedGroupName();
int repeatcount = formController.getLastRepeatedGroupRepeatCount();
if (repeatcount != -1) {
name += " (" + (repeatcount + 1) + ")";
}
android.support.v7.app.AlertDialog alertDialog = new android.support.v7.app.AlertDialog.Builder(context).create();
alertDialog.setTitle(context.getString(R.string.delete_repeat_ask));
alertDialog.setMessage(context.getString(R.string.delete_repeat_confirm, name));
DialogInterface.OnClickListener quitListener = (dialog, i) -> {
switch (i) {
case BUTTON_POSITIVE: // yes
formController.getAuditEventLogger().logEvent(AuditEvent.AuditEventType.DELETE_REPEAT, null, true);
formController.deleteRepeat();

if (onDeleted != null) onDeleted.run();

break;

case BUTTON_NEGATIVE: // no
if (onCanceled != null) onCanceled.run();

break;
}
};
alertDialog.setCancelable(false);
alertDialog.setButton(BUTTON_POSITIVE, context.getString(R.string.discard_group), quitListener);
alertDialog.setButton(BUTTON_NEGATIVE, context.getString(R.string.delete_repeat_no), quitListener);
alertDialog.show();
}

/**
* Ensures that a dialog is dismissed safely and doesn't causes a crash. Useful in the event
* of a screen rotation, async operations or activity navigation.

0 comments on commit 0c82a13

Please sign in to comment.