@stridekick/react-native-google-fit
Advanced tools
Sorry, the diff of this file is not supported yet
| arrowParens: 'always' | ||
| bracketSpacing: true | ||
| printWidth: 120 | ||
| semi: false | ||
| singleQuote: true | ||
| tabWidth: 2 | ||
| trailingComma: 'all' |
@@ -42,6 +42,6 @@ def DEFAULT_COMPILE_SDK_VERSION = 23 | ||
| compile fileTree(include: ['*.jar'], dir: 'libs') | ||
| compile 'com.facebook.react:react-native:+' | ||
| compile "com.google.android.gms:play-services-auth:$googlePlayServicesVersion" | ||
| compile "com.google.android.gms:play-services-fitness:$googlePlayServicesVersion" | ||
| implementation fileTree(include: ['*.jar'], dir: 'libs') | ||
| implementation 'com.facebook.react:react-native:+' | ||
| implementation "com.google.android.gms:play-services-auth:$googlePlayServicesVersion" | ||
| implementation "com.google.android.gms:play-services-fitness:$googlePlayServicesVersion" | ||
| } |
@@ -185,17 +185,23 @@ /** | ||
| for (DataPoint dp : dataSet.getDataPoints()) { | ||
| Log.i(TAG, "Data point:"); | ||
| Log.i(TAG, "\tType: " + dp.getDataType().getName()); | ||
| Log.i(TAG, "\tStart: " + dateFormat.format(dp.getStartTime(TimeUnit.MILLISECONDS))); | ||
| Log.i(TAG, "\tEnd: " + dateFormat.format(dp.getEndTime(TimeUnit.MILLISECONDS))); | ||
| Field field = dp.getDataType().getFields().get(0); | ||
| String fieldName = field.getName(); | ||
| if (fieldName.equals("duration")) { | ||
| activityMap.putDouble("startDate", dp.getStartTime(TimeUnit.MILLISECONDS)); | ||
| activityMap.putDouble("endDate", dp.getEndTime(TimeUnit.MILLISECONDS)); | ||
| activityMap.putDouble("minutes", dp.getValue(field).asInt()); | ||
| activityMap.putDouble("startDate", dp.getStartTime(TimeUnit.MILLISECONDS)); | ||
| activityMap.putDouble("endDate", dp.getEndTime(TimeUnit.MILLISECONDS)); | ||
| for (Field field : dp.getDataType().getFields()) { | ||
| Log.i(TAG, "\tValue: " + dp.getValue(field)); | ||
| String fieldName = field.getName(); | ||
| if (fieldName.equals("duration")) { | ||
| activityMap.putDouble("minutes", dp.getValue(field).asInt()); | ||
| } | ||
| if (fieldName.equals("distance")) { | ||
| activityMap.putDouble("distance", dp.getValue(field).asFloat()); | ||
| } | ||
| if (fieldName.equals("steps")) { | ||
| activityMap.putDouble("steps", dp.getValue(field).asInt()); | ||
| } | ||
| } | ||
| if (fieldName.equals("distance")) { | ||
| activityMap.putDouble("distance", dp.getValue(field).asFloat()); | ||
| } | ||
| if (fieldName.equals("steps")) { | ||
| activityMap.putDouble("steps", dp.getValue(field).asInt()); | ||
| } | ||
| } | ||
@@ -202,0 +208,0 @@ } |
+48
-36
| 'use strict' | ||
| import {DeviceEventEmitter, NativeModules} from 'react-native'; | ||
| import { DeviceEventEmitter, NativeModules } from 'react-native' | ||
| const googleFit = NativeModules.RNGoogleFit; | ||
| const googleFit = NativeModules.RNGoogleFit | ||
@@ -25,53 +25,65 @@ const METERS_PER_MILE = 0.000621371 | ||
| /** | ||
| * Get the total distance per day over a specified date range. | ||
| * @param {Object} options getDailyDistanceSamples accepts an options object containing required startDate: ISO8601Timestamp and endDate: ISO8601Timestamp. | ||
| * @callback callback The function will be called with an array of elements. | ||
| */ | ||
| * Get the total distance per day over a specified date range. | ||
| * @param {Object} options getDailyDistanceSamples accepts an options object containing required startDate: ISO8601Timestamp and endDate: ISO8601Timestamp. | ||
| * @callback callback The function will be called with an array of elements. | ||
| */ | ||
| getActivities(options) { | ||
| let startDate = Date.parse(options.startDate); | ||
| let endDate = Date.parse(options.endDate); | ||
| let startDate = Date.parse(options.startDate) | ||
| let endDate = Date.parse(options.endDate) | ||
| return new Promise((resolve, reject) => { | ||
| googleFit.getActivities(startDate, endDate, (error) => { | ||
| resolve(error); | ||
| }, (response) => { | ||
| if (response.length > 0) { | ||
| const rawResponse = response[0] | ||
| const distance = rawResponse.distance * METERS_PER_MILE | ||
| const activities = { | ||
| ...rawResponse, | ||
| distance, | ||
| googleFit.getActivities( | ||
| startDate, | ||
| endDate, | ||
| (error) => { | ||
| resolve(error) | ||
| }, | ||
| (response) => { | ||
| if (response.length > 0 && !!response[0].startDate) { | ||
| const rawResponse = response[0] | ||
| const distance = rawResponse.distance * METERS_PER_MILE | ||
| const activities = { | ||
| ...rawResponse, | ||
| distance, | ||
| } | ||
| return resolve(activities) | ||
| } | ||
| return resolve(activities) | ||
| } | ||
| return resolve({}) | ||
| }) | ||
| return resolve({}) | ||
| }, | ||
| ) | ||
| }) | ||
| } | ||
| isAvailable(callback) { // true if GoogleFit installed | ||
| isAvailable(callback) { | ||
| // true if GoogleFit installed | ||
| return new Promise((resolve, reject) => { | ||
| googleFit.isAvailable((error) => { | ||
| resolve(error) | ||
| }, (response) => { | ||
| resolve(response) | ||
| }); | ||
| googleFit.isAvailable( | ||
| (error) => { | ||
| resolve(error) | ||
| }, | ||
| (response) => { | ||
| resolve(response) | ||
| }, | ||
| ) | ||
| }) | ||
| } | ||
| isEnabled(callback) { // true if permission granted | ||
| isEnabled(callback) { | ||
| // true if permission granted | ||
| return new Promise((resolve, reject) => { | ||
| googleFit.isEnabled((error) => { | ||
| resolve(error) | ||
| }, (response) => { | ||
| resolve(response) | ||
| }); | ||
| googleFit.isEnabled( | ||
| (error) => { | ||
| resolve(error) | ||
| }, | ||
| (response) => { | ||
| resolve(response) | ||
| }, | ||
| ) | ||
| }) | ||
| } | ||
| } | ||
| export default new RNGoogleFit(); | ||
| export default new RNGoogleFit() |
+1
-1
| { | ||
| "name": "@stridekick/react-native-google-fit", | ||
| "version": "3.0.9", | ||
| "version": "3.0.10", | ||
| "description": "A React Native bridge module for interacting with Google Fit", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
79984
1.06%15
15.38%413
4.82%