From a34a396aa7d42cb4929b1895d76b1d989081d442 Mon Sep 17 00:00:00 2001 From: PaulStets Date: Mon, 26 Feb 2018 12:47:40 +0200 Subject: [PATCH 1/5] Fixed the issue with incorrect values being selected in Charging station filter --- .../osmand/plus/search/QuickSearchPoiFilterFragment.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java index 40b577cd9d..f4da4f76de 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java @@ -45,10 +45,12 @@ import net.osmand.util.Algorithms; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -451,11 +453,11 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { extractPoiAdditionals(otherAdditionalCategories, additionalsMap, excludedPoiAdditionalCategories, true); if (additionalsMap.size() > 0) { + Set filters = new HashSet<>(Arrays.asList(filterByName.split(" "))); for (Entry> entry : additionalsMap.entrySet()) { for (PoiType poiType : entry.getValue()) { String keyName = poiType.getKeyName().replace('_', ':').toLowerCase(); - index = filterByName.indexOf(keyName); - if (index != -1) { + if (filters.contains(keyName)) { selectedPoiAdditionals.add(keyName); filterByName = filterByName.replaceAll(keyName, ""); } From b0b686b258a0952a11e4a5873afe1ab998cd94aa Mon Sep 17 00:00:00 2001 From: PaulStets Date: Mon, 26 Feb 2018 13:43:00 +0200 Subject: [PATCH 2/5] Generate filterByName from the remaining elements in the set --- .../net/osmand/plus/search/QuickSearchPoiFilterFragment.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java index f4da4f76de..28f01c1034 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java @@ -459,7 +459,8 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { String keyName = poiType.getKeyName().replace('_', ':').toLowerCase(); if (filters.contains(keyName)) { selectedPoiAdditionals.add(keyName); - filterByName = filterByName.replaceAll(keyName, ""); + filters.remove(keyName); + filterByName = filters.toString().replaceAll("[,\\[\\]]", ""); } } } From 4f273cd3dff9c7f208752640a9cc3bfb163783c0 Mon Sep 17 00:00:00 2001 From: PaulStets Date: Mon, 26 Feb 2018 14:01:21 +0200 Subject: [PATCH 3/5] Further improvements to Charging station filter --- .../search/QuickSearchPoiFilterFragment.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java index 28f01c1034..5cff317932 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java @@ -51,6 +51,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -460,10 +461,10 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { if (filters.contains(keyName)) { selectedPoiAdditionals.add(keyName); filters.remove(keyName); - filterByName = filters.toString().replaceAll("[,\\[\\]]", ""); } } } + filterByName = nameFromSet(filters); } } if (filterByName.trim().length() > 0 && Algorithms.isEmpty(nameFilterText)) { @@ -472,6 +473,21 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { } } + private String nameFromSet(Set filters) { + Iterator i = filters.iterator(); + if (!i.hasNext()) { + return ""; + } + StringBuilder sb = new StringBuilder(); + for (; ; ) { + String s = i.next(); + sb.append(s); + if (!i.hasNext()) + return sb.toString(); + sb.append(" "); + } + } + @NonNull private Set getExcludedPoiAdditionalCategories() { Set excludedPoiAdditionalCategories = new LinkedHashSet<>(); From 1b9cc4ac98cbdc7f8725eb77d3307d6208e05a93 Mon Sep 17 00:00:00 2001 From: PaulStets Date: Mon, 26 Feb 2018 15:07:00 +0200 Subject: [PATCH 4/5] Replace Set with List in Charging station filter --- .../search/QuickSearchPoiFilterFragment.java | 31 ++++++------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java index 5cff317932..6dbf909e88 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java @@ -50,8 +50,6 @@ import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -454,17 +452,23 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { extractPoiAdditionals(otherAdditionalCategories, additionalsMap, excludedPoiAdditionalCategories, true); if (additionalsMap.size() > 0) { - Set filters = new HashSet<>(Arrays.asList(filterByName.split(" "))); + List filters = new ArrayList<>(Arrays.asList(filterByName.split(" "))); for (Entry> entry : additionalsMap.entrySet()) { for (PoiType poiType : entry.getValue()) { String keyName = poiType.getKeyName().replace('_', ':').toLowerCase(); - if (filters.contains(keyName)) { + index = filters.indexOf(keyName); + if (index != -1) { selectedPoiAdditionals.add(keyName); - filters.remove(keyName); + filters.remove(index); } } } - filterByName = nameFromSet(filters); + StringBuilder sb = new StringBuilder(); + for (String s : filters) { + sb.append(s); + sb.append(" "); + } + filterByName = sb.toString(); } } if (filterByName.trim().length() > 0 && Algorithms.isEmpty(nameFilterText)) { @@ -473,21 +477,6 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { } } - private String nameFromSet(Set filters) { - Iterator i = filters.iterator(); - if (!i.hasNext()) { - return ""; - } - StringBuilder sb = new StringBuilder(); - for (; ; ) { - String s = i.next(); - sb.append(s); - if (!i.hasNext()) - return sb.toString(); - sb.append(" "); - } - } - @NonNull private Set getExcludedPoiAdditionalCategories() { Set excludedPoiAdditionalCategories = new LinkedHashSet<>(); From 41f2cda8a2144f248d7a527925286714396ef974 Mon Sep 17 00:00:00 2001 From: PaulStets Date: Mon, 26 Feb 2018 15:24:47 +0200 Subject: [PATCH 5/5] Minor improvements for list printing --- .../osmand/plus/search/QuickSearchPoiFilterFragment.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java index 6dbf909e88..daaad406a3 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java @@ -10,6 +10,7 @@ import android.support.v7.widget.PopupMenu; import android.support.v7.widget.SwitchCompat; import android.support.v7.widget.Toolbar; import android.text.Editable; +import android.text.TextUtils; import android.text.TextWatcher; import android.view.LayoutInflater; import android.view.MenuItem; @@ -463,12 +464,7 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { } } } - StringBuilder sb = new StringBuilder(); - for (String s : filters) { - sb.append(s); - sb.append(" "); - } - filterByName = sb.toString(); + filterByName = TextUtils.join(" ", filters); } } if (filterByName.trim().length() > 0 && Algorithms.isEmpty(nameFilterText)) {