Skip to content

Commit

Permalink
Support label text in optional
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Aug 23, 2023
1 parent 990f773 commit 79a3b32
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/main/java/de/blau/android/presets/PresetParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ private void parseItem(@NonNull String name, @NonNull Attributes attr) throws SA
switch (name) {
case OPTIONAL:
inOptionalSection = true;
addLabelField(supportLabels, attr);
break;
case KEY_ATTR:
String key = attr.getValue(KEY_ATTR);
Expand Down Expand Up @@ -396,12 +397,7 @@ private void parseItem(@NonNull String name, @NonNull Attributes attr) throws SA
}
break;
case LABEL:
currentLabel = attr.getValue(TEXT);
if (supportLabels) {
PresetLabelField labelField = new PresetLabelField(currentLabel, attr.getValue(TEXT_CONTEXT));
currentItem.addField(labelField);
labelField.setOptional(inOptionalSection);
}
currentLabel = addLabelField(supportLabels, attr);
break;
case CHECKGROUP:
checkGroup = new PresetCheckGroupField(currentItem.getName() + PresetCheckGroupField.class.getSimpleName() + checkGroupCounter);
Expand Down Expand Up @@ -624,6 +620,24 @@ private void parseItem(@NonNull String name, @NonNull Attributes attr) throws SA
}
}

/**
* Extract the label text and add a field if supportLabels is true
*
* @param supportLabels flag
* @param attr XML attributes
* @return the label text or null
*/
@Nullable
private String addLabelField(boolean supportLabels, @NonNull Attributes attr) {
String labelText = attr.getValue(TEXT);
if (supportLabels && labelText != null) {
PresetLabelField labelField = new PresetLabelField(currentLabel, attr.getValue(TEXT_CONTEXT));
currentItem.addField(labelField);
labelField.setOptional(inOptionalSection);
}
return labelText;
}

/**
* If a checkgroup or combo/multselect has the same text value as a preceding label, remove the label
*
Expand Down

0 comments on commit 79a3b32

Please sign in to comment.