diff --git a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java index 4be7ad436..3fe35e102 100644 --- a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java +++ b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java @@ -103,6 +103,7 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand if (PreferencesUtils.isKey(context, R.string.stats_units_key, key)) { boolean metricUnits = PreferencesUtils.isMetricUnits(sharedPreferences, context); voiceExecutor.setMetricUnits(metricUnits); + notificationManager.setMetricUnits(metricUnits); } if (PreferencesUtils.isKey(context, R.string.voice_frequency_key, key)) { voiceExecutor.setTaskFrequency(PreferencesUtils.getVoiceFrequency(sharedPreferences, context)); @@ -557,7 +558,7 @@ public class TrackRecordingService extends Service implements HandlerServer.Hand fillWithSensorDataSet(trackPoint); - notificationManager.updateTrackPoint(this, trackPoint, recordingGpsAccuracy); + notificationManager.updateTrackPoint(this, track.getTrackStatistics(), trackPoint, recordingGpsAccuracy); //TODO Figure out how to avoid loading the lastValidTrackPoint from the database TrackPoint lastValidTrackPoint = getLastValidTrackPointInCurrentSegment(track.getId()); diff --git a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceNotificationManager.java b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceNotificationManager.java index f48bf75ae..a318b8e73 100644 --- a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceNotificationManager.java +++ b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceNotificationManager.java @@ -5,6 +5,7 @@ import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Context; +import android.content.SharedPreferences; import android.os.Build; import androidx.annotation.VisibleForTesting; @@ -12,6 +13,8 @@ import androidx.core.app.NotificationCompat; import de.dennisguse.opentracks.R; import de.dennisguse.opentracks.content.data.TrackPoint; +import de.dennisguse.opentracks.fragments.StatisticsRecordedFragment; +import de.dennisguse.opentracks.stats.TrackStatistics; import de.dennisguse.opentracks.util.PreferencesUtils; import de.dennisguse.opentracks.util.StringUtils; @@ -30,6 +33,8 @@ class TrackRecordingServiceNotificationManager { private boolean previousLocationWasAccurate = true; + private Boolean metricUnits = null; + TrackRecordingServiceNotificationManager(Context context) { notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { @@ -59,11 +64,11 @@ class TrackRecordingServiceNotificationManager { } void updateContent(String content) { - notificationBuilder.setContentText(content); + notificationBuilder.setSubText(content); updateNotification(); } - void updateTrackPoint(Context context, TrackPoint trackPoint, int recordingGpsAccuracy) { + void updateTrackPoint(Context context, TrackStatistics trackStatistics, TrackPoint trackPoint, int recordingGpsAccuracy) { String formattedAccuracy = context.getString(R.string.value_none); if (trackPoint.hasAccuracy()) { formattedAccuracy = StringUtils.formatDistance(context, trackPoint.getAccuracy(), PreferencesUtils.isMetricUnits(PreferencesUtils.getSharedPreferences(context), context)); @@ -74,7 +79,9 @@ class TrackRecordingServiceNotificationManager { previousLocationWasAccurate = currentLocationWasAccurate; } - notificationBuilder.setContentText(context.getString(R.string.track_recording_notification_accuracy, formattedAccuracy)); + notificationBuilder.setContentTitle(context.getString(R.string.track_distance_notification, StringUtils.formatDistance(context, trackStatistics.getTotalDistance(), metricUnits))); + notificationBuilder.setContentText(context.getString(R.string.track_speed_notification, StringUtils.formatSpeed(context, trackPoint.getSpeed(), metricUnits, true))); + notificationBuilder.setSubText(context.getString(R.string.track_recording_notification_accuracy, formattedAccuracy)); updateNotification(); notificationBuilder.setOnlyAlertOnce(true); @@ -93,6 +100,10 @@ class TrackRecordingServiceNotificationManager { return notificationBuilder.build(); } + void setMetricUnits(boolean metricUnits) { + this.metricUnits = metricUnits; + } + private void updateNotification() { notificationManager.notify(NOTIFICATION_ID, getNotification()); } diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 4596099f6..2dd14d496 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -465,6 +465,9 @@ limitations under the License. Track %1$d Recording your track… Location accuracy: %1$s + Distance: %1$s + Speed: %1$s + Pace: %1$s %1$s Markers The track and its markers will be permanently deleted from the device.