Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added settings for disabling idle functionality. #1990

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@ synchronized boolean onNewTrackPoint(@NonNull TrackPoint trackPoint) {
if (trackPoint.hasLocation() && lastStoredTrackPointWithLocation == null) {
insertTrackPoint(trackPoint, true);

handler.removeCallbacks(ON_IDLE);
handler.postDelayed(ON_IDLE, idleDuration.toMillis());
scheduleNewIdleTimeout();
return true;
}

Expand Down Expand Up @@ -199,16 +198,14 @@ synchronized boolean onNewTrackPoint(@NonNull TrackPoint trackPoint) {
trackPoint.setType(TrackPoint.Type.SEGMENT_START_AUTOMATIC);
insertTrackPoint(trackPoint, true);

handler.removeCallbacks(ON_IDLE);
handler.postDelayed(ON_IDLE, idleDuration.toMillis());
scheduleNewIdleTimeout();
return true;
}

if (distanceToLastStoredTrackPoint.greaterOrEqualThan(recordingDistanceInterval)) {
insertTrackPoint(trackPoint, false);

handler.removeCallbacks(ON_IDLE);
handler.postDelayed(ON_IDLE, idleDuration.toMillis());
scheduleNewIdleTimeout();
return true;
}

Expand All @@ -218,6 +215,15 @@ synchronized boolean onNewTrackPoint(@NonNull TrackPoint trackPoint) {
return false;
}

private void scheduleNewIdleTimeout() {
if (idleDuration.isZero()) {
Log.d(TAG, "idle functionality is disabled");
return;
}
handler.removeCallbacks(ON_IDLE);
handler.postDelayed(ON_IDLE, idleDuration.toMillis());
}

TrackStatistics getTrackStatistics() {
return trackStatisticsUpdater == null ? null : trackStatisticsUpdater.getTrackStatistics();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,17 +344,17 @@ public static Duration getVoiceAnnouncementFrequency() {
}

static String[] getVoiceAnnouncementFrequencyEntries() {
String[] values = resources.getStringArray(R.array.voice_announcement_frequency_values);
String[] options = new String[values.length];
for (int i = 0; i < values.length; i++) {
if (resources.getString(R.string.announcement_off).equals(values[i])) {
options[i] = resources.getString(R.string.value_off);
String[] entryValues = resources.getStringArray(R.array.voice_announcement_frequency_values);
String[] entries = new String[entryValues.length];
for (int i = 0; i < entryValues.length; i++) {
if (resources.getString(R.string.announcement_off).equals(entryValues[i])) {
entries[i] = resources.getString(R.string.value_off);
} else {
int value = Integer.parseInt(values[i]);
options[i] = resources.getString(R.string.value_integer_minute, Duration.ofSeconds(value).toMinutes());
int value = Integer.parseInt(entryValues[i]);
entries[i] = resources.getString(R.string.value_integer_minute, Duration.ofSeconds(value).toMinutes());
}
}
return options;
return entries;
}

/**
Expand All @@ -370,23 +370,23 @@ public static Distance getVoiceAnnouncementDistance() {
* @return Result depends on getUnitSystem
*/
static String[] getVoiceAnnouncementDistanceEntries() {
String[] values = resources.getStringArray(R.array.voice_announcement_distance_values);
String[] options = new String[values.length];
String[] entryValues = resources.getStringArray(R.array.voice_announcement_distance_values);
String[] entries = new String[entryValues.length];
UnitSystem unitSystem = getUnitSystem();

DistanceFormatter formatter = DistanceFormatter.Builder()
.setDecimalCount(0)
.setUnit(unitSystem)
.build(resources);
for (int i = 0; i < values.length; i++) {
if (resources.getString(R.string.announcement_off).equals(values[i])) {
options[i] = resources.getString(R.string.value_off);
for (int i = 0; i < entryValues.length; i++) {
if (resources.getString(R.string.announcement_off).equals(entryValues[i])) {
entries[i] = resources.getString(R.string.value_off);
} else {
Distance distance = Distance.one(unitSystem).multipliedBy(Double.parseDouble(values[i]));
options[i] = formatter.formatDistance(distance);
Distance distance = Distance.one(unitSystem).multipliedBy(Double.parseDouble(entryValues[i]));
entries[i] = formatter.formatDistance(distance);
}
}
return options;
return entries;
}

public static float getVoiceSpeedRate() {
Expand Down Expand Up @@ -642,7 +642,9 @@ static String[] getIdleDurationEntries() {
for (int i = 0; i < entryValues.length; i++) {
int value = Integer.parseInt(entryValues[i]);

if (value == idleDurationDefault) {
if (resources.getString(R.string.announcement_off).equals(entryValues[i])) {
entries[i] = resources.getString(R.string.value_off);
} else if (value == idleDurationDefault) {
entries[i] = resources.getString(R.string.value_int_seconds, value);
} else {
entries[i] = value < 60 ? resources.getString(R.string.value_integer_second, value) : resources.getString(R.string.value_integer_minute, value / 60);
Expand Down
2 changes: 2 additions & 0 deletions src/main/res/values/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@

<string name="idle_duration_key" translatable="false">idleSpeedDuration</string>
<string name="idle_duration_default" translatable="false">10</string>
<string name="idle_duration_off" translatable="false">0</string>
<string-array name="idle_duration_values">
<item>@string/idle_duration_off</item>
<item>5</item>
<item>@string/idle_duration_default</item>
<item>15</item>
Expand Down
Loading