Refactor edit poi
This commit is contained in:
parent
862353b602
commit
053abea161
10 changed files with 94 additions and 75 deletions
|
@ -28,7 +28,7 @@ public class Amenity extends MapObject {
|
|||
|
||||
private static final long serialVersionUID = 132083949926339552L;
|
||||
private String subType;
|
||||
private transient PoiCategory type;
|
||||
private PoiCategory type;
|
||||
// duplicate for fast access
|
||||
private String openingHours;
|
||||
private Map<String, String> additionalInfo;
|
||||
|
|
|
@ -18,7 +18,7 @@ import net.osmand.util.Algorithms;
|
|||
import net.sf.junidecode.Junidecode;
|
||||
|
||||
|
||||
public abstract class MapObject implements Comparable<MapObject>, Serializable {
|
||||
public abstract class MapObject implements Comparable<MapObject> {
|
||||
protected String name = null;
|
||||
protected String enName = null;
|
||||
protected Map<String, String> names = null;
|
||||
|
|
|
@ -14,7 +14,7 @@ public abstract class AbstractPoiType {
|
|||
private boolean topVisible;
|
||||
private String lang;
|
||||
private AbstractPoiType baseLangType;
|
||||
|
||||
private boolean notEditableOsm;
|
||||
|
||||
public AbstractPoiType(String keyName, MapPoiTypes registry) {
|
||||
this.keyName = keyName;
|
||||
|
@ -76,6 +76,14 @@ public abstract class AbstractPoiType {
|
|||
return poiAdditionals;
|
||||
}
|
||||
|
||||
public boolean isNotEditableOsm() {
|
||||
return notEditableOsm;
|
||||
}
|
||||
|
||||
public void setNotEditableOsm(boolean notEditableOsm) {
|
||||
this.notEditableOsm = notEditableOsm;
|
||||
}
|
||||
|
||||
public abstract Map<PoiCategory, LinkedHashSet<String>> putTypes(Map<PoiCategory, LinkedHashSet<String>> acceptedTypes);
|
||||
|
||||
|
||||
|
|
|
@ -274,6 +274,7 @@ public class MapPoiTypes {
|
|||
if (name.equals("poi_category")) {
|
||||
lastCategory = new PoiCategory(this, parser.getAttributeValue("", "name"), categories.size());
|
||||
lastCategory.setTopVisible(Boolean.parseBoolean(parser.getAttributeValue("", "top")));
|
||||
lastCategory.setNotEditableOsm("true".equals(parser.getAttributeValue("", "no_edit")));
|
||||
categories.add(lastCategory);
|
||||
} else if (name.equals("poi_filter")) {
|
||||
PoiFilter tp = new PoiFilter(this, lastCategory, parser.getAttributeValue("", "name"));
|
||||
|
|
|
@ -12,7 +12,7 @@ public class PoiType extends AbstractPoiType {
|
|||
private String osmTag2;
|
||||
private String osmValue;
|
||||
private String osmValue2;
|
||||
private boolean notEditableOsm;
|
||||
|
||||
|
||||
private String nameTag;
|
||||
private boolean text;
|
||||
|
@ -145,13 +145,6 @@ public class PoiType extends AbstractPoiType {
|
|||
this.relation = relation;
|
||||
}
|
||||
|
||||
public boolean isNotEditableOsm() {
|
||||
return notEditableOsm;
|
||||
}
|
||||
|
||||
public void setNotEditableOsm(boolean notEditableOsm) {
|
||||
this.notEditableOsm = notEditableOsm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
|
|
@ -110,14 +110,13 @@ public class AdvancedEditPoiFragment extends Fragment
|
|||
nameTextView.setText(value);
|
||||
}
|
||||
if (Algorithms.objectEquals(anyTag, EditPoiData.POI_TYPE_TAG)) {
|
||||
String subType = value == null ? "" : value.trim().toLowerCase();
|
||||
if (allTranslatedSubTypes.get(subType) != null) {
|
||||
PoiType pt = allTranslatedSubTypes.get(subType);
|
||||
PoiType pt = getData().getPoiTypeDefined();
|
||||
if (pt != null) {
|
||||
amenityTagTextView.setText(pt.getOsmTag());
|
||||
amenityTextView.setText(pt.getOsmValue());
|
||||
} else {
|
||||
amenityTagTextView.setText(getData().amenity.getType().getDefaultTag());
|
||||
amenityTextView.setText(subType);
|
||||
amenityTagTextView.setText(getData().getPoiCategory().getDefaultTag());
|
||||
amenityTextView.setText(getData().getPoiTypeString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,12 @@ package net.osmand.plus.osmedit;
|
|||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.osm.PoiCategory;
|
||||
import net.osmand.osm.PoiType;
|
||||
import net.osmand.osm.edit.Node;
|
||||
import net.osmand.osm.edit.OSMSettings;
|
||||
import net.osmand.osm.edit.OSMSettings.OSMTagKey;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -22,16 +24,42 @@ public class EditPoiData {
|
|||
private LinkedHashMap<String, String > tagValues = new LinkedHashMap<String, String>();
|
||||
private boolean isInEdit = false;
|
||||
private Node entity;
|
||||
public final Amenity amenity;
|
||||
|
||||
public static final String POI_TYPE_TAG = "poi_type_tag";
|
||||
private boolean hasChangesBeenMade = false;
|
||||
private Map<String, PoiType> allTranslatedSubTypes;
|
||||
private PoiCategory category;
|
||||
private String subtype;
|
||||
|
||||
public EditPoiData(Amenity amenity, Node node, Map<String, PoiType> allTranslatedSubTypes) {
|
||||
this.amenity = amenity;
|
||||
public EditPoiData(Node node, OsmandApplication app) {
|
||||
allTranslatedSubTypes = app.getPoiTypes().getAllTranslatedNames(true);
|
||||
category = app.getPoiTypes().getOtherPoiCategory();
|
||||
this.subtype = "";
|
||||
entity = node;
|
||||
initTags(node, allTranslatedSubTypes);
|
||||
initTags(node);
|
||||
}
|
||||
|
||||
public Map<String, PoiType> getAllTranslatedSubTypes() {
|
||||
return allTranslatedSubTypes;
|
||||
}
|
||||
|
||||
public void updateType(PoiCategory type) {
|
||||
category = type;
|
||||
subtype = "";
|
||||
}
|
||||
|
||||
|
||||
public PoiCategory getPoiCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public PoiType getPoiTypeDefined() {
|
||||
return allTranslatedSubTypes.get(getPoiTypeString());
|
||||
}
|
||||
|
||||
public String getPoiTypeString() {
|
||||
return subtype;
|
||||
}
|
||||
|
||||
public Node getEntity() {
|
||||
return entity;
|
||||
|
@ -42,8 +70,10 @@ public class EditPoiData {
|
|||
}
|
||||
|
||||
public void updateTags(Map<String, String> mp) {
|
||||
checkNotInEdit();
|
||||
this.tagValues.clear();
|
||||
this.tagValues.putAll(mp);
|
||||
retrieveType();
|
||||
}
|
||||
|
||||
private void tryAddTag(String key, String value) {
|
||||
|
@ -52,18 +82,23 @@ public class EditPoiData {
|
|||
}
|
||||
}
|
||||
|
||||
private void initTags(Node node, Map<String, PoiType> allTranslatedSubTypes) {
|
||||
private void initTags(Node node) {
|
||||
checkNotInEdit();
|
||||
for (String s : node.getTagKeySet()) {
|
||||
tryAddTag(s, node.getTag(s));
|
||||
}
|
||||
String subType = amenity.getSubType();
|
||||
String value ="";
|
||||
PoiType pt = amenity.getType().getPoiTypeByKeyName(subType);
|
||||
if (pt != null) {
|
||||
value = pt.getTranslation();
|
||||
retrieveType();
|
||||
}
|
||||
|
||||
private void retrieveType() {
|
||||
String tp = tagValues.get(POI_TYPE_TAG);
|
||||
if(tp != null) {
|
||||
PoiType pt = allTranslatedSubTypes.get(tp);
|
||||
if (pt != null) {
|
||||
subtype = tp;
|
||||
category = pt.getCategory();
|
||||
}
|
||||
}
|
||||
tagValues.put(POI_TYPE_TAG, value);
|
||||
}
|
||||
|
||||
|
||||
|
@ -147,4 +182,6 @@ public class EditPoiData {
|
|||
return hasChangesBeenMade;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -44,11 +44,11 @@ import android.widget.ImageButton;
|
|||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.osm.PoiCategory;
|
||||
import net.osmand.osm.PoiType;
|
||||
import net.osmand.osm.edit.EntityInfo;
|
||||
import net.osmand.osm.edit.Node;
|
||||
|
@ -75,7 +75,6 @@ public class EditPoiDialogFragment extends DialogFragment {
|
|||
private static final Log LOG = PlatformUtil.getLog(EditPoiDialogFragment.class);
|
||||
|
||||
private static final String KEY_AMENITY_NODE = "key_amenity_node";
|
||||
private static final String KEY_AMENITY = "key_amenity";
|
||||
private static final String TAGS_LIST = "tags_list";
|
||||
private static final String IS_ADDING_POI = "is_adding_poi";
|
||||
|
||||
|
@ -99,10 +98,7 @@ public class EditPoiDialogFragment extends DialogFragment {
|
|||
}
|
||||
|
||||
Node node = (Node) getArguments().getSerializable(KEY_AMENITY_NODE);
|
||||
allTranslatedSubTypes = getMyApplication().getPoiTypes().getAllTranslatedNames(true);
|
||||
|
||||
Amenity amenity = (Amenity) getArguments().getSerializable(KEY_AMENITY);
|
||||
editPoiData = new EditPoiData(amenity, node, allTranslatedSubTypes);
|
||||
editPoiData = new EditPoiData(node, getMyApplication());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -201,7 +197,7 @@ public class EditPoiDialogFragment extends DialogFragment {
|
|||
poiTypeButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
DialogFragment fragment = PoiTypeDialogFragment.createInstance(editPoiData.amenity);
|
||||
DialogFragment fragment = PoiTypeDialogFragment.createInstance();
|
||||
fragment.show(getChildFragmentManager(), "PoiTypeDialogFragment");
|
||||
}
|
||||
});
|
||||
|
@ -249,7 +245,7 @@ public class EditPoiDialogFragment extends DialogFragment {
|
|||
});
|
||||
poiNameEditText.setOnEditorActionListener(mOnEditorActionListener);
|
||||
poiTypeEditText.setOnEditorActionListener(mOnEditorActionListener);
|
||||
poiTypeEditText.setText(editPoiData.amenity.getSubType());
|
||||
poiTypeEditText.setText(editPoiData.getPoiTypeString());
|
||||
|
||||
Button saveButton = (Button) view.findViewById(R.id.saveButton);
|
||||
saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil
|
||||
|
@ -297,7 +293,7 @@ public class EditPoiDialogFragment extends DialogFragment {
|
|||
node.putTag(poiType.getOsmTag2(), poiType.getOsmValue2());
|
||||
}
|
||||
} else {
|
||||
node.putTag(editPoiData.amenity.getType().getDefaultTag(), tag.getValue());
|
||||
node.putTag(editPoiData.getPoiCategory().getDefaultTag(), tag.getValue());
|
||||
|
||||
}
|
||||
} else if (!Algorithms.isEmpty(tag.getKey()) && !Algorithms.isEmpty(tag.getValue())) {
|
||||
|
@ -306,15 +302,15 @@ public class EditPoiDialogFragment extends DialogFragment {
|
|||
}
|
||||
commitNode(action, node, mOpenstreetmapUtil.getEntityInfo(),
|
||||
"",
|
||||
false,//closeChange.isSelected(),
|
||||
false,
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
|
||||
if (plugin != null) {
|
||||
if (plugin != null && mOpenstreetmapUtil instanceof OpenstreetmapLocalUtil) {
|
||||
List<OpenstreetmapPoint> points = plugin.getDBPOI().getOpenstreetmapPoints();
|
||||
if (getActivity() instanceof MapActivity && points.size() > 0) {
|
||||
OsmPoint point = points.get(points.size() - 1);
|
||||
if (getActivity() instanceof MapActivity) {
|
||||
MapActivity mapActivity = (MapActivity) getActivity();
|
||||
mapActivity.getContextMenu().showOrUpdate(new LatLon(point.getLatitude(), point.getLongitude()),
|
||||
plugin.getOsmEditsLayer(mapActivity).getObjectName(point), point);
|
||||
|
@ -408,9 +404,10 @@ public class EditPoiDialogFragment extends DialogFragment {
|
|||
}.execute();
|
||||
}
|
||||
|
||||
public void updateType(Amenity amenity) {
|
||||
poiTypeEditText.setText(amenity.getSubType());
|
||||
poiTypeTextInputLayout.setHint(amenity.getType().getTranslation());
|
||||
public void updateType(PoiCategory type) {
|
||||
editPoiData.updateType(type);
|
||||
poiTypeEditText.setText(editPoiData.getPoiTypeString());
|
||||
poiTypeTextInputLayout.setHint(editPoiData.getPoiCategory().getTranslation());
|
||||
setAdapterForPoiTypeEditText();
|
||||
poiTypeEditText.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
|
@ -421,9 +418,9 @@ public class EditPoiDialogFragment extends DialogFragment {
|
|||
if (event.getX() >= (editText.getRight()
|
||||
- editText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width()
|
||||
- editText.getPaddingRight())) {
|
||||
if (editPoiData.amenity.getType() != null) {
|
||||
if (editPoiData.getPoiCategory() != null) {
|
||||
DialogFragment dialogFragment =
|
||||
PoiSubTypeDialogFragment.createInstance(editPoiData.amenity);
|
||||
PoiSubTypeDialogFragment.createInstance(editPoiData.getPoiCategory());
|
||||
dialogFragment.show(getChildFragmentManager(), "PoiSubTypeDialogFragment");
|
||||
}
|
||||
|
||||
|
@ -497,20 +494,13 @@ public class EditPoiDialogFragment extends DialogFragment {
|
|||
public static EditPoiDialogFragment createAddPoiInstance(double latitude, double longitude,
|
||||
OsmandApplication application) {
|
||||
Node node = new Node(latitude, longitude, -1);
|
||||
Amenity amenity;
|
||||
amenity = new Amenity();
|
||||
amenity.setType(application.getPoiTypes().getOtherPoiCategory());
|
||||
amenity.setSubType("");
|
||||
amenity.setAdditionalInfo(OSMSettings.OSMTagKey.OPENING_HOURS.getValue(), "");
|
||||
return createInstance(node, amenity, true);
|
||||
return createInstance(node, true);
|
||||
}
|
||||
|
||||
public static EditPoiDialogFragment createInstance(Node node, Amenity amenity,
|
||||
boolean isAddingPoi) {
|
||||
public static EditPoiDialogFragment createInstance(Node node, boolean isAddingPoi) {
|
||||
EditPoiDialogFragment editPoiDialogFragment = new EditPoiDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable(KEY_AMENITY_NODE, node);
|
||||
args.putSerializable(KEY_AMENITY, amenity);
|
||||
args.putBoolean(IS_ADDING_POI, isAddingPoi);
|
||||
editPoiDialogFragment.setArguments(args);
|
||||
return editPoiDialogFragment;
|
||||
|
@ -537,7 +527,7 @@ public class EditPoiDialogFragment extends DialogFragment {
|
|||
protected void onPostExecute(Node n) {
|
||||
if (n != null) {
|
||||
EditPoiDialogFragment fragment =
|
||||
EditPoiDialogFragment.createInstance(n, amenity, false);
|
||||
EditPoiDialogFragment.createInstance(n, false);
|
||||
fragment.show(activity.getSupportFragmentManager(), TAG);
|
||||
} else {
|
||||
AccessibleToast.makeText(activity,
|
||||
|
|
|
@ -6,9 +6,9 @@ import android.os.Bundle;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.osm.MapPoiTypes;
|
||||
import net.osmand.osm.PoiCategory;
|
||||
import net.osmand.osm.PoiType;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.osmedit.EditPoiDialogFragment;
|
||||
|
@ -17,15 +17,15 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
public class PoiSubTypeDialogFragment extends DialogFragment {
|
||||
private static final String KEY_AMENITY = "amenity";
|
||||
private static final String KEY_POI_CATEGORY = "amenity";
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
MapPoiTypes poiTypes = ((OsmandApplication) getActivity().getApplication()).getPoiTypes();
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
final Amenity a = (Amenity) getArguments().getSerializable(KEY_AMENITY);
|
||||
final Map<String, PoiType> allTranslatedNames = poiTypes.getAllTranslatedNames(a.getType(), true);
|
||||
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();
|
||||
final String[] subCats = strings.toArray(new String[strings.size()]);
|
||||
builder.setItems(subCats, new DialogInterface.OnClickListener() {
|
||||
|
@ -38,10 +38,10 @@ public class PoiSubTypeDialogFragment extends DialogFragment {
|
|||
return builder.create();
|
||||
}
|
||||
|
||||
public static PoiSubTypeDialogFragment createInstance(Amenity amenity) {
|
||||
public static PoiSubTypeDialogFragment createInstance(PoiCategory cat) {
|
||||
PoiSubTypeDialogFragment fragment = new PoiSubTypeDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable(KEY_AMENITY, amenity);
|
||||
args.putSerializable(KEY_POI_CATEGORY, cat.getKeyName());
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
|
|
@ -17,21 +17,17 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
public class PoiTypeDialogFragment extends DialogFragment {
|
||||
private static final String KEY_AMENITY = "amenity";
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
MapPoiTypes poiTypes = ((OsmandApplication) getActivity().getApplication()).getPoiTypes();
|
||||
final Amenity amenity = (Amenity) getArguments().getSerializable(KEY_AMENITY);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
final List<PoiCategory> categories = poiTypes.getCategories(false);
|
||||
ArrayList<String> vals = new ArrayList<>(categories.size());
|
||||
ArrayList<PoiCategory> toDelete = new ArrayList<>();
|
||||
// TODO replace with constants
|
||||
for (PoiCategory category : categories) {
|
||||
if (category.getKeyName().equals("user_defined_other")
|
||||
|| category.getKeyName().equals("osmwiki")) {
|
||||
if (!category.isNotEditableOsm()) {
|
||||
toDelete.add(category);
|
||||
} else {
|
||||
vals.add(category.getTranslation());
|
||||
|
@ -42,21 +38,16 @@ public class PoiTypeDialogFragment extends DialogFragment {
|
|||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
PoiCategory aType = categories.get(which);
|
||||
if (aType != amenity.getType()) {
|
||||
amenity.setType(aType);
|
||||
amenity.setSubType(""); //$NON-NLS-1$
|
||||
((EditPoiDialogFragment) getParentFragment()).updateType(amenity);
|
||||
}
|
||||
((EditPoiDialogFragment) getParentFragment()).updateType(aType);
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
public static PoiTypeDialogFragment createInstance(Amenity amenity) {
|
||||
public static PoiTypeDialogFragment createInstance() {
|
||||
PoiTypeDialogFragment poiTypeDialogFragment = new PoiTypeDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable(KEY_AMENITY, amenity);
|
||||
poiTypeDialogFragment.setArguments(args);
|
||||
return poiTypeDialogFragment;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue