Skip to content

Commit

Permalink
GH-127: 40261875: Added RecyclerView and updated with values from seg…
Browse files Browse the repository at this point in the history
…ment
  • Loading branch information
kevwad committed Apr 7, 2024
1 parent d7755d4 commit 7d9e2e6
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 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,6 +34,7 @@ public class DaySpecificActivity extends AbstractTrackDeleteActivity {
private TrackDataHub trackDataHub;
private Track.Id trackId;
private List<TrackSegment> trackSegments;
private DaySpecificAdapter adapter;


@Override
Expand All @@ -45,6 +46,13 @@ protected void onCreate(Bundle savedInstanceState) {
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);

}

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

public void updateTrackSegments() {
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.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,7 +101,7 @@ public ViewHolder(@NonNull View itemView) {
view.setOnLongClickListener(this);
}

public void bind(Cursor cursor){
public void bind(TrackSegment segment){
viewBinding.daySpecificActivity.setText("Run");
viewBinding.daySpecificActivityDisplacement.setText("0 m");
viewBinding.daySpecificActivityDistance.setText("0.14 km");
Expand Down
4 changes: 2 additions & 2 deletions src/main/res/layout/day_specific_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

<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"
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:layout_height="0dp"
android:layout_weight="0.8" />
Expand Down
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 7d9e2e6

Please sign in to comment.