Skip to content

Commit

Permalink
Check isGroupSizeLocked before showing add/delete buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperka committed Jan 22, 2019
1 parent afe0934 commit b3d1fa4
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import org.javarosa.core.model.FormIndex;
import org.javarosa.core.model.GroupDef;
import org.javarosa.core.model.IFormElement;
import org.javarosa.form.api.FormEntryCaption;
import org.javarosa.form.api.FormEntryController;
import org.javarosa.form.api.FormEntryPrompt;
Expand Down Expand Up @@ -218,17 +219,29 @@ private void updateOptionsMenu() {
boolean isAtBeginning = screenIndex.isBeginningOfFormIndex() && !shouldShowRepeatGroupPicker();
boolean shouldShowPicker = shouldShowRepeatGroupPicker();
boolean isInRepeat = !isAtBeginning && formController.getEvent(screenIndex) == FormEntryController.EVENT_REPEAT;
boolean isGroupSizeLocked = shouldShowPicker
? isGroupSizeLocked(repeatGroupPickerIndex) : isGroupSizeLocked(screenIndex);

boolean shouldShowDelete = isInRepeat && !shouldShowPicker;
boolean shouldShowDelete = isInRepeat && !shouldShowPicker && !isGroupSizeLocked;
showDeleteButton(shouldShowDelete);

boolean shouldShowAdd = shouldShowPicker;
boolean shouldShowAdd = shouldShowPicker && !isGroupSizeLocked;
showAddButton(shouldShowAdd);

boolean shouldShowGoUp = !isAtBeginning;
showGoUpButton(shouldShowGoUp);
}

/**
* Returns true if the current index is a group that's designated as `noAddRemove`
* (e.g. if `jr:count` is explicitly set).
*/
private boolean isGroupSizeLocked(FormIndex index) {
FormController formController = Collect.getInstance().getFormController();
IFormElement element = formController.getCaptionPrompt(index).getFormElement();
return element instanceof GroupDef && ((GroupDef) element).noAddRemove;
}

/** Override to disable this button. */
protected void showDeleteButton(boolean shouldShow) {
optionsMenu.findItem(R.id.menu_delete_child).setVisible(shouldShow);
Expand Down

0 comments on commit b3d1fa4

Please sign in to comment.