From b9c770bf242152537a36be1b86fece51706444bd Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 30 Sep 2015 13:07:32 +0200 Subject: [PATCH] Update --- .../plus/osmedit/AdvancedDataFragment.java | 8 ++++- .../plus/osmedit/BasicDataFragment.java | 13 +++---- .../osmand/plus/osmedit/EditPoiFragment.java | 6 ---- .../osmand/plus/osmedit/data/EditPoiData.java | 35 +++++++++---------- 4 files changed, 30 insertions(+), 32 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/AdvancedDataFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/AdvancedDataFragment.java index 20c2e8acff..f4763a3707 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/AdvancedDataFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/AdvancedDataFragment.java @@ -93,7 +93,7 @@ public class AdvancedDataFragment extends Fragment { mAdapter.updateViews(); mTagsChangedListener = new EditPoiData.TagsChangedListener() { @Override - public void onTagsChanged() { + public void onTagsChanged(String anyTag) { mAdapter.updateViews(); } }; @@ -189,6 +189,7 @@ public class AdvancedDataFragment extends Fragment { (ImageButton) convertView.findViewById(R.id.deleteItemImageButton); valueEditText.setText(vl); deleteItemImageButton.setImageDrawable(deleteDrawable); + final String[] previousTag = new String[] {tg}; deleteItemImageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -199,6 +200,9 @@ public class AdvancedDataFragment extends Fragment { tagEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { + if (!editPoiData.isInEdit()) { + editPoiData.removeTag(s.toString()); + } } @Override @@ -208,7 +212,9 @@ public class AdvancedDataFragment extends Fragment { @Override public void afterTextChanged(Editable s) { if (!editPoiData.isInEdit()) { + editPoiData.removeTag(previousTag[0]); editPoiData.putTag(s.toString(), valueEditText.getText().toString()); + previousTag[0] = s.toString(); } } }); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/BasicDataFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/BasicDataFragment.java index 655464e01b..fb9dc31caf 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/BasicDataFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/BasicDataFragment.java @@ -180,13 +180,14 @@ public class BasicDataFragment extends Fragment { listeners.add(new TagsChangedListener() { @Override - public void onTagsChanged() { - String vl = getData().getTagValues().get(tag); - if(vl == null) { - vl = ""; + public void onTagsChanged(String t) { + if (tag.equals(t)) { + String vl = getData().getTagValues().get(tag); + if (vl == null) { + vl = ""; + } + e.setText(vl); } - e.setText(vl); - } }); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiFragment.java index e15883977f..e5e453a885 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiFragment.java @@ -77,8 +77,6 @@ public class EditPoiFragment extends DialogFragment { private EditPoiData editPoiData; private ViewPager viewPager; private boolean isLocalEdit; - private boolean mIsUserInput = true; - private EditPoiData.TagsChangedListener mTagsChangedListener; private AutoCompleteTextView poiTypeEditText; private Node node; private Map allTranslatedSubTypes; @@ -406,13 +404,9 @@ public class EditPoiFragment extends DialogFragment { } public void updateType(Amenity amenity) { - mIsUserInput = false; poiTypeEditText.setText(amenity.getSubType()); - mIsUserInput = true; poiTypeTextInputLayout.setHint(amenity.getType().getTranslation()); - setAdapterForPoiTypeEditText(); - poiTypeEditText.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(final View v, MotionEvent event) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/data/EditPoiData.java b/OsmAnd/src/net/osmand/plus/osmedit/data/EditPoiData.java index 9c60b5ed0d..a397e3c696 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/data/EditPoiData.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/data/EditPoiData.java @@ -36,7 +36,7 @@ public class EditPoiData { } private void initTags(Node node, Map allTranslatedSubTypes) { - + checkNotInEdit(); tryAddTag(OSMSettings.OSMTagKey.ADDR_STREET.getValue(), node.getTag(OSMSettings.OSMTagKey.ADDR_STREET)); tryAddTag(OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER.getValue(), @@ -70,38 +70,39 @@ public class EditPoiData { public void putTag(String tag, String value) { - if(isInEdit) { - throw new IllegalStateException("Can't modify in edit mode"); - } + checkNotInEdit(); try { isInEdit = true; tagValues.put(tag, value); - notifyDatasetChanged(); + notifyDatasetChanged(tag); } finally { isInEdit = false; } } - - public void notifyToUpdateUI() { + + + private void checkNotInEdit() { if(isInEdit) { throw new IllegalStateException("Can't modify in edit mode"); } + } + + public void notifyToUpdateUI() { + checkNotInEdit(); try { isInEdit = true; - notifyDatasetChanged(); + notifyDatasetChanged(null); } finally { isInEdit = false; } } public void removeTag(String tag) { - if(isInEdit) { - throw new IllegalStateException("Can't modify in edit mode"); - } + checkNotInEdit(); try { isInEdit = true; tagValues.remove(tag); - notifyDatasetChanged(); + notifyDatasetChanged(tag); } finally { isInEdit = false; } @@ -112,9 +113,9 @@ public class EditPoiData { } - private void notifyDatasetChanged() { + private void notifyDatasetChanged(String tag) { for (TagsChangedListener listener : mListeners) { - listener.onTagsChanged(); + listener.onTagsChanged(tag); } } @@ -128,11 +129,7 @@ public class EditPoiData { public interface TagsChangedListener { - void onTagsChanged(); + void onTagsChanged(String tag); } - - - - } \ No newline at end of file