diff --git a/src/main/java/de/dennisguse/opentracks/data/models/TrackSegment.java b/src/main/java/de/dennisguse/opentracks/data/models/TrackSegment.java index 0705d363f..f0800ee34 100644 --- a/src/main/java/de/dennisguse/opentracks/data/models/TrackSegment.java +++ b/src/main/java/de/dennisguse/opentracks/data/models/TrackSegment.java @@ -1,15 +1,12 @@ package de.dennisguse.opentracks.data.models; -import android.util.Log; - import androidx.annotation.NonNull; import java.time.Duration; import java.time.Instant; import java.util.List; import java.util.ArrayList; - -import de.dennisguse.opentracks.io.file.importer.TrackImporter; +import java.util.Optional; public class TrackSegment { @@ -37,18 +34,39 @@ public Boolean hasTrackPoints() { return !trackPoints.isEmpty(); } - public Distance getDistanceBetweenFirstAndLast() { + public double getInitialElevation() { + Optional firstPoint = trackPoints.stream().findFirst(); + if (firstPoint.isPresent()) { + TrackPoint point = firstPoint.get(); + return point.getAltitude().toM(); + } + return 0; + } + + public long getDisplacement() { + long displacement = 0; + for (TrackPoint point: trackPoints) { + if (point.hasAltitudeGain()) { + displacement += point.getAltitudeGain(); + } + + if (point.hasAltitudeLoss()) { + displacement += point.getAltitudeLoss(); + } + } + + return displacement; + } + public Distance getDistance() { if (trackPoints == null) { return null; } TrackPoint first = trackPoints.get(0); TrackPoint last = trackPoints.get(trackPoints.size() - 1); - Distance distance = last.distanceToPrevious(first); - - return distance; + return last.distanceToPrevious(first); } - public Long getTotalTime(){ + public Duration getTotalTime(){ if(trackPoints == null){ return null; @@ -56,13 +74,13 @@ public Long getTotalTime(){ TrackPoint startTime = trackPoints.get(0); TrackPoint endTime = trackPoints.get(trackPoints.size() - 1); - Duration totalTime = Duration.between(startTime.getTime(), endTime.getTime()); - return totalTime.toMinutes(); + return Duration.between(startTime.getTime(), endTime.getTime()); } - public double getSpeed(Distance totalDistance, Long totalTime){ - return totalDistance.distance_m()/totalTime; + public double getSpeed(){ + // in m/s + double totalDistance = getDistance().toM(); + long totalTime = getTotalTime().toSeconds(); + return totalDistance/totalTime; } - - } \ No newline at end of file diff --git a/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/daySpecificStats/DaySpecificActivity.java b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/daySpecificStats/DaySpecificActivity.java index c9875a3e2..6007514ae 100644 --- a/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/daySpecificStats/DaySpecificActivity.java +++ b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/daySpecificStats/DaySpecificActivity.java @@ -4,13 +4,13 @@ import android.os.Bundle; import android.util.Log; import android.view.View; +import android.widget.Toast; -import de.dennisguse.opentracks.AbstractTrackDeleteActivity; +import de.dennisguse.opentracks.AbstractActivity; import de.dennisguse.opentracks.R; +import de.dennisguse.opentracks.TrackListActivity; import de.dennisguse.opentracks.data.ContentProviderUtils; -import de.dennisguse.opentracks.data.TrackDataHub; import de.dennisguse.opentracks.data.TrackPointIterator; -import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Track; import de.dennisguse.opentracks.data.models.TrackPoint; import de.dennisguse.opentracks.data.models.TrackSegment; @@ -22,20 +22,20 @@ import java.time.ZoneId; import java.util.List; import java.util.ArrayList; -import androidx.recyclerview.widget.LinearLayoutManager; -public class DaySpecificActivity extends AbstractTrackDeleteActivity { +public class DaySpecificActivity extends AbstractActivity { private DaySpecificActivityBinding viewBinding; private static final String TAG = DaySpecificActivity.class.getSimpleName(); - public static final String EXTRA_TRACK_ID = "track_id"; + public static final String EXTRA_TRACK_DATE = "track_date"; private Date activityDate; private ContentProviderUtils contentProviderUtils; - private TrackDataHub trackDataHub; private Track.Id trackId; private List trackSegments; private DaySpecificAdapter dataAdapter; + private String fallbackDate = "2024-03-09"; + @Override protected void onCreate(Bundle savedInstanceState) { @@ -44,13 +44,12 @@ protected void onCreate(Bundle savedInstanceState) { contentProviderUtils = new ContentProviderUtils(this); handleIntent(getIntent()); updateTrackSegments(); - trackDataHub = new TrackDataHub(this); setSupportActionBar(viewBinding.bottomAppBarLayout.bottomAppBar); - viewBinding = DaySpecificActivityBinding.inflate(getLayoutInflater()); dataAdapter = new DaySpecificAdapter(this, viewBinding.segmentList); dataAdapter.swapData(trackSegments); viewBinding.segmentList.setAdapter(dataAdapter); + viewBinding.segmentListToolbar.setTitle(fallbackDate); } @Override @@ -66,6 +65,9 @@ protected void onResume() { } public void updateTrackSegments() { + if (trackId == null) { + return; + } try (TrackPointIterator trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, null)) { TrackSegment currentSegment = null; while (trackPointIterator.hasNext()) { @@ -94,39 +96,35 @@ public void updateTrackSegments() { Log.d(TAG, "No Action for TrackPoint IDLE/SENSORPOINT while recording segments"); } } - - for(int i=0; i tracks = contentProviderUtils.getTracks(); - for (Track track: tracks) { - System.out.println("Track date = " + track.getStartTime().toString()); - } - Track track = contentProviderUtils.getTrack(activityDate); - if (track == null) { - finish(); - } else { - trackId = track.getId(); - } + activityDate = getFallbackDate(); + } else { + activityDate = dateFromCalendar; + } + + Track track = contentProviderUtils.getTrack(activityDate); + if (track == null) { + showNoTracksFoundToast(); + } else { + trackId = track.getId(); } } @@ -135,19 +133,4 @@ protected View getRootView() { viewBinding = DaySpecificActivityBinding.inflate(getLayoutInflater()); return viewBinding.getRoot(); } - - @Override - protected void onDeleteConfirmed() { - - } - - @Override - protected Track.Id getRecordingTrackId() { - return trackId; - } - - @Override - public void onDeleteFinished() { - - } } \ No newline at end of file diff --git a/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/daySpecificStats/DaySpecificAdapter.java b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/daySpecificStats/DaySpecificAdapter.java index 6585a12ec..00e883a18 100644 --- a/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/daySpecificStats/DaySpecificAdapter.java +++ b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/daySpecificStats/DaySpecificAdapter.java @@ -102,14 +102,19 @@ public ViewHolder(@NonNull View itemView) { } public void bind(TrackSegment segment) { - Distance distance = segment.getDistanceBetweenFirstAndLast(); - Long time = segment.getTotalTime(); - double speed = segment.getSpeed(distance, time); - viewBinding.daySpecificActivity.setText("Run"); - viewBinding.daySpecificActivityDisplacement.setText("0 m"); - viewBinding.daySpecificActivityDistance.setText("0.14 km"); - viewBinding.daySpecificActivitySpeed.setText(speed + " km/h"); - viewBinding.daySpecificActivityTime.setText("" + segment.getTotalTime()); + double speed = segment.getSpeed(); + String formattedSpeed = String.format("%.2f", speed); + + double distance = segment.getDistance().toM(); + String formattedDistance = String.format("%.2f", distance); + + double elevation = segment.getInitialElevation(); + String formattedElevation = String.format("%.1f", elevation); + + viewBinding.daySpecificActivityDisplacement.setText(formattedElevation + " m"); + viewBinding.daySpecificActivityDistance.setText(formattedDistance + " mts"); + viewBinding.daySpecificActivitySpeed.setText(formattedSpeed + " m/s"); + viewBinding.daySpecificActivityTime.setText(segment.getTotalTime().toMinutes() + " minutes"); } public void setSelected(boolean isSelected) { diff --git a/src/main/res/layout/day_specific_activity.xml b/src/main/res/layout/day_specific_activity.xml index a2186a90a..ad3d3da38 100644 --- a/src/main/res/layout/day_specific_activity.xml +++ b/src/main/res/layout/day_specific_activity.xml @@ -6,23 +6,32 @@ android:layout_height="match_parent" tools:context=".ui.aggregatedStatistics.daySpecificStats.DaySpecificActivity"> + + + + + diff --git a/src/main/res/layout/day_specific_activity_item.xml b/src/main/res/layout/day_specific_activity_item.xml index bdcd7f094..af814a9ea 100644 --- a/src/main/res/layout/day_specific_activity_item.xml +++ b/src/main/res/layout/day_specific_activity_item.xml @@ -2,7 +2,7 @@ @@ -30,7 +29,7 @@ android:layout_marginBottom="8dp" android:padding="4dp" android:weightSum="4" - android:textSize="10dp" + android:textSize="12sp" android:visibility="visible"> + android:textSize="13sp" + android:text="" + tools:text="0 m"/> + android:textSize="13sp" + android:text="" + tools:text="0.14 km"/> + android:textSize="13sp" + android:text="" + tools:text="0.50"/> + android:text="" + tools:text="36.3 km/h"/> diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index facb7125a..2b5628deb 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -555,9 +555,10 @@ limitations under the License. %1$s° %1$s, %2$s - + Calendar Day Specific Run/Lift + Run %1$d ft (excellent GPS)