Fixed additional poi search
This commit is contained in:
parent
127482bfa1
commit
4a684f197e
1 changed files with 40 additions and 22 deletions
|
@ -48,6 +48,8 @@ import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -78,6 +80,7 @@ public class QuickSearchPoiFilterFragment extends DialogFragment {
|
||||||
private Set<String> selectedPoiAdditionalsOrig = new TreeSet<>();
|
private Set<String> selectedPoiAdditionalsOrig = new TreeSet<>();
|
||||||
private ArrayList<String> collapsedCategories = new ArrayList<>();
|
private ArrayList<String> collapsedCategories = new ArrayList<>();
|
||||||
private ArrayList<String> showAllCategories = new ArrayList<>();
|
private ArrayList<String> showAllCategories = new ArrayList<>();
|
||||||
|
private Map<PoiType, String> poiAdditionalsTranslations = new HashMap<>();
|
||||||
|
|
||||||
public QuickSearchPoiFilterFragment() {
|
public QuickSearchPoiFilterFragment() {
|
||||||
}
|
}
|
||||||
|
@ -441,14 +444,14 @@ public class QuickSearchPoiFilterFragment extends DialogFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (poiAdditionals != null) {
|
if (poiAdditionals != null) {
|
||||||
Map<String, Set<String>> additionalsMap = new TreeMap<>();
|
Map<String, List<PoiType>> additionalsMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
extractPoiAdditionals(poiAdditionals.values(), additionalsMap, excludedPoiAdditionalCategories, true);
|
extractPoiAdditionals(poiAdditionals.values(), additionalsMap, excludedPoiAdditionalCategories, true);
|
||||||
extractPoiAdditionals(otherAdditionalCategories, additionalsMap, excludedPoiAdditionalCategories, true);
|
extractPoiAdditionals(otherAdditionalCategories, additionalsMap, excludedPoiAdditionalCategories, true);
|
||||||
|
|
||||||
if (additionalsMap.size() > 0) {
|
if (additionalsMap.size() > 0) {
|
||||||
for (Entry<String, Set<String>> entry : additionalsMap.entrySet()) {
|
for (Entry<String, List<PoiType>> entry : additionalsMap.entrySet()) {
|
||||||
for (String poiTypeName : entry.getValue()) {
|
for (PoiType poiType : entry.getValue()) {
|
||||||
String keyName = poiTypeName.replace(' ', ':').toLowerCase();
|
String keyName = poiType.getKeyName().replace('_', ':').toLowerCase();
|
||||||
index = filterByName.indexOf(keyName);
|
index = filterByName.indexOf(keyName);
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
selectedPoiAdditionals.add(keyName);
|
selectedPoiAdditionals.add(keyName);
|
||||||
|
@ -523,12 +526,12 @@ public class QuickSearchPoiFilterFragment extends DialogFragment {
|
||||||
selectedPoiAdditionals.contains(keyNameOpen24), null, keyNameOpen24));
|
selectedPoiAdditionals.contains(keyNameOpen24), null, keyNameOpen24));
|
||||||
}
|
}
|
||||||
if (poiAdditionals != null) {
|
if (poiAdditionals != null) {
|
||||||
Map<String, Set<String>> additionalsMap = new TreeMap<>();
|
Map<String, List<PoiType>> additionalsMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
extractPoiAdditionals(poiAdditionals.values(), additionalsMap, excludedPoiAdditionalCategories, false);
|
extractPoiAdditionals(poiAdditionals.values(), additionalsMap, excludedPoiAdditionalCategories, false);
|
||||||
extractPoiAdditionals(otherAdditionalCategories, additionalsMap, excludedPoiAdditionalCategories, false);
|
extractPoiAdditionals(otherAdditionalCategories, additionalsMap, excludedPoiAdditionalCategories, false);
|
||||||
|
|
||||||
if (additionalsMap.size() > 0) {
|
if (additionalsMap.size() > 0) {
|
||||||
for (Entry<String, Set<String>> entry : additionalsMap.entrySet()) {
|
for (Entry<String, List<PoiType>> entry : additionalsMap.entrySet()) {
|
||||||
String category = entry.getKey();
|
String category = entry.getKey();
|
||||||
String categoryLocalizedName = poiTypes.getPoiTranslation(category);
|
String categoryLocalizedName = poiTypes.getPoiTranslation(category);
|
||||||
boolean expanded = !collapsedCategories.contains(category);
|
boolean expanded = !collapsedCategories.contains(category);
|
||||||
|
@ -549,14 +552,26 @@ public class QuickSearchPoiFilterFragment extends DialogFragment {
|
||||||
|
|
||||||
items.add(new PoiFilterListItem(PoiFilterListItemType.GROUP_HEADER,
|
items.add(new PoiFilterListItem(PoiFilterListItemType.GROUP_HEADER,
|
||||||
categoryIconId, categoryLocalizedName, ++groupId, true, expanded, false, category, null));
|
categoryIconId, categoryLocalizedName, ++groupId, true, expanded, false, category, null));
|
||||||
List<String> poiTypeNames = new ArrayList<>(entry.getValue());
|
List<PoiType> categoryPoiAdditionals = new ArrayList<>(entry.getValue());
|
||||||
Collections.sort(poiTypeNames);
|
Collections.sort(categoryPoiAdditionals, new Comparator<PoiType>() {
|
||||||
for (String poiTypeName : poiTypeNames) {
|
@Override
|
||||||
String keyName = poiTypeName.replace(' ', ':').toLowerCase();
|
public int compare(PoiType p1, PoiType p2) {
|
||||||
items.add(new PoiFilterListItem(PoiFilterListItemType.CHECKBOX_ITEM,
|
String firstPoiTypeTranslation = poiAdditionalsTranslations.get(p1);
|
||||||
0, poiTypeName, groupId, false, false, selectedPoiAdditionals.contains(keyName), category, keyName));
|
String secondPoiTypeTranslation = poiAdditionalsTranslations.get(p2);
|
||||||
|
if (firstPoiTypeTranslation != null && secondPoiTypeTranslation != null) {
|
||||||
|
return firstPoiTypeTranslation.compareTo(secondPoiTypeTranslation);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
if (!showAll && poiTypeNames.size() > 0) {
|
}
|
||||||
|
});
|
||||||
|
for (PoiType poiType : categoryPoiAdditionals) {
|
||||||
|
String keyName = poiType.getKeyName().replace('_', ':').toLowerCase();
|
||||||
|
String translation = poiAdditionalsTranslations.get(poiType);
|
||||||
|
items.add(new PoiFilterListItem(PoiFilterListItemType.CHECKBOX_ITEM,
|
||||||
|
0, translation, groupId, false, false, selectedPoiAdditionals.contains(keyName), category, keyName));
|
||||||
|
}
|
||||||
|
if (!showAll && categoryPoiAdditionals.size() > 0) {
|
||||||
items.add(new PoiFilterListItem(PoiFilterListItemType.BUTTON_ITEM,
|
items.add(new PoiFilterListItem(PoiFilterListItemType.BUTTON_ITEM,
|
||||||
0, app.getString(R.string.shared_string_show_all).toUpperCase(), groupId, false, false, false, category, null));
|
0, app.getString(R.string.shared_string_show_all).toUpperCase(), groupId, false, false, false, category, null));
|
||||||
}
|
}
|
||||||
|
@ -567,7 +582,7 @@ public class QuickSearchPoiFilterFragment extends DialogFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void extractPoiAdditionals(Collection<PoiType> poiAdditionals,
|
private void extractPoiAdditionals(Collection<PoiType> poiAdditionals,
|
||||||
Map<String, Set<String>> additionalsMap,
|
Map<String, List<PoiType>> additionalsMap,
|
||||||
Set<String> excludedPoiAdditionalCategories,
|
Set<String> excludedPoiAdditionalCategories,
|
||||||
boolean extractAll) {
|
boolean extractAll) {
|
||||||
for (PoiType poiType : poiAdditionals) {
|
for (PoiType poiType : poiAdditionals) {
|
||||||
|
@ -580,20 +595,24 @@ public class QuickSearchPoiFilterFragment extends DialogFragment {
|
||||||
}
|
}
|
||||||
if (collapsedCategories.contains(category) && !extractAll) {
|
if (collapsedCategories.contains(category) && !extractAll) {
|
||||||
if (!additionalsMap.containsKey(category)) {
|
if (!additionalsMap.containsKey(category)) {
|
||||||
additionalsMap.put(category, new TreeSet<String>());
|
additionalsMap.put(category, new ArrayList<PoiType>());
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
boolean showAll = showAllCategories.contains(category) || extractAll;
|
boolean showAll = showAllCategories.contains(category) || extractAll;
|
||||||
String name = poiType.getTranslation();
|
String keyName = poiType.getKeyName().replace('_', ':').toLowerCase();
|
||||||
String keyName = name.replace(' ', ':').toLowerCase();
|
if (!poiAdditionalsTranslations.containsKey(poiType)) {
|
||||||
if (showAll || poiType.isTopVisible() || selectedPoiAdditionals.contains(keyName)) {
|
poiAdditionalsTranslations.put(poiType, poiType.getTranslation());
|
||||||
Set<String> adds = additionalsMap.get(category);
|
}
|
||||||
|
if (showAll || poiType.isTopVisible() || selectedPoiAdditionals.contains(keyName.replace(' ', ':'))) {
|
||||||
|
List<PoiType> adds = additionalsMap.get(category);
|
||||||
if (adds == null) {
|
if (adds == null) {
|
||||||
adds = new TreeSet<>();
|
adds = new ArrayList<>();
|
||||||
additionalsMap.put(category, adds);
|
additionalsMap.put(category, adds);
|
||||||
}
|
}
|
||||||
adds.add(name);
|
if (!adds.contains(poiType)) {
|
||||||
|
adds.add(poiType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -635,8 +654,7 @@ public class QuickSearchPoiFilterFragment extends DialogFragment {
|
||||||
} else {
|
} else {
|
||||||
topFalseOnlyCategories.remove(category);
|
topFalseOnlyCategories.remove(category);
|
||||||
}
|
}
|
||||||
String name = poiType.getTranslation();
|
String keyName = poiType.getKeyName().replace('_', ':').replace(' ', ':').toLowerCase();
|
||||||
String keyName = name.replace(' ', ':').toLowerCase();
|
|
||||||
if (selectedPoiAdditionals.contains(keyName)) {
|
if (selectedPoiAdditionals.contains(keyName)) {
|
||||||
selectedCategories.add(category);
|
selectedCategories.add(category);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue