Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement: Add Distance to saveWorkout, to match workout fetching. #356

Conversation

SeanDunford
Copy link
Contributor

@SeanDunford SeanDunford commented Apr 30, 2024

Resolves #357

Background

Save Workout did not include distance which is an odd api choice because fetch workout does include distance. For my own personal needs adding distance to workout saving was necessary and i imagine it will be valuable to other users as well. I did mention a notice of missing permissions somewhere in the code but i tested this code and it works as is. Modeled it after the way calories and intensity are optionally added into the save workout payload.

Mention in comments about permission restriction
https://github.com/StasDoskalenko/react-native-google-fit/blob/master/android/src/main/java/com/reactnative/googlefit/ActivityHistory.java#L390

        // distance scope is missing here due to permission restriction
        // will be added in the future while distance is also available from saveWorkout()

What Changed

Updated WorkoutSample type to include optional distance number `distance?: number

  export type WorkoutSample = {
    startDate: string,
    endDate: string,
    activityType: ActivityType,
    sessionName: string,
    identifier: string,
    description?: string,
    calories?: number,
    steps?: number,
    intensity?: number,
 +    distance?: number,
  }

Conditionally add this as a data set into the session Insert Builder similar to calories and intensity:

if (options.hasKey(DISTANCE_FIELD_NAME)) {
... 
  sessionInsertBuilder.addDataSet(distanceDataSet);
... 
} 

How to test

Submit a workout with distance,
Verify that reading the workout includes the same distance
Go to google fit app and verify it was stored with distance

@SeanDunford
Copy link
Contributor Author

SeanDunford commented Apr 30, 2024

@StasDoskalenko - not sure if you're still maintaining this project but it would be nice to get this merged. I'm sure you're busy but let me know if you'd like any other code changes before merge.

CC: @aboveyunhai

@SeanDunford SeanDunford marked this pull request as draft May 1, 2024 00:09
@SeanDunford SeanDunford marked this pull request as ready for review May 1, 2024 00:09
Copy link
Owner

@StasDoskalenko StasDoskalenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@StasDoskalenko StasDoskalenko merged commit a367461 into StasDoskalenko:master May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Distance missing from Save workout
2 participants