From a29bf4ddf8d51d996a9fcc1790b6da5781b03e5b Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Thu, 12 Nov 2015 10:51:31 +0200 Subject: [PATCH] Allowing creation of poi without POI type but with advanced tag. --- OsmAnd/res/values/strings.xml | 1 + .../plus/osmedit/EditPoiDialogFragment.java | 51 +++++++++++++++++-- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 84814ced75..1e6fc96f53 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -2060,5 +2060,6 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A Feedback Contact us Map legend + Do you really want to save poi without POI type? diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java index 0499dc8288..7619bc2cd2 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java @@ -66,6 +66,7 @@ import org.apache.commons.logging.Log; import java.io.Serializable; import java.util.Comparator; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -79,6 +80,17 @@ public class EditPoiDialogFragment extends DialogFragment { private static final String TAGS_LIST = "tags_list"; private static final String IS_ADDING_POI = "is_adding_poi"; + private static final HashSet BASIC_TAGS = new HashSet() { + { + add(OSMSettings.OSMTagKey.NAME.getValue()); + add(OSMSettings.OSMTagKey.ADDR_STREET.getValue()); + add(OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER.getValue()); + add(OSMSettings.OSMTagKey.PHONE.getValue()); + add(OSMSettings.OSMTagKey.WEBSITE.getValue()); + add(OSMSettings.OSMTagKey.OPENING_HOURS.getValue()); + } + }; + private EditPoiData editPoiData; private ViewPager viewPager; private AutoCompleteTextView poiTypeEditText; @@ -258,7 +270,7 @@ public class EditPoiDialogFragment extends DialogFragment { saveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - save(); + trySave(); } }); Button cancelButton = (Button) view.findViewById(R.id.cancelButton); @@ -281,11 +293,22 @@ public class EditPoiDialogFragment extends DialogFragment { return dialog; } - private void save() { + private void trySave() { if (TextUtils.isEmpty(poiTypeEditText.getText())) { - poiTypeEditText.setError(getResources().getString(R.string.please_specify_poi_type)); + HashSet tagsCopy = new HashSet<>(); + tagsCopy.addAll(editPoiData.getTagValues().keySet()); + tagsCopy.removeAll(BASIC_TAGS); + if (tagsCopy.isEmpty()) { + poiTypeEditText.setError(getResources().getString(R.string.please_specify_poi_type)); + } else { + new SaveWithAdvancedTagsDialogFragment().show(getChildFragmentManager(), "dialog"); + } return; } + save(); + } + + private void save() { OsmPoint.Action action = node.getId() == -1 ? OsmPoint.Action.CREATE : OsmPoint.Action.MODIFY; for (Map.Entry tag : editPoiData.getTagValues().entrySet()) { if (tag.getKey().equals(EditPoiData.POI_TYPE_TAG)) { @@ -654,13 +677,31 @@ public class EditPoiDialogFragment extends DialogFragment { } } + public static class SaveWithAdvancedTagsDialogFragment extends DialogFragment { + @NonNull + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setTitle(getResources().getString(R.string.are_you_sure)) + .setMessage(getString(R.string.save_poi_without_poi_type_message)) + .setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + ((EditPoiDialogFragment) getParentFragment()).save(); + } + }) + .setNegativeButton(R.string.shared_string_cancel, null); + return builder.create(); + } + } + public static class AreYouSureDialogFragment extends DialogFragment { @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(getResources().getString(R.string.are_you_sure)) - .setMessage(getResources().getString(R.string.unsaved_changes_will_be_lost)) + .setMessage(getString(R.string.unsaved_changes_will_be_lost)) .setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { @@ -678,7 +719,7 @@ public class EditPoiDialogFragment extends DialogFragment { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { boolean handled = false; if (actionId == EditorInfo.IME_ACTION_SEND) { - save(); + trySave(); handled = true; } return handled;