From a2c4e5903710d6215ef666e549e58f028d77cd73 Mon Sep 17 00:00:00 2001 From: Alessandro Cocco Date: Mon, 25 Apr 2022 15:23:18 +0200 Subject: [PATCH 1/5] [Alarms & Timers] Add bulk actions --- apps/alarm/app.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/apps/alarm/app.js b/apps/alarm/app.js index 5d230c98c..6d15781d3 100644 --- a/apps/alarm/app.js +++ b/apps/alarm/app.js @@ -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(); return E.showMenu(menu); } @@ -177,4 +188,30 @@ function editTimer(alarmIndex, alarm) { return E.showMenu(menu); } +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(); From 4f812cd33cf0029b6234ae65330bb869f317f2d2 Mon Sep 17 00:00:00 2001 From: Marco H Date: Tue, 26 Apr 2022 11:48:14 +0200 Subject: [PATCH 2/5] Fix typos --- apps/activityreminder/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/activityreminder/README.md b/apps/activityreminder/README.md index 03466bbbf..1e643fb54 100644 --- a/apps/activityreminder/README.md +++ b/apps/activityreminder/README.md @@ -3,11 +3,11 @@ 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: +Different settings can be personalized: - 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 +- 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 - Min steps: Minimal amount of steps to count as an activity From 3a9b8dab293287924c468cb2b8b44e10bd207d69 Mon Sep 17 00:00:00 2001 From: Marco H Date: Tue, 26 Apr 2022 11:51:49 +0200 Subject: [PATCH 3/5] Fix typo and add format for settings which have minutes as unit --- apps/activityreminder/settings.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/apps/activityreminder/settings.js b/apps/activityreminder/settings.js index bdd105781..9b9a0ecd8 100644 --- a/apps/activityreminder/settings.js +++ b/apps/activityreminder/settings.js @@ -30,12 +30,15 @@ require("activityreminder").writeSettings(settings); } }, - 'Max innactivity': { + 'Max inactivity': { value: settings.maxInnactivityMin, min: 15, max: 120, onchange: v => { settings.maxInnactivityMin = v; require("activityreminder").writeSettings(settings); + }, + format: x => { + return x + " min"; } }, 'Dismiss delay': { @@ -44,6 +47,9 @@ onchange: v => { settings.dismissDelayMin = v; require("activityreminder").writeSettings(settings); + }, + format: x => { + return x + " min"; } }, 'Min steps': { From 6c8c3805bf806643d690b72f9d02c3c9d25958f7 Mon Sep 17 00:00:00 2001 From: Alessandro Cocco Date: Mon, 25 Apr 2022 15:24:05 +0200 Subject: [PATCH 4/5] [Alarms & Timers] Automatically save the alarm/timer when the user returns to the main menu using the back arrow --- apps/alarm/README.md | 9 +++--- apps/alarm/app.js | 65 ++++++++++++++++++++++++++++++-------------- 2 files changed, 49 insertions(+), 25 deletions(-) diff --git a/apps/alarm/README.md b/apps/alarm/README.md index 42131a5a6..e979dbaf1 100644 --- a/apps/alarm/README.md +++ b/apps/alarm/README.md @@ -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. diff --git a/apps/alarm/app.js b/apps/alarm/app.js index 6d15781d3..3b3421115 100644 --- a/apps/alarm/app.js +++ b/apps/alarm/app.js @@ -92,7 +92,10 @@ function editAlarm(alarmIndex, alarm) { const menu = { '': { 'title': /*LANG*/'Alarm' }, - /*LANG*/'< Back' : () => showMainMenu(), + /*LANG*/'< Back': () => { + saveAlarm(newAlarm, alarmIndex, a, t); + showMainMenu(); + }, /*LANG*/'Hours': { value: t.hrs, min : 0, max : 23, wrap : true, onchange: v => t.hrs=v @@ -126,24 +129,33 @@ function editAlarm(alarmIndex, alarm) { onchange: v => a.as = v } }; - menu[/*LANG*/"Save"] = function() { - 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(); - showMainMenu(); - }; + + menu[/*LANG*/"Cancel"] = () => showMainMenu(); + if (!newAlarm) { - menu[/*LANG*/"Delete"] = function() { - alarms.splice(alarmIndex,1); + menu[/*LANG*/"Delete"] = function () { + alarms.splice(alarmIndex, 1); saveAndReload(); showMainMenu(); }; } + 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) { let newAlarm = alarmIndex < 0; let a = require("sched").newDefaultTimer(); @@ -153,7 +165,10 @@ function editTimer(alarmIndex, alarm) { const menu = { '': { 'title': /*LANG*/'Timer' }, - /*LANG*/'< Back' : () => showMainMenu(), + /*LANG*/'< Back': () => { + saveTimer(newAlarm, alarmIndex, a, t); + showMainMenu(); + }, /*LANG*/'Hours': { value: t.hrs, min : 0, max : 23, wrap : true, onchange: v => t.hrs=v @@ -169,15 +184,9 @@ function editTimer(alarmIndex, alarm) { }, /*LANG*/'Vibrate': require("buzz_menu").pattern(a.vibrate, v => a.vibrate=v ), }; - menu[/*LANG*/"Save"] = function() { - a.timer = require("sched").encodeTime(t); - a.t = getCurrentTime() + a.timer; - a.last = 0; - if (newAlarm) alarms.push(a); - else alarms[alarmIndex] = a; - saveAndReload(); - showMainMenu(); - }; + + menu[/*LANG*/"Cancel"] = () => showMainMenu(); + if (!newAlarm) { menu[/*LANG*/"Delete"] = function() { alarms.splice(alarmIndex,1); @@ -188,6 +197,20 @@ function editTimer(alarmIndex, alarm) { 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" From f07ef11f3ebdd8cd2773e8320981ca748976f0d9 Mon Sep 17 00:00:00 2001 From: Alessandro Cocco Date: Mon, 25 Apr 2022 15:24:53 +0200 Subject: [PATCH 5/5] [Alarms & Timers] Update changelog and metadata --- apps/alarm/ChangeLog | 2 ++ apps/alarm/metadata.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/alarm/ChangeLog b/apps/alarm/ChangeLog index bb59a63d5..41dd93081 100644 --- a/apps/alarm/ChangeLog +++ b/apps/alarm/ChangeLog @@ -22,3 +22,5 @@ 0.21: Fix time reset after a day of week change (#1676) 0.22: Refactor some methods to scheduling library 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 diff --git a/apps/alarm/metadata.json b/apps/alarm/metadata.json index cd1f1f699..2084c2a30 100644 --- a/apps/alarm/metadata.json +++ b/apps/alarm/metadata.json @@ -2,7 +2,7 @@ "id": "alarm", "name": "Alarms & Timers", "shortName": "Alarms", - "version": "0.23", + "version": "0.24", "description": "Set alarms and timers on your Bangle", "icon": "app.png", "tags": "tool,alarm,widget",