Skip to content

Commit

Permalink
Improvement: Add Distance to saveWorkout, to match workout fetching. (#…
Browse files Browse the repository at this point in the history
…356)

Co-authored-by: Sean Dunford <[email protected]>
  • Loading branch information
SeanDunford and Sean Dunford authored May 17, 2024
1 parent 4dbaade commit a367461
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,23 @@ public void saveWorkout(long startTime, long endTime, ReadableMap options, final
fitnessOptionsBuilder.addDataType(DataType.TYPE_STEP_COUNT_DELTA, FitnessOptions.ACCESS_WRITE);
}

if (options.hasKey(DISTANCE_FIELD_NAME)) {
float distance = (float) options.getDouble(DISTANCE_FIELD_NAME);
DataSource distanceDataSource = createWorkoutDataSource(DataType.TYPE_DISTANCE_DELTA);

DataPoint distanceDataPoint = DataPoint.builder(distanceDataSource)
.setTimeInterval(startTime, endTime, TimeUnit.MILLISECONDS)
.setField(Field.FIELD_DISTANCE, distance)
.build();

DataSet distanceDataSet = DataSet.builder(distanceDataSource)
.add(distanceDataPoint)
.build();

sessionInsertBuilder.addDataSet(distanceDataSet);
fitnessOptionsBuilder.addDataType(DataType.TYPE_DISTANCE_DELTA, FitnessOptions.ACCESS_WRITE);
}

// add dataSet into session
SessionInsertRequest insertRequest = sessionInsertBuilder.build();

Expand Down
1 change: 1 addition & 0 deletions index.android.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ declare module 'react-native-google-fit' {
calories?: number,
steps?: number,
intensity?: number,
distance?: number,
}

export type Granularity = {
Expand Down

0 comments on commit a367461

Please sign in to comment.