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