Update poi types
This commit is contained in:
parent
c6ad42ee79
commit
f498454734
2 changed files with 115 additions and 42 deletions
|
@ -14,6 +14,7 @@ import java.util.Map;
|
|||
import java.util.TreeMap;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.StringMatcher;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -120,6 +121,31 @@ public class MapPoiTypes {
|
|||
return translation;
|
||||
}
|
||||
|
||||
public Map<String, AbstractPoiType> getAllTypesTranslatedNames(StringMatcher matcher) {
|
||||
TreeMap<String, AbstractPoiType> tm = new TreeMap<String, AbstractPoiType>(Collator.getInstance());
|
||||
Map<String, PoiType> translation = new TreeMap<String, PoiType>();
|
||||
for(PoiCategory pc : categories) {
|
||||
addIf(tm, pc, matcher);
|
||||
for(PoiFilter pt : pc.getPoiFilters()) {
|
||||
addIf(tm, pt, matcher);
|
||||
}
|
||||
for(PoiType pt : pc.getPoiTypes()) {
|
||||
if(pt.isReference()) {
|
||||
continue;
|
||||
}
|
||||
addIf(tm, pt, matcher);
|
||||
}
|
||||
}
|
||||
return tm;
|
||||
}
|
||||
|
||||
private void addIf(Map<String, AbstractPoiType> tm, AbstractPoiType pc, StringMatcher matcher) {
|
||||
if(matcher.matches(pc.getTranslation()) || matcher.matches(pc.getKeyName().replace('_', ' '))) {
|
||||
tm.put(pc.getTranslation(), pc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Map<String, PoiType> getAllTranslatedNames(PoiCategory pc, boolean onlyTranslation) {
|
||||
Map<String, PoiType> translation = new TreeMap<String, PoiType>();
|
||||
for (PoiType pt : pc.getPoiTypes()) {
|
||||
|
|
|
@ -5,9 +5,14 @@ package net.osmand.plus.activities.search;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.osmand.CollatorStringMatcher;
|
||||
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.osm.AbstractPoiType;
|
||||
import net.osmand.osm.PoiType;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -19,6 +24,7 @@ import net.osmand.plus.poi.PoiLegacyFilter;
|
|||
import net.osmand.plus.poi.SearchByNameFilter;
|
||||
import net.osmand.plus.render.RenderingIcons;
|
||||
import net.osmand.plus.resources.ResourceManager;
|
||||
import net.osmand.util.Algorithms;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
|
@ -85,6 +91,11 @@ public class SearchPoiFilterFragment extends ListFragment implements SearchActiv
|
|||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if(currentTask != null) {
|
||||
currentTask.cancel(true);
|
||||
}
|
||||
currentTask = new SearchPoiByNameTask();
|
||||
currentTask.execute(s.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -92,16 +103,30 @@ public class SearchPoiFilterFragment extends ListFragment implements SearchActiv
|
|||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
refreshPoiListAdapter();
|
||||
poiFitlersAdapter = new PoiFiltersAdapter(getFilters(""));
|
||||
setListAdapter(poiFitlersAdapter);
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
public void refreshPoiListAdapter() {
|
||||
PoiFiltersHelper poiFilters = getApp().getPoiFilters();
|
||||
List<PoiLegacyFilter> filters = new ArrayList<PoiLegacyFilter>() ;
|
||||
filters.addAll(poiFilters.getTopDefinedPoiFilters());
|
||||
poiFitlersAdapter = new PoiFiltersAdapter(filters);
|
||||
setListAdapter(poiFitlersAdapter);
|
||||
public List<Object> getFilters(String s) {
|
||||
List<Object> filters = new ArrayList<Object>() ;
|
||||
if (Algorithms.isEmpty(s)) {
|
||||
PoiFiltersHelper poiFilters = getApp().getPoiFilters();
|
||||
filters.addAll(poiFilters.getTopDefinedPoiFilters());
|
||||
} else {
|
||||
PoiFiltersHelper poiFilters = getApp().getPoiFilters();
|
||||
for(PoiLegacyFilter pf : poiFilters.getTopDefinedPoiFilters()) {
|
||||
if(!pf.isStandardFilter()) {
|
||||
filters.add(pf);
|
||||
}
|
||||
}
|
||||
Map<String, AbstractPoiType> res =
|
||||
getApp().getPoiTypes().getAllTypesTranslatedNames(new CollatorStringMatcher(s, StringMatcherMode.CHECK_STARTS_FROM_SPACE));
|
||||
for(AbstractPoiType p : res.values()) {
|
||||
filters.add(p);
|
||||
}
|
||||
}
|
||||
return filters;
|
||||
}
|
||||
|
||||
public OsmandApplication getApp(){
|
||||
|
@ -137,76 +162,100 @@ public class SearchPoiFilterFragment extends ListFragment implements SearchActiv
|
|||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if(requestCode == REQUEST_POI_EDIT) {
|
||||
refreshPoiListAdapter();
|
||||
poiFitlersAdapter.setResult(getFilters(searchEditText == null ? "" : searchEditText.getText().toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView listView, View v, int position, long id) {
|
||||
final PoiLegacyFilter filter = ((PoiFiltersAdapter) getListAdapter()).getItem(position);
|
||||
if(!(filter instanceof NameFinderPoiFilter)){
|
||||
ResourceManager rm = getApp().getResourceManager();
|
||||
if(!rm.containsAmenityRepositoryToSearch(filter instanceof SearchByNameFilter)){
|
||||
AccessibleToast.makeText(getActivity(), R.string.data_to_search_poi_not_available, Toast.LENGTH_LONG);
|
||||
return;
|
||||
}
|
||||
final Object item = ((PoiFiltersAdapter) getListAdapter()).getItem(position);
|
||||
ResourceManager rm = getApp().getResourceManager();
|
||||
if (!rm.containsAmenityRepositoryToSearch(false)) {
|
||||
AccessibleToast.makeText(getActivity(), R.string.data_to_search_poi_not_available, Toast.LENGTH_LONG);
|
||||
return;
|
||||
}
|
||||
if (item instanceof PoiLegacyFilter) {
|
||||
showFilterActivity(((PoiLegacyFilter) item).getFilterId());
|
||||
} else {
|
||||
showFilterActivity(PoiLegacyFilter.STD_PREFIX + ((AbstractPoiType) item).getKeyName());
|
||||
}
|
||||
showFilterActivity(filter);
|
||||
}
|
||||
|
||||
private void showFilterActivity(final PoiLegacyFilter filter) {
|
||||
private void showFilterActivity(String filterId) {
|
||||
final Intent newIntent = new Intent(getActivity(), SearchPOIActivity.class);
|
||||
newIntent.putExtra(SearchPOIActivity.AMENITY_FILTER, filter.getFilterId());
|
||||
newIntent.putExtra(SearchPOIActivity.AMENITY_FILTER, filterId);
|
||||
updateIntentToLaunch(newIntent);
|
||||
startActivityForResult(newIntent, 0);
|
||||
}
|
||||
|
||||
class SearchPoiByNameTask extends AsyncTask<Void, PoiLegacyFilter, List<PoiLegacyFilter>> {
|
||||
class SearchPoiByNameTask extends AsyncTask<String, Object, List<Object>> {
|
||||
|
||||
@Override
|
||||
protected List<PoiLegacyFilter> doInBackground(Void... params) {
|
||||
return null;
|
||||
protected List<Object> doInBackground(String... params) {
|
||||
String filter = params[0];
|
||||
return getFilters(filter);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<PoiLegacyFilter> result) {
|
||||
super.onPostExecute(result);
|
||||
protected void onPostExecute(List<Object> result) {
|
||||
if(!isCancelled() && isVisible()){
|
||||
poiFitlersAdapter.setResult(result);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class PoiFiltersAdapter extends ArrayAdapter<PoiLegacyFilter> {
|
||||
class PoiFiltersAdapter extends ArrayAdapter<Object> {
|
||||
|
||||
|
||||
PoiFiltersAdapter(List<PoiLegacyFilter> list) {
|
||||
PoiFiltersAdapter(List<Object> list) {
|
||||
super(getActivity(), R.layout.searchpoifolder_list, list);
|
||||
}
|
||||
|
||||
public void setResult(List<Object> filters) {
|
||||
setNotifyOnChange(false);
|
||||
clear();
|
||||
for(Object o : filters) {
|
||||
add(o);
|
||||
}
|
||||
setNotifyOnChange(true);
|
||||
notifyDataSetInvalidated();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View row = convertView;
|
||||
if(row == null) {
|
||||
if (row == null) {
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
row = inflater.inflate(R.layout.searchpoifolder_list, parent, false);
|
||||
}
|
||||
TextView label = (TextView) row.findViewById(R.id.folder_label);
|
||||
ImageView icon = (ImageView) row.findViewById(R.id.folder_icon);
|
||||
OsmandApplication app = getMyApplication();
|
||||
final PoiLegacyFilter model = getItem(position);
|
||||
label.setText(model.getName());
|
||||
IconsCache iconsCache = app.getIconsCache();
|
||||
if(model.getFilterId().equals(PoiLegacyFilter.CUSTOM_FILTER_ID)) {
|
||||
icon.setImageDrawable(iconsCache.getContentIcon(R.drawable.ic_action_filter_dark));
|
||||
} else if (model.getFilterId().equals(PoiLegacyFilter.BY_NAME_FILTER_ID)) {
|
||||
icon.setImageResource(android.R.drawable.ic_search_category_default);
|
||||
} else {
|
||||
if(RenderingIcons.containsBigIcon(model.getSimplifiedId())) {
|
||||
Object item = getItem(position);
|
||||
String name;
|
||||
if (item instanceof PoiLegacyFilter) {
|
||||
final PoiLegacyFilter model = (PoiLegacyFilter) item;
|
||||
if (RenderingIcons.containsBigIcon(model.getSimplifiedId())) {
|
||||
icon.setImageDrawable(RenderingIcons.getBigIcon(getActivity(), model.getSimplifiedId()));
|
||||
} else {
|
||||
icon.setImageResource(R.drawable.mx_user_defined);
|
||||
}
|
||||
name = model.getName();
|
||||
} else {
|
||||
AbstractPoiType st = (AbstractPoiType) item;
|
||||
if (RenderingIcons.containsBigIcon(st.getKeyName())) {
|
||||
icon.setImageDrawable(RenderingIcons.getBigIcon(getActivity(), st.getKeyName()));
|
||||
} else if (st instanceof PoiType
|
||||
&& RenderingIcons.containsBigIcon(((PoiType) st).getOsmTag() + "_"
|
||||
+ ((PoiType) st).getOsmValue())) {
|
||||
icon.setImageResource(RenderingIcons.getBigIconResourceId(((PoiType) st).getOsmTag() + "_"
|
||||
+ ((PoiType) st).getOsmValue()));
|
||||
} else {
|
||||
icon.setImageDrawable(null);
|
||||
}
|
||||
name = st.getTranslation();
|
||||
}
|
||||
label.setText(name);
|
||||
return (row);
|
||||
}
|
||||
}
|
||||
|
@ -221,11 +270,9 @@ public class SearchPoiFilterFragment extends ListFragment implements SearchActiv
|
|||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
PoiLegacyFilter filter = getApp().getPoiFilters().getFilterById(PoiLegacyFilter.CUSTOM_FILTER_ID);
|
||||
if(filter != null) {
|
||||
filter.clearFilter();
|
||||
showEditActivity(filter);
|
||||
}
|
||||
PoiLegacyFilter filter = getApp().getPoiFilters().getCustomPOIFilter();
|
||||
filter.clearFilter();
|
||||
showEditActivity(filter);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue