Changed calendar format to array and graying out old events

pull/1884/head
Gabriele Monaco 2022-05-30 20:44:28 +02:00
parent 0f079a2752
commit 5fee259dd0
6 changed files with 50 additions and 57 deletions

View File

@ -1,3 +1,3 @@
# Calendar # Agenda
Basic agenda reading the events synchronised from GadgetBridge Basic agenda reading the events synchronised from GadgetBridge

View File

@ -1 +1 @@
require("heatshrink").decompress(atob("mEwwcCpMkyQC3wAIFgIRJn8JAoeQ/gRYwB0Bn57F/gCBHAgfCn8EDgdI/kSAoIR8oBkFgAFCCIysKCPM//4AKZAgR3/0Aj+Ag/ggP4gF/CPpr/Nf5r/NfYRhw4RL8IRDyEAABUJCIYC/AVI=")) require("heatshrink").decompress(atob("mEwwg1yhGIxAPMBwIPFhH//GAC5n/C4oHBC5/IGwoXBHQQAKC4OIFAWOxHv9GO9wAKI4XoC4foEIIWLC4IABC4gIBFxnuE4IqBC4gARC4ZzNAAwXaxe7ACO4C625C4m4xIJBzAeCxGbCAOIFgQOBC4pOBxe4AYIPBAYQKCAYYXE3GL/ADBx/oxb3BC4X+xG4xwOBC4uP/YDB54MBf4Po3eM/4XBx/+C4pTBGIIkBLgOYAYIvB9GJBwI6BL45zCL4aCCL4h3GU64ALdYS1CI55bBAAgXFO4mMO4QDBDIO/////YxBU53IxIVB/GfDAWYa5wtC/GPAYWIL4wXBL4oSBC4jcBC4m4QIWYSwWIIQIAG/CnMMAIAC/JLCMIIvMIwZHFJAJfLC5yPHAYIRDAoy/KCIi7BMon4d4+Od4IXBxAZBEQLtB/+YxIXDL4SLCL4WPzAXCNgRFBLIKnKLIrcEI4gXNAAp3CxGZAAzCBC5KnCKAIAICxBlBC4IAJxG/C4/4wAXLhBgD/IcD3AXMGAIqDDgRGNGAoXDFxxhEI4W4FxwwCaoYWBFx4YDAAQWRAEQ"))

View File

