Skip to content

Commit

Permalink
Merge branch 'rilling:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
vhd1 authored Feb 16, 2024
2 parents ea11f35 + 0b8e259 commit 23796bb
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 92 deletions.
10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,4 @@ dependencies {

androidTestUtil 'androidx.test:orchestrator:1.4.2'
}

Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void addTrackPoint_TestingTrack() {

assertEquals(2.5, statistics.getMinAltitude(), 0.01);
assertEquals(32.5, statistics.getMaxAltitude(), 0.01);
assertEquals(36, statistics.getTotalAltitudeGain(), 0.01);
assertEquals(36, 0.01, statistics.getTotalAltitudeGain());
assertEquals(36, statistics.getTotalAltitudeLoss(), 0.01);

assertEquals(11.85, statistics.getMaxSpeed().toMPS(), 0.01);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Fragment createFragment(int position) {
return fc.newInstance();
}

throw new RuntimeException("There isn't Fragment associated with the position: " + position);
throw new IllegalArgumentException("There isn't Fragment associated with the position: " + position);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,16 @@ void writePace(Speed speed, StringBuilder builder, int resId, String lineBreak)
}

/**
* @param altitudeM altitudeM in meters
* @param altitude_M altitude_M in meters
* @param builder StringBuilder to append
* @param resId resource id of altitude string
* @param lineBreak line break string
*/
@VisibleForTesting
void writeAltitude(double altitudeM, StringBuilder builder, int resId, String lineBreak) {
long altitudeInM = Math.round(altitudeM);
long altitudeInFt = Math.round(Distance.of(altitudeM).toFT());
builder.append(context.getString(resId, altitudeInM, altitudeInFt));
void writeAltitude(double altitude_M, StringBuilder builder, int resId, String lineBreak) {
long altitude_M = Math.round(altitude_M);
long altitudeInFt = Math.round(Distance.of(altitude_M).toFT());
builder.append(context.getString(resId, altitude_M, altitudeInFt));
builder.append(lineBreak);
}
}
80 changes: 44 additions & 36 deletions src/main/java/de/dennisguse/opentracks/stats/TrackStatistics.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 totalAltitudeGain_m = null;
private Float totalAltitudeLoss_m = null;
private Float totalAltitudeGainMeters = null;
private Float totalAltitudeLossMeters = null;
// The average heart rate seen on this track
private HeartRate avgHeartRate = null;

