Merge remote-tracking branch 'osmandapp/tag_autocomplete_fix'
This commit is contained in:
commit
921e7bae4f
2 changed files with 83 additions and 13 deletions
|
@ -23,6 +23,11 @@ import android.widget.LinearLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
|
import net.osmand.StringMatcher;
|
||||||
|
import net.osmand.osm.AbstractPoiType;
|
||||||
|
import net.osmand.osm.MapPoiTypes;
|
||||||
|
import net.osmand.osm.PoiCategory;
|
||||||
|
import net.osmand.osm.PoiFilter;
|
||||||
import net.osmand.osm.PoiType;
|
import net.osmand.osm.PoiType;
|
||||||
import net.osmand.osm.edit.OSMSettings;
|
import net.osmand.osm.edit.OSMSettings;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
@ -32,9 +37,9 @@ import net.osmand.plus.osmedit.data.Tag;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
|
||||||
|
|
||||||
public class AdvancedDataFragment extends Fragment {
|
public class AdvancedDataFragment extends Fragment {
|
||||||
private static final String TAG = "AdvancedDataFragment";
|
private static final String TAG = "AdvancedDataFragment";
|
||||||
|
@ -72,7 +77,7 @@ public class AdvancedDataFragment extends Fragment {
|
||||||
(LinearLayout) view.findViewById(R.id.editTagsList);
|
(LinearLayout) view.findViewById(R.id.editTagsList);
|
||||||
mAdapter = new TagAdapterLinearLayoutHack(editTagsLineaLayout, getData(),
|
mAdapter = new TagAdapterLinearLayoutHack(editTagsLineaLayout, getData(),
|
||||||
nameTextView, amenityTagTextView, amenityTextView,
|
nameTextView, amenityTagTextView, amenityTextView,
|
||||||
((OsmandApplication) getActivity().getApplication()).getPoiTypes().getAllTranslatedNames());
|
((OsmandApplication) getActivity().getApplication()).getPoiTypes());
|
||||||
// setListViewHeightBasedOnChildren(editTagsLineaLayout);
|
// setListViewHeightBasedOnChildren(editTagsLineaLayout);
|
||||||
Button addTagButton = (Button) view.findViewById(R.id.addTagButton);
|
Button addTagButton = (Button) view.findViewById(R.id.addTagButton);
|
||||||
addTagButton.setOnClickListener(new View.OnClickListener() {
|
addTagButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@ -127,19 +132,28 @@ public class AdvancedDataFragment extends Fragment {
|
||||||
private final TextView amenityTagTextView;
|
private final TextView amenityTagTextView;
|
||||||
private final TextView amenityTextView;
|
private final TextView amenityTextView;
|
||||||
private final Map<String, PoiType> allTranslatedSubTypes;
|
private final Map<String, PoiType> allTranslatedSubTypes;
|
||||||
|
private final Map<String, AbstractPoiType> allTypes;
|
||||||
|
private final MapPoiTypes mapPoiTypes;
|
||||||
|
|
||||||
public TagAdapterLinearLayoutHack(LinearLayout linearLayout,
|
public TagAdapterLinearLayoutHack(LinearLayout linearLayout,
|
||||||
EditPoiData editPoiData,
|
EditPoiData editPoiData,
|
||||||
TextView nameTextView,
|
TextView nameTextView,
|
||||||
TextView amenityTagTextView,
|
TextView amenityTagTextView,
|
||||||
TextView amenityTextView,
|
TextView amenityTextView,
|
||||||
Map<String, PoiType> allTranslatedSubTypes) {
|
MapPoiTypes mapPoiTypes) {
|
||||||
this.linearLayout = linearLayout;
|
this.linearLayout = linearLayout;
|
||||||
this.editPoiData = editPoiData;
|
this.editPoiData = editPoiData;
|
||||||
this.nameTextView = nameTextView;
|
this.nameTextView = nameTextView;
|
||||||
this.amenityTagTextView = amenityTagTextView;
|
this.amenityTagTextView = amenityTagTextView;
|
||||||
this.amenityTextView = amenityTextView;
|
this.amenityTextView = amenityTextView;
|
||||||
this.allTranslatedSubTypes = allTranslatedSubTypes;
|
this.allTranslatedSubTypes = mapPoiTypes.getAllTranslatedNames();
|
||||||
|
this.allTypes = mapPoiTypes.getAllTypesTranslatedNames(new StringMatcher() {
|
||||||
|
@Override
|
||||||
|
public boolean matches(String name) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.mapPoiTypes = mapPoiTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTag(Tag tag) {
|
public void addTag(Tag tag) {
|
||||||
|
@ -185,14 +199,10 @@ public class AdvancedDataFragment extends Fragment {
|
||||||
deleteItemImageButton.setOnClickListener(new View.OnClickListener() {
|
deleteItemImageButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
LOG.debug("onClick(" + "v=" + v + ") tag=" + tag
|
|
||||||
+ "; editPoiData.tags" + editPoiData.tags);
|
|
||||||
linearLayout.removeView((View) v.getParent());
|
linearLayout.removeView((View) v.getParent());
|
||||||
editPoiData.tags.remove(tag);
|
editPoiData.tags.remove(tag);
|
||||||
LOG.debug("editPoiData.tags" + editPoiData.tags + " mIsUserInput=" + mIsUserInput);
|
|
||||||
if (mIsUserInput)
|
if (mIsUserInput)
|
||||||
editPoiData.notifyDatasetChanged(null);
|
editPoiData.notifyDatasetChanged(null);
|
||||||
LOG.debug("editPoiData.tags" + editPoiData.tags);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
tagEditText.addTextChangedListener(new TextWatcher() {
|
tagEditText.addTextChangedListener(new TextWatcher() {
|
||||||
|
@ -213,12 +223,14 @@ public class AdvancedDataFragment extends Fragment {
|
||||||
editPoiData.notifyDatasetChanged(mTagsChangedListener);
|
editPoiData.notifyDatasetChanged(mTagsChangedListener);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
final Set<String> tagKeys = new TreeSet<>();
|
final Set<String> tagKeys = new HashSet<>();
|
||||||
for (OSMSettings.OSMTagKey t : OSMSettings.OSMTagKey.values()) {
|
for (String s : allTypes.keySet()) {
|
||||||
if (t != OSMSettings.OSMTagKey.NAME) {
|
AbstractPoiType abstractPoiType = allTypes.get(s);
|
||||||
tagKeys.add(t.getValue());
|
addPoiToStringSet(abstractPoiType, tagKeys);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// addPoiToStringSet(mapPoiTypes.getOtherPoiCategory(), tagKeys);
|
||||||
|
addPoiToStringSet(mapPoiTypes.getOtherMapCategory(), tagKeys);
|
||||||
|
TagTester.areAllTagsPresent(tagKeys);
|
||||||
|
|
||||||
ArrayAdapter<Object> adapter = new ArrayAdapter<>(linearLayout.getContext(),
|
ArrayAdapter<Object> adapter = new ArrayAdapter<>(linearLayout.getContext(),
|
||||||
R.layout.list_textview, tagKeys.toArray());
|
R.layout.list_textview, tagKeys.toArray());
|
||||||
|
@ -262,4 +274,36 @@ public class AdvancedDataFragment extends Fragment {
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void addPoiToStringSet(AbstractPoiType abstractPoiType, Set<String> stringSet) {
|
||||||
|
if (abstractPoiType instanceof PoiType) {
|
||||||
|
PoiType poiType = (PoiType) abstractPoiType;
|
||||||
|
if (poiType.getOsmTag() != null &&
|
||||||
|
!poiType.getOsmTag().equals(OSMSettings.OSMTagKey.NAME.getValue())) {
|
||||||
|
stringSet.add(poiType.getOsmTag());
|
||||||
|
if (poiType.getOsmTag2() != null) {
|
||||||
|
stringSet.add(poiType.getOsmTag2());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (abstractPoiType instanceof PoiCategory) {
|
||||||
|
PoiCategory poiCategory = (PoiCategory) abstractPoiType;
|
||||||
|
for (PoiFilter filter : poiCategory.getPoiFilters()) {
|
||||||
|
addPoiToStringSet(filter, stringSet);
|
||||||
|
}
|
||||||
|
for (PoiType poiType : poiCategory.getPoiTypes()) {
|
||||||
|
addPoiToStringSet(poiType, stringSet);
|
||||||
|
}
|
||||||
|
for (PoiType poiType : poiCategory.getPoiAdditionals()) {
|
||||||
|
addPoiToStringSet(poiType, stringSet);
|
||||||
|
}
|
||||||
|
} else if (abstractPoiType instanceof PoiFilter) {
|
||||||
|
PoiFilter poiFilter = (PoiFilter) abstractPoiType;
|
||||||
|
for (PoiType poiType : poiFilter.getPoiTypes()) {
|
||||||
|
addPoiToStringSet(poiType, stringSet);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("abstractPoiType can't be instance of class "
|
||||||
|
+ abstractPoiType.getClass());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
26
OsmAnd/src/net/osmand/plus/osmedit/TagTester.java
Normal file
26
OsmAnd/src/net/osmand/plus/osmedit/TagTester.java
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue