Skip to content

Commit

Permalink
Designed UI for Day Specific Activity (#146)
Browse files Browse the repository at this point in the history
# Thanks for your contribution.

## PLEASE REMOVE
To support us in providing a nice (and fast) open-source experience:
1. Verify that the tests are passing
2. Check that the code is properly formatted (using AndroidStudio's
autoformatter)
3. Provide write access to the
[branch](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/allowing-changes-to-a-pull-request-branch-created-from-a-fork)
4. If the PR is not ready for review, please submit it as a
[draft](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests#draft-pull-requests)
## PLEASE REMOVE

**Describe the pull request**
A clear and concise description of what the pull request changes/adds.

**Link to the the issue**
(If available): The link to the issue that this pull request solves.

**License agreement**
By opening this pull request, you are providing your contribution under
the _Apache License 2.0_ (see [LICENSE.md](LICENSE.md)).

**Note: new dependencies/libraries**
Please refrain from introducing new libraries without consulting the
team.
  • Loading branch information
kevwad authored Apr 7, 2024
2 parents 302364b + 7f49857 commit 21b1f05
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<TrackSegment> 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() {
Expand All @@ -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<Track> 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();
}

Expand All @@ -131,7 +81,7 @@ protected void onDeleteConfirmed() {

@Override
protected Track.Id getRecordingTrackId() {
return trackId;
return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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<RecyclerView.ViewHolder> 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;
}
}
}
29 changes: 29 additions & 0 deletions src/main/res/layout/day_specific_activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
android:layout_height="match_parent"
tools:context=".ui.aggregatedStatistics.daySpecificStats.DaySpecificActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
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:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.8" />
</LinearLayout>


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

</androidx.constraintlayout.widget.ConstraintLayout>
77 changes: 77 additions & 0 deletions src/main/res/layout/day_specific_activity_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<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">

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

<TextView
android:id="@+id/day_specific_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:text="Run"
android:textSize="15dp"
android:textStyle="bold" />

<!-- Row for Run -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:padding="4dp"
android:weightSum="4"
android:textSize="10dp"
android:visibility="visible">

<TextView
android:id="@+id/day_specific_activity_displacement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:textSize="13dp"
android:text="0 m" />

<TextView
android:id="@+id/day_specific_activity_distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:textSize="13dp"
android:text="0.14 km" />

<TextView
android:id="@+id/day_specific_activity_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:textSize="13dp"
android:text="0.50" />

<TextView
android:id="@+id/day_specific_activity_speed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="13dp"
android:layout_weight="1"
android:text="36.3 km/h" />
</LinearLayout>

<!-- Bottom Line -->
<View
android:id="@+id/marker_list_item_bottom_line"
style="@style/HorizontalLine"
android:layout_marginBottom="0dp"/>

</LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 21b1f05

Please sign in to comment.