mirror of https://github.com/espruino/BangleApps
Add Activity Reminder app
parent
070376cbed
commit
745bc1ec7e
|
@ -0,0 +1 @@
|
|||
0.01: New App!
|
|
@ -0,0 +1,13 @@
|
|||
# Activity reminder
|
||||
|
||||
A reminder to take short walks for the ones with a sedentary lifestyle.
|
||||
The alert will popup only if you didn't take your short walk yet
|
||||
|
||||
Differents settings can be personnalized:
|
||||
- Enable : Enable/Disable the app
|
||||
- Start hour: Hour to start the reminder
|
||||
- End hour: Hour to end the reminder
|
||||
- Max innactivity: Maximum innactivity time to allow before the alert. From 15 min to 60 min
|
||||
- Dismiss delay: Delay added before the next alert if the alert is dismissed. From 5 to 15 min
|
||||
- Min steps: Minimal amount of steps to count as an activity
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
global.activityreminder = Object.assign({
|
||||
enabled: true,
|
||||
startHour: 9,
|
||||
endHour: 20,
|
||||
maxInnactivityMin: 30,
|
||||
dismissDelayMin: 15,
|
||||
minSteps: 50,
|
||||
}, require("Storage").readJSON("activityreminder.json", true) || {});
|
||||
|
||||
|
||||
|
||||
if (global.activityreminder) {
|
||||
|
||||
activityreminder =
|
||||
Object.assign(activityreminder,
|
||||
{
|
||||
stepsArray: [],
|
||||
|
||||
run: function(){
|
||||
var now = new Date();
|
||||
var h = now.getHours();
|
||||
if(h >= activityreminder.startHour && h < activityreminder.endHour)
|
||||
{
|
||||
var health = Bangle.getHealthStatus("day");
|
||||
activityreminder.stepsArray.unshift(health.steps);
|
||||
activityreminder.stepsArray = activityreminder.stepsArray.slice(0, activityreminder.maxInnactivityMin);
|
||||
}
|
||||
else{
|
||||
activityreminder.stepsArray = [];
|
||||
}
|
||||
if(activityreminder.stepsArray.length == activityreminder.maxInnactivityMin){
|
||||
if (activityreminder.stepsArray[0] - activityreminder.stepsArray[activityreminder.stepsArray.length-1] < activityreminder.minSteps)
|
||||
{
|
||||
activityreminder.showAlert();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
|
||||
showAlert: function(){
|
||||
E.showPrompt("Innactivity detected",{
|
||||
title:"Activity reminder",
|
||||
buttons : {"Ok": true,"Dismiss": false}
|
||||
}).then(function(v) {
|
||||
if(v == true){
|
||||
activityreminder.stepsArray = activityreminder.stepsArray.slice(0, activityreminder.maxInnactivityMin - 3);
|
||||
}
|
||||
if(v == false){
|
||||
activityreminder.stepsArray = activityreminder.stepsArray.slice(0, activityreminder.maxInnactivityMin - activityreminder.dismissDelayMin);
|
||||
}
|
||||
load();
|
||||
});
|
||||
Bangle.buzz();
|
||||
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
setInterval(global.activityreminder.run, 60000);
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"id": "activityreminder",
|
||||
"name": "Activity Reminder",
|
||||
"shortName":"Activity Reminder",
|
||||
"description": "A reminder to take short walks for the ones with a sedentary lifestyle",
|
||||
"version":"0.01",
|
||||
"tags": "tool",
|
||||
"supports": ["BANGLEJS", "BANGLEJS2"],
|
||||
"readme": "README.md",
|
||||
"storage": [
|
||||
{"name": "activityreminder.boot.js","url": "boot.js"},
|
||||
{"name": "activityreminder.settings.js","url": "settings.js"},
|
||||
],
|
||||
"data": [
|
||||
{"name": "activityreminder.json"}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
(function(back) {
|
||||
var FILE = "activityreminder.json";
|
||||
// Load settings
|
||||
var settings = Object.assign({
|
||||
enabled: true,
|
||||
startHour: 9,
|
||||
endHour: 20,
|
||||
maxInnactivityMin: 30,
|
||||
delayondismiss: 15,
|
||||
minsteps: 50,
|
||||
}, require('Storage').readJSON(FILE, true) || {});
|
||||
|
||||
function writeSettings() {
|
||||
require('Storage').writeJSON(FILE, settings);
|
||||
}
|
||||
|
||||
// Show the menu
|
||||
E.showMenu({
|
||||
"" : { "title" : "Activity Reminder" },
|
||||
"< Back" : () => back(),
|
||||
'Enable': {
|
||||
value: !!settings.enabled,
|
||||
format: v => v?"Yes":"No",
|
||||
onchange: v => {
|
||||
settings.enabled = v;
|
||||
writeSettings();
|
||||
}
|
||||
},
|
||||
'Start hour': {
|
||||
value: 9|settings.startHour,
|
||||
min: 0, max: 24,
|
||||
onchange: v => {
|
||||
settings.startHour = v;
|
||||
writeSettings();
|
||||
}
|
||||
},
|
||||
'End hour': {
|
||||
value: 20|settings.endHour,
|
||||
min: 0, max: 24,
|
||||
onchange: v => {
|
||||
settings.endHour = v;
|
||||
writeSettings();
|
||||
}
|
||||
},
|
||||
'Max innactivity': {
|
||||
value: 30|settings.maxInnactivityMin,
|
||||
min: 15, max: 60,
|
||||
onchange: v => {
|
||||
settings.maxInnactivityMin = v;
|
||||
writeSettings();
|
||||
}
|
||||
},
|
||||
'Dismiss delay': {
|
||||
value: 15|settings.dismissDelayMin,
|
||||
min: 5, max: 15,
|
||||
onchange: v => {
|
||||
settings.dismissDelayMin = v;
|
||||
writeSettings();
|
||||
}
|
||||
},
|
||||
'Min steps': {
|
||||
value: 50|settings.minSteps,
|
||||
min: 5, max: 60,
|
||||
onchange: v => {
|
||||
settings.minSteps = v;
|
||||
writeSettings();
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
Loading…
Reference in New Issue