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 1dc963ed8..c9875a3e2 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 @@ -22,7 +22,7 @@ import java.time.ZoneId; import java.util.List; import java.util.ArrayList; -import android.widget.Toast; +import androidx.recyclerview.widget.LinearLayoutManager; public class DaySpecificActivity extends AbstractTrackDeleteActivity { @@ -34,17 +34,23 @@ public class DaySpecificActivity extends AbstractTrackDeleteActivity { private TrackDataHub trackDataHub; private Track.Id trackId; private List trackSegments; + private DaySpecificAdapter dataAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.day_specific_activity); + trackSegments = new ArrayList<>(); contentProviderUtils = new ContentProviderUtils(this); handleIntent(getIntent()); + updateTrackSegments(); trackDataHub = new TrackDataHub(this); setSupportActionBar(viewBinding.bottomAppBarLayout.bottomAppBar); - trackSegments = new ArrayList<>(); + + viewBinding = DaySpecificActivityBinding.inflate(getLayoutInflater()); + dataAdapter = new DaySpecificAdapter(this, viewBinding.segmentList); + dataAdapter.swapData(trackSegments); + viewBinding.segmentList.setAdapter(dataAdapter); } @Override @@ -56,6 +62,7 @@ protected void onStart() { protected void onResume() { super.onResume(); updateTrackSegments(); + dataAdapter.swapData(trackSegments); } public void updateTrackSegments() { @@ -100,8 +107,7 @@ 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; + return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); } private void handleIntent(Intent intent) { 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 e950b256d..6585a12ec 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 @@ -13,14 +13,19 @@ import androidx.appcompat.view.ActionMode; import androidx.recyclerview.widget.RecyclerView; +import java.util.List; + import de.dennisguse.opentracks.R; +import de.dennisguse.opentracks.data.models.Distance; import de.dennisguse.opentracks.data.models.Track; +import de.dennisguse.opentracks.data.models.TrackSegment; import de.dennisguse.opentracks.databinding.DaySpecificActivityItemBinding; -import de.dennisguse.opentracks.ui.TrackListAdapter; import de.dennisguse.opentracks.ui.util.ActivityUtils; public class DaySpecificAdapter extends RecyclerView.Adapter implements ActionMode.Callback { + private static final String TAG = DaySpecificAdapter.class.getSimpleName(); + DaySpecificActivityItemBinding viewBinding; private final AppCompatActivity context; private final RecyclerView recyclerView; @@ -28,8 +33,8 @@ public class DaySpecificAdapter extends RecyclerView.Adapter trackSegments; public DaySpecificAdapter(AppCompatActivity context, RecyclerView recyclerView) { this.context = context; @@ -65,15 +70,18 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { - TrackListAdapter.ViewHolder viewHolder = (TrackListAdapter.ViewHolder) holder; - - cursor.moveToPosition(position); - viewHolder.bind(cursor); + DaySpecificAdapter.ViewHolder viewHolder = (DaySpecificAdapter.ViewHolder) holder; + TrackSegment segment = trackSegments.get(position); + viewHolder.bind(segment); } + public void swapData(List segments) { + this.trackSegments = segments; + this.notifyDataSetChanged(); + } @Override public int getItemCount() { - return 0; + return trackSegments.size(); } public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener { @@ -93,12 +101,15 @@ public ViewHolder(@NonNull View itemView) { view.setOnLongClickListener(this); } - public void bind(Cursor cursor){ + 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("36.3 km/h"); - viewBinding.daySpecificActivityTime.setText("0.50"); + viewBinding.daySpecificActivitySpeed.setText(speed + " km/h"); + viewBinding.daySpecificActivityTime.setText("" + segment.getTotalTime()); } public void setSelected(boolean isSelected) { diff --git a/src/main/res/layout/activity_day_specific.xml b/src/main/res/layout/activity_day_specific.xml deleted file mode 100644 index 6bcb377f4..000000000 --- a/src/main/res/layout/activity_day_specific.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/main/res/layout/day_specific_activity.xml b/src/main/res/layout/day_specific_activity.xml index 3309764d1..a2186a90a 100644 --- a/src/main/res/layout/day_specific_activity.xml +++ b/src/main/res/layout/day_specific_activity.xml @@ -1,5 +1,5 @@ - + android:layout_weight="0.8" + android:paddingTop="16dp" + android:paddingBottom="16dp" + app:layoutManager="LinearLayoutManager"/> @@ -26,4 +31,4 @@ android:id="@+id/bottom_app_bar_layout" layout="@layout/bottomappbar" /> - \ No newline at end of file + \ No newline at end of file diff --git a/src/main/res/layout/day_specific_activity_item.xml b/src/main/res/layout/day_specific_activity_item.xml index 5c221d6c5..bdcd7f094 100644 --- a/src/main/res/layout/day_specific_activity_item.xml +++ b/src/main/res/layout/day_specific_activity_item.xml @@ -2,13 +2,17 @@ + android:layout_height="match_parent" + xmlns:app="http://schemas.android.com/apk/res-auto"> + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + android:padding="8dp" + > Calendar + Day Specific Run/Lift %1$d ft (excellent GPS)