Added OR AND for poi additional filter
This commit is contained in:
parent
f54fdefd81
commit
28bb3bf873
1 changed files with 42 additions and 25 deletions
|
@ -1,18 +1,8 @@
|
||||||
package net.osmand.plus.poi;
|
package net.osmand.plus.poi;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import android.content.Context;
|
||||||
import java.util.Calendar;
|
import android.support.annotation.NonNull;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
|
|
||||||
import net.osmand.CollatorStringMatcher;
|
import net.osmand.CollatorStringMatcher;
|
||||||
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
||||||
|
@ -34,8 +24,19 @@ import net.osmand.util.Algorithms;
|
||||||
import net.osmand.util.MapUtils;
|
import net.osmand.util.MapUtils;
|
||||||
import net.osmand.util.OpeningHoursParser;
|
import net.osmand.util.OpeningHoursParser;
|
||||||
import net.osmand.util.OpeningHoursParser.OpeningHours;
|
import net.osmand.util.OpeningHoursParser.OpeningHours;
|
||||||
import android.content.Context;
|
|
||||||
import android.support.annotation.NonNull;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>, CustomSearchPoiFilter {
|
public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>, CustomSearchPoiFilter {
|
||||||
|
|
||||||
|
@ -289,7 +290,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
||||||
String[] items = filter.split(" ");
|
String[] items = filter.split(" ");
|
||||||
boolean allTime = false;
|
boolean allTime = false;
|
||||||
boolean open = false;
|
boolean open = false;
|
||||||
Map<PoiType, String> poiAdditionalsFilter = null;
|
List<PoiType> poiAdditionalsFilter = null;
|
||||||
for (String s : items) {
|
for (String s : items) {
|
||||||
s = s.trim();
|
s = s.trim();
|
||||||
if (!Algorithms.isEmpty(s)) {
|
if (!Algorithms.isEmpty(s)) {
|
||||||
|
@ -299,9 +300,12 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
||||||
open = true;
|
open = true;
|
||||||
} else if (poiAdditionals.containsKey(s.toLowerCase())) {
|
} else if (poiAdditionals.containsKey(s.toLowerCase())) {
|
||||||
if (poiAdditionalsFilter == null) {
|
if (poiAdditionalsFilter == null) {
|
||||||
poiAdditionalsFilter = new LinkedHashMap<PoiType, String>();
|
poiAdditionalsFilter = new ArrayList<>();
|
||||||
|
}
|
||||||
|
PoiType pt = poiAdditionals.get(s.toLowerCase());
|
||||||
|
if (pt != null) {
|
||||||
|
poiAdditionalsFilter.add(pt);
|
||||||
}
|
}
|
||||||
poiAdditionalsFilter.put(poiAdditionals.get(s.toLowerCase()), null);
|
|
||||||
} else {
|
} else {
|
||||||
nmFilter.append(s).append(" ");
|
nmFilter.append(s).append(" ");
|
||||||
}
|
}
|
||||||
|
@ -311,7 +315,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
||||||
}
|
}
|
||||||
|
|
||||||
private AmenityNameFilter getNameFilterInternal(StringBuilder nmFilter,
|
private AmenityNameFilter getNameFilterInternal(StringBuilder nmFilter,
|
||||||
final boolean allTime, final boolean open, final Map<PoiType, String> poiAdditionals) {
|
final boolean allTime, final boolean open, final List<PoiType> poiAdditionals) {
|
||||||
final CollatorStringMatcher sm =
|
final CollatorStringMatcher sm =
|
||||||
nmFilter.length() > 0 ?
|
nmFilter.length() > 0 ?
|
||||||
new CollatorStringMatcher(nmFilter.toString().trim(), StringMatcherMode.CHECK_CONTAINS) : null;
|
new CollatorStringMatcher(nmFilter.toString().trim(), StringMatcherMode.CHECK_CONTAINS) : null;
|
||||||
|
@ -327,13 +331,26 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (poiAdditionals != null) {
|
if (poiAdditionals != null) {
|
||||||
Iterator<Entry<PoiType, String>> it = poiAdditionals.entrySet().iterator();
|
Map<String, List<PoiType>> poiAdditionalCategoriesMap = new HashMap<>();
|
||||||
while (it.hasNext()) {
|
for (PoiType pt : poiAdditionals) {
|
||||||
Entry<PoiType, String> e = it.next();
|
String category = pt.getPoiAdditionalCategory();
|
||||||
String inf = a.getAdditionalInfo(e.getKey().getKeyName());
|
List<PoiType> types = poiAdditionalCategoriesMap.get(category);
|
||||||
if (inf == null) {
|
if (types == null) {
|
||||||
return false;
|
types = new ArrayList<>();
|
||||||
} else if (e.getValue() != null && !e.getValue().equalsIgnoreCase(inf)) {
|
poiAdditionalCategoriesMap.put(category, types);
|
||||||
|
}
|
||||||
|
types.add(pt);
|
||||||
|
}
|
||||||
|
for (List<PoiType> types : poiAdditionalCategoriesMap.values()) {
|
||||||
|
boolean acceptedAnyInCategory = false;
|
||||||
|
for (PoiType p : types) {
|
||||||
|
String inf = a.getAdditionalInfo(p.getKeyName());
|
||||||
|
if (inf != null) {
|
||||||
|
acceptedAnyInCategory = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!acceptedAnyInCategory) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue