forked from upstream-mirrors/OpenTracks
Update calorie when activity recognition api sets the track category
This commit is contained in:
@@ -763,35 +763,44 @@ public class TrackRecordingService extends Service {
|
|||||||
|
|
||||||
// Update database
|
// Update database
|
||||||
Track track = myTracksProviderUtils.getTrack(trackId);
|
Track track = myTracksProviderUtils.getTrack(trackId);
|
||||||
if (track != null && !paused) {
|
if (track != null) {
|
||||||
insertLocation(track, lastLocation, getLastValidTrackPointInCurrentSegment(trackId));
|
|
||||||
|
|
||||||
int activityRecognitionType = PreferencesUtils.getInt(this,
|
// If not paused, add the last location
|
||||||
R.string.activity_recognition_type_key,
|
if (!paused) {
|
||||||
PreferencesUtils.ACTIVITY_RECOGNITION_TYPE_DEFAULT);
|
insertLocation(track, lastLocation, getLastValidTrackPointInCurrentSegment(trackId));
|
||||||
if (activityRecognitionType != PreferencesUtils.ACTIVITY_RECOGNITION_TYPE_DEFAULT) {
|
}
|
||||||
String iconValue = null;
|
|
||||||
switch (activityRecognitionType) {
|
// Update the recording track time
|
||||||
case DetectedActivity.IN_VEHICLE:
|
updateRecordingTrack(track, myTracksProviderUtils.getLastTrackPointId(trackId), false);
|
||||||
iconValue = TrackIconUtils.DRIVE;
|
|
||||||
break;
|
if (track.getCategory().equals(PreferencesUtils.DEFAULT_ACTIVITY_DEFAULT)) {
|
||||||
case DetectedActivity.ON_BICYCLE:
|
int activityRecognitionType = PreferencesUtils.getInt(this,
|
||||||
iconValue = TrackIconUtils.BIKE;
|
R.string.activity_recognition_type_key,
|
||||||
break;
|
PreferencesUtils.ACTIVITY_RECOGNITION_TYPE_DEFAULT);
|
||||||
case DetectedActivity.ON_FOOT:
|
if (activityRecognitionType != PreferencesUtils.ACTIVITY_RECOGNITION_TYPE_DEFAULT) {
|
||||||
iconValue = TrackIconUtils.WALK;
|
String iconValue = null;
|
||||||
break;
|
switch (activityRecognitionType) {
|
||||||
default:
|
case DetectedActivity.IN_VEHICLE:
|
||||||
break;
|
iconValue = TrackIconUtils.DRIVE;
|
||||||
}
|
break;
|
||||||
if (iconValue != null) {
|
case DetectedActivity.ON_BICYCLE:
|
||||||
track.setIcon(iconValue);
|
iconValue = TrackIconUtils.BIKE;
|
||||||
track.setCategory(getString(TrackIconUtils.getIconActivityType(iconValue)));
|
break;
|
||||||
|
case DetectedActivity.ON_FOOT:
|
||||||
|
iconValue = TrackIconUtils.WALK;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (iconValue != null) {
|
||||||
|
track.setIcon(iconValue);
|
||||||
|
track.setCategory(getString(TrackIconUtils.getIconActivityType(iconValue)));
|
||||||
|
myTracksProviderUtils.updateTrack(track);
|
||||||
|
CalorieUtils.updateTrackCalorie(context, track);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateRecordingTrack(track, myTracksProviderUtils.getLastTrackPointId(trackId), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
endRecording(true, trackId);
|
endRecording(true, trackId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1031,15 +1040,23 @@ public class TrackRecordingService extends Service {
|
|||||||
sendTrackBroadcast(R.string.track_update_broadcast_action, track.getId());
|
sendTrackBroadcast(R.string.track_update_broadcast_action, track.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the recording track time. Also updates the startId and the stopId.
|
||||||
|
* Increase the number of points if it is a new and valid track point.
|
||||||
|
*
|
||||||
|
* @param track the track
|
||||||
|
* @param lastTrackPointId the last track point id
|
||||||
|
* @param increaseNumberOfPoints true to increase the number of points
|
||||||
|
*/
|
||||||
private void updateRecordingTrack(
|
private void updateRecordingTrack(
|
||||||
Track track, long trackPointId, boolean isTrackPointNewAndValid) {
|
Track track, long lastTrackPointId, boolean increaseNumberOfPoints) {
|
||||||
if (trackPointId >= 0) {
|
if (lastTrackPointId >= 0) {
|
||||||
if (track.getStartId() < 0) {
|
if (track.getStartId() < 0) {
|
||||||
track.setStartId(trackPointId);
|
track.setStartId(lastTrackPointId);
|
||||||
}
|
}
|
||||||
track.setStopId(trackPointId);
|
track.setStopId(lastTrackPointId);
|
||||||
}
|
}
|
||||||
if (isTrackPointNewAndValid) {
|
if (increaseNumberOfPoints) {
|
||||||
track.setNumberOfPoints(track.getNumberOfPoints() + 1);
|
track.setNumberOfPoints(track.getNumberOfPoints() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user