Skip to content

Commit

Permalink
Code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 committed Jul 20, 2017
1 parent 6e5bf00 commit 5d88a28
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2061,6 +2061,15 @@ private void createClearDialog(final QuestionWidget qw) {
.getActivityLogger()
.logInstanceAction(this, "createClearDialog", "show", qw.getPrompt().getIndex());

CollectDialogBundle.Builder dialogBuilder = new CollectDialogBundle.Builder();
dialogBuilder.setDialogMessage(getString(R.string.clearanswer_confirm, getQuestionForRemoveResponseDialog(qw)));

CollectDialogBundle collectDialogBundle = dialogBuilder.build();
RemoveResponseDialog dialogFragment = RemoveResponseDialog.newInstance(collectDialogBundle);
dialogFragment.show(getSupportFragmentManager(), collectDialogBundle.getDialogTag());
}

private String getQuestionForRemoveResponseDialog(QuestionWidget qw) {
String question = qw.getPrompt().getLongText();
if (question == null) {
question = "";
Expand All @@ -2069,18 +2078,7 @@ private void createClearDialog(final QuestionWidget qw) {
question = question.substring(0, 50) + "...";
}

CollectDialogBundle.Builder dialogBuilder = new CollectDialogBundle.Builder();
dialogBuilder
.setIcon(android.R.drawable.ic_dialog_info)
.setDialogTitle(getString(R.string.clear_answer_ask))
.setDialogMessage(getString(R.string.clearanswer_confirm, question))
.setPositiveButtonText(getString(R.string.discard_answer))
.setNegativeButtonText(getString(R.string.clear_answer_no))
.setCancelable(false);

CollectDialogBundle collectDialogBundle = dialogBuilder.build();
RemoveResponseDialog dialogFragment = RemoveResponseDialog.newInstance(collectDialogBundle);
dialogFragment.show(getSupportFragmentManager(), collectDialogBundle.getDialogTag());
return question;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public class CollectDialogBundle implements Serializable {
private String positiveButtonText;
private String neutralButtonText;

private boolean cancelable;

private int icon;

CollectDialogBundle(Builder builder) {
Expand All @@ -40,7 +38,6 @@ public class CollectDialogBundle implements Serializable {
negativeButtonText = builder.negativeButtonText;
positiveButtonText = builder.positiveButtonText;
neutralButtonText = builder.neutralButtonText;
cancelable = builder.cancelable;
icon = builder.icon;
}

Expand Down Expand Up @@ -68,10 +65,6 @@ public String getNeutralButtonText() {
return neutralButtonText;
}

public boolean isCancelable() {
return cancelable;
}

public Integer getIcon() {
return icon;
}
Expand All @@ -85,8 +78,6 @@ public static class Builder {
private String positiveButtonText;
private String neutralButtonText;

private boolean cancelable;

private int icon;

public Builder() {
Expand Down Expand Up @@ -122,11 +113,6 @@ public Builder setNeutralButtonText(String neutralButtonText) {
return this;
}

public Builder setCancelable(Boolean cancelable) {
this.cancelable = cancelable;
return this;
}

public Builder setIcon(int icon) {
this.icon = icon;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
.setMessage(collectDialogBundle.getDialogMessage())
.setIcon(collectDialogBundle.getIcon());

setCancelable(collectDialogBundle.isCancelable());
setCancelable(false);
}

return builder.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.content.DialogInterface;
import android.os.Bundle;

import org.odk.collect.android.R;
import org.odk.collect.android.bundle.CollectDialogBundle;

public class RemoveResponseDialog extends CollectAbstractDialog {
Expand All @@ -45,20 +46,23 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
collectDialogBundle = (CollectDialogBundle) getArguments().getSerializable(COLLECT_DIALOG_BUNDLE);
builder = new AlertDialog.Builder(getActivity());

builder.setPositiveButton(collectDialogBundle.getPositiveButtonText(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
if (callback != null) {
callback.removeAnswer(dialog);
}
}
});
builder
.setPositiveButton(getString(R.string.discard_answer), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
if (callback != null) {
callback.removeAnswer(dialog);
}
}
})
.setNegativeButton(getString(R.string.clear_answer_no), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
})
.setIcon(android.R.drawable.ic_dialog_info)
.setTitle(getContext().getString(R.string.clear_answer_ask));

builder.setNegativeButton(collectDialogBundle.getNegativeButtonText(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
});

super.onCreateDialog(savedInstanceState);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@

import org.odk.collect.android.bundle.CollectDialogBundle;

public class ResetSettingsFinalDialog extends CollectAbstractDialog {
/**
* This class might be used as an universal simple dialog. You can use it if you just need to
* display it and you don't need any callback.
*/
public class SimpleDialog extends CollectAbstractDialog {

public static ResetSettingsFinalDialog newInstance(CollectDialogBundle collectDialogBundle) {
ResetSettingsFinalDialog dialogFragment = new ResetSettingsFinalDialog();
public static SimpleDialog newInstance(CollectDialogBundle collectDialogBundle) {
SimpleDialog dialogFragment = new SimpleDialog();
Bundle bundle = new Bundle();
bundle.putSerializable(COLLECT_DIALOG_BUNDLE, collectDialogBundle);
dialogFragment.setArguments(bundle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import org.odk.collect.android.R;
import org.odk.collect.android.bundle.CollectDialogBundle;
import org.odk.collect.android.fragments.dialogs.ResetSettingsFinalDialog;
import org.odk.collect.android.fragments.dialogs.SimpleDialog;
import org.odk.collect.android.utilities.ResetUtility;
import org.odk.collect.android.utilities.ToastUtils;

Expand Down Expand Up @@ -187,11 +187,10 @@ private void buildAndShowResetSettingsFinalDialog(String message) {
.setIcon(android.R.drawable.ic_dialog_info)
.setDialogTitle(getContext().getString(R.string.reset_app_state_result))
.setDialogMessage(message)
.setPositiveButtonText(getContext().getString(R.string.ok))
.setCancelable(false);
.setPositiveButtonText(getContext().getString(R.string.ok));

CollectDialogBundle collectDialogBundle = dialogBuilder.build();
ResetSettingsFinalDialog dialogFragment = ResetSettingsFinalDialog.newInstance(collectDialogBundle);
SimpleDialog dialogFragment = SimpleDialog.newInstance(collectDialogBundle);
dialogFragment.show(((AdminPreferencesActivity) context).getSupportFragmentManager(), collectDialogBundle.getDialogTag());
}
}

0 comments on commit 5d88a28

Please sign in to comment.