diff --git a/apps/clkinfocal/ChangeLog b/apps/clkinfocal/ChangeLog index 5560f00bc..815c197c4 100644 --- a/apps/clkinfocal/ChangeLog +++ b/apps/clkinfocal/ChangeLog @@ -1 +1,2 @@ 0.01: New App! +0.02: added settings options to change date format diff --git a/apps/clkinfocal/clkinfo.js b/apps/clkinfocal/clkinfo.js index a7949cda4..d4e7b0efc 100644 --- a/apps/clkinfocal/clkinfo.js +++ b/apps/clkinfocal/clkinfo.js @@ -1,5 +1,20 @@ (function() { require("Font4x8Numeric").add(Graphics); + + var settings = require("Storage").readJSON("clkinfocal.json",1)||{}; + settings.fmt = settings.fmt||"DDD"; + + var getDateString = function(dt) { + switch(settings.fmt) { + case "dd MMM": + return '' + dt.getDate() + ' ' + require("locale").month(dt,1).toUpperCase(); + case "DDD dd": + return require("locale").dow(dt,1).toUpperCase() + ' ' + dt.getDate(); + default: // DDD + return require("locale").dow(dt,1).toUpperCase(); + } + }; + return { name: "Bangle", items: [ @@ -10,7 +25,7 @@ g.drawImage(atob("FhgBDADAMAMP/////////////////////8AADwAAPAAA8AADwAAPAAA8AADwAAPAAA8AADwAAPAAA8AADwAAP///////"),1,0); g.setFont("6x15").setFontAlign(0,0).drawString(d.getDate(),11,17); return { - text : require("locale").dow(d,1).toUpperCase(), + text : getDateString(d), img : g.asImage("string") }; }, diff --git a/apps/clkinfocal/metadata.json b/apps/clkinfocal/metadata.json index 1d14c3b59..a4fcc85ee 100644 --- a/apps/clkinfocal/metadata.json +++ b/apps/clkinfocal/metadata.json @@ -1,13 +1,15 @@ { "id": "clkinfocal", "name": "Calendar Clockinfo", - "version":"0.01", - "description": "For clocks that display 'clockinfo' (messages that can be cycled through using the clock_info module) this displays the day of the month in the icon, and the weekday", + "version":"0.02", + "description": "For clocks that display 'clockinfo' (messages that can be cycled through using the clock_info module) this displays the day of the month in the icon, and the weekday. There is also a settings menu to select the format of the text", "icon": "app.png", "screenshots": [{"url":"screenshot.png"}], "type": "clkinfo", "tags": "clkinfo,calendar", "supports" : ["BANGLEJS2"], "storage": [ - {"name":"clkinfocal.clkinfo.js","url":"clkinfo.js"} - ] + {"name":"clkinfocal.clkinfo.js","url":"clkinfo.js"}, + {"name":"clkinfocal.settings.js","url":"settings.js"} + ], + "data": [{"name":"clkinfocal.json"}] } diff --git a/apps/clkinfocal/settings.js b/apps/clkinfocal/settings.js new file mode 100644 index 000000000..6fe8f2817 --- /dev/null +++ b/apps/clkinfocal/settings.js @@ -0,0 +1,37 @@ +(function(back) { + const SETTINGS_FILE = "clkinfocal.json"; + + // initialize with default settings... + let s = {'fmt': 0}; + + // and overwrite them with any saved values + // this way saved values are preserved if a new version adds more settings + const storage = require('Storage'); + let settings = storage.readJSON(SETTINGS_FILE, 1) || {}; + const saved = settings || {}; + for (const key in saved) { + s[key] = saved[key]; + } + + function save() { + settings = s; + storage.write(SETTINGS_FILE, settings); + } + + var date_options = ["DDD","DDD dd","dd MMM"]; + + E.showMenu({ + '': { 'title': 'Cal Clkinfo' }, + '< Back': back, + 'Format': { + value: 0 | date_options.indexOf(s.fmt), + min: 0, max: 2, + format: v => date_options[v], + onchange: v => { + s.fmt = date_options[v]; + save(); + }, + } + }); + +});