import Toybox.Lang; import Toybox.Application; // Every stored preference in one place, with the defaults that reproduce the // design comps. Keys match resources/settings/properties.xml. // // Properties.getValue returns null for a key the watch has not stored yet -- // a fresh install, or a setting added by an update -- so every read falls back // to the default rather than trusting the stored value. module Settings { // Field ids follow https://watchface.io/docs/datafields. const DEF_LEFT_TOP = 712; // sunrise const DEF_RIGHT_TOP = 639; // forecast high / low const DEF_BOTTOM_LEFT = 3; // distance const DEF_BOTTOM_RIGHT = 1; // steps function number(key as String, def as Number) as Number { var v = Application.Properties.getValue(key); if (v == null) { return def; } return v as Number; } function bool(key as String, def as Boolean) as Boolean { var v = Application.Properties.getValue(key); if (v == null) { return def; } return v as Boolean; } function text(key as String) as String { var v = Application.Properties.getValue(key); if (v == null) { return ""; } return v.toString(); } // Theme index, clamped into range in case a stored value outlives a // release that removed a theme. function themeIndex(count as Number) as Number { var i = number("Theme", 1) - 1; if (i < 0 || i >= count) { return 0; } return i; } function leftTop() as Number { return number("LeftTop", DEF_LEFT_TOP); } function rightTop() as Number { return number("RightTop", DEF_RIGHT_TOP); } function bottomLeft() as Number { return number("BottomLeft", DEF_BOTTOM_LEFT); } function bottomRight() as Number { return number("BottomRight", DEF_BOTTOM_RIGHT); } function ringTR() as Number { return number("RingTR", 0); } function ringTL() as Number { return number("RingTL", 1); } function ringBR() as Number { return number("RingBR", 4); } function ringBL() as Number { return number("RingBL", 3); } function tempUnit() as Number { return number("TempUnit", 0); } function showTop() as Boolean { return bool("ShowTop", true); } function showBand() as Boolean { return bool("ShowBand", true); } function showBottom() as Boolean { return bool("ShowBottom", true); } }