Skip to content

Commit

Permalink
Kevin/daily activity list (#152)
Browse files Browse the repository at this point in the history
**Describe the pull request**
Adds a recyclerView to display the TrackSegments

**Link to the the issue**

[Issue-127](#127)
  • Loading branch information
kevwad authored Apr 8, 2024
2 parents c5ba10e + d99d9c3 commit b4479a9
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -34,17 +34,23 @@ public class DaySpecificActivity extends AbstractTrackDeleteActivity {
private TrackDataHub trackDataHub;
private Track.Id trackId;
private List<TrackSegment> 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
Expand All @@ -56,6 +62,7 @@ protected void onStart() {
protected void onResume() {
super.onResume();
updateTrackSegments();
dataAdapter.swapData(trackSegments);
}

public void updateTrackSegments() {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,28 @@
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<RecyclerView.ViewHolder> implements ActionMode.Callback {

private static final String TAG = DaySpecificAdapter.class.getSimpleName();
DaySpecificActivityItemBinding viewBinding;
private final AppCompatActivity context;
private final RecyclerView recyclerView;

private final SparseBooleanArray selection = new SparseBooleanArray();

private Cursor cursor;

private boolean selectionMode = false;
private ActivityUtils.ContextualActionModeCallback actionModeCallback;
private List<TrackSegment> trackSegments;

public DaySpecificAdapter(AppCompatActivity context, RecyclerView recyclerView) {
this.context = context;
Expand Down Expand Up @@ -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<TrackSegment> 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 {
Expand All @@ -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) {
Expand Down
13 changes: 0 additions & 13 deletions src/main/res/layout/activity_day_specific.xml

This file was deleted.

15 changes: 10 additions & 5 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 @@ -8,22 +8,27 @@

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="match_parent"
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/track_list"
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>
8 changes: 6 additions & 2 deletions src/main/res/layout/day_specific_activity_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:padding="8dp"
>

<TextView
android:id="@+id/day_specific_activity"
Expand Down
1 change: 1 addition & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ limitations under the License.
<!-- Value -->
<!-- Day-Specific Activities -->
<string name="day_specific_calendar">Calendar</string>
<string name="day_specific_title">Day Specific Run/Lift</string>
<!-- Day-Specific Activities -->

<string name="value_integer_feet_excellent_gps">%1$d ft (excellent GPS)</string>
Expand Down

0 comments on commit b4479a9

Please sign in to comment.