diff --git a/.idea/migrations.xml b/.idea/migrations.xml deleted file mode 100644 index f8051a6f9..000000000 --- a/.idea/migrations.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/build.gradle b/build.gradle index d5e169bd1..6a76fcf7c 100644 --- a/build.gradle +++ b/build.gradle @@ -146,4 +146,3 @@ dependencies { androidTestUtil 'androidx.test:orchestrator:1.4.2' } - diff --git a/src/androidTest/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdaterTest.java b/src/androidTest/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdaterTest.java index ea952d3f6..59c9425a9 100644 --- a/src/androidTest/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdaterTest.java +++ b/src/androidTest/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdaterTest.java @@ -87,7 +87,7 @@ public void addTrackPoint_TestingTrack() { assertEquals(2.5, statistics.getMinAltitude(), 0.01); assertEquals(32.5, statistics.getMaxAltitude(), 0.01); - assertEquals(36, 0.01, statistics.getTotalAltitudeGain()); + assertEquals(36, statistics.getTotalAltitudeGain(), 0.01); assertEquals(36, statistics.getTotalAltitudeLoss(), 0.01); assertEquals(11.85, statistics.getMaxSpeed().toMPS(), 0.01); diff --git a/src/main/java/de/dennisguse/opentracks/settings/ImportExportSettingsFragment.java b/src/main/java/de/dennisguse/opentracks/settings/ImportExportSettingsFragment.java index a088f93e7..817883dfa 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/ImportExportSettingsFragment.java +++ b/src/main/java/de/dennisguse/opentracks/settings/ImportExportSettingsFragment.java @@ -18,7 +18,6 @@ public class ImportExportSettingsFragment extends PreferenceFragmentCompat { - private static final String TAG = ImportExportSettingsFragment.class.getSimpleName(); @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { diff --git a/src/main/java/de/dennisguse/opentracks/settings/PreferencesOpenHelper.java b/src/main/java/de/dennisguse/opentracks/settings/PreferencesOpenHelper.java index 217ef708e..bc3139fb6 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/PreferencesOpenHelper.java +++ b/src/main/java/de/dennisguse/opentracks/settings/PreferencesOpenHelper.java @@ -34,7 +34,8 @@ private void onUpgrade() { switch (i) { case 1 -> upgradeFrom0to1(); case 2 -> upgradeFrom1to2(); - default -> throw new RuntimeException("Not implemented: upgrade to " + version); + default -> throw new UnsupportedOperationException("Upgrade to version " + version + " not implemented"); + } } } diff --git a/src/main/java/de/dennisguse/opentracks/settings/SensorsSettingsFragment.java b/src/main/java/de/dennisguse/opentracks/settings/SensorsSettingsFragment.java index 22629c6e2..06442cf3f 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/SensorsSettingsFragment.java +++ b/src/main/java/de/dennisguse/opentracks/settings/SensorsSettingsFragment.java @@ -16,7 +16,7 @@ public class SensorsSettingsFragment extends PreferenceFragmentCompat { - private final static String TAG = SensorsSettingsFragment.class.getSimpleName(); + private static final String TAG = SensorsSettingsFragment.class.getSimpleName(); @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { diff --git a/src/main/java/de/dennisguse/opentracks/settings/SettingsCustomLayoutEditActivity.java b/src/main/java/de/dennisguse/opentracks/settings/SettingsCustomLayoutEditActivity.java index fc962e49e..dfe98ea83 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/SettingsCustomLayoutEditActivity.java +++ b/src/main/java/de/dennisguse/opentracks/settings/SettingsCustomLayoutEditActivity.java @@ -25,7 +25,6 @@ public class SettingsCustomLayoutEditActivity extends AbstractActivity implement public static final String EXTRA_LAYOUT = "extraLayout"; private ActivitySettingsCustomLayoutBinding viewBinding; - private GridLayoutManager gridLayoutManager; private SettingsCustomLayoutEditAdapter adapterFieldsVisible; private SettingsCustomLayoutEditAdapter adapterFieldsHidden; private String profile; @@ -36,7 +35,8 @@ public class SettingsCustomLayoutEditActivity extends AbstractActivity implement @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - + GridLayoutManager gridLayoutManager; + // Recycler view with visible stats. RecordingLayout recordingLayout = getIntent().getParcelableExtra(EXTRA_LAYOUT); profile = recordingLayout.getName(); diff --git a/src/main/java/de/dennisguse/opentracks/settings/UnitSystem.java b/src/main/java/de/dennisguse/opentracks/settings/UnitSystem.java index 1d4f41f0a..04ca7520c 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/UnitSystem.java +++ b/src/main/java/de/dennisguse/opentracks/settings/UnitSystem.java @@ -20,6 +20,9 @@ public int getPreferenceId() { return preferenceIdentifier; } + /** + * @deprecated (when, why, etc...) + */ @Deprecated //TODO used to initialize before loading from preferences; should be loaded first public static UnitSystem defaultUnitSystem() { return METRIC; diff --git a/src/main/java/de/dennisguse/opentracks/settings/bluetooth/BluetoothLeSensorPreference.java b/src/main/java/de/dennisguse/opentracks/settings/bluetooth/BluetoothLeSensorPreference.java index 013c2be98..7eca3b4ce 100644 --- a/src/main/java/de/dennisguse/opentracks/settings/bluetooth/BluetoothLeSensorPreference.java +++ b/src/main/java/de/dennisguse/opentracks/settings/bluetooth/BluetoothLeSensorPreference.java @@ -49,19 +49,19 @@ public abstract class BluetoothLeSensorPreference extends DialogPreference { private static final int SENSOR_INTERNAL_RESOURCEID = R.string.value_internal_sensor; - public BluetoothLeSensorPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + protected BluetoothLeSensorPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } - public BluetoothLeSensorPreference(Context context, AttributeSet attrs, int defStyleAttr) { + protected BluetoothLeSensorPreference(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } - public BluetoothLeSensorPreference(Context context, AttributeSet attrs) { + protected BluetoothLeSensorPreference(Context context, AttributeSet attrs) { super(context, attrs); } - public BluetoothLeSensorPreference(Context context) { + protected BluetoothLeSensorPreference(Context context) { super(context); } diff --git a/src/main/java/de/dennisguse/opentracks/stats/TrackStatistics.java b/src/main/java/de/dennisguse/opentracks/stats/TrackStatistics.java index 35b6e78f9..41fa6d8e7 100644 --- a/src/main/java/de/dennisguse/opentracks/stats/TrackStatistics.java +++ b/src/main/java/de/dennisguse/opentracks/stats/TrackStatistics.java @@ -56,8 +56,8 @@ public class TrackStatistics { private Duration movingTime; // The maximum speed (meters/second) that we believe is valid. private Speed maxSpeed; - private Float totalAltitudeGainMeters = null; - private Float totalAltitudeLossMeters = null; + private Float totalAltitudeGain_m = null; + private Float totalAltitudeLoss_m = null; // The average heart rate seen on this track private HeartRate avgHeartRate = null; @@ -80,22 +80,22 @@ public TrackStatistics(TrackStatistics other) { movingTime = other.movingTime; maxSpeed = other.maxSpeed; altitudeExtremities.set(other.altitudeExtremities.getMin(), other.altitudeExtremities.getMax()); - totalAltitudeGainMeters = other.totalAltitudeGainMeters; - totalAltitudeLossMeters = other.totalAltitudeLossMeters; + totalAltitudeGain_m = other.totalAltitudeGain_m; + totalAltitudeLoss_m = other.totalAltitudeLoss_m; avgHeartRate = other.avgHeartRate; isIdle = other.isIdle; } @VisibleForTesting - public TrackStatistics(String startTime, String stopTime, double totalDistance_m, int totalTime_s, int movingTime_s, float maxSpeed_mps, Float totalAltitudeGainMeters, Float totalAltitudeLossMeters) { + public TrackStatistics(String startTime, String stopTime, double totalDistance_m, int totalTime_s, int movingTime_s, float maxSpeed_mps, Float totalAltitudeGain_m, Float totalAltitudeLoss_m) { this.startTime = Instant.parse(startTime); this.stopTime = Instant.parse(stopTime); this.totalDistance = Distance.of(totalDistance_m); this.totalTime = Duration.ofSeconds(totalTime_s); this.movingTime = Duration.ofSeconds(movingTime_s); this.maxSpeed = Speed.of(maxSpeed_mps); - this.totalAltitudeGainMeters = totalAltitudeGainMeters; - this.totalAltitudeLossMeters = totalAltitudeLossMeters; + this.totalAltitudeGain_m = totalAltitudeGain_m; + this.totalAltitudeLoss_m = totalAltitudeLoss_m; } /** @@ -137,22 +137,22 @@ public void merge(TrackStatistics other) { altitudeExtremities.update(other.altitudeExtremities.getMin()); altitudeExtremities.update(other.altitudeExtremities.getMax()); } - if (totalAltitudeGainMeters == null) { - if (other.totalAltitudeGainMeters != null) { - totalAltitudeGainMeters = other.totalAltitudeGainMeters; + if (totalAltitudeGain_m == null) { + if (other.totalAltitudeGain_m != null) { + totalAltitudeGain_m = other.totalAltitudeGain_m; } } else { - if (other.totalAltitudeGainMeters != null) { - totalAltitudeGainMeters += other.totalAltitudeGainMeters; + if (other.totalAltitudeGain_m != null) { + totalAltitudeGain_m += other.totalAltitudeGain_m; } } - if (totalAltitudeLossMeters == null) { - if (other.totalAltitudeLossMeters != null) { - totalAltitudeLossMeters = other.totalAltitudeLossMeters; + if (totalAltitudeLoss_m == null) { + if (other.totalAltitudeLoss_m != null) { + totalAltitudeLoss_m = other.totalAltitudeLoss_m; } } else { - if (other.totalAltitudeLossMeters != null) { - totalAltitudeLossMeters += other.totalAltitudeLossMeters; + if (other.totalAltitudeLoss_m != null) { + totalAltitudeLoss_m += other.totalAltitudeLoss_m; } } } @@ -301,8 +301,8 @@ public double getMinAltitude() { return altitudeExtremities.getMin(); } - public void setMinAltitude(double altitudeMeter) { - altitudeExtremities.setMin(altitudeMeter); + public void setMinAltitude(double altitude_m) { + altitudeExtremities.setMin(altitude_m); } public boolean hasAltitudeMax() { @@ -317,8 +317,8 @@ public double getMaxAltitude() { return altitudeExtremities.getMax(); } - public void setMaxAltitude(double altitudeMeter) { - altitudeExtremities.setMax(altitudeMeter); + public void setMaxAltitude(double altitude_m) { + altitudeExtremities.setMax(altitude_m); } public void updateAltitudeExtremities(Altitude altitude) { @@ -334,45 +334,45 @@ public void setAverageHeartRate(HeartRate heartRate) { } public boolean hasTotalAltitudeGain() { - return totalAltitudeGainMeters != null; + return totalAltitudeGain_m != null; } @Nullable public Float getTotalAltitudeGain() { - return totalAltitudeGainMeters; + return totalAltitudeGain_m; } - public void setTotalAltitudeGain(Float totalAltitudeGainMeters) { - this.totalAltitudeGainMeters = totalAltitudeGainMeters; + public void setTotalAltitudeGain(Float totalAltitudeGain_m) { + this.totalAltitudeGain_m = totalAltitudeGain_m; } @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE) public void addTotalAltitudeGain(float gain_m) { - if (totalAltitudeGainMeters == null) { - totalAltitudeGainMeters = 0f; + if (totalAltitudeGain_m == null) { + totalAltitudeGain_m = 0f; } - totalAltitudeGainMeters += gain_m; + totalAltitudeGain_m += gain_m; } public boolean hasTotalAltitudeLoss() { - return totalAltitudeLossMeters != null; + return totalAltitudeLoss_m != null; } @Nullable public Float getTotalAltitudeLoss() { - return totalAltitudeLossMeters; + return totalAltitudeLoss_m; } - public void setTotalAltitudeLoss(Float totalAltitudeLossMeters) { - this.totalAltitudeLossMeters = totalAltitudeLossMeters; + public void setTotalAltitudeLoss(Float totalAltitudeLoss_m) { + this.totalAltitudeLoss_m = totalAltitudeLoss_m; } @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE) - public void addTotalAltitudeLoss(float lossM) { - if (totalAltitudeLossMeters == null) { - totalAltitudeLossMeters = 0f; + public void addTotalAltitudeLoss(float loss_m) { + if (totalAltitudeLoss_m == null) { + totalAltitudeLoss_m = 0f; } - totalAltitudeLossMeters += lossM; + totalAltitudeLoss_m += loss_m; } @Override @@ -383,14 +383,6 @@ public boolean equals(Object o) { return toString().equals(o.toString()); } - @Override - public int hashCode() { - final int primeNumber = 31; - int result = 1; - result = result * primeNumber + (startTime == null ? 0 : startTime.hashCode()); - return result; - } - @NonNull @Override public String toString() { diff --git a/src/main/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdater.java b/src/main/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdater.java index 23081f93d..31dc37936 100644 --- a/src/main/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdater.java +++ b/src/main/java/de/dennisguse/opentracks/stats/TrackStatisticsUpdater.java @@ -125,7 +125,36 @@ public void addTrackPoint(TrackPoint trackPoint) { currentSegment.setAverageHeartRate(HeartRate.of(averageHeartRateBPM)); } - updateDistanceAndSpeed(trackPoint); + { + // Update total distance + Distance movingDistance = null; + if (trackPoint.hasSensorDistance()) { + movingDistance = trackPoint.getSensorDistance(); + } else if (lastTrackPoint != null + && lastTrackPoint.hasLocation() + && trackPoint.hasLocation()) { + // GPS-based distance/speed + movingDistance = trackPoint.distanceToPrevious(lastTrackPoint); + } + if (movingDistance != null) { + currentSegment.setIdle(false); + currentSegment.addTotalDistance(movingDistance); + } + + if (!currentSegment.isIdle() && !trackPoint.isSegmentManualStart()) { + if (lastTrackPoint != null) { + currentSegment.addMovingTime(trackPoint, lastTrackPoint); + } + } + + if (trackPoint.getType() == TrackPoint.Type.IDLE) { + currentSegment.setIdle(true); + } + + if (trackPoint.hasSpeed()) { + updateSpeed(trackPoint); + } + } if (trackPoint.isSegmentManualEnd()) { reset(trackPoint); @@ -135,30 +164,6 @@ public void addTrackPoint(TrackPoint trackPoint) { lastTrackPoint = trackPoint; } - // Extracted method for updating total distance and speed - private void updateDistanceAndSpeed(TrackPoint trackPoint) { - Distance movingDistance = null; - if (trackPoint.hasSensorDistance()) { - movingDistance = trackPoint.getSensorDistance(); - } else if (lastTrackPoint != null && lastTrackPoint.hasLocation() && trackPoint.hasLocation()) { - // GPS-based distance/speed - movingDistance = trackPoint.distanceToPrevious(lastTrackPoint); - } - if (movingDistance != null) { - currentSegment.setIdle(false); - currentSegment.addTotalDistance(movingDistance); - } - if (!currentSegment.isIdle() && !trackPoint.isSegmentManualStart() && lastTrackPoint != null) { - currentSegment.addMovingTime(trackPoint, lastTrackPoint); - } - if (trackPoint.getType() == TrackPoint.Type.IDLE) { - currentSegment.setIdle(true); - } - if (trackPoint.hasSpeed()) { - updateSpeed(trackPoint); - } - } - private void reset(TrackPoint trackPoint) { if (currentSegment.isInitialized()) { trackStatistics.merge(currentSegment);