do not add the distances between "recording paused" and "recording resumed"

This commit is contained in:
y20k 2020-03-02 16:45:12 +01:00
parent 37a813717e
commit d68a767e3e
No known key found for this signature in database
GPG key ID: 824D4259F41FAFF6
5 changed files with 27 additions and 14 deletions

View file

@ -11,8 +11,8 @@ android {
applicationId 'org.y20k.trackbook'
minSdkVersion 25
targetSdkVersion 27
versionCode 38
versionName '2.0.1'
versionCode 39
versionName '2.0.2'
resConfigs "en", "da", "de", "fr", "id", "it", "ja", "nb-rNO", "nl", "sv", "zh-rCN"
}

View file

@ -63,6 +63,7 @@ class TrackerService(): Service(), CoroutineScope, SensorEventListener {
var locationAccuracyThreshold: Int = Keys.DEFAULT_THRESHOLD_LOCATION_ACCURACY
var currentBestLocation: Location = LocationHelper.getDefaultLocation()
var stepCountOffset: Float = 0f
var resumed: Boolean = false
var track: Track = Track()
var gpsLocationListenerRegistered: Boolean = false
var networkLocationListenerRegistered: Boolean = false
@ -213,6 +214,8 @@ class TrackerService(): Service(), CoroutineScope, SensorEventListener {
val lastWayPointIndex = track.wayPoints.size - 1
track.wayPoints.get(lastWayPointIndex).isStopOver = true
}
// set resumed flag
resumed = true
// calculate length of recording break
track.recordingPaused = TrackHelper.calculateRecordingPaused(track.recordingStop)
LogHelper.e(TAG, "We took a break for ${DateTimeHelper.convertToReadableTime(this, track.recordingPaused)}") // todo remove
@ -457,7 +460,14 @@ class TrackerService(): Service(), CoroutineScope, SensorEventListener {
private val periodicTrackUpdate: Runnable = object : Runnable {
override fun run() {
// add waypoint to track - step count is continuously updated in onSensorChanged
track = TrackHelper.addWayPointToTrack(track, currentBestLocation, locationAccuracyThreshold)
val result: Pair<Track, Boolean> = TrackHelper.addWayPointToTrack(track, currentBestLocation, locationAccuracyThreshold, resumed)
// get track from result
track = result.first
// check if waypoint was successfully added (= result.second)
if (resumed && result.second) {
// reset resumed flag, if necessary
resumed = false
}
// update notification
displayNotification()
// save temp track using GlobalScope.launch = fire & forget (no return value from save)

View file

@ -40,7 +40,6 @@ class NotificationHelper(private val trackerService: TrackerService) {
private val TAG: String = LogHelper.makeLogTag(NotificationHelper::class.java)
/* Main class variables */
private val notificationManager: NotificationManager = trackerService.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

View file

@ -45,7 +45,7 @@ object TrackHelper {
/* Adds given locatiom as waypoint to track */
fun addWayPointToTrack(track: Track, location: Location, locationAccuracyThreshold: Int): Track {
fun addWayPointToTrack(track: Track, location: Location, locationAccuracyThreshold: Int, resumed: Boolean): Pair<Track, Boolean> {
// get previous location
val previousLocation: Location?
@ -69,8 +69,10 @@ object TrackHelper {
&& LocationHelper.isDifferentEnough(previousLocation, location))
if (shouldBeAdded) {
// update distance
// update distance (do not update if resumed -> we do not want to add values calculated during a recording pause)
if (!resumed) {
track.length = track.length + LocationHelper.calculateDistance(previousLocation, location)
}
if (location.altitude != 0.0) {
// update altitude values
@ -78,19 +80,21 @@ object TrackHelper {
track.maxAltitude = location.altitude
track.minAltitude = location.altitude
} else {
// calculate elevation values
// calculate elevation values (upwards / downwards movements)
val elevationDifferences: Pair<Double, Double> = LocationHelper.calculateElevationDifferences(previousLocation, location, track)
// check if significant differences were calculated
// check if any differences were calculated
if (elevationDifferences != Pair(track.positiveElevation, track.negativeElevation)) {
// update altitude values
if (location.altitude > track.maxAltitude) track.maxAltitude = location.altitude
if (location.altitude < track.minAltitude) track.minAltitude = location.altitude
// update elevation values
// update elevation values (do not update if resumed -> we do not want to add values calculated during a recording pause)
if (!resumed) {
track.positiveElevation = elevationDifferences.first
track.negativeElevation = elevationDifferences.second
}
}
}
}
// toggle stop over status, if necessary
if (track.wayPoints.size < 0) {
@ -114,7 +118,7 @@ object TrackHelper {
track.wayPoints.add(WayPoint(location.provider, location.latitude, location.longitude, location.altitude, location.accuracy, location.time, track.length, numberOfSatellites))
}
return track
return Pair(track, shouldBeAdded)
}

View file

@ -8,7 +8,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.0'
classpath 'com.android.tools.build:gradle:3.6.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.2.0"
// NOTE: Do not place your application dependencies here; they belong