Skip to content

Commit cd46238

Browse files
committed
weather 0.28: Fix UV positioning, hide when 0
1 parent 7ace5bd commit cd46238

File tree

3 files changed

+39
-31
lines changed

3 files changed

+39
-31
lines changed

apps/weather/ChangeLog

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@
2323
0.24: Redraw clock_info on update and provide color field for condition
2424
0.25: Added monochrome parameter to drawIcon in lib
2525
0.26: Expose update function (for use by iOS integration)
26-
0.27: Add UV index display
26+
0.27: Add UV index display
27+
0.28: Fix UV positioning, hide when 0

apps/weather/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ It also adds a ClockInfo list to Bangle.js.
77
You can view the full report through the app:
88

99
![Screenshot](screenshot.png)
10+
1011
## iOS Setup
11-
Use the iOS shortcut [here](https://www.icloud.com/shortcuts/dbf7159200d945179e0938c15e64f102). The shortcut uses Apple Weather for weather updates, and sends a notification, which is read by Bangle.js. To push weather every hour, or interval, you will need to create a shortcut automation for every time you want to push the weather.
12+
13+
Use the iOS shortcut [here](https://www.icloud.com/shortcuts/ae5f3d7d6ed3460c98a3396b267aa1c5). The shortcut uses Apple Weather for weather updates, and sends a notification, which is read by Bangle.js. To push weather every hour, or interval, you will need to create a shortcut automation for every time you want to push the weather.
14+
1215
## Android Setup
1316

1417
1. Install [Gadgetbridge for Android](https://f-droid.org/packages/nodomain.freeyourgadget.gadgetbridge/) on your phone.
@@ -51,15 +54,16 @@ When you first load QuickWeather, it will take you through the setup process. Yo
5154

5255
**Note:** at one time, the Weather Notification app also worked with Gadgetbridge. However, many users are reporting it's no longer seeing the OpenWeatherMap API key as valid. The app has not received any updates since August of 2020, and may be unmaintained.
5356

54-
5557
## Clock Infos
58+
5659
Tap on any clockInfo when focused to directly open the weather app.
5760
Adds:
5861
* Condition ClockInfo with condition icon
5962
* Temperature ClockInfo with condition icon.
6063
* Wind speed ClockInfo.
6164
* Chance of rain ClockInfo.
6265
* Temperature ClockInfo without condition icon.
66+
6367
## Settings
6468

6569
* Expiration timespan can be set after which the local weather data is considered as invalid

apps/weather/app.js

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,56 @@ Bangle.loadWidgets();
99
var layout = new Layout({type:"v", bgCol: g.theme.bg, c: [
1010
{filly: 1},
1111
{type: "h", filly: 0, c: [
12-
{type: "v", width: g.getWidth()/2, c: [ // Vertical container for icon + UV
12+
{type: "v", width: g.getWidth()/2, c: [ // Vertical container for icon
1313
{type: "custom", fillx: 1, height: g.getHeight()/2 - 30, valign: -1, txt: "unknown", id: "icon",
14-
render: l => weather.drawIcon(l, l.x+l.w/2, l.y+l.h/2, l.w/2-10)},
15-
{type: "custom", fillx: 1, height: 20, id: "uvDisplay",
14+
render: l => weather.drawIcon(l, l.x+l.w/2, l.y+l.h/2, l.w/2-5)},
15+
]},
16+
{type: "v", fillx: 1, c: [
17+
{type: "h", pad: 2, c: [
18+
{type: "txt", font: "18%", id: "temp", label: "000"},
19+
{type: "txt", font: "12%", valign: -1, id: "tempUnit", label: "°C"},
20+
]},
21+
{filly: 1},
22+
{type: "txt", font: "6x8", pad: 2, halign: 1, label: /*LANG*/"Humidity"},
23+
{type: "txt", font: "9%", pad: 2, halign: 1, id: "hum", label: "000%"},
24+
{type: "txt", font: "6x8", pad: [2, 2, 2, 2], halign: -1, label: /*LANG*/"Wind"},
25+
{type: "h", pad: [0, 2, 2, 2], halign: -1, c: [
26+
{type: "txt", font: "9%", pad: 2, id: "wind", label: "00"},
27+
{type: "txt", font: "6x8", pad: 2, valign: -1, id: "windUnit", label: "km/h"},
28+
]},
29+
{type: "custom", fillx: 1, height: 15, id: "uvDisplay",
1630
render: l => {
17-
if (!current || current.uv === undefined) return;
31+
if (!current || current.uv === undefined || current.uv === 0) return;
1832
const uv = Math.min(parseInt(current.uv), 11); // Cap at 11
1933

2034
// UV color thresholds: [max_value, color] based on WHO standards
2135
const colors = [[2,"#0F0"], [5,"#FF0"], [7,"#F80"], [10,"#F00"], [11,"#F0F"]];
2236
const color = colors.find(c => uv <= c[0])[1];
37+
const blockH = 8, blockW = 3;
2338

24-
// Setup and measure label
39+
// Draw UV title and blocks on same line
2540
g.setFont("6x8").setFontAlign(-1, 0);
26-
const label = "UV: ";
41+
const label = "UV";
2742
const labelW = g.stringWidth(label);
2843

29-
// Calculate centered position (4px block + 1px spacing) * blocks - last spacing
30-
const totalW = labelW + uv * 5 - (uv > 0 ? 1 : 0);
31-
const x = l.x + (l.w - totalW) / 2;
32-
const y = l.y + l.h;
44+
const x = l.x + 2;
45+
const y = l.y + l.h / 2;
3346

34-
// Draw label
47+
// Draw title
3548
g.setColor(g.theme.fg).drawString(label, x, y);
3649

37-
// Draw UV blocks
50+
// Draw UV blocks after title
3851
g.setColor(color);
3952
for (let i = 0; i < uv; i++) {
40-
g.fillRect(x + labelW + i * 5, y - 3, x + labelW + i * 5 + 3, y + 3);
53+
const blockX = x + labelW + 4 + i * (blockW + 2);
54+
g.fillRect(blockX, y - blockH/2, blockX + blockW, y + blockW/2);
4155
}
56+
57+
// Reset graphics state to prevent interference
58+
g.reset();
4259
}
4360
},
4461
]},
45-
{type: "v", fillx: 1, c: [
46-
{type: "h", pad: 2, c: [
47-
{type: "txt", font: "18%", id: "temp", label: "000"},
48-
{type: "txt", font: "12%", valign: -1, id: "tempUnit", label: "°C"},
49-
]},
50-
{filly: 1},
51-
{type: "txt", font: "6x8", pad: 2, halign: 1, label: /*LANG*/"Humidity"},
52-
{type: "txt", font: "9%", pad: 2, halign: 1, id: "hum", label: "000%"},
53-
{filly: 1},
54-
{type: "txt", font: "6x8", pad: 2, halign: -1, label: /*LANG*/"Wind"},
55-
{type: "h", halign: -1, c: [
56-
{type: "txt", font: "9%", pad: 2, id: "wind", label: "00"},
57-
{type: "txt", font: "6x8", pad: 2, valign: -1, id: "windUnit", label: "km/h"},
58-
]},
59-
]},
6062
]},
6163
{filly: 1},
6264
{type: "txt", font: "9%", wrap: true, height: g.getHeight()*0.18, fillx: 1, id: "cond", label: /*LANG*/"Weather condition"},
@@ -91,6 +93,7 @@ function draw() {
9193
layout.loc.label = current.loc;
9294
layout.updateTime.label = `${formatDuration(Date.now() - current.time)} ago`; // How to autotranslate this and similar?
9395
layout.update();
96+
layout.forgetLazyState();
9497
layout.render();
9598
}
9699

0 commit comments

Comments
 (0)