Skip to content

Commit

Permalink
Mark required questions using an asterisk (getodk#1828)
Browse files Browse the repository at this point in the history
  • Loading branch information
grzesiek2010 authored and shobhitagarwal1612 committed May 15, 2018
1 parent fd8cc80 commit 32d4177
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public void refreshView() {
// or if it is read-only and the label is not blank.
String answerDisplay = FormEntryPromptUtils.getAnswerText(fp, this);
formList.add(
new HierarchyElement(fp.getLongText(), answerDisplay, null,
new HierarchyElement(FormEntryPromptUtils.markQuestionIfIsRequired(label, fp.isRequired()), answerDisplay, null,
Color.WHITE, QUESTION, fp.getIndex()));
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,15 @@ public static String getAnswerText(FormEntryPrompt fep, Context context) {

return fep.getAnswerText();
}

public static String markQuestionIfIsRequired(String questionText, boolean isRequired) {
if (isRequired) {
if (questionText == null) {
questionText = "";
}
questionText = "<span style=\"color:#F44336\">*</span> " + questionText;
}

return questionText;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.odk.collect.android.utilities.DependencyProvider;
import org.odk.collect.android.listeners.AudioPlayListener;
import org.odk.collect.android.logic.FormController;
import org.odk.collect.android.utilities.FormEntryPromptUtils;
import org.odk.collect.android.utilities.TextUtils;
import org.odk.collect.android.utilities.ViewIds;
import org.odk.collect.android.views.MediaLayout;
Expand Down Expand Up @@ -142,13 +143,14 @@ private MediaLayout createQuestionMediaLayout(FormEntryPrompt prompt) {
questionText.setTypeface(null, Typeface.BOLD);
questionText.setTextColor(ContextCompat.getColor(getContext(), R.color.primaryTextColor));
questionText.setPadding(0, 0, 0, 7);
questionText.setText(promptText == null ? "" : TextUtils.textToHtml(promptText));
questionText.setText(TextUtils.textToHtml(FormEntryPromptUtils.markQuestionIfIsRequired(promptText, prompt.isRequired())));
questionText.setMovementMethod(LinkMovementMethod.getInstance());

// Wrap to the size of the parent view
questionText.setHorizontallyScrolling(false);

if (promptText == null || promptText.length() == 0) {
if ((promptText == null || promptText.isEmpty())
&& !(prompt.isRequired() && (prompt.getHelpText() == null || prompt.getHelpText().isEmpty()))) {
questionText.setVisibility(GONE);
}

Expand Down Expand Up @@ -324,7 +326,11 @@ private TextView createHelpText(FormEntryPrompt prompt) {
// wrap to the widget of view
helpText.setHorizontallyScrolling(false);
helpText.setTypeface(null, Typeface.ITALIC);
helpText.setText(TextUtils.textToHtml(s));
if (prompt.getLongText() == null || prompt.getLongText().isEmpty()) {
helpText.setText(TextUtils.textToHtml(FormEntryPromptUtils.markQuestionIfIsRequired(s, prompt.isRequired())));
} else {
helpText.setText(TextUtils.textToHtml(s));
}
helpText.setTextColor(ContextCompat.getColor(getContext(), R.color.primaryTextColor));
helpText.setMovementMethod(LinkMovementMethod.getInstance());
return helpText;
Expand Down

0 comments on commit 32d4177

Please sign in to comment.