Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#6439] Fix UI of repeat labels #6459

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ When you first run Collect, it is set to download forms from [https://demo.getod

1. Once you have the XForm, use [adb](https://developer.android.com/studio/command-line/adb.html) to push the form to your device (after [enabling USB debugging](https://www.kingoapp.com/root-tutorials/how-to-enable-usb-debugging-mode-on-android.htm)) or emulator.
```
adb push my_form.xml /sdcard/Android/data/org.odk.collect.android/files/forms
adb push my_form.xml /sdcard/Android/data/org.odk.collect.android/files/formsprojects/DEMO/forms
karntrehan marked this conversation as resolved.
Show resolved Hide resolved
```

1. Launch ODK Collect and tap `Fill Blank Form`. The new form will be there.
1. Launch ODK Collect and tap `+ Start new form`. The new form will be there.

## Using APIs for local development

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class AddRepeatTest {
private static final String ONE_QUESTION_REPEAT = "one-question-repeat.xml";
private static final String FIELD_LIST_REPEAT = "field-list-repeat.xml";
private static final String FIXED_COUNT_REPEAT = "fixed-count-repeat.xml";
private static final String REPEAT_WITHOUT_LABEL = "repeat_without_label.xml";

private final CollectTestRule rule = new CollectTestRule();

Expand Down Expand Up @@ -117,4 +118,17 @@ public void whenInHierarchyForRepeat_clickingPlus_addsRepeatAtEndOfSeries() {
.addGroup()
.assertText("Person > 3");
}

@Test
public void whenInEmptyRepeat_swipingNext_andClickingAdd_addsAnotherRepeat() {
karntrehan marked this conversation as resolved.
Show resolved Hide resolved
rule.startAtMainMenu()
.copyForm(REPEAT_WITHOUT_LABEL)
.startBlankForm("Repeat without label")
.assertText("> 1")
.assertQuestion("First name", true)
karntrehan marked this conversation as resolved.
Show resolved Hide resolved
.answerQuestion("First name", true, "Karan")
.swipeToNextQuestionWithRepeatGroup("")
.clickOnAdd(new FormEntryPage("Repeat without label"))
.assertText("> 2");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ public AddNewRepeatDialog(String repeatName) {

@Override
public AddNewRepeatDialog assertOnPage() {
onView(withText(getTranslatedString(org.odk.collect.strings.R.string.add_repeat_question, repeatName)))
String dialogMessage;
if (repeatName.isBlank()) {
dialogMessage = getTranslatedString(org.odk.collect.strings.R.string.add_another_question);
} else {
dialogMessage = getTranslatedString(org.odk.collect.strings.R.string.add_repeat_question, repeatName);
}
onView(withText(dialogMessage))
.inRoot(isDialog())
.check(matches(isDisplayed()));
return this;
Expand All @@ -27,7 +33,7 @@ public <D extends Page<D>> D clickOnAdd(D destination) {
}

public <D extends Page<D>> D clickOnDoNotAdd(D destination) {
return clickOnTextInDialog(org.odk.collect.strings.R.string.dont_add_repeat, destination);
return clickOnTextInDialog(org.odk.collect.strings.R.string.cancel, destination);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,31 @@

public class AddRepeatDialog {

private AddRepeatDialog() {}
private AddRepeatDialog() {
}

public static void show(Context context, String groupLabel, Listener listener) {
AlertDialog alertDialog = new MaterialAlertDialogBuilder(context).create();
DialogInterface.OnClickListener repeatListener = (dialog, i) -> {
switch (i) {
case BUTTON_POSITIVE:
listener.onAddRepeatClicked();
break;
case BUTTON_NEGATIVE:
listener.onCancelClicked();
break;
case BUTTON_POSITIVE -> listener.onAddRepeatClicked();
karntrehan marked this conversation as resolved.
Show resolved Hide resolved
case BUTTON_NEGATIVE -> listener.onCancelClicked();
}
};

alertDialog.setMessage(context.getString(org.odk.collect.strings.R.string.add_repeat_question,
groupLabel));
String dialogMessage;
if (groupLabel.isBlank()) {
dialogMessage = context.getString(org.odk.collect.strings.R.string.add_another_question);
} else {
dialogMessage = context.getString(org.odk.collect.strings.R.string.add_repeat_question,
groupLabel);
}

alertDialog.setTitle(dialogMessage);

alertDialog.setButton(BUTTON_POSITIVE, context.getString(org.odk.collect.strings.R.string.add_repeat),
repeatListener);
alertDialog.setButton(BUTTON_NEGATIVE, context.getString(org.odk.collect.strings.R.string.dont_add_repeat),
alertDialog.setButton(BUTTON_NEGATIVE, context.getString(org.odk.collect.strings.R.string.cancel),
repeatListener);

alertDialog.setCancelable(false);
Expand Down
1 change: 1 addition & 0 deletions strings/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
<string name="add_repeat">Add</string>
<string name="dont_add_repeat">Do not add</string>
<string name="add_another_menu">Add another</string>
<string name="add_another_question">Add another?</string>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how translations are done. Did not see it in the readme also. Kindly advice.


<!-- Title of overlay menu displayed when long pressing on a question in a form -->
<string name="edit_prompt">Edit Prompt</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version="1.0"?><h:html xmlns="http://www.w3.org/2002/xforms" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:jr="http://openrosa.org/javarosa" xmlns:orx="http://openrosa.org/xforms" xmlns:odk="http://www.opendatakit.org/xforms"><h:head><h:title>Repeat without label</h:title><model odk:xforms-version="1.0.0"><instance><data id="repeat_no_label" version="20241014214421"><repeat jr:template=""><first_name/></repeat><repeat><first_name/></repeat><meta><instanceID/></meta></data></instance><bind nodeset="/data/repeat/first_name" type="string" required="true()"/><bind nodeset="/data/meta/instanceID" type="string" readonly="true()" jr:preload="uid"/></model></h:head><h:body><group ref="/data/repeat"><label></label><repeat nodeset="/data/repeat"><input ref="/data/repeat/first_name"><label>First name</label></input></repeat></group></h:body></h:html>