aboutsummaryrefslogtreecommitdiff
path: root/source/ui/GlanceView.mc
blob: a7207cecb091a6349cf44148c520412acf9a0cea (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Author:  cirakg & claude ai
// Summary: The glance (widget-list preview): app name and number of entries.
//
// Glances run with very little memory, so this reads only the entry index
// from storage and opens no vault and no keys. The opt-in favourite code
// (README 13.1) comes with M8.

import Toybox.Application;
import Toybox.Graphics;
import Toybox.Lang;
import Toybox.WatchUi;

(:glance)
class OtpGlanceView extends WatchUi.GlanceView {

    function initialize() {
        GlanceView.initialize();
    }

    function onUpdate(dc as Graphics.Dc) as Void {
        var count = 0;
        var meta = Application.Storage.getValue("m");
        if (meta instanceof Dictionary) {
            var ids = meta["ids"];
            if (ids instanceof Array) {
                count = ids.size();
            }
        }
        var h = dc.getHeight();
        dc.setColor(Graphics.COLOR_WHITE, Graphics.COLOR_TRANSPARENT);
        dc.drawText(0, h / 2 - dc.getFontHeight(Graphics.FONT_GLANCE), Graphics.FONT_GLANCE, "OTP WALLET", Graphics.TEXT_JUSTIFY_LEFT);
        dc.setColor(Graphics.COLOR_LT_GRAY, Graphics.COLOR_TRANSPARENT);
        dc.drawText(0, h / 2, Graphics.FONT_GLANCE, count == 1 ? "1 entry" : count + " entries", Graphics.TEXT_JUSTIFY_LEFT);
        // The simulator starts in the glance; launch scripts open the app from it.
        Diag.shown("glance");
    }
}