From dab8c1511d45c99199f278bc35a72f897f2052dc Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 18 Sep 2017 11:03:16 +0300 Subject: [PATCH] Add gpx-sync to methods --- .../net/osmand/plus/GpxSelectionHelper.java | 25 +++++++++++++++++-- .../src/net/osmand/plus/MapMarkersHelper.java | 5 ++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 9612eec32d..260b791ba3 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -6,13 +6,14 @@ import android.support.annotation.NonNull; import android.support.v4.content.ContextCompat; import net.osmand.IProgress; +import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXTrackAnalysis; import net.osmand.plus.GPXUtilities.Route; import net.osmand.plus.GPXUtilities.Track; import net.osmand.plus.GPXUtilities.TrkSegment; import net.osmand.plus.GPXUtilities.WptPt; -import net.osmand.plus.GPXDatabase.GpxDataItem; +import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup; import net.osmand.plus.OsmandSettings.MetricsConstants; import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.helpers.GpxUiHelper; @@ -491,18 +492,38 @@ public class GpxSelectionHelper { public void clearPoints(GPXFile gpxFile) { gpxFile.clearPoints(); + syncGpx(gpxFile); } public void addPoint(WptPt point, GPXFile gpxFile) { gpxFile.addPoint(point); + syncGpx(gpxFile); } public void addPoints(Collection collection, GPXFile gpxFile) { gpxFile.addPoints(collection); + syncGpx(gpxFile); } public boolean removePoint(WptPt point, GPXFile gpxFile) { - return gpxFile.removePoint(point); + boolean res = gpxFile.removePoint(point); + syncGpx(gpxFile); + return res; + } + + private void syncGpx(GPXFile gpxFile) { + File gpx = new File(gpxFile.path); + if (gpx.exists()) { + app.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(gpx.getAbsolutePath(), trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE)); + } + } + + private String trimExtension(String src) { + int index = src.lastIndexOf('.'); + if (index != -1) { + return src.substring(0, index); + } + return src; } diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 3baadd86fd..8c46ea114f 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -338,12 +338,12 @@ public class MapMarkersHelper { List dbMarkers = markersDbHelper.getMarkersFromGroup(group); if (group.getType() == MarkersSyncGroup.FAVORITES_TYPE) { - FavouritesDbHelper.FavoriteGroup favGroup = ctx.getFavorites().getGroup(group.name); + FavouritesDbHelper.FavoriteGroup favGroup = ctx.getFavorites().getGroup(group.getName()); if (favGroup == null) { return; } if (!favGroup.visible) { - removeActiveMarkersFromSyncGroup(group.id); + removeActiveMarkersFromSyncGroup(group.getId()); return; } @@ -367,6 +367,7 @@ public class MapMarkersHelper { gpx = gpxHelper.getSelectedFileByPath(group.getId()).getGpxFile(); } if (gpx == null) { + removeActiveMarkersFromSyncGroup(group.getId()); return; }