Skip to content

Commit aa23831

Browse files
committed
Get BodyTemperature and OxygenSaturation
1 parent 7a13b5c commit aa23831

File tree

5 files changed

+100
-23
lines changed

5 files changed

+100
-23
lines changed

android/src/main/java/com/reactnative/googlefit/GoogleFitManager.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class GoogleFitManager implements ActivityEventListener {
5353
private DistanceHistory distanceHistory;
5454
private StepHistory stepHistory;
5555
private BodyHistory bodyHistory;
56-
private HeartrateHistory heartrateHistory;
56+
private HealthHistory healthHistory;
5757
private CalorieHistory calorieHistory;
5858
private NutritionHistory nutritionHistory;
5959
private StepCounter mStepCounter;
@@ -78,7 +78,7 @@ public GoogleFitManager(ReactContext reactContext, Activity activity) {
7878
this.mStepCounter = new StepCounter(mReactContext, this, activity);
7979
this.stepHistory = new StepHistory(mReactContext, this);
8080
this.bodyHistory = new BodyHistory(mReactContext, this);
81-
this.heartrateHistory = new HeartrateHistory(mReactContext, this);
81+
this.healthHistory = new HealthHistory(mReactContext, this);
8282
this.distanceHistory = new DistanceHistory(mReactContext, this);
8383
this.calorieHistory = new CalorieHistory(mReactContext, this);
8484
this.nutritionHistory = new NutritionHistory(mReactContext, this);
@@ -109,8 +109,8 @@ public BodyHistory getBodyHistory() {
109109
return bodyHistory;
110110
}
111111

112-
public HeartrateHistory getHeartrateHistory() {
113-
return heartrateHistory;
112+
public HealthHistory getHealthHistory() {
113+
return healthHistory;
114114
}
115115

116116
public DistanceHistory getDistanceHistory() {

android/src/main/java/com/reactnative/googlefit/GoogleFitModule.java

+42-12
Original file line numberDiff line numberDiff line change
@@ -375,9 +375,39 @@ public void getBloodPressureSamples(double startDate,
375375
String bucketUnit,
376376
Promise promise) {
377377
try {
378-
HeartrateHistory heartrateHistory = mGoogleFitManager.getHeartrateHistory();
379-
heartrateHistory.setDataType(HealthDataTypes.TYPE_BLOOD_PRESSURE);
380-
promise.resolve(heartrateHistory.getHistory((long)startDate, (long)endDate, bucketInterval, bucketUnit));
378+
HealthHistory healthHistory = mGoogleFitManager.getHealthHistory();
379+
healthHistory.setDataType(HealthDataTypes.TYPE_BLOOD_PRESSURE);
380+
promise.resolve(healthHistory.getHistory((long)startDate, (long)endDate, bucketInterval, bucketUnit));
381+
} catch (IllegalViewOperationException e) {
382+
promise.reject(e);
383+
}
384+
}
385+
386+
@ReactMethod
387+
public void getBodyTemperatureSamples(double startDate,
388+
double endDate,
389+
int bucketInterval,
390+
String bucketUnit,
391+
Promise promise) {
392+
try {
393+
HealthHistory healthHistory = mGoogleFitManager.getHealthHistory();
394+
healthHistory.setDataType(HealthDataTypes.TYPE_BODY_TEMPERATURE);
395+
promise.resolve(healthHistory.getHistory((long)startDate, (long)endDate, bucketInterval, bucketUnit));
396+
} catch (IllegalViewOperationException e) {
397+
promise.reject(e);
398+
}
399+
}
400+
401+
@ReactMethod
402+
public void getOxygenSaturationSamples(double startDate,
403+
double endDate,
404+
int bucketInterval,
405+
String bucketUnit,
406+
Promise promise) {
407+
try {
408+
HealthHistory healthHistory = mGoogleFitManager.getHealthHistory();
409+
healthHistory.setDataType(HealthDataTypes.TYPE_OXYGEN_SATURATION);
410+
promise.resolve(healthHistory.getHistory((long)startDate, (long)endDate, bucketInterval, bucketUnit));
381411
} catch (IllegalViewOperationException e) {
382412
promise.reject(e);
383413
}
@@ -390,9 +420,9 @@ public void getBloodGlucoseSamples(double startDate,
390420
String bucketUnit,
391421
Promise promise) {
392422
try {
393-
HeartrateHistory heartrateHistory = mGoogleFitManager.getHeartrateHistory();
394-
heartrateHistory.setDataType(HealthDataTypes.TYPE_BLOOD_GLUCOSE);
395-
promise.resolve(heartrateHistory.getHistory((long)startDate, (long)endDate, bucketInterval, bucketUnit));
423+
HealthHistory healthHistory = mGoogleFitManager.getHealthHistory();
424+
healthHistory.setDataType(HealthDataTypes.TYPE_BLOOD_GLUCOSE);
425+
promise.resolve(healthHistory.getHistory((long)startDate, (long)endDate, bucketInterval, bucketUnit));
396426
} catch (IllegalViewOperationException e) {
397427
promise.reject(e);
398428
}
@@ -401,9 +431,9 @@ public void getBloodGlucoseSamples(double startDate,
401431
@ReactMethod
402432
public void saveBloodGlucose(ReadableMap bloodGlucoseSample, Promise promise) {
403433
try {
404-
HeartrateHistory heartrateHistory = mGoogleFitManager.getHeartrateHistory();
405-
heartrateHistory.setDataType(HealthDataTypes.TYPE_BLOOD_GLUCOSE);
406-
heartrateHistory.saveBloodGlucose(bloodGlucoseSample);
434+
HealthHistory healthHistory = mGoogleFitManager.getHealthHistory();
435+
healthHistory.setDataType(HealthDataTypes.TYPE_BLOOD_GLUCOSE);
436+
healthHistory.saveBloodGlucose(bloodGlucoseSample);
407437
} catch (Error e) {
408438
promise.reject(e);
409439
}
@@ -417,9 +447,9 @@ public void getHeartRateSamples(double startDate,
417447
Promise promise) {
418448

419449
try {
420-
HeartrateHistory heartrateHistory = mGoogleFitManager.getHeartrateHistory();
421-
heartrateHistory.setDataType(DataType.TYPE_HEART_RATE_BPM);
422-
promise.resolve(heartrateHistory.getHistory((long)startDate, (long)endDate, bucketInterval, bucketUnit));
450+
HealthHistory healthHistory = mGoogleFitManager.getHealthHistory();
451+
healthHistory.setDataType(DataType.TYPE_HEART_RATE_BPM);
452+
promise.resolve(healthHistory.getHistory((long)startDate, (long)endDate, bucketInterval, bucketUnit));
423453
} catch (IllegalViewOperationException e) {
424454
promise.reject(e);
425455
}

android/src/main/java/com/reactnative/googlefit/HeartrateHistory.java renamed to android/src/main/java/com/reactnative/googlefit/HealthHistory.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,22 @@
4545
import static com.google.android.gms.fitness.data.HealthFields.FIELD_TEMPORAL_RELATION_TO_SLEEP;
4646

4747

48-
public class HeartrateHistory {
48+
public class HealthHistory {
4949

5050
private ReactContext mReactContext;
5151
private GoogleFitManager googleFitManager;
5252
private DataSet Dataset;
5353
private DataType dataType;
5454

55-
private static final String TAG = "Heart Rate History";
55+
private static final String TAG = "Health History";
5656

57-
public HeartrateHistory(ReactContext reactContext, GoogleFitManager googleFitManager, DataType dataType){
57+
public HealthHistory(ReactContext reactContext, GoogleFitManager googleFitManager, DataType dataType){
5858
this.mReactContext = reactContext;
5959
this.googleFitManager = googleFitManager;
6060
this.dataType = dataType;
6161
}
6262

63-
public HeartrateHistory(ReactContext reactContext, GoogleFitManager googleFitManager){
63+
public HealthHistory(ReactContext reactContext, GoogleFitManager googleFitManager){
6464
this(reactContext, googleFitManager, DataType.TYPE_HEART_RATE_BPM);
6565
}
6666

@@ -184,10 +184,7 @@ private DataSet createDataForRequest(DataType dataType, int dataSourceType, doub
184184
}
185185

186186
private void processDataSet(DataSet dataSet, WritableArray map) {
187-
188-
//Log.i(TAG, "Data returned for Data type: " + dataSet.getDataType().getName());
189187
Format formatter = new SimpleDateFormat("EEE");
190-
// WritableMap stepMap = Arguments.createMap();
191188

192189
for (DataPoint dp : dataSet.getDataPoints()) {
193190
WritableMap stepMap = Arguments.createMap();

index.android.d.ts

+22
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ declare module 'react-native-google-fit' {
119119
options: StartAndEndDate & Partial<BucketOptions>
120120
) => Promise<BloodGlucoseResponse[]>;
121121

122+
getBodyTemperatureSamples: (
123+
options: StartAndEndDate & Partial<BucketOptions>
124+
) => Promise<BodyTemperatureResponse[]>;
125+
126+
getOxygenSaturationSamples: (
127+
options: StartAndEndDate & Partial<BucketOptions>
128+
) => Promise<OxygenSaturationResponse[]>;
129+
122130
saveBloodGlucose: (
123131
options: { date: string, value: number },
124132
) => Promise<Boolean | undefined>
@@ -312,6 +320,20 @@ declare module 'react-native-google-fit' {
312320
day: Day
313321
}
314322

323+
export type BodyTemperatureResponse = {
324+
startDate: string,
325+
endDate: string,
326+
value: number,
327+
day: Day
328+
}
329+
330+
export type OxygenSaturationResponse = {
331+
startDate: string,
332+
endDate: string,
333+
value: number,
334+
day: Day
335+
}
336+
315337
export type WeightData = { date: string } & ({ unit: 'pound', value: number } | {});
316338

317339
export type AuthorizeResponse = { success: true} | {success: false, message: string };

index.android.js

+28
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,34 @@ class RNGoogleFit {
581581
return result;
582582
}
583583

584+
getBodyTemperatureSamples = async (options, callback) => {
585+
const { startDate, endDate, bucketInterval, bucketUnit } = prepareInput(options);
586+
const result = await googleFit.getBodyTemperatureSamples(
587+
startDate,
588+
endDate,
589+
bucketInterval,
590+
bucketUnit,
591+
);
592+
if (result.length > 0) {
593+
return prepareResponse(result);
594+
}
595+
return result;
596+
}
597+
598+
getOxygenSaturationSamples = async (options, callback) => {
599+
const { startDate, endDate, bucketInterval, bucketUnit } = prepareInput(options);
600+
const result = await googleFit.getOxygenSaturationSamples(
601+
startDate,
602+
endDate,
603+
bucketInterval,
604+
bucketUnit,
605+
);
606+
if (result.length > 0) {
607+
return prepareResponse(result);
608+
}
609+
return result;
610+
}
611+
584612
saveBloodGlucose = async (options) => {
585613
options.date = Date.parse(options.date)
586614
const result = await googleFit.saveBloodGlucose(options);

0 commit comments

Comments
 (0)