Merge branch 'master' of github.com:espruino/BangleApps

pull/1755/head
Gordon Williams 2022-04-26 15:05:47 +01:00
commit 0b08f84293
6 changed files with 98 additions and 29 deletions

View File

@ -3,11 +3,11 @@
A reminder to take short walks for the ones with a sedentary lifestyle. 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 The alert will popup only if you didn't take your short walk yet
Differents settings can be personnalized: Different settings can be personalized:
- Enable : Enable/Disable the app - Enable : Enable/Disable the app
- Start hour: Hour to start the reminder - Start hour: Hour to start the reminder
- End hour: Hour to end 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 - Max inactivity: Maximum inactivity time to allow before the alert. From 15 to 60 min
- Dismiss delay: Delay added before the next alert if the alert is dismissed. From 5 to 15 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 - Min steps: Minimal amount of steps to count as an activity

View File

@ -30,12 +30,15 @@
require("activityreminder").writeSettings(settings); require("activityreminder").writeSettings(settings);
} }
}, },
'Max innactivity': { 'Max inactivity': {
value: settings.maxInnactivityMin, value: settings.maxInnactivityMin,
min: 15, max: 120, min: 15, max: 120,
onchange: v => { onchange: v => {
settings.maxInnactivityMin = v; settings.maxInnactivityMin = v;
require("activityreminder").writeSettings(settings); require("activityreminder").writeSettings(settings);
},
format: x => {
return x + " min";
} }
}, },
'Dismiss delay': { 'Dismiss delay': {
@ -44,6 +47,9 @@
onchange: v => { onchange: v => {
settings.dismissDelayMin = v; settings.dismissDelayMin = v;
require("activityreminder").writeSettings(settings); require("activityreminder").writeSettings(settings);
},
format: x => {
return x + " min";
} }
}, },
'Min steps': { 'Min steps': {

View File

@ -22,3 +22,5 @@
0.21: Fix time reset after a day of week change (#1676) 0.21: Fix time reset after a day of week change (#1676)
0.22: Refactor some methods to scheduling library 0.22: Refactor some methods to scheduling library
0.23: Fix regression with Days of Week (#1735) 0.23: Fix regression with Days of Week (#1735)
0.24: Automatically save the alarm/timer when the user returns to the main menu using the back arrow
Add "Enable All", "Disable All" and "Remove All" actions

View File

@ -1,6 +1,7 @@
Default Alarm & Timer Alarms & Timers
====================== ===============
This allows you to add/modify any running timers. This app allows you to add/modify any alarms and timers.
It uses the [`sched` library](https://github.com/espruino/BangleApps/blob/master/apps/sched) to handle the alarm scheduling in an efficient way that can work alongside other apps. It uses the [`sched` library](https://github.com/espruino/BangleApps/blob/master/apps/sched)
to handle the alarm scheduling in an efficient way that can work alongside other apps.

View File

@ -52,6 +52,17 @@ function showMainMenu() {
} }
}; };
}); });
if (alarms.some(e => !e.on)) {
menu[/*LANG*/"Enable All"] = () => enableAll(true);
}
if (alarms.some(e => e.on)) {
menu[/*LANG*/"Disable All"] = () => enableAll(false);
}
if (alarms.length > 0) {
menu[/*LANG*/"Delete All"] = () => deleteAll();
}
if (WIDGETS["alarm"]) WIDGETS["alarm"].reload(); if (WIDGETS["alarm"]) WIDGETS["alarm"].reload();
return E.showMenu(menu); return E.showMenu(menu);
} }
@ -81,7 +92,10 @@ function editAlarm(alarmIndex, alarm) {
const menu = { const menu = {
'': { 'title': /*LANG*/'Alarm' }, '': { 'title': /*LANG*/'Alarm' },
/*LANG*/'< Back' : () => showMainMenu(), /*LANG*/'< Back': () => {
saveAlarm(newAlarm, alarmIndex, a, t);
showMainMenu();
},
/*LANG*/'Hours': { /*LANG*/'Hours': {
value: t.hrs, min : 0, max : 23, wrap : true, value: t.hrs, min : 0, max : 23, wrap : true,
onchange: v => t.hrs=v onchange: v => t.hrs=v
@ -115,24 +129,33 @@ function editAlarm(alarmIndex, alarm) {
onchange: v => a.as = v onchange: v => a.as = v
} }
}; };
menu[/*LANG*/"Save"] = function() {
a.t = require("sched").encodeTime(t); menu[/*LANG*/"Cancel"] = () => showMainMenu();
a.last = (a.t < getCurrentTime()) ? (new Date()).getDate() : 0;
if (newAlarm) alarms.push(a);
else alarms[alarmIndex] = a;
saveAndReload();
showMainMenu();
};
if (!newAlarm) { if (!newAlarm) {
menu[/*LANG*/"Delete"] = function() { menu[/*LANG*/"Delete"] = function () {
alarms.splice(alarmIndex,1); alarms.splice(alarmIndex, 1);
saveAndReload(); saveAndReload();
showMainMenu(); showMainMenu();
}; };
} }
return E.showMenu(menu); return E.showMenu(menu);
} }
function saveAlarm(newAlarm, alarmIndex, a, t) {
a.t = require("sched").encodeTime(t);
a.last = (a.t < getCurrentTime()) ? (new Date()).getDate() : 0;
if (newAlarm) {
alarms.push(a);
} else {
alarms[alarmIndex] = a;
}
saveAndReload();
}
function editTimer(alarmIndex, alarm) { function editTimer(alarmIndex, alarm) {
let newAlarm = alarmIndex < 0; let newAlarm = alarmIndex < 0;
let a = require("sched").newDefaultTimer(); let a = require("sched").newDefaultTimer();
@ -142,7 +165,10 @@ function editTimer(alarmIndex, alarm) {
const menu = { const menu = {
'': { 'title': /*LANG*/'Timer' }, '': { 'title': /*LANG*/'Timer' },
/*LANG*/'< Back' : () => showMainMenu(), /*LANG*/'< Back': () => {
saveTimer(newAlarm, alarmIndex, a, t);
showMainMenu();
},
/*LANG*/'Hours': { /*LANG*/'Hours': {
value: t.hrs, min : 0, max : 23, wrap : true, value: t.hrs, min : 0, max : 23, wrap : true,
onchange: v => t.hrs=v onchange: v => t.hrs=v
@ -158,15 +184,9 @@ function editTimer(alarmIndex, alarm) {
}, },
/*LANG*/'Vibrate': require("buzz_menu").pattern(a.vibrate, v => a.vibrate=v ), /*LANG*/'Vibrate': require("buzz_menu").pattern(a.vibrate, v => a.vibrate=v ),
}; };
menu[/*LANG*/"Save"] = function() {
a.timer = require("sched").encodeTime(t); menu[/*LANG*/"Cancel"] = () => showMainMenu();
a.t = getCurrentTime() + a.timer;
a.last = 0;
if (newAlarm) alarms.push(a);
else alarms[alarmIndex] = a;
saveAndReload();
showMainMenu();
};
if (!newAlarm) { if (!newAlarm) {
menu[/*LANG*/"Delete"] = function() { menu[/*LANG*/"Delete"] = function() {
alarms.splice(alarmIndex,1); alarms.splice(alarmIndex,1);
@ -177,4 +197,44 @@ function editTimer(alarmIndex, alarm) {
return E.showMenu(menu); return E.showMenu(menu);
} }
function saveTimer(newAlarm, alarmIndex, a, t) {
a.timer = require("sched").encodeTime(t);
a.t = getCurrentTime() + a.timer;
a.last = 0;
if (newAlarm) {
alarms.push(a);
} else {
alarms[alarmIndex] = a;
}
saveAndReload();
}
function enableAll(on) {
E.showPrompt(/*LANG*/"Are you sure?", {
title: on ? /*LANG*/"Enable All" : /*LANG*/"Disable All"
}).then((confirm) => {
if (confirm) {
alarms.forEach(alarm => alarm.on = on);
saveAndReload();
}
showMainMenu();
});
}
function deleteAll() {
E.showPrompt(/*LANG*/"Are you sure?", {
title: /*LANG*/"Delete All"
}).then((confirm) => {
if (confirm) {
alarms = [];
saveAndReload();
}
showMainMenu();
});
}
showMainMenu(); showMainMenu();

View File

@ -2,7 +2,7 @@
"id": "alarm", "id": "alarm",
"name": "Alarms & Timers", "name": "Alarms & Timers",
"shortName": "Alarms", "shortName": "Alarms",
"version": "0.23", "version": "0.24",
"description": "Set alarms and timers on your Bangle", "description": "Set alarms and timers on your Bangle",
"icon": "app.png", "icon": "app.png",
"tags": "tool,alarm,widget", "tags": "tool,alarm,widget",