@felicienfrancois/cordova-plugin-stepper
Advanced tools
Comparing version 0.2.33 to 0.2.34
{ | ||
"name": "@felicienfrancois/cordova-plugin-stepper", | ||
"version": "0.2.33", | ||
"version": "0.2.34", | ||
"description": "Lightweight pedometer Cordova/Phonegap plugin for Android using the hardware step sensor, with notifications.", | ||
@@ -5,0 +5,0 @@ "cordova": { |
@@ -67,3 +67,2 @@ # cordova-plugin-stepper | ||
#### startStepperUpdates (offset, onSuccess, onError, options) | ||
#### startStepperUpdates (options, onSuccess, onError) | ||
@@ -75,3 +74,2 @@ Run with options and listener data updates. The success handler is called once during the first call and then called from the background thread whenever data is available. | ||
The `options` parameter may contain optional parameters. Below parameters recommended for notification localization (in Android platform): | ||
- offset - _int_ - the step count to starts with (Usually 0). Default to today's step count if available or 0 if not | ||
- goal - _int_ - the goal (default to no goal) | ||
@@ -85,12 +83,12 @@ - pedometerIsCountingText - _string_ - Set title text for notification | ||
```js | ||
var offset = 0, options = { | ||
pedometerIsCountingText: 'Pedometer is counting', | ||
pedometerStepsToGoFormatText: '%s steps to go', // available variables: [stepsToGo, todaySteps, goal]. Insert using %1$s, %2$s, %3$s placeholders | ||
pedometerYourProgressFormatText: 'Your progress will be shown here soon', | ||
pedometerGoalReachedFormatText: '%s steps today', // available variables: [todaySteps, goal]. Insert using %1$s, %2$s placeholders | ||
}; | ||
const options = { | ||
pedometerIsCountingText: 'Pedometer is counting', | ||
pedometerStepsToGoFormatText: '%s steps to go', // available variables: [stepsToGo, todaySteps, goal]. Insert using %1$s, %2$s, %3$s placeholders | ||
pedometerYourProgressFormatText: 'Your progress will be shown here soon', | ||
pedometerGoalReachedFormatText: '%s steps today', // available variables: [todaySteps, goal]. Insert using %1$s, %2$s placeholders | ||
}; | ||
stepper.startStepperUpdates(offset, options).then((result) => { | ||
var stepsToday = result.steps_today; | ||
}).catch((err) => { | ||
stepper.startStepperUpdates(options, (result) => { | ||
console.log(result.steps_today); | ||
}, (err) => { | ||
console.error(err); | ||
@@ -139,2 +137,18 @@ }); | ||
#### destroy () => Promise | ||
Android Only: Stop pedometer updates and clear database | ||
Example: | ||
```js | ||
stepper.destroy() | ||
.then(() => { | ||
console.error("Stopped and cleared"); | ||
}) | ||
.catch((error) => { | ||
console.error(err); | ||
}); | ||
``` | ||
_Note: Background service can only be stopped by this method._ | ||
#### setGoal (num) => Promise | ||
@@ -141,0 +155,0 @@ Set a goal (number of steps) for a pedometer. |
@@ -20,5 +20,5 @@ var exec = require("cordova/exec"); | ||
let promise = new Promise(function(resolve, reject) { | ||
if(!/^android|amazon/i.test(device.platform)) { | ||
return resolve(true); | ||
} | ||
if(!/^android|amazon/i.test(device.platform)) { | ||
return resolve(true); | ||
} | ||
exec(resolve, reject, "Stepper", "requestPermission", []); | ||
@@ -34,5 +34,5 @@ }); | ||
let promise = new Promise(function(resolve) { | ||
if(!/^android|amazon/i.test(device.platform)) { | ||
return resolve(false); | ||
} | ||
if(!/^android|amazon/i.test(device.platform)) { | ||
return resolve(false); | ||
} | ||
exec(resolve, () => resolve(false), "Stepper", "disableBatteryOptimizations", []); | ||
@@ -46,10 +46,8 @@ }); | ||
// IOS & Android - Documented | ||
Stepper.prototype.startStepperUpdates = function (offset, onSuccess, onError, options) { | ||
let opts = options || {}; | ||
if (typeof(offset) === "object") { | ||
opts = offset; | ||
} else if (typeof(opts.offset) === "undefined" && typeof(offset) !== "undefined") { | ||
opts.offset = offset; | ||
} | ||
exec(onSuccess, onError, "Stepper", "startStepperUpdates", [opts]); | ||
Stepper.prototype.startStepperUpdates = function(options, onSuccess, onError, extra) { | ||
let opts = extra || {}; | ||
if (typeof(options) === "object") { | ||
opts = options; | ||
} | ||
exec(onSuccess, onError, "Stepper", "startStepperUpdates", [opts]); | ||
}; | ||
@@ -67,2 +65,15 @@ | ||
// IOS & Android - Documented | ||
Stepper.prototype.destroy = function (onSuccess, onError) { | ||
if(!/^android|amazon/i.test(device.platform)) { | ||
return resolve(false); | ||
} | ||
let promise = new Promise(function(resolve, reject) { | ||
exec(resolve, reject, "Stepper", "destroy", []); | ||
}); | ||
if (onSuccess) promise = promise.then(onSuccess); | ||
if (onError) promise = promise.catch(onError); | ||
return promise; | ||
}; | ||
// Android - Not Available - UnDocumented | ||
@@ -105,6 +116,6 @@ Stepper.prototype.getCurrentSteps = function (onSuccess, onError) { | ||
Stepper.prototype.getStepsByPeriod = function (start, end, onSuccess, onError) { | ||
const startDate = new Date(start || 0); | ||
startDate.setHours(0, 0, 0, 0); | ||
const endDate = new Date(end || new Date()); | ||
endDate.setHours(23, 59, 59, 999); | ||
const startDate = new Date(start || 0); | ||
startDate.setHours(0, 0, 0, 0); | ||
const endDate = new Date(end || new Date()); | ||
endDate.setHours(23, 59, 59, 999); | ||
let promise = new Promise(function(resolve, reject) { | ||
@@ -111,0 +122,0 @@ exec(resolve, reject, "Stepper", "getStepsByPeriod", [startDate.toISOString(), endDate.toISOString()]); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
259
78128
1435