should fix crash described in issue #70 - adds check if file manager is present
This commit is contained in:
parent
4bed93f821
commit
59c736630f
3 changed files with 33 additions and 11 deletions
|
@ -457,7 +457,7 @@ class TrackerService(): Service(), CoroutineScope, SensorEventListener {
|
||||||
private val periodicTrackUpdate: Runnable = object : Runnable {
|
private val periodicTrackUpdate: Runnable = object : Runnable {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
// add waypoint to track - step count is continuously updated in onSensorChanged
|
// add waypoint to track - step count is continuously updated in onSensorChanged
|
||||||
val result: Pair<Track, Boolean> = TrackHelper.addWayPointToTrack(track, currentBestLocation, locationAccuracyThreshold, resumed)
|
val result: Pair<Track, Boolean> = TrackHelper.addWayPointToTrack(this@TrackerService, track, currentBestLocation, locationAccuracyThreshold, resumed)
|
||||||
// get track from result
|
// get track from result
|
||||||
track = result.first
|
track = result.first
|
||||||
// check if waypoint was successfully added (= result.second)
|
// check if waypoint was successfully added (= result.second)
|
||||||
|
|
|
@ -17,7 +17,9 @@
|
||||||
|
|
||||||
package org.y20k.trackbook.helpers
|
package org.y20k.trackbook.helpers
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.location.Location
|
import android.location.Location
|
||||||
|
import android.widget.Toast
|
||||||
import org.y20k.trackbook.core.Track
|
import org.y20k.trackbook.core.Track
|
||||||
import org.y20k.trackbook.core.TracklistElement
|
import org.y20k.trackbook.core.TracklistElement
|
||||||
import org.y20k.trackbook.core.WayPoint
|
import org.y20k.trackbook.core.WayPoint
|
||||||
|
@ -45,24 +47,27 @@ object TrackHelper {
|
||||||
|
|
||||||
|
|
||||||
/* Adds given locatiom as waypoint to track */
|
/* Adds given locatiom as waypoint to track */
|
||||||
fun addWayPointToTrack(track: Track, location: Location, locationAccuracyThreshold: Int, resumed: Boolean): Pair<Track, Boolean> {
|
fun addWayPointToTrack(context: Context, track: Track, location: Location, locationAccuracyThreshold: Int, resumed: Boolean): Pair<Track, Boolean> {
|
||||||
// get previous location
|
// get previous location
|
||||||
val previousLocation: Location?
|
val previousLocation: Location?
|
||||||
var numberOfWayPoints: Int = track.wayPoints.size
|
var numberOfWayPoints: Int = track.wayPoints.size
|
||||||
|
|
||||||
// CASE: First location
|
// CASE: First location
|
||||||
if (numberOfWayPoints == 0) {
|
if (numberOfWayPoints == 0) {
|
||||||
|
LogHelper.e(TAG, "First Location." ) // todo remove
|
||||||
previousLocation = null
|
previousLocation = null
|
||||||
}
|
}
|
||||||
// CASE: Second location - check if first location was plausible & remove implausible location
|
// CASE: Second location - check if first location was plausible & remove implausible location
|
||||||
else if (numberOfWayPoints == 1 && !LocationHelper.isFirstLocationPlausible(location, track)) {
|
else if (numberOfWayPoints == 1 && !LocationHelper.isFirstLocationPlausible(location, track)) {
|
||||||
|
LogHelper.e(TAG, "Second Location not plausible.") // todo remove
|
||||||
previousLocation = null
|
previousLocation = null
|
||||||
numberOfWayPoints = 0
|
numberOfWayPoints = 0
|
||||||
track.wayPoints.removeAt(0)
|
track.wayPoints.removeAt(0)
|
||||||
}
|
}
|
||||||
// CASE: Third location or second location (if first was plausible)
|
// CASE: Third location or second location (if first was plausible)
|
||||||
else {
|
else {
|
||||||
previousLocation = track.wayPoints.get(numberOfWayPoints - 1).toLocation()
|
LogHelper.e(TAG, "Yay.") // todo remove
|
||||||
|
previousLocation = track.wayPoints[numberOfWayPoints - 1].toLocation()
|
||||||
}
|
}
|
||||||
|
|
||||||
// update duration
|
// update duration
|
||||||
|
@ -73,9 +78,24 @@ object TrackHelper {
|
||||||
|
|
||||||
// add only if recent and accurate
|
// add only if recent and accurate
|
||||||
val shouldBeAdded: Boolean
|
val shouldBeAdded: Boolean
|
||||||
shouldBeAdded = (LocationHelper.isRecentEnough(location)
|
|
||||||
&& LocationHelper.isAccurateEnough(location, locationAccuracyThreshold)
|
// todo remove for production
|
||||||
&& LocationHelper.isDifferentEnough(previousLocation, location))
|
val recentEnough: Boolean = LocationHelper.isRecentEnough(location)
|
||||||
|
val accurateEnough: Boolean = LocationHelper.isAccurateEnough(location, locationAccuracyThreshold)
|
||||||
|
val differentEnough: Boolean = LocationHelper.isDifferentEnough(previousLocation, location)
|
||||||
|
|
||||||
|
if (!recentEnough && accurateEnough && differentEnough) { Toast.makeText(context, "Debug: Not recent enough", Toast.LENGTH_LONG).show() }
|
||||||
|
else if (!accurateEnough && recentEnough && differentEnough) { Toast.makeText(context, "Debug: Not accurate enough", Toast.LENGTH_LONG).show() }
|
||||||
|
else if (!differentEnough && recentEnough && accurateEnough) { Toast.makeText(context, "Debug: Not different enough", Toast.LENGTH_LONG).show() }
|
||||||
|
else if (!recentEnough && !accurateEnough && differentEnough) { Toast.makeText(context, "Debug: Not recent and accurate enough", Toast.LENGTH_LONG).show() }
|
||||||
|
else if (!recentEnough && !differentEnough && accurateEnough) { Toast.makeText(context, "Debug: Not recent and different enough", Toast.LENGTH_LONG).show() }
|
||||||
|
else if (!accurateEnough && !differentEnough && recentEnough) { Toast.makeText(context, "Debug: Not accurate and different enough", Toast.LENGTH_LONG).show() }
|
||||||
|
else { Toast.makeText(context, "Debug: bad location.", Toast.LENGTH_LONG).show() }
|
||||||
|
|
||||||
|
shouldBeAdded = recentEnough && accurateEnough && differentEnough
|
||||||
|
//shouldBeAdded = (LocationHelper.isRecentEnough(location) &&
|
||||||
|
// LocationHelper.isAccurateEnough(location, locationAccuracyThreshold) &&
|
||||||
|
// LocationHelper.isDifferentEnough(previousLocation, location))
|
||||||
|
|
||||||
if (shouldBeAdded) {
|
if (shouldBeAdded) {
|
||||||
// update distance (do not update if resumed -> we do not want to add values calculated during a recording pause)
|
// update distance (do not update if resumed -> we do not want to add values calculated during a recording pause)
|
||||||
|
@ -124,7 +144,7 @@ object TrackHelper {
|
||||||
track.longitude = location.longitude
|
track.longitude = location.longitude
|
||||||
|
|
||||||
// add location as new waypoint
|
// add location as new waypoint
|
||||||
track.wayPoints.add(WayPoint(location.provider, location.latitude, location.longitude, location.altitude, location.accuracy, location.time, track.length, numberOfSatellites))
|
track.wayPoints.add(WayPoint(provider = location.provider, latitude = location.latitude, longitude = location.longitude, altitude = location.altitude, accuracy = location.accuracy, time = location.time, distanceToStartingPoint = track.length, numberSatellites = numberOfSatellites))
|
||||||
}
|
}
|
||||||
|
|
||||||
return Pair(track, shouldBeAdded)
|
return Pair(track, shouldBeAdded)
|
||||||
|
|
|
@ -162,10 +162,12 @@ data class TrackFragmentLayoutHolder(var context: Context, var inflater: LayoutI
|
||||||
/* Saves zoom level and center of this map */
|
/* Saves zoom level and center of this map */
|
||||||
fun saveViewStateToTrack() {
|
fun saveViewStateToTrack() {
|
||||||
val center: IGeoPoint = mapView.mapCenter
|
val center: IGeoPoint = mapView.mapCenter
|
||||||
track.latitude = center.latitude
|
if (center.latitude != 0.0 && center.longitude != 0.0) {
|
||||||
track.longitude = center.longitude
|
track.latitude = center.latitude
|
||||||
track.zoomLevel = mapView.zoomLevelDouble
|
track.longitude = center.longitude
|
||||||
GlobalScope.launch { FileHelper.saveTrackSuspended(track, false) }
|
track.zoomLevel = mapView.zoomLevelDouble
|
||||||
|
GlobalScope.launch { FileHelper.saveTrackSuspended(track, false) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue