Skip to content

Commit

Permalink
#16632: Fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
Corwin-Kh committed Jun 25, 2023
1 parent be40bed commit 2c9b03d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
6 changes: 3 additions & 3 deletions OsmAnd/src/net/osmand/plus/auto/TracksScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.osmand.plus.auto
import android.os.AsyncTask
import android.text.SpannableString
import android.text.Spanned
import androidx.annotation.WorkerThread
import androidx.car.app.CarContext
import androidx.car.app.model.*
import androidx.car.app.navigation.model.PlaceListNavigationTemplate
Expand Down Expand Up @@ -35,7 +36,7 @@ class TracksScreen(
) : BaseOsmAndAndroidAutoScreen(carContext) {
val gpxDbHelper: GpxDbHelper = app.gpxDbHelper
var loadGpxFilesThread: Thread? = null
private val loadedGpxFiles = HashMap<TrackItem, SelectedGpxFile>()
private var loadedGpxFiles = HashMap<TrackItem, SelectedGpxFile>()
private lateinit var loadTracksTask: LoadTracksTask

init {
Expand Down Expand Up @@ -86,7 +87,7 @@ class TracksScreen(
}

private fun prepareTrackItems() {
loadedGpxFiles.clear()
loadedGpxFiles = HashMap()
for (track in trackTab.trackItems) {
track.file?.let { file ->
val item = gpxDbHelper.getItem(file) { updateTrack(track, it) }
Expand All @@ -99,7 +100,6 @@ class TracksScreen(
loadedGpxFiles[track] = selectedGpxFile
}
}
invalidate()
}

private fun updateTrack(trackItem: TrackItem, dataItem: GpxDataItem?) {
Expand Down
16 changes: 10 additions & 6 deletions OsmAnd/src/net/osmand/plus/views/layers/FavouritesLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import java.util.List;

public class FavouritesLayer extends OsmandMapLayer implements IContextMenuProvider,
IMoveObjectProvider, MapTextProvider<FavouritePoint> {
IMoveObjectProvider, MapTextProvider<FavouritePoint> {

private static final int START_ZOOM = 6;
private static final Log LOG = PlatformUtil.getLog(FavouritesLayer.class);
Expand Down Expand Up @@ -138,8 +138,12 @@ public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSett

if (hasMapRenderer()) {
if (mapActivityInvalidated || mapRendererChanged || nightModeChanged || showFavoritesChanged
|| favoritesChanged || textScaleChanged || textVisibleChanged || customObjectsDelegate != null) {
|| favoritesChanged || textScaleChanged || textVisibleChanged
|| (customObjectsDelegate != null && customObjectsDelegate.isChanged())) {
showFavorites();
if(customObjectsDelegate != null){
customObjectsDelegate.acceptChanges();
}
mapRendererChanged = false;
}
} else {
Expand All @@ -153,7 +157,7 @@ public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSett
QuadRect latLonBounds = tileBox.getLatLonBounds();
List<LatLon> fullObjectsLatLon = new ArrayList<>();
List<LatLon> smallObjectsLatLon = new ArrayList<>();
if(customObjectsDelegate != null){
if (customObjectsDelegate != null) {
drawPoints(customObjectsDelegate.getMapObjects(), latLonBounds, false, tileBox, boundIntersections, iconSize, canvas,
fullObjectsLatLon, smallObjectsLatLon);
} else {
Expand Down Expand Up @@ -182,8 +186,8 @@ private void drawPoints(List<FavouritePoint> pointsToDraw, QuadRect latLonBounds
double lat = favoritePoint.getLatitude();
double lon = favoritePoint.getLongitude();
if (favoritePoint.isVisible() && favoritePoint != contextMenuLayer.getMoveableObject()
&& lat >= latLonBounds.bottom && lat <= latLonBounds.top
&& lon >= latLonBounds.left && lon <= latLonBounds.right) {
&& lat >= latLonBounds.bottom && lat <= latLonBounds.top
&& lon >= latLonBounds.left && lon <= latLonBounds.right) {
MapMarker marker = null;
if (synced) {
marker = mapMarkersHelper.getMapMarker(favoritePoint);
Expand Down Expand Up @@ -256,7 +260,7 @@ public synchronized void showFavorites() {
favoritesMapLayerProvider = new FavoritesTileProvider(getContext(), getPointsOrder(), isTextVisible(),
getTextStyle(textScale), view.getDensity());

if(customObjectsDelegate != null){
if (customObjectsDelegate != null) {
List<FavouritePoint> points = customObjectsDelegate.getMapObjects();
showFavoritePoints(textScale, false, points);
favoritesMapLayerProvider.drawSymbols(mapRenderer);
Expand Down
9 changes: 3 additions & 6 deletions OsmAnd/src/net/osmand/plus/views/layers/MapMarkersLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,18 +278,15 @@ public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSett
OsmandApplication app = getApplication();
OsmandSettings settings = app.getSettings();
if ((!settings.SHOW_MAP_MARKERS.get() && customObjectsDelegate == null)
|| (customObjectsDelegate != null && Algorithms.isEmpty(customObjectsDelegate.getMapObjects()))) {
|| (customObjectsDelegate != null && Algorithms.isEmpty(customObjectsDelegate.getMapObjects()))) {
clearMapMarkersCollections();
clearVectorLinesCollections();
resetCachedRenderer();
return;
}

MapMarkersHelper markersHelper = app.getMapMarkersHelper();
List<MapMarker> activeMapMarkers = markersHelper.getMapMarkers();
if (customObjectsDelegate != null) {
activeMapMarkers = customObjectsDelegate.getMapObjects();
}
List<MapMarker> activeMapMarkers = (customObjectsDelegate != null) ? customObjectsDelegate.getMapObjects() : markersHelper.getMapMarkers();
MapRendererView mapRenderer = getMapRenderer();
if (mapRenderer != null) {
if (markersCount != activeMapMarkers.size() || mapActivityInvalidated) {
Expand Down Expand Up @@ -380,7 +377,7 @@ public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode
OsmandSettings settings = app.getSettings();

if (customObjectsDelegate != null && Algorithms.isEmpty(customObjectsDelegate.getMapObjects())
|| customObjectsDelegate == null && (tileBox.getZoom() < 3 || !settings.SHOW_MAP_MARKERS.get())) {
|| customObjectsDelegate == null && (tileBox.getZoom() < 3 || !settings.SHOW_MAP_MARKERS.get())) {
clearVectorLinesCollections();
return;
}
Expand Down
15 changes: 14 additions & 1 deletion OsmAnd/src/net/osmand/plus/views/layers/base/OsmandMapLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -85,19 +86,31 @@ public abstract class OsmandMapLayer implements MapRendererViewListener {

public static class CustomMapObjects<T> {
protected List<T> customMapObjects;
private boolean isChanged;

@NonNull
public List<T> getMapObjects() {
if (customMapObjects == null) {
return new ArrayList<>();
return Collections.emptyList();
} else {
return customMapObjects;
}
}

public void setCustomMapObjects(List<T> customMapObjects) {
if(this.customMapObjects != customMapObjects){
isChanged = true;
}
this.customMapObjects = customMapObjects;
}

public void acceptChanges() {
isChanged = false;
}

public boolean isChanged() {
return isChanged;
}
}

public enum MapGestureType {
Expand Down

0 comments on commit 2c9b03d

Please sign in to comment.