Fix poi editing
This commit is contained in:
parent
e5b240b728
commit
7e8b008a81
3 changed files with 44 additions and 14 deletions
|
@ -77,20 +77,26 @@ public class MapPoiTypes {
|
|||
return otherCategory;
|
||||
}
|
||||
|
||||
public Map<String, PoiType> getAllTranslatedNames() {
|
||||
public Map<String, PoiType> getAllTranslatedNames(boolean onlyTranslation) {
|
||||
Map<String, PoiType> translation = new TreeMap<String, PoiType>();
|
||||
for(PoiCategory pc : categories) {
|
||||
for(PoiType pt : pc.getPoiTypes()) {
|
||||
translation.put(pt.getTranslation(), pt);
|
||||
if (!onlyTranslation) {
|
||||
translation.put(Algorithms.capitalizeFirstLetterAndLowercase(pt.getKeyName().replace('_', ' ')), pt);
|
||||
}
|
||||
}
|
||||
}
|
||||
return translation;
|
||||
}
|
||||
|
||||
public Map<String, PoiType> getAllTranslatedNames(PoiCategory pc) {
|
||||
public Map<String, PoiType> getAllTranslatedNames(PoiCategory pc, boolean onlyTranslation) {
|
||||
Map<String, PoiType> translation = new TreeMap<String, PoiType>();
|
||||
for (PoiType pt : pc.getPoiTypes()) {
|
||||
translation.put(pt.getTranslation(), pt);
|
||||
if (!onlyTranslation) {
|
||||
translation.put(pt.getKeyName(), pt);
|
||||
}
|
||||
}
|
||||
return translation;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.osmedit;
|
|||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -45,6 +46,8 @@ import android.text.method.LinkMovementMethod;
|
|||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemSelectedListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
|
@ -97,7 +100,7 @@ public class EditingPOIActivity implements DialogProvider {
|
|||
this.ctx = uiContext;
|
||||
|
||||
poiTypes = uiContext.getMyApplication().getPoiTypes();
|
||||
allTranslatedSubTypes = poiTypes.getAllTranslatedNames();
|
||||
allTranslatedSubTypes = poiTypes.getAllTranslatedNames(false);
|
||||
settings = ((OsmandApplication) uiContext.getApplication()).getSettings();
|
||||
if (settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) {
|
||||
this.openstreetmapUtil = new OpenstreetmapLocalUtil(ctx);
|
||||
|
@ -462,7 +465,7 @@ public class EditingPOIActivity implements DialogProvider {
|
|||
.getString(R.string.poi_action_change);
|
||||
OsmPoint.Action action = n.getId() == -1 ? OsmPoint.Action.CREATE : OsmPoint.Action.MODIFY;
|
||||
String subType = typeText.getText().toString();
|
||||
if(allTranslatedSubTypes.get(subType) != null) {
|
||||
if(allTranslatedSubTypes.get(subType.trim()) != null) {
|
||||
PoiType pt = allTranslatedSubTypes.get(subType);
|
||||
n.putTag(pt.getOsmTag() , pt.getOsmValue());
|
||||
if(pt.getOsmTag2() != null) {
|
||||
|
@ -527,14 +530,34 @@ public class EditingPOIActivity implements DialogProvider {
|
|||
}
|
||||
|
||||
private void updateSubTypesAdapter(PoiCategory poiCategory) {
|
||||
Set<String> subCategories = new LinkedHashSet<String>(poiTypes.getAllTranslatedNames(poiCategory).keySet());
|
||||
for (String s : poiTypes.getAllTranslatedNames().keySet()) {
|
||||
if (!subCategories.contains(s)) {
|
||||
subCategories.add(s);
|
||||
}
|
||||
}
|
||||
ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(ctx, R.layout.list_textview, subCategories.toArray());
|
||||
final Map<String, PoiType> subCategories = getSubCategoriesMap(poiCategory);
|
||||
final ArrayAdapter<Object> adapter = new ArrayAdapter<Object>(ctx, R.layout.list_textview, subCategories.keySet().toArray());
|
||||
typeText.setAdapter(adapter);
|
||||
typeText.setOnItemSelectedListener(new OnItemSelectedListener() {
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
Object item = parent.getAdapter().getItem(position);
|
||||
if(subCategories.containsKey(item)) {
|
||||
String kn = subCategories.get(item).getKeyName();
|
||||
typeText.setText(kn);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Map<String, PoiType> getSubCategoriesMap(PoiCategory poiCategory) {
|
||||
Map<String, PoiType> subCategories = new LinkedHashMap<>(poiTypes.getAllTranslatedNames(poiCategory, false));
|
||||
for (Map.Entry<String, PoiType> s : poiTypes.getAllTranslatedNames(false).entrySet()) {
|
||||
if (!subCategories.containsKey(s.getKey())) {
|
||||
subCategories.put(s.getKey(), s.getValue());
|
||||
}
|
||||
}
|
||||
return subCategories;
|
||||
}
|
||||
|
||||
private void updateType(Amenity a){
|
||||
|
@ -627,12 +650,14 @@ public class EditingPOIActivity implements DialogProvider {
|
|||
case DIALOG_SUB_CATEGORIES: {
|
||||
Builder builder = new AlertDialog.Builder(ctx);
|
||||
final Amenity a = (Amenity) args.getSerializable(KEY_AMENITY);
|
||||
final String[] subCats = poiTypes.getAllTranslatedNames(a.getType()).keySet().toArray(new String[0]);
|
||||
final Map<String, PoiType> allTranslatedNames = poiTypes.getAllTranslatedNames(a.getType(), true);
|
||||
final String[] subCats = allTranslatedNames.keySet().toArray(new String[0]);
|
||||
builder.setItems(subCats, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
typeText.setText(subCats[which]);
|
||||
a.setSubType(subCats[which]);
|
||||
PoiType poiType = allTranslatedNames.get(subCats[which]);
|
||||
typeText.setText(poiType.getKeyName());
|
||||
a.setSubType(poiType.getKeyName());
|
||||
ctx.removeDialog(DIALOG_SUB_CATEGORIES);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -2,7 +2,6 @@ package net.osmand.plus.osmedit;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import net.osmand.data.AmenityType;
|
||||
import net.osmand.osm.edit.Node;
|
||||
import net.osmand.osm.edit.OSMSettings.OSMTagKey;
|
||||
|
||||
|
|
Loading…
Reference in a new issue