From 7f4985708bdb38325f04abba78841784690dba89 Mon Sep 17 00:00:00 2001 From: Rushi Donga <65907580+RushiDonga@users.noreply.github.com> Date: Sun, 7 Apr 2024 16:03:36 +0000 Subject: [PATCH] ui-changes --- .../daySpecificStats/DaySpecificActivity.java | 74 ++--------- .../daySpecificStats/DaySpecificAdapter.java | 123 ++++++++++++++++++ src/main/res/layout/day_specific_activity.xml | 29 +++++ .../res/layout/day_specific_activity_item.xml | 77 +++++++++++ 4 files changed, 241 insertions(+), 62 deletions(-) create mode 100644 src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/daySpecificStats/DaySpecificAdapter.java create mode 100644 src/main/res/layout/day_specific_activity.xml create mode 100644 src/main/res/layout/day_specific_activity_item.xml 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 1a56b70c3..f16b92f38 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 @@ -9,94 +9,39 @@ import de.dennisguse.opentracks.R; import de.dennisguse.opentracks.data.ContentProviderUtils; import de.dennisguse.opentracks.data.TrackDataHub; -import de.dennisguse.opentracks.data.TrackPointIterator; import de.dennisguse.opentracks.data.models.Track; -import de.dennisguse.opentracks.data.models.TrackPoint; -import de.dennisguse.opentracks.data.models.TrackSegment; -import de.dennisguse.opentracks.databinding.ActivityDaySpecificBinding; +import de.dennisguse.opentracks.databinding.DaySpecificActivityBinding; import java.time.format.DateTimeFormatter; import java.time.LocalDate; -import java.util.ArrayList; import java.util.Date; import java.time.ZoneId; import java.util.List; public class DaySpecificActivity extends AbstractTrackDeleteActivity { - private ActivityDaySpecificBinding viewBinding; + private DaySpecificActivityBinding viewBinding; private static final String TAG = DaySpecificActivity.class.getSimpleName(); public static final String EXTRA_TRACK_ID = "track_id"; private Date activityDate; private ContentProviderUtils contentProviderUtils; private TrackDataHub trackDataHub; private Track.Id trackId; - private List trackSegments; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_day_specific); + setContentView(R.layout.day_specific_activity); contentProviderUtils = new ContentProviderUtils(this); handleIntent(getIntent()); trackDataHub = new TrackDataHub(this); - trackSegments = new ArrayList<>(); setSupportActionBar(viewBinding.bottomAppBarLayout.bottomAppBar); } @Override protected void onStart() { super.onStart(); -// trackDataHub.start(); - } - - @Override - protected void onResume() { - super.onResume(); - updateTrackSegments(); - } - - @Override - protected void onPause() { - super.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - } - - public void updateTrackSegments() { - try (TrackPointIterator trackPointIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, null)) { - TrackSegment currentSegment = null; - while (trackPointIterator.hasNext()) { - TrackPoint nextPoint = trackPointIterator.next(); - - switch (nextPoint.getType()) { - case SEGMENT_START_AUTOMATIC: - case SEGMENT_START_MANUAL: - if (currentSegment != null) { - trackSegments.add(currentSegment); - } - currentSegment = new TrackSegment(nextPoint.getTime()); - break; - - case SEGMENT_END_MANUAL: - trackSegments.add(currentSegment); - currentSegment = null; - - case TRACKPOINT: - if (currentSegment != null) { - currentSegment.addTrackPoint(nextPoint); - } - break; - - default: - Log.d(TAG, "No Action for TrackPoint IDLE/SENSORPOINT while recording segments"); - } - } - System.out.println("Segments count: " + trackSegments.size()); - } + trackDataHub.start(); } private Date getDummyDate() { @@ -111,16 +56,21 @@ private void handleIntent(Intent intent) { trackId = intent.getParcelableExtra(EXTRA_TRACK_ID); if (trackId == null) { Log.e(TAG, DaySpecificActivity.class.getSimpleName() + " needs EXTRA_TRACK_ID."); +// finish(); // None provided, we will assume a specific date on our own activityDate = getDummyDate(); + List tracks = contentProviderUtils.getTracks(); + for (Track track: tracks) { + System.out.println("Track date = " + track.getStartTime().toString()); + } Track track = contentProviderUtils.getTrack(activityDate); - trackId = track.getId(); +// trackId = track.getId(); } } @Override protected View getRootView() { - viewBinding = ActivityDaySpecificBinding.inflate(getLayoutInflater()); + viewBinding = DaySpecificActivityBinding.inflate(getLayoutInflater()); return viewBinding.getRoot(); } @@ -131,7 +81,7 @@ protected void onDeleteConfirmed() { @Override protected Track.Id getRecordingTrackId() { - return trackId; + return null; } @Override 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 new file mode 100644 index 000000000..e950b256d --- /dev/null +++ b/src/main/java/de/dennisguse/opentracks/ui/aggregatedStatistics/daySpecificStats/DaySpecificAdapter.java @@ -0,0 +1,123 @@ +package de.dennisguse.opentracks.ui.aggregatedStatistics.daySpecificStats; + +import android.database.Cursor; +import android.util.SparseBooleanArray; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.view.ActionMode; +import androidx.recyclerview.widget.RecyclerView; + +import de.dennisguse.opentracks.R; +import de.dennisguse.opentracks.data.models.Track; +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 final AppCompatActivity context; + private final RecyclerView recyclerView; + + private final SparseBooleanArray selection = new SparseBooleanArray(); + + private Cursor cursor; + + private boolean selectionMode = false; + private ActivityUtils.ContextualActionModeCallback actionModeCallback; + + public DaySpecificAdapter(AppCompatActivity context, RecyclerView recyclerView) { + this.context = context; + this.recyclerView = recyclerView; + } + + @Override + public boolean onCreateActionMode(ActionMode mode, Menu menu) { + return false; + } + + @Override + public boolean onPrepareActionMode(ActionMode mode, Menu menu) { + return false; + } + + @Override + public boolean onActionItemClicked(ActionMode mode, MenuItem item) { + return false; + } + + @Override + public void onDestroyActionMode(ActionMode mode) { + + } + + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.day_specific_activity_item, parent, false); + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { + TrackListAdapter.ViewHolder viewHolder = (TrackListAdapter.ViewHolder) holder; + + cursor.moveToPosition(position); + viewHolder.bind(cursor); + } + + @Override + public int getItemCount() { + return 0; + } + + public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener { + + private final DaySpecificActivityItemBinding viewBinding; + private final View view; + + private Track.Id trackId; + + public ViewHolder(@NonNull View itemView) { + super(itemView); + + viewBinding = DaySpecificActivityItemBinding.bind(itemView); + view = itemView; + + view.setOnClickListener(this); + view.setOnLongClickListener(this); + } + + public void bind(Cursor cursor){ + 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"); + } + + public void setSelected(boolean isSelected) { + selection.put((int) getId(), isSelected); + view.setActivated(isSelected); + } + + public long getId() { + return trackId.id(); + } + + @Override + public void onClick(View view) { + + } + + @Override + public boolean onLongClick(View view) { + return false; + } + } +} diff --git a/src/main/res/layout/day_specific_activity.xml b/src/main/res/layout/day_specific_activity.xml new file mode 100644 index 000000000..3309764d1 --- /dev/null +++ b/src/main/res/layout/day_specific_activity.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + \ 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 new file mode 100644 index 000000000..5c221d6c5 --- /dev/null +++ b/src/main/res/layout/day_specific_activity_item.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file