Skip to content

Commit

Permalink
GH-127: 40261875, Recycler View linear layout
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwad committed Apr 8, 2024
1 parent 7d9e2e6 commit d99d9c3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,23 @@ public class DaySpecificActivity extends AbstractTrackDeleteActivity {
private TrackDataHub trackDataHub;
private Track.Id trackId;
private List<TrackSegment> trackSegments;
private DaySpecificAdapter adapter;
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());
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
adapter = new DaySpecificAdapter(this, viewBinding.segmentList);
viewBinding.segmentList.setLayoutManager(layoutManager);
viewBinding.segmentList.setAdapter(adapter);

dataAdapter = new DaySpecificAdapter(this, viewBinding.segmentList);
dataAdapter.swapData(trackSegments);
viewBinding.segmentList.setAdapter(dataAdapter);
}

@Override
Expand All @@ -64,7 +62,7 @@ protected void onStart() {
protected void onResume() {
super.onResume();
updateTrackSegments();
adapter.swapData(trackSegments);
dataAdapter.swapData(trackSegments);
}

public void updateTrackSegments() {
Expand Down Expand Up @@ -109,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
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<RecyclerView.ViewHolder> implements ActionMode.Callback {
Expand Down Expand Up @@ -101,12 +101,15 @@ public ViewHolder(@NonNull View itemView) {
view.setOnLongClickListener(this);
}

public void bind(TrackSegment segment){
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) {
Expand Down
11 changes: 8 additions & 3 deletions src/main/res/layout/day_specific_activity.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
Expand All @@ -12,18 +12,23 @@
android:clipToPadding="false"
android:orientation="vertical"
android:paddingBottom="?attr/actionBarSize"
android:padding="16dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/segment_list"
android:layout_width="match_parent"
android:background="#C0C0C0"
android:layout_height="0dp"
android:layout_weight="0.8" />
android:layout_weight="0.8"
android:paddingTop="16dp"
android:paddingBottom="16dp"
app:layoutManager="LinearLayoutManager"/>
</LinearLayout>


<include
android:id="@+id/bottom_app_bar_layout"
layout="@layout/bottomappbar" />

</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

0 comments on commit d99d9c3

Please sign in to comment.