diff --git a/app/app.iml b/app/app.iml index f64cbca..8bddab4 100644 --- a/app/app.iml +++ b/app/app.iml @@ -85,6 +85,7 @@ + diff --git a/app/build.gradle b/app/build.gradle index 5a1d2a5..819ba43 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,6 +26,7 @@ repositories { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile group: 'com.google.guava', name: 'guava', version: '18.0' + compile 'org.apache.commons:commons-lang3:3.0' compile project(':MapboxAndroidSDK') compile 'com.android.support:appcompat-v7:22.2.1' compile 'com.android.support:design:22.2.1' diff --git a/app/src/main/java/org/redcross/openmapkit/odkcollect/tag/ODKTag.java b/app/src/main/java/org/redcross/openmapkit/odkcollect/tag/ODKTag.java index 1c4583e..98c6d2a 100644 --- a/app/src/main/java/org/redcross/openmapkit/odkcollect/tag/ODKTag.java +++ b/app/src/main/java/org/redcross/openmapkit/odkcollect/tag/ODKTag.java @@ -5,12 +5,16 @@ import android.widget.EditText; import android.widget.TextView; +import org.apache.commons.lang3.StringUtils; + import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; /** * Structure for ODK OSM Tag elements in XForm. @@ -95,32 +99,26 @@ public boolean hasCheckedTagValues() { } public String getSemiColonDelimitedTagValues(String customValues) { - String values = null; - boolean firstVal = true; + Set values = new HashSet<>(); for (CheckBox cb : checkBoxes) { if (cb.isChecked()) { int id = cb.getId(); ODKTagItem item = buttonIdToODKTagItemHash.get(id); if (item != null) { - if (firstVal) { - firstVal = false; - values = item.getValue(); - } else { - values += ';' + item.getValue(); - } + values.add(item.getValue()); } } } if (customValues != null) { customValues = customValues.trim(); - if (customValues.length() > 0) { - if (firstVal) { - values = customValues; - } else { - values += ';' + customValues; + String[] customValuesArr = customValues.split(";"); + if (customValuesArr.length > 0) { + for (int i = 0; i < customValuesArr.length; i++) { + String customVal = customValuesArr[i]; + values.add(customVal); } } } - return values; + return StringUtils.join(values, ";"); } }