refactor speed camera restriction

This commit is contained in:
veliymolfar 2020-06-18 12:29:59 +03:00
parent 4009946a32
commit 05ffbdffaa
8 changed files with 31 additions and 22 deletions

View file

@ -715,6 +715,10 @@ public class BinaryMapPoiReaderAdapter {
am.setRoutePoint(arp); am.setRoutePoint(arp);
} }
} }
PoiType poiType = poiTypes.getPoiTypeByKeyInCategory(am.getType(), am.getSubType());
if (poiType != null && poiType.isForbidden()) {
return null;
}
return am; return am;
case OsmandOdb.OsmAndPoiBoxDataAtom.DX_FIELD_NUMBER: case OsmandOdb.OsmAndPoiBoxDataAtom.DX_FIELD_NUMBER:
x = (codedIS.readSInt32() + (px << (24 - zoom))) << 7; x = (codedIS.readSInt32() + (px << (24 - zoom))) << 7;

View file

@ -21,6 +21,7 @@ public abstract class AbstractPoiType {
private String synonyms; private String synonyms;
private String enTranslation; private String enTranslation;
private String translation; private String translation;
private boolean isForbidden;
public AbstractPoiType(String keyName, MapPoiTypes registry) { public AbstractPoiType(String keyName, MapPoiTypes registry) {
this.keyName = keyName; this.keyName = keyName;
@ -67,6 +68,13 @@ public abstract class AbstractPoiType {
return this instanceof PoiType && this.isAdditional(); return this instanceof PoiType && this.isAdditional();
} }
public void setForbidden(boolean forbidden) {
isForbidden = forbidden;
}
public boolean isForbidden() {
return isForbidden;
}
public String getTranslation() { public String getTranslation() {
if(translation == null) { if(translation == null) {

View file

@ -946,13 +946,11 @@ public class MapPoiTypes {
} }
} }
public void excludeSpeedCameraPoiType() { public void forbidPoiType(String keyName) {
for (PoiCategory category : categories) { for (PoiCategory category : categories) {
Iterator<PoiType> poiIter = category.getPoiTypes().iterator(); for (PoiType poiType : category.getPoiTypes()) {
while (poiIter.hasNext()) { if (keyName.equals(poiType.getKeyName())) {
PoiType poiType = poiIter.next(); poiType.setForbidden(true);
if ("speed_camera".equals(poiType.getKeyName())) {
poiIter.remove();
} }
} }
} }

View file

@ -657,8 +657,6 @@ public class SearchUICore {
private List<MapObject> exportedObjects; private List<MapObject> exportedObjects;
private List<City> exportedCities; private List<City> exportedCities;
public static boolean speedCamerasUninstalled = false;
public SearchResultMatcher(ResultMatcher<SearchResult> matcher, SearchPhrase phrase, int request, public SearchResultMatcher(ResultMatcher<SearchResult> matcher, SearchPhrase phrase, int request,
AtomicInteger requestNumber, int totalLimit) { AtomicInteger requestNumber, int totalLimit) {
this.matcher = matcher; this.matcher = matcher;
@ -736,7 +734,7 @@ public class SearchUICore {
@Override @Override
public boolean publish(SearchResult object) { public boolean publish(SearchResult object) {
if (speedCamerasUninstalled && isSpeedCameraObject(object.object)) { if (isPoiTypeForbidden(object.object)) {
return false; return false;
} }
if (phrase != null && object.otherNames != null && !phrase.getFirstUnknownNameStringMatcher().matches(object.localeName)) { if (phrase != null && object.otherNames != null && !phrase.getFirstUnknownNameStringMatcher().matches(object.localeName)) {
@ -893,14 +891,11 @@ public class SearchUICore {
return json; return json;
} }
private boolean isSpeedCameraObject(Object object) { private boolean isPoiTypeForbidden(Object object) {
String key = "";
if (object instanceof PoiType) { if (object instanceof PoiType) {
key = ((PoiType) object).getKeyName(); return ((PoiType) object).isForbidden();
} else if (object instanceof Amenity) {
key = ((Amenity) object).getSubType();
} }
return "speed_camera".equals(key); return false;
} }
} }

View file

@ -86,6 +86,7 @@ import java.util.Random;
import btools.routingapp.BRouterServiceConnection; import btools.routingapp.BRouterServiceConnection;
import static net.osmand.plus.AppVersionUpgradeOnInit.LAST_APP_VERSION; 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.getPendingIntent;
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLastCheck; import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLastCheck;
import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLiveUpdatesOn; import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLiveUpdatesOn;
@ -407,7 +408,7 @@ public class AppInitializer implements IProgress {
} }
}); });
if (app.getSettings().SPEED_CAMERAS_UNINSTALLED.get()) { if (app.getSettings().SPEED_CAMERAS_UNINSTALLED.get()) {
app.getPoiTypes().excludeSpeedCameraPoiType(); app.getPoiTypes().forbidPoiType(SPEED_CAMERA_KEY_NAME);
} }
} }

View file

@ -8,7 +8,6 @@ import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; 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;
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference; import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
import net.osmand.plus.settings.fragments.OnPreferenceChanged; 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 class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment {
public static final String TAG = SpeedCamerasBottomSheet.class.getName(); public static final String TAG = SpeedCamerasBottomSheet.class.getName();
public static final String SPEED_CAMERA_KEY_NAME = "speed_camera";
private OsmandApplication app; private OsmandApplication app;
private OsmandSettings settings; private OsmandSettings settings;
@ -65,8 +63,7 @@ public class SpeedCamerasBottomSheet extends MenuBottomSheetDialogFragment {
speedCamUninstalled.set(true); speedCamUninstalled.set(true);
settings.SPEAK_SPEED_CAMERA.set(false); settings.SPEAK_SPEED_CAMERA.set(false);
settings.SHOW_CAMERAS.set(false); settings.SHOW_CAMERAS.set(false);
app.getPoiTypes().excludeSpeedCameraPoiType(); app.getPoiTypes().forbidPoiType(SPEED_CAMERA_KEY_NAME);
SearchResultMatcher.speedCamerasUninstalled = true;
Fragment targetFragment = getTargetFragment(); Fragment targetFragment = getTargetFragment();
if (targetFragment instanceof OnPreferenceChanged) { if (targetFragment instanceof OnPreferenceChanged) {
((OnPreferenceChanged) targetFragment).onPreferenceChanged(speedCamUninstalled.getId()); ((OnPreferenceChanged) targetFragment).onPreferenceChanged(speedCamUninstalled.getId());

View file

@ -70,7 +70,6 @@ public class QuickSearchHelper implements ResourceListener {
core = new SearchUICore(app.getPoiTypes(), settings.MAP_PREFERRED_LOCALE.get(), core = new SearchUICore(app.getPoiTypes(), settings.MAP_PREFERRED_LOCALE.get(),
settings.MAP_TRANSLITERATE_NAMES.get()); settings.MAP_TRANSLITERATE_NAMES.get());
app.getResourceManager().addResourceListener(this); app.getResourceManager().addResourceListener(this);
SearchResultMatcher.speedCamerasUninstalled = settings.SPEED_CAMERAS_UNINSTALLED.get();
} }
public SearchUICore getCore() { public SearchUICore getCore() {

View file

@ -35,6 +35,7 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -86,6 +87,12 @@ public class QuickSearchSubCategoriesFragment extends BaseOsmAndDialogFragment {
acceptedCategories = new HashSet<>(savedInstanceState.getStringArrayList(ACCEPTED_CATEGORIES_KEY)); acceptedCategories = new HashSet<>(savedInstanceState.getStringArrayList(ACCEPTED_CATEGORIES_KEY));
} }
poiTypeList = new ArrayList<>(poiCategory.getPoiTypes()); poiTypeList = new ArrayList<>(poiCategory.getPoiTypes());
Iterator<PoiType> iter = poiTypeList.iterator();
while (iter.hasNext()) {
if (iter.next().isForbidden()) {
iter.remove();
}
}
Collections.sort(poiTypeList, new Comparator<PoiType>() { Collections.sort(poiTypeList, new Comparator<PoiType>() {
@Override @Override
public int compare(PoiType poiType, PoiType t1) { public int compare(PoiType poiType, PoiType t1) {