diff options
Diffstat (limited to 'source/settings/Results.mc')
| -rw-r--r-- | source/settings/Results.mc | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/source/settings/Results.mc b/source/settings/Results.mc new file mode 100644 index 0000000..37c932f --- /dev/null +++ b/source/settings/Results.mc @@ -0,0 +1,43 @@ +// Author: cirakg & claude ai +// Summary: The latest settings results (README 10.3): kept in storage for the results screen, with an unseen flag for the list. + +import Toybox.Application; +import Toybox.Lang; + +module Results { + + const KEY = "res"; + const MAX_LINES = 60; + + // Replace the stored results with these lines (marked unseen). + function save(lines as Array<String>) as Void { + var kept = lines.size() > MAX_LINES ? lines.slice(0, MAX_LINES) as Array<String> : lines; + Application.Storage.setValue(KEY, {"l" => kept, "u" => true} as Dictionary<Application.Storage.KeyType, Application.Storage.ValueType>); + } + + // The stored lines, or a short explanation when there are none. + function lines() as Array<String> { + var stored = Application.Storage.getValue(KEY); + if (stored instanceof Dictionary && stored["l"] instanceof Array) { + return stored["l"] as Array<String>; + } + return ["Nothing yet. Results appear here after you import or change entries in the phone settings."]; + } + + function unseen() as Boolean { + var stored = Application.Storage.getValue(KEY); + return stored instanceof Dictionary && isTrue(stored["u"]); + } + + function markSeen() as Void { + var stored = Application.Storage.getValue(KEY); + if (stored instanceof Dictionary && isTrue(stored["u"])) { + stored["u"] = false; + Application.Storage.setValue(KEY, stored as Dictionary<Application.Storage.KeyType, Application.Storage.ValueType>); + } + } + + function isTrue(value as Application.Storage.ValueType) as Boolean { + return value instanceof Boolean && value; + } +} |
