diff --git a/src/main/java/de/blau/android/presets/PresetParser.java b/src/main/java/de/blau/android/presets/PresetParser.java index b757676792..787eb065ce 100644 --- a/src/main/java/de/blau/android/presets/PresetParser.java +++ b/src/main/java/de/blau/android/presets/PresetParser.java @@ -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); @@ -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); @@ -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 *