From e9f3a0ff3a54cd3009af1152b69f613e238e3d27 Mon Sep 17 00:00:00 2001 From: Stiralbios Date: Thu, 7 Apr 2022 19:19:42 +0200 Subject: [PATCH] Refactor, untested --- apps/activityreminder/app.js | 72 +++++++++++++++++++++++++---------- apps/activityreminder/boot.js | 24 ++++++++---- 2 files changed, 67 insertions(+), 29 deletions(-) diff --git a/apps/activityreminder/app.js b/apps/activityreminder/app.js index 45d9247bb..5fefbc97a 100644 --- a/apps/activityreminder/app.js +++ b/apps/activityreminder/app.js @@ -1,24 +1,54 @@ +global.activityreminder = Object.assign({ + enabled: true, + startHour: 9, + endHour: 20, + maxInnactivityMin: 30, + dismissDelayMin: 15, + minSteps: 50 +}, require("Storage").readJSON("activityreminder.json", true) || {}); + +var stepsArray = []; // todo load from storage and save in storage on activityreminder.data. Create lib.js to read and write in it + + +function drawAlert(){ + E.showPrompt("Innactivity detected",{ + title:"Activity reminder", + buttons : {"Ok": true,"Dismiss": false} + }).then(function(v) { + console.log(global.stepsArray); + if(v == true){ + stepsArray = global.stepsArray.slice(0, activityreminder.maxInnactivityMin - 3); + // todo save stepsArray + } + if(v == false){ + stepsArray = global.stepsArray.slice(0, activityreminder.maxInnactivityMin - activityreminder.dismissDelayMin); + // todo save stepsArray + } + load(); + }); + + Bangle.buzz(); + setTimeout(load, 10000); + +} + +function run() +{ + if(stepsArray.length == activityreminder.maxInnactivityMin){ + if (stepsArray[0] - stepsArray[stepsArray.length-1] < activityreminder.minSteps) + { + drawAlert(); + } + }else{ + // todo find something else to do when there is no alert to show, showing the setting is a placeholder for now + eval(require("Storage").read("android.settings.js"))(()=>load()); + } + + +} + + g.clear(); Bangle.loadWidgets(); Bangle.drawWidgets(); - - -/* draw the alert */ -E.showPrompt("Innactivity detected",{ - title:"Activity reminder", - buttons : {"Ok": true,"Dismiss": false} -}).then(function(v) { - console.log(global.stepsArray); - if(v == true){ - global.stepsArray = global.stepsArray.slice(0, activityreminder.maxInnactivityMin - 3); - } - if(v == false){ - global.stepsArray = global.stepsArray.slice(0, activityreminder.maxInnactivityMin - activityreminder.dismissDelayMin); - } - load(); -}); - - -Bangle.buzz(); -setTimeout(load, 10000); - +run(); diff --git a/apps/activityreminder/boot.js b/apps/activityreminder/boot.js index 3b4c12205..7b33b35ff 100644 --- a/apps/activityreminder/boot.js +++ b/apps/activityreminder/boot.js @@ -4,12 +4,14 @@ global.activityreminder = Object.assign({ endHour: 20, maxInnactivityMin: 30, dismissDelayMin: 15, - minSteps: 50, + minSteps: 50 }, require("Storage").readJSON("activityreminder.json", true) || {}); -global.stepsArray = []; +var stepsArray = []; // todo load from storage and save in storage on activityreminder.data. Create lib.js to read and write in it +// todo put it in sequential to see if it work still + if (global.activityreminder) { activityreminder = @@ -23,14 +25,20 @@ if (global.activityreminder) { if(h >= activityreminder.startHour && h < activityreminder.endHour) { var health = Bangle.getHealthStatus("day"); - global.stepsArray.unshift(health.steps); - global.stepsArray = global.stepsArray.slice(0, activityreminder.maxInnactivityMin); + stepsArray.unshift(health.steps); + stepsArray = stepsArray.slice(0, activityreminder.maxInnactivityMin); + // todo save stepsArray } else{ - global.stepsArray = []; + if(stepsArray != []) + { + stepsArray = []; + // todo save stepsArray + } + } - if(global.stepsArray.length == activityreminder.maxInnactivityMin){ - if (global.stepsArray[0] - global.stepsArray[stepsArray.length-1] < activityreminder.minSteps) + if(stepsArray.length == activityreminder.maxInnactivityMin){ + if (stepsArray[0] - stepsArray[stepsArray.length-1] < activityreminder.minSteps) { load('activityreminder.app.js'); } @@ -38,6 +46,6 @@ if (global.activityreminder) { } }); - setInterval(global.activityreminder.run, 2000); + setInterval(global.activityreminder.run, 60000); }