Skip to content

Commit

Permalink
Refactor naming of ClickableWay classes
Browse files Browse the repository at this point in the history
  • Loading branch information
RZR-UA committed Jan 15, 2025
1 parent 338c133 commit c93de76
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseLoadAsyncTask;

public class ClickableWayReaderTask extends BaseLoadAsyncTask<Void, Void, ClickableWay> {
public class ClickableWayAsyncTask extends BaseLoadAsyncTask<Void, Void, ClickableWay> {
private final ClickableWay clickableWay;
private final CallbackWithObject<ClickableWay> readHeightData;
private final CallbackWithObject<ClickableWay> openAsGpxFile;

public ClickableWayReaderTask(@NonNull MapActivity mapActivity,
@NonNull ClickableWay clickableWay,
@NonNull CallbackWithObject<ClickableWay> readHeightData,
@NonNull CallbackWithObject<ClickableWay> openAsGpxFile) {
public ClickableWayAsyncTask(@NonNull MapActivity mapActivity,
@NonNull ClickableWay clickableWay,
@NonNull CallbackWithObject<ClickableWay> readHeightData,
@NonNull CallbackWithObject<ClickableWay> openAsGpxFile) {
super(mapActivity);
this.clickableWay = clickableWay;
this.readHeightData = readHeightData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

import gnu.trove.list.array.TIntArrayList;

public class ClickableWayLoader {
public class ClickableWayHelper {
public static final Set<String> clickableTags = Set.of("piste:type", "piste:difficulty", "mtb:scale", "dirtbike:scale");
public static final Map<String, String> forbiddenTags = Map.of("area", "yes", "access", "no");
public static final Map<String, String> gpxColors = Map.ofEntries(
Expand All @@ -62,12 +62,14 @@ public class ClickableWayLoader {

private final OsmandApplication app;
private final OsmandMapTileView view;
private final ClickableWayActivator activator;
private final ClickableWayMenuActivator activator;

public ClickableWayLoader(@NonNull OsmandApplication app, @NonNull OsmandMapTileView view) {
// private static final Log log = PlatformUtil.getLog(ClickableWay.class);

public ClickableWayHelper(@NonNull OsmandApplication app, @NonNull OsmandMapTileView view) {
this.app = app;
this.view = view;
this.activator = new ClickableWayActivator(view, this::readHeightData, this::openAsGpxFile);
this.activator = new ClickableWayMenuActivator(view, this::readHeightData, this::openAsGpxFile);
}

@NonNull
Expand Down Expand Up @@ -194,6 +196,22 @@ private boolean isClickableWayTags(@NonNull Map<String, String> tags) {

private boolean readHeightData(ClickableWay clickableWay) {
// TODO read height data, implement simple cache
// BinaryMapIndexReader[] readers = app.getResourceManager().getReverseGeocodingMapFiles();
// NetworkRouteSelector.NetworkRouteSelectorFilter selectorFilter = new NetworkRouteSelector.NetworkRouteSelectorFilter();
// NetworkRouteSelector routeSelector = new NetworkRouteSelector(readers, selectorFilter, null);
// try {
// QuadRect bbox31 = clickableWay.getBbox();
// QuadRect bboxLatLon = new QuadRect(
// MapUtils.get31LongitudeX((int)bbox31.left),
// MapUtils.get31LatitudeY((int)bbox31.top),
// MapUtils.get31LongitudeX((int)bbox31.right),
// MapUtils.get31LatitudeY((int)bbox31.bottom)
// );
// Map<NetworkRouteSelector.RouteKey, GpxFile> routes = routeSelector.getRoutes(bboxLatLon, true, null);
// System.err.printf("XXX routes\n");
// } catch (IOException e) {
// log.error(e);
// }
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

import java.util.List;

public class ClickableWayActivator implements ContextMenuLayer.IContextMenuProvider {
public class ClickableWayMenuActivator implements ContextMenuLayer.IContextMenuProvider {
private final OsmandMapTileView view;
private final CallbackWithObject<ClickableWay> readHeights;
private final CallbackWithObject<ClickableWay> openAsGpxFile;

public ClickableWayActivator(@NonNull OsmandMapTileView view,
@NonNull CallbackWithObject<ClickableWay> readHeightData,
@NonNull CallbackWithObject<ClickableWay> openAsGpxFile) {
public ClickableWayMenuActivator(@NonNull OsmandMapTileView view,
@NonNull CallbackWithObject<ClickableWay> readHeightData,
@NonNull CallbackWithObject<ClickableWay> openAsGpxFile) {
this.view = view;
this.readHeights = readHeightData;
this.openAsGpxFile = openAsGpxFile;
Expand All @@ -36,7 +36,7 @@ public boolean showMenuAction(@Nullable Object object) {
if (object instanceof ClickableWay that) {
MapActivity mapActivity = view.getMapActivity();
if (mapActivity != null) {
(new ClickableWayReaderTask(mapActivity, that, readHeights, openAsGpxFile))
(new ClickableWayAsyncTask(mapActivity, that, readHeights, openAsGpxFile))
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
return true;
}
Expand Down
18 changes: 9 additions & 9 deletions OsmAnd/src/net/osmand/plus/views/layers/MapSelectionHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
import net.osmand.util.Algorithms;
import net.osmand.util.GeoParsedPoint;
import net.osmand.util.MapUtils;
import net.osmand.plus.track.clickable.ClickableWayLoader;
import net.osmand.plus.track.clickable.ClickableWayHelper;

import org.apache.commons.logging.Log;

Expand Down Expand Up @@ -108,13 +108,13 @@ public class MapSelectionHelper {
private Map<LatLon, BackgroundType> touchedFullMapObjects = new HashMap<>();
private Map<LatLon, BackgroundType> touchedSmallMapObjects = new HashMap<>();

private ClickableWayLoader clickableWayLoader;
private ClickableWayHelper clickableWayHelper;

public MapSelectionHelper(@NonNull Context context) {
app = (OsmandApplication) context.getApplicationContext();
view = app.getOsmandMap().getMapView();
mapLayers = app.getOsmandMap().getMapLayers();
clickableWayLoader = new ClickableWayLoader(app, view);
clickableWayHelper = new ClickableWayHelper(app, view);
}

@NonNull
Expand Down Expand Up @@ -232,7 +232,7 @@ private void selectObjectsFromNative(@NonNull MapSelectionResult result, @NonNul

boolean isTravelGpx = !Algorithms.isEmpty(travelGpxFilter);
boolean isOsmRoute = !Algorithms.isEmpty(OsmRouteType.getRouteKeys(tags));
boolean isClickableWay = clickableWayLoader.isClickableWayV1(renderedObject);
boolean isClickableWay = clickableWayHelper.isClickableWayV1(renderedObject);

if (!isClickableWay && !isTravelGpx && !isOsmRoute && (renderedObject.getId() == null
|| !renderedObject.isVisible() || renderedObject.isDrawOnPath())) {
Expand Down Expand Up @@ -350,7 +350,7 @@ private void selectObjectsFromOpenGl(@NonNull MapSelectionResult result, @NonNul

boolean isTravelGpx = app.getTravelHelper().isTravelGpxTags(tags);
boolean isOsmRoute = !Algorithms.isEmpty(OsmRouteType.getRouteKeys(tags));
boolean isClickableWay = clickableWayLoader.isClickableWayV2(obfMapObject, tags);
boolean isClickableWay = clickableWayHelper.isClickableWayV2(obfMapObject, tags);

if (isOsmRoute && !isDerivedGpxSelected) {
NetworkRouteSelectorFilter routeFilter = createRouteFilter();
Expand Down Expand Up @@ -491,19 +491,19 @@ private boolean addTravelGpx(@NonNull MapSelectionResult result, @Nullable Strin
}

private boolean addClickableWayV1(@NonNull MapSelectionResult result, @NonNull RenderedObject renderedObject) {
ClickableWay clickableWay = clickableWayLoader.loadClickableWayV1(result.pointLatLon, renderedObject);
ClickableWay clickableWay = clickableWayHelper.loadClickableWayV1(result.pointLatLon, renderedObject);
if (clickableWay != null && isUniqueClickableWay(result.selectedObjects, clickableWay)) {
result.selectedObjects.put(clickableWay, clickableWayLoader.getContextMenuProvider());
result.selectedObjects.put(clickableWay, clickableWayHelper.getContextMenuProvider());
return true;
}
return false;
}

private boolean addClickableWayV2(@NonNull MapSelectionResult result, @NonNull ObfMapObject obfMapObject,
@NonNull Map<String, String> tags) {
ClickableWay clickableWay = clickableWayLoader.loadClickableWayV2(result.pointLatLon, obfMapObject, tags);
ClickableWay clickableWay = clickableWayHelper.loadClickableWayV2(result.pointLatLon, obfMapObject, tags);
if (clickableWay != null && isUniqueClickableWay(result.selectedObjects, clickableWay)) {
result.selectedObjects.put(clickableWay, clickableWayLoader.getContextMenuProvider());
result.selectedObjects.put(clickableWay, clickableWayHelper.getContextMenuProvider());
return true;
}
return false;
Expand Down

0 comments on commit c93de76

Please sign in to comment.