forked from upstream-mirrors/OpenTracks
Bugfix: prevent NPE when disabling voice announcements while recording.
Fixes #940.
This commit is contained in:
+22
-25
@@ -62,13 +62,8 @@ public class VoiceAnnouncementManager {
|
|||||||
voiceAnnouncement.start();
|
voiceAnnouncement.start();
|
||||||
|
|
||||||
this.trackStatistics = trackStatistics;
|
this.trackStatistics = trackStatistics;
|
||||||
|
updateNextDuration();
|
||||||
if (!totalTimeFrequency.isZero()) {
|
updateNextTaskDistance();
|
||||||
nextTotalTime = calculateNextDuration();
|
|
||||||
}
|
|
||||||
if (!distanceFrequency.isZero()) {
|
|
||||||
nextTotalDistance = calculateNextTaskDistance();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(@NonNull Track track) {
|
public void update(@NonNull Track track) {
|
||||||
@@ -80,11 +75,11 @@ public class VoiceAnnouncementManager {
|
|||||||
boolean announce = false;
|
boolean announce = false;
|
||||||
this.trackStatistics = track.getTrackStatistics();
|
this.trackStatistics = track.getTrackStatistics();
|
||||||
if (trackStatistics.getTotalDistance().greaterThan(nextTotalDistance)) {
|
if (trackStatistics.getTotalDistance().greaterThan(nextTotalDistance)) {
|
||||||
nextTotalDistance = calculateNextTaskDistance();
|
updateNextTaskDistance();
|
||||||
announce = true;
|
announce = true;
|
||||||
}
|
}
|
||||||
if (!trackStatistics.getTotalTime().minus(nextTotalTime).isNegative()) {
|
if (!trackStatistics.getTotalTime().minus(nextTotalTime).isNegative()) {
|
||||||
nextTotalTime = calculateNextDuration();
|
updateNextDuration();
|
||||||
announce = true;
|
announce = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,27 +105,29 @@ public class VoiceAnnouncementManager {
|
|||||||
restore(this.trackStatistics);
|
restore(this.trackStatistics);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
public void updateNextTaskDistance() {
|
||||||
public Distance calculateNextTaskDistance() {
|
if (trackStatistics == null || distanceFrequency.isZero()) {
|
||||||
if (trackStatistics == null) {
|
nextTotalDistance = DISTANCE_OFF;
|
||||||
return DISTANCE_OFF;
|
} else {
|
||||||
|
|
||||||
|
Distance distance = trackStatistics.getTotalDistance();
|
||||||
|
|
||||||
|
int index = (int) (distance.dividedBy(distanceFrequency));
|
||||||
|
nextTotalDistance = distanceFrequency.multipliedBy(index + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Distance distance = trackStatistics.getTotalDistance();
|
|
||||||
|
|
||||||
int index = (int) (distance.dividedBy(distanceFrequency));
|
|
||||||
return distanceFrequency.multipliedBy(index + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Duration calculateNextDuration() {
|
private void updateNextDuration() {
|
||||||
if (trackStatistics == null) {
|
if (trackStatistics == null || totalTimeFrequency.isZero()) {
|
||||||
return TOTALTIME_OFF;
|
nextTotalTime = TOTALTIME_OFF;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Duration totalTime = trackStatistics.getTotalTime();
|
||||||
|
Duration intervalMod = Duration.ofMillis(trackStatistics.getTotalTime().toMillis() % totalTimeFrequency.toMillis());
|
||||||
|
|
||||||
|
nextTotalTime = totalTime.plus(totalTimeFrequency.minus(intervalMod));
|
||||||
}
|
}
|
||||||
|
|
||||||
Duration totalTime = trackStatistics.getTotalTime();
|
|
||||||
Duration intervalMod = Duration.ofMillis(trackStatistics.getTotalTime().toMillis() % totalTimeFrequency.toMillis());
|
|
||||||
|
|
||||||
return totalTime.plus(totalTimeFrequency.minus(intervalMod));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
|||||||
Reference in New Issue
Block a user