diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java index aa51de0c4b..a080b25851 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/BinaryMapPoiReaderAdapter.java @@ -715,6 +715,10 @@ public class BinaryMapPoiReaderAdapter { am.setRoutePoint(arp); } } + PoiType poiType = poiTypes.getPoiTypeByKeyInCategory(am.getType(), am.getSubType()); + if (poiType != null && poiType.isForbidden()) { + return null; + } return am; case OsmandOdb.OsmAndPoiBoxDataAtom.DX_FIELD_NUMBER: x = (codedIS.readSInt32() + (px << (24 - zoom))) << 7; diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/AbstractPoiType.java b/OsmAnd-java/src/main/java/net/osmand/osm/AbstractPoiType.java index 5a8d801d25..3d9ae43b66 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/AbstractPoiType.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/AbstractPoiType.java @@ -21,6 +21,7 @@ public abstract class AbstractPoiType { private String synonyms; private String enTranslation; private String translation; + private boolean isForbidden; public AbstractPoiType(String keyName, MapPoiTypes registry) { this.keyName = keyName; @@ -67,6 +68,13 @@ public abstract class AbstractPoiType { return this instanceof PoiType && this.isAdditional(); } + public void setForbidden(boolean forbidden) { + isForbidden = forbidden; + } + + public boolean isForbidden() { + return isForbidden; + } public String getTranslation() { if(translation == null) { diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java index d0c941a898..9f6b42933e 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/MapPoiTypes.java @@ -946,13 +946,11 @@ public class MapPoiTypes { } } - public void excludeSpeedCameraPoiType() { + public void forbidPoiType(String keyName) { for (PoiCategory category : categories) { - Iterator poiIter = category.getPoiTypes().iterator(); - while (poiIter.hasNext()) { - PoiType poiType = poiIter.next(); - if ("speed_camera".equals(poiType.getKeyName())) { - poiIter.remove(); + for (PoiType poiType : category.getPoiTypes()) { + if (keyName.equals(poiType.getKeyName())) { + poiType.setForbidden(true); } } } diff --git a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java index 1143a2965b..53c035fdaa 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/SearchUICore.java @@ -657,8 +657,6 @@ public class SearchUICore { private List exportedObjects; private List exportedCities; - public static boolean speedCamerasUninstalled = false; - public SearchResultMatcher(ResultMatcher matcher, SearchPhrase phrase, int request, AtomicInteger requestNumber, int totalLimit) { this.matcher = matcher; @@ -736,7 +734,7 @@ public class SearchUICore { @Override public boolean publish(SearchResult object) { - if (speedCamerasUninstalled && isSpeedCameraObject(object.object)) { + if (isPoiTypeForbidden(object.object)) { return false; } if (phrase != null && object.otherNames != null && !phrase.getFirstUnknownNameStringMatcher().matches(object.localeName)) { @@ -893,14 +891,11 @@ public class SearchUICore { return json; } - private boolean isSpeedCameraObject(Object object) { - String key = ""; + private boolean isPoiTypeForbidden(Object object) { if (object instanceof PoiType) { - key = ((PoiType) object).getKeyName(); - } else if (object instanceof Amenity) { - key = ((Amenity) object).getSubType(); + return ((PoiType) object).isForbidden(); } - return "speed_camera".equals(key); + return false; } } diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index e07399832c..f7c1d89aba 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -86,6 +86,7 @@ import java.util.Random; import btools.routingapp.BRouterServiceConnection; import static net.osmand.plus.AppVersionUpgradeOnInit.LAST_APP_VERSION; +import static net.osmand.plus.dialogs.SpeedCamerasBottomSheet.SPEED_CAMERA_KEY_NAME; import static net.osmand.plus.liveupdates.LiveUpdatesHelper.getPendingIntent; import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLastCheck; import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLiveUpdatesOn; @@ -407,7 +408,7 @@ public class AppInitializer implements IProgress { } }); if (app.getSettings().SPEED_CAMERAS_UNINSTALLED.get()) { - app.getPoiTypes().excludeSpeedCameraPoiType(); + app.getPoiTypes().forbidPoiType(SPEED_CAMERA_KEY_NAME); } } diff --git a/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java b/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java index dc2b01fcb8..cd6b8f487a 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/SpeedCamerasBottomSheet.java @@ -8,7 +8,6 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -21,12 +20,11 @@ import net.osmand.plus.helpers.FontCache; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference; import net.osmand.plus.settings.fragments.OnPreferenceChanged; -import net.osmand.plus.widgets.style.CustomTypefaceSpan; -import net.osmand.search.SearchUICore.SearchResultMatcher; public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment { public static final String TAG = SpeedCamerasBottomSheet.class.getName(); + public static final String SPEED_CAMERA_KEY_NAME = "speed_camera"; private OsmandApplication app; private OsmandSettings settings; @@ -65,8 +63,7 @@ public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment { speedCamUninstalled.set(true); settings.SPEAK_SPEED_CAMERA.set(false); settings.SHOW_CAMERAS.set(false); - app.getPoiTypes().excludeSpeedCameraPoiType(); - SearchResultMatcher.speedCamerasUninstalled = true; + app.getPoiTypes().forbidPoiType(SPEED_CAMERA_KEY_NAME); Fragment targetFragment = getTargetFragment(); if (targetFragment instanceof OnPreferenceChanged) { ((OnPreferenceChanged) targetFragment).onPreferenceChanged(speedCamUninstalled.getId()); diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java index 0878f0a37c..55da1967d0 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java @@ -70,7 +70,6 @@ public class QuickSearchHelper implements ResourceListener { core = new SearchUICore(app.getPoiTypes(), settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get()); app.getResourceManager().addResourceListener(this); - SearchResultMatcher.speedCamerasUninstalled = settings.SPEED_CAMERAS_UNINSTALLED.get(); } public SearchUICore getCore() { diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchSubCategoriesFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchSubCategoriesFragment.java index 09777e794d..f7b58f6ab6 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchSubCategoriesFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchSubCategoriesFragment.java @@ -35,6 +35,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; +import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -86,6 +87,12 @@ public class QuickSearchSubCategoriesFragment extends BaseOsmAndDialogFragment { acceptedCategories = new HashSet<>(savedInstanceState.getStringArrayList(ACCEPTED_CATEGORIES_KEY)); } poiTypeList = new ArrayList<>(poiCategory.getPoiTypes()); + Iterator iter = poiTypeList.iterator(); + while (iter.hasNext()) { + if (iter.next().isForbidden()) { + iter.remove(); + } + } Collections.sort(poiTypeList, new Comparator() { @Override public int compare(PoiType poiType, PoiType t1) {