diff --git a/src/main/java/de/dennisguse/opentracks/CalendarActivity.java b/src/main/java/de/dennisguse/opentracks/CalendarActivity.java index aab780c71..f5121a003 100644 --- a/src/main/java/de/dennisguse/opentracks/CalendarActivity.java +++ b/src/main/java/de/dennisguse/opentracks/CalendarActivity.java @@ -1,4 +1,5 @@ package de.dennisguse.opentracks; +import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; @@ -10,8 +11,16 @@ import com.google.android.material.appbar.MaterialToolbar; +import de.dennisguse.opentracks.ui.aggregatedStatistics.daySpecificStats.DaySpecificActivity; +import de.dennisguse.opentracks.ui.aggregatedStatistics.daystatistics.DayStatisticsActivity; + +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.Calendar; import java.util.Date; +import java.util.Locale; import java.util.Objects; @@ -19,6 +28,7 @@ public class CalendarActivity extends AppCompatActivity { private Date selectedDate; private Calendar calendar = Calendar.getInstance(); + public static final String EXTRA_TRACK_DATE = "track_date"; @Override @@ -39,26 +49,18 @@ public void onSelectedDayChange(@NonNull CalendarView view, int year, int month, } }); dateSelectButton.setOnClickListener((View v)->{ - Intent intent = new Intent(v.getContext(), ElevationAndSpeedActivity.class);; + Context context = v.getContext(); + Intent intent = new Intent(context, DaySpecificActivity.class); + if(extras!=null && Objects.equals(extras.getString("Display Fields"), "Elevation and Speed")){ intent = new Intent(v.getContext(), ElevationAndSpeedActivity.class); - } else{ - intent = new Intent(v.getContext(), RunsAndLiftsActivity.class); } - calendar.setTime(selectedDate); - int year = calendar.get(Calendar.YEAR) - 1900; - int month = calendar.get(Calendar.MONTH); - int day = calendar.get(Calendar.DAY_OF_MONTH); - intent.putExtra("Year", year); - intent.putExtra("Year", month); - intent.putExtra("Day", day); + calendar.setTime(selectedDate); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); + String dateString = dateFormat.format(selectedDate); + intent.putExtra(EXTRA_TRACK_DATE, dateString); v.getContext().startActivity(intent); -// Bundle extras = getIntent().getExtras(); -// if (extras != null) { -// String value = extras.getString("key"); -// //The key argument here must match that used in the other activity -// } }); } 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 b2f492e75..4905b175d 100644 --- a/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/AggregatedStatisticsAdapter.java +++ b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/AggregatedStatisticsAdapter.java @@ -23,7 +23,6 @@ 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.ui.aggregatedStatistics.daystatistics.DayStatisticsActivity; import de.dennisguse.opentracks.util.StringUtils; public class AggregatedStatisticsAdapter extends RecyclerView.Adapter { @@ -111,17 +110,7 @@ public void onClick(View v) { 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); - } - }); - + /*viewBinding.dayStatisticsBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { 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 6007514ae..5f38e4b93 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 @@ -7,8 +7,6 @@ import android.widget.Toast; 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.TrackPointIterator; import de.dennisguse.opentracks.data.models.Track; @@ -28,13 +26,13 @@ public class DaySpecificActivity extends AbstractActivity { private DaySpecificActivityBinding viewBinding; private static final String TAG = DaySpecificActivity.class.getSimpleName(); public static final String EXTRA_TRACK_DATE = "track_date"; - private Date activityDate; + private String activityDate; private ContentProviderUtils contentProviderUtils; private Track.Id trackId; private List trackSegments; private DaySpecificAdapter dataAdapter; - private String fallbackDate = "2024-03-09"; + private final String fallBackDate = "2024-03-09"; @Override @@ -49,7 +47,7 @@ protected void onCreate(Bundle savedInstanceState) { dataAdapter = new DaySpecificAdapter(this, viewBinding.segmentList); dataAdapter.swapData(trackSegments); viewBinding.segmentList.setAdapter(dataAdapter); - viewBinding.segmentListToolbar.setTitle(fallbackDate); + viewBinding.segmentListToolbar.setTitle(activityDate); } @Override @@ -101,26 +99,25 @@ public void updateTrackSegments() { private void showNoTracksFoundToast() { finish(); - Toast.makeText(DaySpecificActivity.this, "No Tracks found for date: " + fallbackDate + "\n Please import GPX file from Moodle", Toast.LENGTH_LONG).show(); + Toast.makeText(DaySpecificActivity.this, "No Tracks found for date: " + activityDate + "\n Please import GPX file from Moodle", Toast.LENGTH_LONG).show(); } - private Date getFallbackDate() { + private Date getDateFromString(String dateString) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - LocalDate localDate = LocalDate.parse(fallbackDate, formatter); + LocalDate localDate = LocalDate.parse(dateString, formatter); return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); } private void handleIntent(Intent intent) { - Date dateFromCalendar = intent.getParcelableExtra(EXTRA_TRACK_DATE); - if (dateFromCalendar == null) { + activityDate = intent.getStringExtra(EXTRA_TRACK_DATE); + if (activityDate == null) { Log.e(TAG, DaySpecificActivity.class.getSimpleName() + " needs EXTRA_TRACK_ID."); // None provided, we will assume a specific date on our own - activityDate = getFallbackDate(); - } else { - activityDate = dateFromCalendar; + activityDate = this.fallBackDate; } - Track track = contentProviderUtils.getTrack(activityDate); + Date dayOfActivity = getDateFromString(activityDate); + Track track = contentProviderUtils.getTrack(dayOfActivity); if (track == null) { showNoTracksFoundToast(); } else { diff --git a/src/main/res/layout/aggregated_stats_list_item.xml b/src/main/res/layout/aggregated_stats_list_item.xml index 06211a3ba..d159720d2 100644 --- a/src/main/res/layout/aggregated_stats_list_item.xml +++ b/src/main/res/layout/aggregated_stats_list_item.xml @@ -250,53 +250,42 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/aggregated_stats_horizontal_line" /> + +