mirror of https://github.com/espruino/BangleApps
Merge pull request #2520 from glemco/devel
agenda: added color field and updating clkinfo periodicallypull/2521/head
commit
020919bfd7
|
@ -11,3 +11,4 @@
|
|||
0.10: Update clock_info to avoid a redraw
|
||||
0.11: Setting to use "Today" and "Yesterday" instead of dates
|
||||
Added dynamic, short and range fields to clkinfo
|
||||
0.12: Added color field and updating clkinfo periodically (running events)
|
||||
|
|
|
@ -5,6 +5,51 @@
|
|||
if(passed<0) return 0;
|
||||
return passed;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the array [interval, switchTimeout]
|
||||
* `interval` is the refresh rate (hourly or per minute)
|
||||
* `switchTimeout` is the time before the refresh rate should change (or expiration)
|
||||
*/
|
||||
function getRefreshIntervals(ev) {
|
||||
const threshold = 2 * 60 * 1000; //2 mins
|
||||
const slices = 16;
|
||||
var now = new Date();
|
||||
var passed = now - (ev.timestamp*1000);
|
||||
var remaining = (ev.durationInSeconds*1000) - passed;
|
||||
if(remaining<0)
|
||||
return [];
|
||||
if(passed<0) //check once it's started
|
||||
return [ 2*-passed, -passed ];
|
||||
var slice = Math.round(remaining/slices);
|
||||
if(slice < threshold) { //no need to refresh frequently
|
||||
return [ threshold, remaining ];
|
||||
}
|
||||
return [ slice, remaining ];
|
||||
}
|
||||
|
||||
function _doInterval(interval) {
|
||||
return setTimeout(()=>{
|
||||
this.emit("redraw");
|
||||
this.interval = setInterval(()=>{
|
||||
this.emit("redraw");
|
||||
}, interval);
|
||||
}, interval);
|
||||
}
|
||||
function _doSwitchTimeout(ev, switchTimeout) {
|
||||
return setTimeout(()=>{
|
||||
this.emit("redraw");
|
||||
clearInterval(this.interval);
|
||||
this.interval = undefined;
|
||||
var tmp = getRefreshIntervals(ev);
|
||||
var interval = tmp[0];
|
||||
var switchTimeout = tmp[1];
|
||||
if(!interval) return;
|
||||
this.interval = _doInterval.call(this, interval);
|
||||
this.switchTimeout = _doSwitchTimeout.call(this, ev, switchTimeout);
|
||||
}, switchTimeout);
|
||||
}
|
||||
|
||||
var agendaItems = {
|
||||
name: "Agenda",
|
||||
img: atob("GBiBAAAAAAAAAADGMA///w///wf//wAAAA///w///w///w///x///h///h///j///D///X//+f//8wAABwAADw///w///wf//gAAAA=="),
|
||||
|
@ -23,16 +68,33 @@
|
|||
var date = new Date(entry.timestamp*1000);
|
||||
var dateStr = locale.date(date).replace(/\d\d\d\d/,"");
|
||||
var shortStr = ((date-now) > 86400000 || entry.allDay) ? dateStr : locale.time(date,1);
|
||||
var color = "#"+(0x1000000+Number(entry.color)).toString(16).padStart(6,"0");
|
||||
dateStr += entry.durationInSeconds < 86400 ? "/ " + locale.time(date,1) : "";
|
||||
shortStr = shortStr.trim().replace(" ", "\n");
|
||||
|
||||
agendaItems.items.push({
|
||||
name: "Agenda "+i,
|
||||
hasRange: true,
|
||||
get: () => ({ text: title + "\n" + dateStr,
|
||||
img: agendaItems.img, short: shortStr.trim(),
|
||||
img: agendaItems.img, short: shortStr,
|
||||
color: color,
|
||||
v: getPassedSec(date), min: 0, max: entry.durationInSeconds}),
|
||||
show: function() {},
|
||||
hide: function () {}
|
||||
show: function() {
|
||||
var tmp = getRefreshIntervals(entry);
|
||||
var interval = tmp[0];
|
||||
var switchTimeout = tmp[1];
|
||||
if(!interval) return;
|
||||
this.interval = _doInterval.call(this, interval);
|
||||
this.switchTimeout = _doSwitchTimeout.call(this, entry, switchTimeout);
|
||||
},
|
||||
hide: function() {
|
||||
if(this.interval)
|
||||
clearInterval(this.interval);
|
||||
if(this.switchTimeout)
|
||||
clearTimeout(this.switchTimeout);
|
||||
this.interval = undefined;
|
||||
this.switchTimeout = undefined;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "agenda",
|
||||
"name": "Agenda",
|
||||
"version": "0.11",
|
||||
"version": "0.12",
|
||||
"description": "Simple agenda",
|
||||
"icon": "agenda.png",
|
||||
"screenshots": [{"url":"screenshot_agenda_overview.png"}, {"url":"screenshot_agenda_event1.png"}, {"url":"screenshot_agenda_event2.png"}],
|
||||
|
|
Loading…
Reference in New Issue