Expand All @@ -80,22 +80,22 @@ public TrackStatistics(TrackStatistics other) {
movingTime = other.movingTime;
maxSpeed = other.maxSpeed;
altitudeExtremities.set(other.altitudeExtremities.getMin(), other.altitudeExtremities.getMax());
totalAltitudeGain_m = other.totalAltitudeGain_m;
totalAltitudeLoss_m = other.totalAltitudeLoss_m;
totalAltitudeGainMeters = other.totalAltitudeGainMeters;
totalAltitudeLossMeters = other.totalAltitudeLossMeters;
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 totalAltitudeGain_m, Float totalAltitudeLoss_m) {
public TrackStatistics(String startTime, String stopTime, double totalDistance_m, int totalTime_s, int movingTime_s, float maxSpeed_mps, Float totalAltitudeGainMeters, Float totalAltitudeLossMeters) {
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.totalAltitudeGain_m = totalAltitudeGain_m;
this.totalAltitudeLoss_m = totalAltitudeLoss_m;
this.totalAltitudeGainMeters = totalAltitudeGainMeters;
this.totalAltitudeLossMeters = totalAltitudeLossMeters;
}

/**
Expand Down Expand Up @@ -137,22 +137,22 @@ public void merge(TrackStatistics other) {
altitudeExtremities.update(other.altitudeExtremities.getMin());
altitudeExtremities.update(other.altitudeExtremities.getMax());
}
if (totalAltitudeGain_m == null) {
if (other.totalAltitudeGain_m != null) {
totalAltitudeGain_m = other.totalAltitudeGain_m;
if (totalAltitudeGainMeters == null) {
if (other.totalAltitudeGainMeters != null) {
totalAltitudeGainMeters = other.totalAltitudeGainMeters;
}
} else {
if (other.totalAltitudeGain_m != null) {
totalAltitudeGain_m += other.totalAltitudeGain_m;
if (other.totalAltitudeGainMeters != null) {
totalAltitudeGainMeters += other.totalAltitudeGainMeters;
}
}
if (totalAltitudeLoss_m == null) {
if (other.totalAltitudeLoss_m != null) {
totalAltitudeLoss_m = other.totalAltitudeLoss_m;
if (totalAltitudeLossMeters == null) {
if (other.totalAltitudeLossMeters != null) {
totalAltitudeLossMeters = other.totalAltitudeLossMeters;
}
} else {
if (other.totalAltitudeLoss_m != null) {
totalAltitudeLoss_m += other.totalAltitudeLoss_m;
if (other.totalAltitudeLossMeters != null) {
totalAltitudeLossMeters += other.totalAltitudeLossMeters;
}
}
}
Expand Down Expand Up @@ -301,8 +301,8 @@ public double getMinAltitude() {
return altitudeExtremities.getMin();
}

public void setMinAltitude(double altitude_m) {
altitudeExtremities.setMin(altitude_m);
public void setMinAltitude(double altitudeMeter) {
altitudeExtremities.setMin(altitudeMeter);
}

public boolean hasAltitudeMax() {
Expand All @@ -317,8 +317,8 @@ public double getMaxAltitude() {
return altitudeExtremities.getMax();
}

public void setMaxAltitude(double altitude_m) {
altitudeExtremities.setMax(altitude_m);
public void setMaxAltitude(double altitudeMeter) {
altitudeExtremities.setMax(altitudeMeter);
}

public void updateAltitudeExtremities(Altitude altitude) {
Expand All @@ -334,45 +334,45 @@ public void setAverageHeartRate(HeartRate heartRate) {
}

public boolean hasTotalAltitudeGain() {
return totalAltitudeGain_m != null;
return totalAltitudeGainMeters != null;
}

@Nullable
public Float getTotalAltitudeGain() {
return totalAltitudeGain_m;
return totalAltitudeGainMeters;
}

public void setTotalAltitudeGain(Float totalAltitudeGain_m) {
this.totalAltitudeGain_m = totalAltitudeGain_m;
public void setTotalAltitudeGain(Float totalAltitudeGainMeters) {
this.totalAltitudeGainMeters = totalAltitudeGainMeters;
}

@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public void addTotalAltitudeGain(float gain_m) {
if (totalAltitudeGain_m == null) {
totalAltitudeGain_m = 0f;
if (totalAltitudeGainMeters == null) {
totalAltitudeGainMeters = 0f;
}
totalAltitudeGain_m += gain_m;
totalAltitudeGainMeters += gain_m;
}

public boolean hasTotalAltitudeLoss() {
return totalAltitudeLoss_m != null;
return totalAltitudeLossMeters != null;
}

@Nullable
public Float getTotalAltitudeLoss() {
return totalAltitudeLoss_m;
return totalAltitudeLossMeters;
}

public void setTotalAltitudeLoss(Float totalAltitudeLoss_m) {
this.totalAltitudeLoss_m = totalAltitudeLoss_m;
public void setTotalAltitudeLoss(Float totalAltitudeLossMeters) {
this.totalAltitudeLossMeters = totalAltitudeLossMeters;
}

@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public void addTotalAltitudeLoss(float loss_m) {
if (totalAltitudeLoss_m == null) {
totalAltitudeLoss_m = 0f;
public void addTotalAltitudeLoss(float lossM) {
if (totalAltitudeLossMeters == null) {
totalAltitudeLossMeters = 0f;
}
totalAltitudeLoss_m += loss_m;
totalAltitudeLossMeters += lossM;
}

@Override
Expand All @@ -383,6 +383,14 @@ 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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,36 +125,7 @@ public void addTrackPoint(TrackPoint trackPoint) {
currentSegment.setAverageHeartRate(HeartRate.of(averageHeartRateBPM));
}

{
// 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);
}
}
updateDistanceAndSpeed(trackPoint);

if (trackPoint.isSegmentManualEnd()) {
reset(trackPoint);
Expand All @@ -164,6 +135,30 @@ 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.time.ZoneOffset;
import java.time.temporal.WeekFields;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import de.dennisguse.opentracks.R;
Expand All @@ -38,9 +39,9 @@ public static void showDialog(FragmentManager fragmentManager) {
filterDialogFragment.show(fragmentManager, TAG);
}

public static void showDialog(FragmentManager fragmentManager, ArrayList<FilterItem> items) {
public static void showDialog(FragmentManager fragmentManager, List<FilterItem> items) {
Bundle bundle = new Bundle();
bundle.putParcelableArrayList(KEY_FILTER_ITEMS, items);
bundle.putParcelableArrayList(KEY_FILTER_ITEMS,(ArrayList<? extends Parcelable>) items);

FilterDialogFragment filterDialogFragment = new FilterDialogFragment();
filterDialogFragment.setArguments(bundle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public List<DataField> getFields() {

public RecordingLayout toRecordingLayout(boolean visibility) {
RecordingLayout result = new RecordingLayout(this.getName());
result.addFields(dataFields.stream().filter(f -> f.isVisible() == visibility).collect(Collectors.toList()));
result.addFields(dataFields.stream().filter(f -> f.isVisible() == visibility).toList());
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public class RecordingLayoutIO {
private static final String YES_VALUE = "1";
private static final String NOT_VALUE = "0";

// Private constructor to hide the implicit public one
private RecordingLayoutIO() {
throw new AssertionError("This class should not be instantiated.");
}

public static RecordingLayout fromCsv(@NonNull String csvLine, @NonNull Resources resources) {
List<String> csvParts = CsvLayoutUtils.getCsvLineParts(csvLine);
if (csvParts == null) {
Expand All @@ -32,7 +37,7 @@ public static RecordingLayout fromCsv(@NonNull String csvLine, @NonNull Resource
Log.e(TAG, "Invalid CSV layout. It shouldn't happen: " + csvLine);
return recordingLayout;
}
recordingLayout.addField(fromCSV(fieldParts, resources));
recordingLayout.addField(getFieldFromCSVRecord(fieldParts, resources));
}
return recordingLayout;
}
Expand All @@ -41,7 +46,7 @@ public static String toCSV(List<RecordingLayout> recordingLayouts) {
return recordingLayouts.stream().map(RecordingLayout::toCsv).collect(Collectors.joining(CsvLayoutUtils.LINE_SEPARATOR));
}

private static DataField fromCSV(String[] fieldParts, @NonNull Resources resources) {
private static DataField getFieldFromCSVRecord(String[] fieldParts, @NonNull Resources resources) {
return new DataField(
fieldParts[0],
YES_VALUE.equals(fieldParts[1]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ public class IntervalStatistics {
private TrackStatisticsUpdater trackStatisticsUpdater = new TrackStatisticsUpdater();
private final List<Interval> intervalList;
private final Distance distanceInterval;
private Interval interval, lastInterval;

private Interval interval;
private Interval lastInterval;

/**
* @param distanceInterval distance of every interval.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
return viewBinding.getRoot();
}

/**
* This method is deprecated.
*
* This method is marked as deprecated and should be re-implemented with updated functionality.
* Deprecated methods are discouraged from use as they may be removed or replaced in future versions.
* Developers are advised to find alternative approaches or update the method to meet current requirements.
*
* @deprecated This method is deprecated and should be re-implemented.
*
*/
@Deprecated //TODO This method must be re-implemented.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,11 @@ protected void onCreate(Bundle savedInstanceState) {
takePictureFromCamera = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> {
switch (result.getResultCode()) {
case RESULT_CANCELED ->
Toast.makeText(this, R.string.marker_add_photo_canceled, Toast.LENGTH_LONG).show();
case RESULT_OK -> viewModel.onNewCameraPhoto(cameraPhotoUri,
int resultCode = result.getResultCode();
if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, R.string.marker_add_photo_canceled, Toast.LENGTH_LONG).show();
} else if (resultCode == RESULT_OK) {
viewModel.onNewCameraPhoto(cameraPhotoUri,
viewBinding.markerEditName.getText().toString(),
viewBinding.markerEditMarkerType.getText().toString(),
viewBinding.markerEditDescription.getText().toString());
Expand Down
Loading

0 comments on commit 23796bb

Please sign in to comment.