Refactor, untested

master
Stiralbios 2022-04-07 19:19:42 +02:00
parent 919175671d
commit e9f3a0ff3a
2 changed files with 67 additions and 29 deletions

View File

@ -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();

View File

@ -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);
}