refactor speed camera restriction
This commit is contained in:
parent
4009946a32
commit
05ffbdffaa
8 changed files with 31 additions and 22 deletions
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -946,13 +946,11 @@ public class MapPoiTypes {
|
|||
}
|
||||
}
|
||||
|
||||
public void excludeSpeedCameraPoiType() {
|
||||
public void forbidPoiType(String keyName) {
|
||||
for (PoiCategory category : categories) {
|
||||
Iterator<PoiType> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -657,8 +657,6 @@ public class SearchUICore {
|
|||
private List<MapObject> exportedObjects;
|
||||
private List<City> exportedCities;
|
||||
|
||||
public static boolean speedCamerasUninstalled = false;
|
||||
|
||||
public SearchResultMatcher(ResultMatcher<SearchResult> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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<PoiType> iter = poiTypeList.iterator();
|
||||
while (iter.hasNext()) {
|
||||
if (iter.next().isForbidden()) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
Collections.sort(poiTypeList, new Comparator<PoiType>() {
|
||||
@Override
|
||||
public int compare(PoiType poiType, PoiType t1) {
|
||||
|
|
Loading…
Reference in a new issue