From fe8a2fa9b46517aade22c44266eccbaed779b3a2 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Sat, 30 Sep 2017 09:53:31 +0300 Subject: [PATCH 1/2] Fix #4328 --- .../src/net/osmand/plus/views/GPXLayer.java | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 46efbd799d..5bff7b3cb9 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -465,29 +465,39 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex private void drawSelectedFilesSegments(Canvas canvas, RotatedTileBox tileBox, List selectedGPXFiles, DrawSettings settings) { + SelectedGpxFile currentTrack = null; for (SelectedGpxFile g : selectedGPXFiles) { - GpxDataItem gpxDataItem = null; - if (!g.isShowCurrentTrack()) { - gpxDataItem = view.getApplication().getGpxDatabase().getItem(new File(g.getGpxFile().path)); - } - List segments = g.getPointsToDisplay(); - for (TrkSegment ts : segments) { - int color = gpxDataItem != null ? gpxDataItem.getColor() : 0; - if (g.isShowCurrentTrack()) { - color = currentTrackColor; + if (g.isShowCurrentTrack()) { + currentTrack = g; + } else { + List segments = g.getPointsToDisplay(); + for (TrkSegment ts : segments) { + GpxDataItem gpxDataItem = view.getApplication().getGpxDatabase().getItem(new File(g.getGpxFile().path)); + int color = gpxDataItem != null ? gpxDataItem.getColor() : 0; + if (color == 0) { + color = ts.getColor(cachedColor); + } + if (ts.renders.isEmpty() // only do once (CODE HERE NEEDS TO BE UI INSTEAD) + && !ts.points.isEmpty()) { // hmmm. 0-point tracks happen, but.... how? + ts.renders.add(new Renderable.StandardTrack(ts.points, 17.2)); + } + updatePaints(color, g.isRoutePoints(), false, settings, tileBox); + ts.drawRenderers(view.getZoom(), paint, canvas, tileBox); } + } + } + if (currentTrack != null) { + List segments = currentTrack.getPointsToDisplay(); + for (TrkSegment ts : segments) { + int color = currentTrackColor; if (color == 0) { color = ts.getColor(cachedColor); } if (ts.renders.isEmpty() // only do once (CODE HERE NEEDS TO BE UI INSTEAD) && !ts.points.isEmpty()) { // hmmm. 0-point tracks happen, but.... how? - if (g.isShowCurrentTrack()) { - ts.renders.add(new Renderable.CurrentTrack(ts.points)); - } else { - ts.renders.add(new Renderable.StandardTrack(ts.points, 17.2)); - } + ts.renders.add(new Renderable.CurrentTrack(ts.points)); } - updatePaints(color, g.isRoutePoints(), g.isShowCurrentTrack(), settings, tileBox); + updatePaints(color, currentTrack.isRoutePoints(), true, settings, tileBox); ts.drawRenderers(view.getZoom(), paint, canvas, tileBox); } } From d46604361f4e8b6f51c88178520f8754afc40026 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Sun, 1 Oct 2017 13:16:43 +0300 Subject: [PATCH 2/2] Fix copy paste --- .../src/net/osmand/plus/views/GPXLayer.java | 55 ++++++++++--------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 5bff7b3cb9..dc20503604 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -470,36 +470,39 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex if (g.isShowCurrentTrack()) { currentTrack = g; } else { - List segments = g.getPointsToDisplay(); - for (TrkSegment ts : segments) { - GpxDataItem gpxDataItem = view.getApplication().getGpxDatabase().getItem(new File(g.getGpxFile().path)); - int color = gpxDataItem != null ? gpxDataItem.getColor() : 0; - if (color == 0) { - color = ts.getColor(cachedColor); - } - if (ts.renders.isEmpty() // only do once (CODE HERE NEEDS TO BE UI INSTEAD) - && !ts.points.isEmpty()) { // hmmm. 0-point tracks happen, but.... how? - ts.renders.add(new Renderable.StandardTrack(ts.points, 17.2)); - } - updatePaints(color, g.isRoutePoints(), false, settings, tileBox); - ts.drawRenderers(view.getZoom(), paint, canvas, tileBox); - } + drawSelectedFileSegments(g, false, canvas, tileBox, settings); } } if (currentTrack != null) { - List segments = currentTrack.getPointsToDisplay(); - for (TrkSegment ts : segments) { - int color = currentTrackColor; - if (color == 0) { - color = ts.getColor(cachedColor); - } - if (ts.renders.isEmpty() // only do once (CODE HERE NEEDS TO BE UI INSTEAD) - && !ts.points.isEmpty()) { // hmmm. 0-point tracks happen, but.... how? - ts.renders.add(new Renderable.CurrentTrack(ts.points)); - } - updatePaints(color, currentTrack.isRoutePoints(), true, settings, tileBox); - ts.drawRenderers(view.getZoom(), paint, canvas, tileBox); + drawSelectedFileSegments(currentTrack, true, canvas, tileBox, settings); + } + } + + private void drawSelectedFileSegments(SelectedGpxFile selectedGpxFile, boolean currentTrack, Canvas canvas, + RotatedTileBox tileBox, DrawSettings settings) { + GpxDataItem gpxDataItem = null; + if (!currentTrack) { + gpxDataItem = view.getApplication().getGpxDatabase().getItem(new File(selectedGpxFile.getGpxFile().path)); + } + List segments = selectedGpxFile.getPointsToDisplay(); + for (TrkSegment ts : segments) { + int color = gpxDataItem != null ? gpxDataItem.getColor() : 0; + if (currentTrack) { + color = currentTrackColor; } + if (color == 0) { + color = ts.getColor(cachedColor); + } + if (ts.renders.isEmpty() // only do once (CODE HERE NEEDS TO BE UI INSTEAD) + && !ts.points.isEmpty()) { // hmmm. 0-point tracks happen, but.... how? + if (currentTrack) { + ts.renders.add(new Renderable.CurrentTrack(ts.points)); + } else { + ts.renders.add(new Renderable.StandardTrack(ts.points, 17.2)); + } + } + updatePaints(color, selectedGpxFile.isRoutePoints(), currentTrack, settings, tileBox); + ts.drawRenderers(view.getZoom(), paint, canvas, tileBox); } }