From 64a6a04072b5af42c9729620a76700601f92fe14 Mon Sep 17 00:00:00 2001 From: kevwad Date: Sat, 6 Apr 2024 19:36:50 -0400 Subject: [PATCH 01/11] 40261875: Added empty activity named DaySpecificActivity Added track getter for a given specific day --- src/main/AndroidManifest.xml | 3 + .../opentracks/data/ContentProviderUtils.java | 20 +++- .../AggregatedStatisticsAdapter.java | 23 +++-- .../daySpecificStats/DaySpecificActivity.java | 91 +++++++++++++++++++ src/main/res/layout/activity_day_specific.xml | 13 +++ .../res/layout/aggregated_stats_list_item.xml | 28 ++++++ src/main/res/values/strings.xml | 3 + 7 files changed, 174 insertions(+), 7 deletions(-) create mode 100644 src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/daySpecificStats/DaySpecificActivity.java create mode 100644 src/main/res/layout/activity_day_specific.xml diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 9e32f6738..5c5284ea1 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -82,6 +82,9 @@ limitations under the License. android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/OpenTracksTheme"> + diff --git a/src/main/java/de/dennisguse/opentracks/data/ContentProviderUtils.java b/src/main/java/de/dennisguse/opentracks/data/ContentProviderUtils.java index 1f58a7b78..fc1f41b8e 100644 --- a/src/main/java/de/dennisguse/opentracks/data/ContentProviderUtils.java +++ b/src/main/java/de/dennisguse/opentracks/data/ContentProviderUtils.java @@ -32,13 +32,16 @@ import java.io.File; import java.time.Duration; import java.time.Instant; +import java.time.LocalDate; +import java.time.ZoneId; import java.time.ZoneOffset; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.UUID; - +import java.util.Date; +import java.text.SimpleDateFormat; import de.dennisguse.opentracks.BuildConfig; import de.dennisguse.opentracks.data.models.ActivityType; import de.dennisguse.opentracks.data.models.Altitude; @@ -267,6 +270,21 @@ public Track getTrack(@NonNull Track.Id trackId) { } return null; } + public Track getTrack(@NonNull Date date) { + long millisecondsSinceEpoch = date.getTime(); + LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + LocalDate modifiedLocalDate = localDate.plusDays(1); + Date modifiedDate = Date.from(modifiedLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + long millisNextDaySinceEpoch = modifiedDate.getTime(); + + String query = TracksColumns.STARTTIME + ">? AND " + TracksColumns.STARTTIME + "<=?"; + try (Cursor cursor = getTrackCursor(query, new String[]{Long.toString(millisecondsSinceEpoch), Long.toString(millisNextDaySinceEpoch)}, TracksColumns._ID)) { + if (cursor != null && cursor.moveToNext()) { + return createTrack(cursor); + } + } + return null; + } public Track getTrack(@NonNull UUID trackUUID) { String trackUUIDsearch = UUIDUtils.toHex(trackUUID); diff --git a/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/AggregatedStatisticsAdapter.java b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/AggregatedStatisticsAdapter.java index 949466bdc..9691930bf 100644 --- a/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/AggregatedStatisticsAdapter.java +++ b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/AggregatedStatisticsAdapter.java @@ -22,6 +22,7 @@ import de.dennisguse.opentracks.settings.PreferencesUtils; import de.dennisguse.opentracks.settings.UnitSystem; import de.dennisguse.opentracks.ui.aggregatedStatistics.SeasonStats.SeasonStatActivity; +import de.dennisguse.opentracks.ui.aggregatedStatistics.daySpecificStats.DaySpecificActivity; import de.dennisguse.opentracks.util.StringUtils; public class AggregatedStatisticsAdapter extends RecyclerView.Adapter { @@ -93,22 +94,32 @@ public void onClick(View v) { } }); - viewBinding.runsAndLiftsButton.setOnClickListener(new View.OnClickListener(){ + viewBinding.runsAndLiftsButton.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View v){ - Intent intent=new Intent(v.getContext(), CalendarActivity.class); + public void onClick(View v) { + Intent intent = new Intent(v.getContext(), CalendarActivity.class); intent.putExtra("Display Fields", "Runs and Lifts"); v.getContext().startActivity(intent); } }); - viewBinding.elevationAndSpeedButton.setOnClickListener(new View.OnClickListener(){ + viewBinding.elevationAndSpeedButton.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View v){ - Intent intent=new Intent(v.getContext(), CalendarActivity.class); + public void onClick(View v) { + Intent intent = new Intent(v.getContext(), CalendarActivity.class); intent.putExtra("Display Fields", "Elevation and Speed"); v.getContext().startActivity(intent); } }); + + viewBinding.calendarButton.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + Context context = viewBinding.getRoot().getContext(); + Intent intent = new Intent(context, DaySpecificActivity.class); + context.startActivity(intent); + } + }); } public void setSpeed(AggregatedStatistics.AggregatedStatistic aggregatedStatistic) { 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 new file mode 100644 index 000000000..f7dac722e --- /dev/null +++ b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/daySpecificStats/DaySpecificActivity.java @@ -0,0 +1,91 @@ +package de.dennisguse.opentracks.ui.aggregatedStatistics.daySpecificStats; + +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; +import android.view.View; + +import de.dennisguse.opentracks.AbstractTrackDeleteActivity; +import de.dennisguse.opentracks.R; +import de.dennisguse.opentracks.data.ContentProviderUtils; +import de.dennisguse.opentracks.data.TrackDataHub; +import de.dennisguse.opentracks.data.models.Track; +import de.dennisguse.opentracks.databinding.ActivityDaySpecificBinding; + +import java.time.format.DateTimeFormatter; +import java.time.LocalDate; +import java.util.Date; +import java.time.ZoneId; +import java.util.List; + +public class DaySpecificActivity extends AbstractTrackDeleteActivity { + + private ActivityDaySpecificBinding viewBinding; + private static final String TAG = DaySpecificActivity.class.getSimpleName(); + public static final String EXTRA_TRACK_ID = "track_id"; + private Date activityDate; + private ContentProviderUtils contentProviderUtils; + private TrackDataHub trackDataHub; + private Track.Id trackId; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_day_specific); + contentProviderUtils = new ContentProviderUtils(this); + handleIntent(getIntent()); + trackDataHub = new TrackDataHub(this); + setSupportActionBar(viewBinding.bottomAppBarLayout.bottomAppBar); + } + + @Override + protected void onStart() { + super.onStart(); + trackDataHub.start(); + } + + private Date getDummyDate() { + String dateString = "2024-03-02"; + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate localDate = LocalDate.parse(dateString, formatter); + Date date = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + return date; + } + + private void handleIntent(Intent intent) { + trackId = intent.getParcelableExtra(EXTRA_TRACK_ID); + if (trackId == null) { + Log.e(TAG, DaySpecificActivity.class.getSimpleName() + " needs EXTRA_TRACK_ID."); +// finish(); + // None provided, we will assume a specific date on our own + activityDate = getDummyDate(); + List tracks = contentProviderUtils.getTracks(); + for (Track track: tracks) { + System.out.println("Track date = " + track.getStartTime().toString()); + } + Track track = contentProviderUtils.getTrack(activityDate); + trackId = track.getId(); + } + } + + @Override + protected View getRootView() { + viewBinding = ActivityDaySpecificBinding.inflate(getLayoutInflater()); + return viewBinding.getRoot(); + } + + @Override + protected void onDeleteConfirmed() { + + } + + @Override + protected Track.Id getRecordingTrackId() { + return null; + } + + @Override + public void onDeleteFinished() { + + } +} \ No newline at end of file diff --git a/src/main/res/layout/activity_day_specific.xml b/src/main/res/layout/activity_day_specific.xml new file mode 100644 index 000000000..6bcb377f4 --- /dev/null +++ b/src/main/res/layout/activity_day_specific.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/src/main/res/layout/aggregated_stats_list_item.xml b/src/main/res/layout/aggregated_stats_list_item.xml index 9d5eeae43..844c53428 100644 --- a/src/main/res/layout/aggregated_stats_list_item.xml +++ b/src/main/res/layout/aggregated_stats_list_item.xml @@ -244,4 +244,32 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/aggregated_stats_horizontal_line" /> + + + +