diff --git a/apps/health/boot.js b/apps/health/boot.js index 7b9aa51aa..e73d37c69 100644 --- a/apps/health/boot.js +++ b/apps/health/boot.js @@ -36,6 +36,10 @@ Bangle.on("health", health => { const DB_HEADER_LEN = 8; const DB_FILE_LEN = DB_HEADER_LEN + DB_RECORDS_PER_MONTH*DB_RECORD_LEN; + if (health && health.steps > 0) { + handleStepGoalNotification(); + } + function getRecordFN(d) { return "health-"+d.getFullYear()+"-"+(d.getMonth()+1)+".raw"; } @@ -92,3 +96,22 @@ Bangle.on("health", health => { health.movement /= health.movCnt; require("Storage").write(fn, getRecordData(health), sumPos, DB_FILE_LEN); }); + +function handleStepGoalNotification() { + var settings = require("Storage").readJSON("health.json",1)||{}; + const steps = Bangle.getHealthStatus("day").steps; + if (settings.stepGoalNotification && settings.stepGoal > 0 && steps >= settings.stepGoal) { + const now = new Date(Date.now()).toISOString().split('T')[0]; // yyyy-mm-dd + if (!settings.stepGoalNotificationDate || settings.stepGoalNotificationDate < now) { // notification not yet shown today? + Bangle.buzz(200, 0.5); + /*LANG*/E.showPrompt("You reached your daily goal of " + settings.stepGoal + " steps!", { + /*LANG*/title: "Step goal reached!", + buttons: { "Ok": 1} + }).then(function (v) { + load(); + }); + settings.stepGoalNotificationDate = now; + require("Storage").writeJSON("health.json", settings); + } + } +} diff --git a/apps/health/settings.js b/apps/health/settings.js index f94efbb16..e7b0a7c15 100644 --- a/apps/health/settings.js +++ b/apps/health/settings.js @@ -1,7 +1,8 @@ (function (back) { var settings = Object.assign({ hrm: 0, - stepGoal: 10000 + stepGoal: 10000, + stepGoalNotification: false }, require("Storage").readJSON("health.json", true) || {}); E.showMenu({ @@ -34,6 +35,14 @@ settings.stepGoal = v; setSettings(settings); } + }, + /*LANG*/"Step Goal Notification": { + value: "stepGoalNotification" in settings ? settings.stepGoalNotification : false, + format: () => (settings.stepGoalNotification ? 'Yes' : 'No'), + onchange: () => { + settings.stepGoalNotification = !settings.stepGoalNotification; + setSettings(); + } } });