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) {
|
||||
Map<String, PoiType> translation = new HashMap<String, PoiType>();
|
||||
for(PoiCategory pc : categories) {
|
||||
if(skipNonEditable && pc.isNotEditableOsm()) {
|
||||
continue;
|
||||
}
|
||||
for(PoiType pt : pc.getPoiTypes()) {
|
||||
if(pt.isReference() ) {
|
||||
continue;
|
||||
|
|
|
@ -44,7 +44,6 @@ import android.widget.ImageButton;
|
|||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
|
@ -253,17 +252,35 @@ public class EditPoiDialogFragment extends DialogFragment {
|
|||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (!getEditPoiData().isInEdit()) {
|
||||
PoiType pt = getEditPoiData().getAllTranslatedSubTypes().get(s.toString().toLowerCase());
|
||||
if(pt != null) {
|
||||
poiTypeTextInputLayout.setHint(pt.getCategory().getTranslation());
|
||||
}
|
||||
getEditPoiData().updateTypeTag(s.toString());
|
||||
poiTypeTextInputLayout.setHint(editPoiData.getPoiCategory().getTranslation());
|
||||
}
|
||||
}
|
||||
});
|
||||
poiNameEditText.setOnEditorActionListener(mOnEditorActionListener);
|
||||
poiTypeEditText.setOnEditorActionListener(mOnEditorActionListener);
|
||||
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);
|
||||
saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil
|
||||
|
@ -299,7 +316,7 @@ public class EditPoiDialogFragment extends DialogFragment {
|
|||
HashSet<String> tagsCopy = new HashSet<>();
|
||||
tagsCopy.addAll(editPoiData.getTagValues().keySet());
|
||||
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));
|
||||
} else {
|
||||
new SaveWithAdvancedTagsDialogFragment().show(getChildFragmentManager(), "dialog");
|
||||
|
@ -446,41 +463,26 @@ public class EditPoiDialogFragment extends DialogFragment {
|
|||
}.execute();
|
||||
}
|
||||
|
||||
public void updateType(PoiCategory type) {
|
||||
public void setPoiCategory(PoiCategory type) {
|
||||
editPoiData.updateType(type);
|
||||
poiTypeEditText.setText(editPoiData.getPoiTypeString());
|
||||
poiTypeTextInputLayout.setHint(editPoiData.getPoiCategory().getTranslation());
|
||||
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() {
|
||||
final Map<String, PoiType> subCategories = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, PoiType> s : editPoiData.getAllTranslatedSubTypes().entrySet()) {
|
||||
if (!subCategories.containsKey(s.getKey())) {
|
||||
subCategories.put(Algorithms.capitalizeFirstLetterAndLowercase(s.getKey()), s.getValue());
|
||||
PoiCategory ct = editPoiData.getPoiCategory();
|
||||
if(ct != null) {
|
||||
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;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
adapter = new ArrayAdapter<>(getActivity(),
|
||||
|
@ -518,7 +520,7 @@ public class EditPoiDialogFragment extends DialogFragment {
|
|||
//noinspection SuspiciousMethodCalls
|
||||
PoiType pt = subCategories.get(item);
|
||||
String keyName = pt.getKeyName();
|
||||
poiTypeTextInputLayout.setHint(pt.getCategory().getTranslation());
|
||||
setAdapterForPoiTypeEditText();
|
||||
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() {
|
||||
return (OsmandApplication) getActivity().getApplication();
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package net.osmand.plus.osmedit.dialogs;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.osm.MapPoiTypes;
|
||||
import net.osmand.osm.PoiCategory;
|
||||
|
@ -24,8 +24,12 @@ public class PoiSubTypeDialogFragment extends DialogFragment {
|
|||
MapPoiTypes poiTypes = ((OsmandApplication) getActivity().getApplication()).getPoiTypes();
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
final PoiCategory a = poiTypes.getPoiCategoryByName((String) getArguments().getSerializable(KEY_POI_CATEGORY));
|
||||
final Map<String, PoiType> allTranslatedNames = poiTypes.getAllTranslatedNames(a, true);
|
||||
Set<String> strings = allTranslatedNames.keySet();
|
||||
List<String> strings = new ArrayList<>();
|
||||
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()]);
|
||||
builder.setItems(subCats, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
|
|
|
@ -36,7 +36,7 @@ public class PoiTypeDialogFragment extends DialogFragment {
|
|||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
PoiCategory aType = categories.get(which);
|
||||
((EditPoiDialogFragment) getParentFragment()).updateType(aType);
|
||||
((EditPoiDialogFragment) getParentFragment()).setPoiCategory(aType);
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue