Add Activity Reminder app

pull/1714/head
Stiralbios 2022-04-05 16:27:16 +02:00
parent 070376cbed
commit 745bc1ec7e
5 changed files with 163 additions and 0 deletions

View File

@ -0,0 +1 @@
0.01: New App!

View File

@ -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

View File

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

View File

@ -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"}
]
}

View File

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