From 4a2237cffef590cb51ab802f46fd03de0bb09168 Mon Sep 17 00:00:00 2001 From: Nicholas Hallahan Date: Wed, 6 Jan 2016 12:52:55 -0800 Subject: [PATCH] writing semicolon values in xml almost working correctly #103 --- .../openmapkit/odkcollect/tag/ODKTag.java | 12 +++++++++++- .../SelectMultipleTagValueFragment.java | 2 +- .../redcross/openmapkit/tagswipe/TagEdit.java | 17 +++++++++++++++-- 3 files changed, 27 insertions(+), 4 deletions(-) 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 6f38b47..1c4583e 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 @@ -94,7 +94,7 @@ public boolean hasCheckedTagValues() { return false; } - public String getSemiColonDelimitedTagValues() { + public String getSemiColonDelimitedTagValues(String customValues) { String values = null; boolean firstVal = true; for (CheckBox cb : checkBoxes) { @@ -111,6 +111,16 @@ public String getSemiColonDelimitedTagValues() { } } } + if (customValues != null) { + customValues = customValues.trim(); + if (customValues.length() > 0) { + if (firstVal) { + values = customValues; + } else { + values += ';' + customValues; + } + } + } return values; } } diff --git a/app/src/main/java/org/redcross/openmapkit/tagswipe/SelectMultipleTagValueFragment.java b/app/src/main/java/org/redcross/openmapkit/tagswipe/SelectMultipleTagValueFragment.java index 5ef940b..70d1b53 100644 --- a/app/src/main/java/org/redcross/openmapkit/tagswipe/SelectMultipleTagValueFragment.java +++ b/app/src/main/java/org/redcross/openmapkit/tagswipe/SelectMultipleTagValueFragment.java @@ -72,7 +72,6 @@ private void setupWidgets() { @SuppressWarnings("ResourceType") private void setupCheckBoxes() { - tagEdit.setCheckBoxMode(true); final LinearLayout checkboxLinearLayout = (LinearLayout)rootView.findViewById(R.id.checkboxLinearLayout); final Activity activity = getActivity(); ODKTag odkTag = tagEdit.getODKTag(); @@ -150,6 +149,7 @@ public void onClick(View view) { } } }); + tagEdit.setupEditCheckbox(editTextCheckBox, editText); LinearLayout customLinearLayout = new LinearLayout(activity); customLinearLayout.setOrientation(LinearLayout.HORIZONTAL); diff --git a/app/src/main/java/org/redcross/openmapkit/tagswipe/TagEdit.java b/app/src/main/java/org/redcross/openmapkit/tagswipe/TagEdit.java index 6df324e..7a241ed 100644 --- a/app/src/main/java/org/redcross/openmapkit/tagswipe/TagEdit.java +++ b/app/src/main/java/org/redcross/openmapkit/tagswipe/TagEdit.java @@ -1,5 +1,6 @@ package org.redcross.openmapkit.tagswipe; +import android.widget.CheckBox; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.RadioButton; @@ -39,6 +40,12 @@ public class TagEdit { private int idx = -1; private EditText editText; private RadioGroup radioGroup; + + /** + * For CheckBox mode. + */ + private CheckBox editTextCheckBox; + private EditText checkBoxEditText; public static List buildTagEdits() { int idx = 0; @@ -137,8 +144,10 @@ public void setRadioGroup(RadioGroup radioGroup) { this.radioGroup = radioGroup; } - public void setCheckBoxMode(boolean bool) { + public void setupEditCheckbox(CheckBox cb, EditText et) { checkBoxMode = true; + editTextCheckBox = cb; + checkBoxEditText = et; } public ODKTag getODKTag() { @@ -149,7 +158,11 @@ private void updateTagInOSMElement() { // check boxes if (odkTag != null && checkBoxMode) { if (odkTag.hasCheckedTagValues()) { - tagVal = odkTag.getSemiColonDelimitedTagValues(); + if (editTextCheckBox.isChecked()) { + tagVal = odkTag.getSemiColonDelimitedTagValues(checkBoxEditText.getText().toString()); + } else { + tagVal = odkTag.getSemiColonDelimitedTagValues(null); + } osmElement.addOrEditTag(tagKey, tagVal); } else { osmElement.deleteTag(tagKey);