Fix poi issues for editing
This commit is contained in:
parent
f8616e04d7
commit
23c1cc4d5f
4 changed files with 53 additions and 38 deletions
|
@ -146,6 +146,9 @@ public class MapPoiTypes {
|
||||||
public Map<String, PoiType> getAllTranslatedNames(boolean skipNonEditable) {
|
public Map<String, PoiType> getAllTranslatedNames(boolean skipNonEditable) {
|
||||||
Map<String, PoiType> translation = new HashMap<String, PoiType>();
|
Map<String, PoiType> translation = new HashMap<String, PoiType>();
|
||||||
for(PoiCategory pc : categories) {
|
for(PoiCategory pc : categories) {
|
||||||
|
if(skipNonEditable && pc.isNotEditableOsm()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
for(PoiType pt : pc.getPoiTypes()) {
|
for(PoiType pt : pc.getPoiTypes()) {
|
||||||
if(pt.isReference() ) {
|
if(pt.isReference() ) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -44,7 +44,6 @@ import android.widget.ImageButton;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import net.osmand.CallbackWithObject;
|
import net.osmand.CallbackWithObject;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.access.AccessibleToast;
|
import net.osmand.access.AccessibleToast;
|
||||||
|
@ -253,17 +252,35 @@ public class EditPoiDialogFragment extends DialogFragment {
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
if (!getEditPoiData().isInEdit()) {
|
if (!getEditPoiData().isInEdit()) {
|
||||||
PoiType pt = getEditPoiData().getAllTranslatedSubTypes().get(s.toString().toLowerCase());
|
|
||||||
if(pt != null) {
|
|
||||||
poiTypeTextInputLayout.setHint(pt.getCategory().getTranslation());
|
|
||||||
}
|
|
||||||
getEditPoiData().updateTypeTag(s.toString());
|
getEditPoiData().updateTypeTag(s.toString());
|
||||||
|
poiTypeTextInputLayout.setHint(editPoiData.getPoiCategory().getTranslation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
poiNameEditText.setOnEditorActionListener(mOnEditorActionListener);
|
poiNameEditText.setOnEditorActionListener(mOnEditorActionListener);
|
||||||
poiTypeEditText.setOnEditorActionListener(mOnEditorActionListener);
|
poiTypeEditText.setOnEditorActionListener(mOnEditorActionListener);
|
||||||
poiTypeEditText.setText(editPoiData.getPoiTypeString());
|
poiTypeEditText.setText(editPoiData.getPoiTypeString());
|
||||||
|
poiTypeEditText.setOnTouchListener(new View.OnTouchListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onTouch(final View v, MotionEvent event) {
|
||||||
|
final EditText editText = (EditText) v;
|
||||||
|
final int DRAWABLE_RIGHT = 2;
|
||||||
|
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||||
|
if (event.getX() >= (editText.getRight()
|
||||||
|
- editText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width()
|
||||||
|
- editText.getPaddingRight())) {
|
||||||
|
if (editPoiData.getPoiCategory() != null) {
|
||||||
|
DialogFragment dialogFragment =
|
||||||
|
PoiSubTypeDialogFragment.createInstance(editPoiData.getPoiCategory());
|
||||||
|
dialogFragment.show(getChildFragmentManager(), "PoiSubTypeDialogFragment");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Button saveButton = (Button) view.findViewById(R.id.saveButton);
|
Button saveButton = (Button) view.findViewById(R.id.saveButton);
|
||||||
saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil
|
saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil
|
||||||
|
@ -299,7 +316,7 @@ public class EditPoiDialogFragment extends DialogFragment {
|
||||||
HashSet<String> tagsCopy = new HashSet<>();
|
HashSet<String> tagsCopy = new HashSet<>();
|
||||||
tagsCopy.addAll(editPoiData.getTagValues().keySet());
|
tagsCopy.addAll(editPoiData.getTagValues().keySet());
|
||||||
tagsCopy.removeAll(BASIC_TAGS);
|
tagsCopy.removeAll(BASIC_TAGS);
|
||||||
if (tagsCopy.isEmpty()) {
|
if (tagsCopy.isEmpty() || editPoiData.getPoiCategory() == getMyApplication().getPoiTypes().getOtherPoiCategory()) {
|
||||||
poiTypeEditText.setError(getResources().getString(R.string.please_specify_poi_type));
|
poiTypeEditText.setError(getResources().getString(R.string.please_specify_poi_type));
|
||||||
} else {
|
} else {
|
||||||
new SaveWithAdvancedTagsDialogFragment().show(getChildFragmentManager(), "dialog");
|
new SaveWithAdvancedTagsDialogFragment().show(getChildFragmentManager(), "dialog");
|
||||||
|
@ -446,41 +463,26 @@ public class EditPoiDialogFragment extends DialogFragment {
|
||||||
}.execute();
|
}.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateType(PoiCategory type) {
|
public void setPoiCategory(PoiCategory type) {
|
||||||
editPoiData.updateType(type);
|
editPoiData.updateType(type);
|
||||||
poiTypeEditText.setText(editPoiData.getPoiTypeString());
|
poiTypeEditText.setText(editPoiData.getPoiTypeString());
|
||||||
poiTypeTextInputLayout.setHint(editPoiData.getPoiCategory().getTranslation());
|
|
||||||
setAdapterForPoiTypeEditText();
|
setAdapterForPoiTypeEditText();
|
||||||
poiTypeEditText.setOnTouchListener(new View.OnTouchListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onTouch(final View v, MotionEvent event) {
|
|
||||||
final EditText editText = (EditText) v;
|
|
||||||
final int DRAWABLE_RIGHT = 2;
|
|
||||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
|
||||||
if (event.getX() >= (editText.getRight()
|
|
||||||
- editText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width()
|
|
||||||
- editText.getPaddingRight())) {
|
|
||||||
if (editPoiData.getPoiCategory() != null) {
|
|
||||||
DialogFragment dialogFragment =
|
|
||||||
PoiSubTypeDialogFragment.createInstance(editPoiData.getPoiCategory());
|
|
||||||
dialogFragment.show(getChildFragmentManager(), "PoiSubTypeDialogFragment");
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setAdapterForPoiTypeEditText() {
|
private void setAdapterForPoiTypeEditText() {
|
||||||
final Map<String, PoiType> subCategories = new LinkedHashMap<>();
|
final Map<String, PoiType> subCategories = new LinkedHashMap<>();
|
||||||
for (Map.Entry<String, PoiType> s : editPoiData.getAllTranslatedSubTypes().entrySet()) {
|
PoiCategory ct = editPoiData.getPoiCategory();
|
||||||
if (!subCategories.containsKey(s.getKey())) {
|
if(ct != null) {
|
||||||
subCategories.put(Algorithms.capitalizeFirstLetterAndLowercase(s.getKey()), s.getValue());
|
for (PoiType s : ct.getPoiTypes()) {
|
||||||
|
if(!s.isReference() && !s.isNotEditableOsm() && s.getBaseLangType() == null) {
|
||||||
|
addMapEntryAdapter(subCategories, s.getTranslation(), s);
|
||||||
|
addMapEntryAdapter(subCategories, s.getKeyName().replace('_', ' '), s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (Map.Entry<String, PoiType> s : editPoiData.getAllTranslatedSubTypes().entrySet()) {
|
||||||
|
addMapEntryAdapter(subCategories, s.getKey(), s.getValue());
|
||||||
|
}
|
||||||
final ArrayAdapter<Object> adapter;
|
final ArrayAdapter<Object> adapter;
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
adapter = new ArrayAdapter<>(getActivity(),
|
adapter = new ArrayAdapter<>(getActivity(),
|
||||||
|
@ -518,7 +520,7 @@ public class EditPoiDialogFragment extends DialogFragment {
|
||||||
//noinspection SuspiciousMethodCalls
|
//noinspection SuspiciousMethodCalls
|
||||||
PoiType pt = subCategories.get(item);
|
PoiType pt = subCategories.get(item);
|
||||||
String keyName = pt.getKeyName();
|
String keyName = pt.getKeyName();
|
||||||
poiTypeTextInputLayout.setHint(pt.getCategory().getTranslation());
|
setAdapterForPoiTypeEditText();
|
||||||
poiTypeEditText.setText(keyName);
|
poiTypeEditText.setText(keyName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -530,6 +532,12 @@ public class EditPoiDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addMapEntryAdapter(final Map<String, PoiType> subCategories, String key, PoiType v) {
|
||||||
|
if (!subCategories.containsKey(key.toLowerCase())) {
|
||||||
|
subCategories.put(Algorithms.capitalizeFirstLetterAndLowercase(key), v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private OsmandApplication getMyApplication() {
|
private OsmandApplication getMyApplication() {
|
||||||
return (OsmandApplication) getActivity().getApplication();
|
return (OsmandApplication) getActivity().getApplication();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package net.osmand.plus.osmedit.dialogs;
|
package net.osmand.plus.osmedit.dialogs;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.ArrayList;
|
||||||
import java.util.Set;
|
import java.util.List;
|
||||||
|
|
||||||
import net.osmand.osm.MapPoiTypes;
|
import net.osmand.osm.MapPoiTypes;
|
||||||
import net.osmand.osm.PoiCategory;
|
import net.osmand.osm.PoiCategory;
|
||||||
|
@ -24,8 +24,12 @@ public class PoiSubTypeDialogFragment extends DialogFragment {
|
||||||
MapPoiTypes poiTypes = ((OsmandApplication) getActivity().getApplication()).getPoiTypes();
|
MapPoiTypes poiTypes = ((OsmandApplication) getActivity().getApplication()).getPoiTypes();
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
final PoiCategory a = poiTypes.getPoiCategoryByName((String) getArguments().getSerializable(KEY_POI_CATEGORY));
|
final PoiCategory a = poiTypes.getPoiCategoryByName((String) getArguments().getSerializable(KEY_POI_CATEGORY));
|
||||||
final Map<String, PoiType> allTranslatedNames = poiTypes.getAllTranslatedNames(a, true);
|
List<String> strings = new ArrayList<>();
|
||||||
Set<String> strings = allTranslatedNames.keySet();
|
for (PoiType s : a.getPoiTypes()) {
|
||||||
|
if (!s.isReference() && !s.isNotEditableOsm() && s.getBaseLangType() == null) {
|
||||||
|
strings.add(s.getTranslation());
|
||||||
|
}
|
||||||
|
}
|
||||||
final String[] subCats = strings.toArray(new String[strings.size()]);
|
final String[] subCats = strings.toArray(new String[strings.size()]);
|
||||||
builder.setItems(subCats, new DialogInterface.OnClickListener() {
|
builder.setItems(subCats, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class PoiTypeDialogFragment extends DialogFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
PoiCategory aType = categories.get(which);
|
PoiCategory aType = categories.get(which);
|
||||||
((EditPoiDialogFragment) getParentFragment()).updateType(aType);
|
((EditPoiDialogFragment) getParentFragment()).setPoiCategory(aType);
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue