POI multiselection: combine standard filters for faster filtering

This commit is contained in:
Roman Inflianskas 2016-04-22 23:31:29 +03:00
parent b1875f8287
commit 2390c95a1b
4 changed files with 58 additions and 19 deletions

View file

@ -271,6 +271,9 @@ public class MapActivityLayers {
for (PoiUIFilter f : poiFilters.getTopDefinedPoiFilters()) {
addFilterToList(adapter, list, f);
}
for (PoiUIFilter f : poiFilters.getSearchPoiFilters()) {
addFilterToList(adapter, list, f);
}
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
ListAdapter listAdapter = adapter.createListAdapter(activity, app.getSettings().isLightContent());

View file

@ -15,8 +15,10 @@ import net.osmand.util.Algorithms;
import android.support.annotation.NonNull;
import android.util.ArraySet;
import java.lang.reflect.Array;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
@ -126,7 +128,7 @@ public class PoiFiltersHelper {
}
return null;
}
public PoiUIFilter getFilterById(String filterId){
if (filterId == null){
return null;
@ -182,13 +184,23 @@ public class PoiFiltersHelper {
}
return userDefinedFilters;
}
public List<PoiUIFilter> getSearchPoiFilters() {
List<PoiUIFilter> result = new ArrayList<>();
List<PoiUIFilter> filters = Arrays.asList(getCustomPOIFilter(), // getShowAllPOIFilter(),
getSearchByNamePOIFilter(), getNominatimPOIFilter(), getNominatimAddressFilter());
for (PoiUIFilter f : filters)
if (f != null && !f.isEmpty())
result.add(f);
return result;
}
public List<PoiUIFilter> getTopDefinedPoiFilters() {
if (cacheTopStandardFilters == null) {
List<PoiUIFilter> top = new ArrayList<PoiUIFilter>();
// user defined
top.addAll(getUserDefinedPoiFilters());
if(getLocalWikiPOIFilter() != null) {
if (getLocalWikiPOIFilter() != null) {
top.add(getLocalWikiPOIFilter());
}
// default
@ -294,14 +306,20 @@ public class PoiFiltersHelper {
saveSelectedPoiFilters();
}
public String getSelectedPoiFiltersName() {
if (!isShowingAnyPoi()) {
public String getFiltersName(Set<PoiUIFilter> filters) {
if (filters.isEmpty()) {
return application.getResources().getString(R.string.shared_string_none);
}
List<String> names = new ArrayList<String>();
for (PoiUIFilter filter : selectedPoiFilters)
names.add(filter.getName());
return android.text.TextUtils.join(", ", names);
else {
List<String> names = new ArrayList<>();
for (PoiUIFilter filter : filters)
names.add(filter.getName());
return android.text.TextUtils.join(", ", names);
}
}
public String getSelectedPoiFiltersName() {
return getFiltersName(selectedPoiFilters);
}
public boolean isPoiFilterSelected(PoiUIFilter filter) {

View file

@ -11,7 +11,9 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import net.osmand.CollatorStringMatcher;
import net.osmand.CollatorStringMatcher.StringMatcherMode;
@ -353,8 +355,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
public String getNameTokenOpen() {
return app.getString(R.string.shared_string_open);
}
private ResultMatcher<Amenity> wrapResultMatcher(final ResultMatcher<Amenity> matcher) {
final AmenityNameFilter nm = getNameFilter(filterByName);
return new ResultMatcher<Amenity>() {
@ -488,14 +489,31 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
}
}
public void replaceWithPoiFilter(PoiUIFilter f) {
acceptedTypes.clear();
public void combineWithPoiFilter(PoiUIFilter f) {
acceptedTypes.putAll(f.acceptedTypes);
poiAdditionals.clear();
poiAdditionals.putAll(f.poiAdditionals);
}
public static void combineStandardPoiFilters(Set<PoiUIFilter> filters, OsmandApplication app) {
Set<PoiUIFilter> standardFilters = new TreeSet<>();
for (PoiUIFilter filter : filters)
if (filter.isStandardFilter() && filter.filterId.startsWith(PoiUIFilter.STD_PREFIX))
standardFilters.add(filter);
if (!standardFilters.isEmpty()) {
PoiUIFilter standardFiltersCombined = new PoiUIFilter(
null, app, app.getPoiFilters().getFiltersName(standardFilters));
for (PoiUIFilter f : standardFilters)
standardFiltersCombined.combineWithPoiFilter(f);
filters.removeAll(standardFilters);
filters.add(standardFiltersCombined);
}
}
public void replaceWithPoiFilter(PoiUIFilter f) {
clearFilter();
combineWithPoiFilter(f);
}
public Map<PoiCategory, LinkedHashSet<String>> getAcceptedTypes(){
return new LinkedHashMap<PoiCategory, LinkedHashSet<String>>(acceptedTypes);
}
@ -563,7 +581,8 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
@Override
public boolean isEmpty() {
return acceptedTypes.isEmpty();
return acceptedTypes.isEmpty() &&
(currentSearchResult == null || currentSearchResult.isEmpty());
}
@Override
@ -579,6 +598,4 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
public boolean accept(Amenity a) ;
}
}

View file

@ -122,6 +122,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
int z = (int) Math.floor(tileBox.getZoom() + Math.log(view.getSettings().MAP_DENSITY.get()) / Math.log(2));
List<Amenity> res = new ArrayList<>();
PoiUIFilter.combineStandardPoiFilters(filters, app);
for (PoiUIFilter filter : filters)
res.addAll(filter.searchAmenities(latLonBounds.top, latLonBounds.left,
latLonBounds.bottom, latLonBounds.right, z, new ResultMatcher<Amenity>() {