From 816882d086a9e95d33cfa809be96988b8401b99a Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 5 Nov 2019 16:38:49 +0200 Subject: [PATCH] Fix #7789 --- .../src/net/osmand/plus/AppInitializer.java | 3 +- OsmAnd/src/net/osmand/plus/OsmandPlugin.java | 2 +- .../osmand/plus/activities/MapActivity.java | 1 + .../plus/activities/SavingTrackHelper.java | 62 ++++++++----------- .../plus/monitoring/LiveMonitoringHelper.java | 5 +- .../plus/notifications/ErrorNotification.java | 2 +- .../plus/notifications/GpxNotification.java | 8 +-- 7 files changed, 35 insertions(+), 48 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 7044b599d3..85a38a0b27 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -38,7 +38,6 @@ import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.plus.liveupdates.LiveUpdatesHelper; import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.plus.monitoring.LiveMonitoringHelper; -import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.render.MapRenderRepositories; import net.osmand.plus.render.NativeOsmandLibrary; @@ -766,7 +765,7 @@ public class AppInitializer implements IProgress { app.savingTrackHelper.loadGpxFromDatabase(); } } - if(app.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get() && OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null){ + if (app.savingTrackHelper.getIsRecording()) { int interval = app.getSettings().SAVE_GLOBAL_TRACK_INTERVAL.get(); app.startNavigationService(NavigationService.USED_BY_GPX, app.navigationServiceGpsInterval(interval)); } diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index 52935c0c20..a972d8146c 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -182,8 +182,8 @@ public abstract class OsmandPlugin { LOG.error("Plugin initialization failed " + plugin.getId(), e); } } else if (plugin.isActive()) { - plugin.disable(app); plugin.setActive(false); + plugin.disable(app); } } } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 229d3285c2..f5fa184ce3 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -1499,6 +1499,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } }); getMapView().refreshMap(true); + getMyApplication().getNotificationHelper().refreshNotifications(); } public void updateMapSettings() { diff --git a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java index 8072f5bf1f..45596f8607 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/SavingTrackHelper.java @@ -5,22 +5,20 @@ import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.text.format.DateFormat; -import net.osmand.PlatformUtil; -import net.osmand.data.LatLon; -import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.GPXUtilities.Track; import net.osmand.GPXUtilities.TrkSegment; import net.osmand.GPXUtilities.WptPt; +import net.osmand.PlatformUtil; +import net.osmand.data.LatLon; +import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.Version; -import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.notifications.OsmandNotification.NotificationType; import net.osmand.util.MapUtils; @@ -409,30 +407,27 @@ public class SavingTrackHelper extends SQLiteOpenHelper { long locationTime = System.currentTimeMillis(); OsmandSettings settings = ctx.getSettings(); boolean record = false; - if(location != null && - OsmAndLocationProvider.isNotSimulatedLocation(location) ) { - if (OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null) { - if (settings.SAVE_TRACK_TO_GPX.get() - && locationTime - lastTimeUpdated > settings.SAVE_TRACK_INTERVAL.get() - && ctx.getRoutingHelper().isFollowingMode()) { - record = true; - } else if (settings.SAVE_GLOBAL_TRACK_TO_GPX.get() - && locationTime - lastTimeUpdated > settings.SAVE_GLOBAL_TRACK_INTERVAL.get()) { - record = true; - } - float minDistance = settings.SAVE_TRACK_MIN_DISTANCE.get(); - if(minDistance > 0 && lastPoint != null && MapUtils.getDistance(lastPoint, location.getLatitude(), location.getLongitude()) < - minDistance) { - record = false; - } - float precision = settings.SAVE_TRACK_PRECISION.get(); - if(precision > 0 && (!location.hasAccuracy() || location.getAccuracy() > precision)) { - record = false; - } - float minSpeed = settings.SAVE_TRACK_MIN_SPEED.get(); - if(minSpeed > 0 && (!location.hasSpeed() || location.getSpeed() < minSpeed)) { - record = false; - } + if (location != null && OsmAndLocationProvider.isNotSimulatedLocation(location)) { + if (settings.SAVE_TRACK_TO_GPX.get() + && locationTime - lastTimeUpdated > settings.SAVE_TRACK_INTERVAL.get() + && ctx.getRoutingHelper().isFollowingMode()) { + record = true; + } else if (settings.SAVE_GLOBAL_TRACK_TO_GPX.get() + && locationTime - lastTimeUpdated > settings.SAVE_GLOBAL_TRACK_INTERVAL.get()) { + record = true; + } + float minDistance = settings.SAVE_TRACK_MIN_DISTANCE.get(); + if (minDistance > 0 && lastPoint != null && MapUtils.getDistance(lastPoint, location.getLatitude(), location.getLongitude()) < + minDistance) { + record = false; + } + float precision = settings.SAVE_TRACK_PRECISION.get(); + if (precision > 0 && (!location.hasAccuracy() || location.getAccuracy() > precision)) { + record = false; + } + float minSpeed = settings.SAVE_TRACK_MIN_SPEED.get(); + if (minSpeed > 0 && (!location.hasSpeed() || location.getSpeed() < minSpeed)) { + record = false; } } if (record) { @@ -654,13 +649,8 @@ public class SavingTrackHelper extends SQLiteOpenHelper { } public boolean getIsRecording() { - if (OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null) { - if (ctx.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get() || - (ctx.getSettings().SAVE_TRACK_TO_GPX.get() && ctx.getRoutingHelper().isFollowingMode())) { - return true; - } - } - return false; + return ctx.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get() || + (ctx.getSettings().SAVE_TRACK_TO_GPX.get() && ctx.getRoutingHelper().isFollowingMode()); } public float getDistance() { diff --git a/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java b/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java index c3f9649a28..4d73b90105 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java @@ -7,7 +7,6 @@ import net.osmand.PlatformUtil; import net.osmand.data.LatLon; import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.util.MapUtils; @@ -47,9 +46,7 @@ public class LiveMonitoringHelper { public void updateLocation(net.osmand.Location location) { boolean record = false; long locationTime = System.currentTimeMillis(); - if (location != null && isLiveMonitoringEnabled() - && OsmAndLocationProvider.isNotSimulatedLocation(location) - && OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null) { + if (location != null && isLiveMonitoringEnabled() && OsmAndLocationProvider.isNotSimulatedLocation(location)) { if (locationTime - lastTimeUpdated > settings.LIVE_MONITORING_INTERVAL.get()) { record = true; } diff --git a/OsmAnd/src/net/osmand/plus/notifications/ErrorNotification.java b/OsmAnd/src/net/osmand/plus/notifications/ErrorNotification.java index af9a3841c9..3ea07aa690 100644 --- a/OsmAnd/src/net/osmand/plus/notifications/ErrorNotification.java +++ b/OsmAnd/src/net/osmand/plus/notifications/ErrorNotification.java @@ -62,7 +62,7 @@ public class ErrorNotification extends OsmandNotification { boolean planning = routingHelper.isRoutePlanningMode(); boolean pause = routingHelper.isPauseNavigation(); - boolean gpxEnabled = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null; + boolean gpxEnabled = app.getSavingTrackHelper().getIsRecording() || OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null; String usedBy = service != null ? "" + service.getUsedBy() : "X"; notificationText = "Info: " + (following ? "1" : "") + (planning ? "2" : "") + (pause ? "3" : "") + (gpxEnabled ? "4" : "") + "-" + usedBy + ". " diff --git a/OsmAnd/src/net/osmand/plus/notifications/GpxNotification.java b/OsmAnd/src/net/osmand/plus/notifications/GpxNotification.java index c56b92027b..f0defc9be8 100644 --- a/OsmAnd/src/net/osmand/plus/notifications/GpxNotification.java +++ b/OsmAnd/src/net/osmand/plus/notifications/GpxNotification.java @@ -40,7 +40,7 @@ public class GpxNotification extends OsmandNotification { @Override public void onReceive(Context context, Intent intent) { - final OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class); + final OsmandMonitoringPlugin plugin = OsmandPlugin.getPlugin(OsmandMonitoringPlugin.class); if (plugin != null) { plugin.saveCurrentTrack(); if (!app.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get()) { @@ -54,7 +54,7 @@ public class GpxNotification extends OsmandNotification { @Override public void onReceive(Context context, Intent intent) { - final OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class); + final OsmandMonitoringPlugin plugin = OsmandPlugin.getPlugin(OsmandMonitoringPlugin.class); if (plugin != null) { plugin.startGPXMonitoring(null); plugin.updateControl(); @@ -66,7 +66,7 @@ public class GpxNotification extends OsmandNotification { @Override public void onReceive(Context context, Intent intent) { - final OsmandMonitoringPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class); + final OsmandMonitoringPlugin plugin = OsmandPlugin.getPlugin(OsmandMonitoringPlugin.class); if (plugin != null) { plugin.stopRecording(); plugin.updateControl(); @@ -95,7 +95,7 @@ public class GpxNotification extends OsmandNotification { @Override public boolean isEnabled() { - return OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null; + return app.getSavingTrackHelper().getIsRecording() || OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null; } @Override