Fix poi additional categories

This commit is contained in:
Alexey Kulish 2016-10-18 19:11:26 +03:00
parent 90cb023cff
commit f911f9f9f5
2 changed files with 27 additions and 15 deletions

View file

@ -141,6 +141,13 @@ public class MapPoiTypes {
return null;
}
public PoiType getPoiTypeByKeyInCategory(PoiCategory category, String keyName) {
if (category != null) {
return category.getPoiTypeByKeyName(keyName);
}
return null;
}
public AbstractPoiType getAnyPoiTypeByKey(String name) {
for (PoiCategory pc : categories) {
if (pc.getKeyName().equals(name)) {

View file

@ -469,18 +469,23 @@ public class QuickSearchPoiFilterFragment extends DialogFragment {
@NonNull
private Set<String> getExcludedPoiAdditionalCategories() {
MapPoiTypes poiTypes = getMyApplication().getPoiTypes();
Set<String> excludedPoiAdditionalCategories = new LinkedHashSet<>();
if (filter.getAcceptedTypes().size() == 0) {
return excludedPoiAdditionalCategories;
}
MapPoiTypes poiTypes = getMyApplication().getPoiTypes();
PoiCategory topCategory = null;
for (Entry<PoiCategory, LinkedHashSet<String>> entry : filter.getAcceptedTypes().entrySet()) {
boolean needTopLevelExclude = false;
Set<String> excluded = new LinkedHashSet<>();
if (topCategory == null) {
topCategory = entry.getKey();
}
if (entry.getValue() != null) {
Set<String> excluded = new LinkedHashSet<>();
for (String keyName : entry.getValue()) {
PoiType poiType = poiTypes.getPoiTypeByKey(keyName);
PoiType poiType = poiTypes.getPoiTypeByKeyInCategory(topCategory, keyName);
if (poiType != null) {
collectExcludedPoiAdditionalCategories(poiType, excluded);
if (!poiType.isReference()) {
needTopLevelExclude = true;
PoiFilter poiFilter = poiType.getFilter();
if (poiFilter != null) {
collectExcludedPoiAdditionalCategories(poiFilter, excluded);
@ -491,19 +496,19 @@ public class QuickSearchPoiFilterFragment extends DialogFragment {
}
}
}
}
} else {
needTopLevelExclude = true;
}
if (excludedPoiAdditionalCategories.size() == 0) {
excludedPoiAdditionalCategories.addAll(excluded);
} else {
excludedPoiAdditionalCategories.retainAll(excluded);
}
if (needTopLevelExclude && entry.getKey().getExcludedPoiAdditionalCategories() != null) {
excludedPoiAdditionalCategories.addAll(entry.getKey().getExcludedPoiAdditionalCategories());
excluded.clear();
}
}
}
if (topCategory != null && topCategory.getExcludedPoiAdditionalCategories() != null) {
excludedPoiAdditionalCategories.addAll(topCategory.getExcludedPoiAdditionalCategories());
}
return excludedPoiAdditionalCategories;
}