Skip to content

Commit

Permalink
Group-8: Connected Calendar widget in 'Runs and Lifts' section with D…
Browse files Browse the repository at this point in the history
…aySpecificActivity (#210)

**Describe the pull request**
Connected Calendar widget on Statistics page with DaySpecificActivity

**Link to the the issue**

[GH-127](#127)
:
  • Loading branch information
kevwad authored Apr 25, 2024
2 parents d0caa31 + e059155 commit e197a58
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 68 deletions.
32 changes: 17 additions & 15 deletions src/main/java/de/dennisguse/opentracks/CalendarActivity.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package de.dennisguse.opentracks;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
Expand All @@ -10,15 +11,24 @@

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;


public class CalendarActivity extends AppCompatActivity {

private Date selectedDate;
private Calendar calendar = Calendar.getInstance();
public static final String EXTRA_TRACK_DATE = "track_date";


@Override
Expand All @@ -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
// }
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RecyclerView.ViewHolder> {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<TrackSegment> trackSegments;
private DaySpecificAdapter dataAdapter;

private String fallbackDate = "2024-03-09";
private final String fallBackDate = "2024-03-09";


@Override
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
43 changes: 16 additions & 27 deletions src/main/res/layout/aggregated_stats_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -250,53 +250,42 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/aggregated_stats_horizontal_line" />

<View
android:id="@+id/list_of_seasons_horizontal_line"
style="@style/HorizontalLine"
android:layout_marginTop="8dp"
app:layout_constraintStart_toEndOf="@id/guideline1"
app:layout_constraintEnd_toStartOf="@id/guideline3"
app:layout_constraintTop_toBottomOf="@id/list_of_seasons_btn234" />

<Button
android:id="@+id/runs_and_lifts_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="90dp"
android:layout_marginTop="8dp"
android:text="Runs and lifts"
android:gravity="center"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/aggregated_stats_horizontal_line" />

<Button
android:id="@+id/elevation_and_speed_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="140dp"
android:text="Elevation and speed"
android:gravity="center"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/aggregated_stats_horizontal_line" />
app:layout_constraintTop_toBottomOf="@id/list_of_seasons_horizontal_line" />

<View
android:id="@+id/elevation_and_speed_horizontal_line"
android:id="@+id/runs_and_lifts_button_horizontal_line"
style="@style/HorizontalLine"
android:layout_marginTop="8dp"
app:layout_constraintStart_toEndOf="@id/guideline1"
app:layout_constraintEnd_toStartOf="@id/guideline3"
app:layout_constraintTop_toBottomOf="@id/elevation_and_speed_button" />
app:layout_constraintTop_toBottomOf="@id/runs_and_lifts_button" />

<Button
android:id="@+id/calendar_button"
android:id="@+id/elevation_and_speed_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/day_specific_calendar"
android:layout_marginTop="8dp"
android:text="Elevation and speed"
android:gravity="center"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/elevation_and_speed_button" />

<View
android:id="@+id/calendar_btn_horizontal_line"
style="@style/HorizontalLine"
android:layout_marginTop="8dp"
app:layout_constraintStart_toEndOf="@id/guideline1"
app:layout_constraintEnd_toStartOf="@id/guideline3"
app:layout_constraintTop_toBottomOf="@id/calendar_button" />
app:layout_constraintTop_toBottomOf="@id/runs_and_lifts_button_horizontal_line" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit e197a58

Please sign in to comment.