@ -8,7 +8,6 @@
location, location,
allDay: bool, allDay: bool,
} }
the file on storage has the same content but is an object indexed by id
*/ */
Bangle.loadWidgets(); Bangle.loadWidgets();
@ -24,14 +23,9 @@ var fontBig = g.getFonts().includes("12x20")?"12x20":"6x8:2";
var fontLarge = g.getFonts().includes("6x15")?"6x15:2":"6x8:4"; var fontLarge = g.getFonts().includes("6x15")?"6x15:2":"6x8:4";
//FIXME maybe write the end from GB already? Not durationInSeconds here (or do while receiving?) //FIXME maybe write the end from GB already? Not durationInSeconds here (or do while receiving?)
var cal; var CALENDAR = require("Storage").readJSON("android.calendar.json",true)||[];
try { cal = require("Storage").readJSON("android.calendar.json"); } catch (e) {}
if (!cal) //cal = {}; // first event CALENDAR=CALENDAR.sort((a,b)=>a.timestamp - b.timestamp)
cal = { //FIXME test
1: {id: 1, title:"foo", timestamp: 1653577989371, durationInSeconds: 3000, location: "somewhere", description: "something very very long"},
2: {id: 2, title:"last", timestamp: 1653579989371, durationInSeconds: 3000, location: "somewhere"},
3: {id: 3, title:"bar", timestamp: 1653578989371, durationInSeconds: 3000, location: "somewhere"}
};
function getDate(timestamp) { function getDate(timestamp) {
return new Date(timestamp*1000); return new Date(timestamp*1000);
@ -48,6 +42,7 @@ function formatDateShort(date) {
var lines = []; var lines = [];
function showEvent(ev) { function showEvent(ev) {
var bodyFont = fontBig; var bodyFont = fontBig;
if(!ev) return;
g.setFont(bodyFont); g.setFont(bodyFont);
//var lines = []; //var lines = [];
if (ev.title) lines = g.wrapString(ev.title, g.getWidth()-10) if (ev.title) lines = g.wrapString(ev.title, g.getWidth()-10)
@ -93,11 +88,11 @@ function showEvent(ev) {
}); });
} }
CALENDAR=Object.keys(cal)
.sort((a,b)=>cal[a].timestamp - cal[b].timestamp)
.map(k=>cal[k]); //make it an array
function showList() { function showList() {
if(CALENDAR.length == 0) {
E.showMessage("No events");
return;
}
E.showScroller({ E.showScroller({
h : 52, h : 52,
c : Math.max(CALENDAR.length,3), // workaround for 2v10.219 firmware (min 3 not needed for 2v11) c : Math.max(CALENDAR.length,3), // workaround for 2v10.219 firmware (min 3 not needed for 2v11)
@ -106,12 +101,14 @@ function showList() {
g.setColor(g.theme.fg); g.setColor(g.theme.fg);
g.clearRect(r.x,r.y,r.x+r.w, r.y+r.h); g.clearRect(r.x,r.y,r.x+r.w, r.y+r.h);
if (!ev) return; if (!ev) return;
var isPast = ev.timestamp + ev.durationInSeconds < (new Date())/1000;
var x = r.x+2, title = ev.title; var x = r.x+2, title = ev.title;
var body = formatDateShort(getDate(ev.timestamp))+"\n"+ev.location; var body = formatDateShort(getDate(ev.timestamp))+"\n"+ev.location;
var m = ev.title+"\n"+ev.location, longBody=false; var m = ev.title+"\n"+ev.location, longBody=false;
if (title) g.setFontAlign(-1,-1).setFont(fontBig).drawString(title, x,r.y+2); if (title) g.setFontAlign(-1,-1).setFont(fontBig)
.setColor(isPast ? "#888" : g.theme.fg).drawString(title, x,r.y+2);
if (body) { if (body) {
g.setFontAlign(-1,-1).setFont(fontMedium); g.setFontAlign(-1,-1).setFont(fontMedium).setColor(isPast ? "#888" : g.theme.fg);
var l = g.wrapString(body, r.w-(x+14)); var l = g.wrapString(body, r.w-(x+14));
if (l.length>3) { if (l.length>3) {
l = l.slice(0,3); l = l.slice(0,3);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -1,7 +1,7 @@
{ {
"id": "agenda", "id": "agenda",
"name": "Agenda", "name": "Agenda",
"version": "3.01", "version": "2.01",
"description": "Simple agenda", "description": "Simple agenda",
"icon": "agenda.png", "icon": "agenda.png",
"screenshots": [{"url":"screenshot_agenda.png"}], "screenshots": [{"url":"screenshot_agenda.png"}],

View File

@ -92,17 +92,13 @@
}, },
//TODO perhaps move those in a library (like messages), used also for viewing events? //TODO perhaps move those in a library (like messages), used also for viewing events?
"calendar" : function() { "calendar" : function() {
var cal; var cal = require("Storage").readJSON("android.calendar.json",true)||[];
try { cal = require("Storage").readJSON("android.calendar.json"); } catch (e) {} cal.push(event);
if (!cal) cal = {}; // first event
cal[event.id] = event;
require("Storage").writeJSON("android.calendar.json", cal); require("Storage").writeJSON("android.calendar.json", cal);
}, },
"calendar-" : function() { "calendar-" : function() {
var cal; var cal = require("Storage").readJSON("android.calendar.json",true)||return;
try { cal = require("Storage").readJSON("android.calendar.json"); } catch (e) {} cal = cal.filter(e=>e.id!=event.id);
if (!cal) return; //nothing to remove
if (event.id in cal) delete cal[event.id];
require("Storage").writeJSON("android.calendar.json", cal); require("Storage").writeJSON("android.calendar.json", cal);
} }
}; };