Skip to content

Commit 025e405

Browse files
committed
#329: Improved layout of the systemsmall widget
1 parent 4dd30ca commit 025e405

File tree

8 files changed

+143
-100
lines changed

8 files changed

+143
-100
lines changed

Gemfile.lock

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,22 @@ GEM
99
public_suffix (>= 2.0.2, < 7.0)
1010
artifactory (3.0.17)
1111
atomos (0.1.3)
12-
aws-eventstream (1.3.0)
13-
aws-partitions (1.968.0)
14-
aws-sdk-core (3.201.5)
12+
aws-eventstream (1.3.1)
13+
aws-partitions (1.1050.0)
14+
aws-sdk-core (3.218.1)
1515
aws-eventstream (~> 1, >= 1.3.0)
16-
aws-partitions (~> 1, >= 1.651.0)
16+
aws-partitions (~> 1, >= 1.992.0)
1717
aws-sigv4 (~> 1.9)
18+
base64
1819
jmespath (~> 1, >= 1.6.1)
19-
aws-sdk-kms (1.88.0)
20-
aws-sdk-core (~> 3, >= 3.201.0)
20+
aws-sdk-kms (1.98.0)
21+
aws-sdk-core (~> 3, >= 3.216.0)
2122
aws-sigv4 (~> 1.5)
22-
aws-sdk-s3 (1.159.0)
23-
aws-sdk-core (~> 3, >= 3.201.0)
23+
aws-sdk-s3 (1.181.0)
24+
aws-sdk-core (~> 3, >= 3.216.0)
2425
aws-sdk-kms (~> 1)
2526
aws-sigv4 (~> 1.5)
26-
aws-sigv4 (1.9.1)
27+
aws-sigv4 (1.11.0)
2728
aws-eventstream (~> 1, >= 1.0.2)
2829
babosa (1.0.4)
2930
base64 (0.2.0)
@@ -33,14 +34,14 @@ GEM
3334
commander (4.6.0)
3435
highline (~> 2.0.0)
3536
declarative (0.0.20)
36-
digest-crc (0.6.5)
37+
digest-crc (0.7.0)
3738
rake (>= 12.0.0, < 14.0.0)
3839
domain_name (0.5.20190701)
3940
unf (>= 0.0.5, < 1.0.0)
4041
dotenv (2.8.1)
4142
emoji_regex (3.2.3)
4243
excon (0.109.0)
43-
faraday (1.10.3)
44+
faraday (1.10.4)
4445
faraday-em_http (~> 1.0)
4546
faraday-em_synchrony (~> 1.0)
4647
faraday-excon (~> 1.1)
@@ -59,17 +60,17 @@ GEM
5960
faraday-em_synchrony (1.0.0)
6061
faraday-excon (1.1.0)
6162
faraday-httpclient (1.0.1)
62-
faraday-multipart (1.0.4)
63-
multipart-post (~> 2)
63+
faraday-multipart (1.1.0)
64+
multipart-post (~> 2.0)
6465
faraday-net_http (1.0.2)
6566
faraday-net_http_persistent (1.2.0)
6667
faraday-patron (1.0.0)
6768
faraday-rack (1.0.0)
6869
faraday-retry (1.0.3)
69-
faraday_middleware (1.2.0)
70+
faraday_middleware (1.2.1)
7071
faraday (~> 1.0)
71-
fastimage (2.3.1)
72-
fastlane (2.222.0)
72+
fastimage (2.4.0)
73+
fastlane (2.226.0)
7374
CFPropertyList (>= 2.3, < 4.0.0)
7475
addressable (>= 2.8, < 3.0.0)
7576
artifactory (~> 3.0)
@@ -85,6 +86,7 @@ GEM
8586
faraday-cookie_jar (~> 0.0.6)
8687
faraday_middleware (~> 1.0)
8788
fastimage (>= 2.1.0, < 3.0.0)
89+
fastlane-sirp (>= 1.0.0)
8890
gh_inspector (>= 1.1.2, < 2.0.0)
8991
google-apis-androidpublisher_v3 (~> 0.3)
9092
google-apis-playcustomapp_v1 (~> 0.1)
@@ -108,8 +110,10 @@ GEM
108110
tty-spinner (>= 0.8.0, < 1.0.0)
109111
word_wrap (~> 1.0.0)
110112
xcodeproj (>= 1.13.0, < 2.0.0)
111-
xcpretty (~> 0.3.0)
113+
xcpretty (~> 0.4.0)
112114
xcpretty-travis-formatter (>= 0.0.3, < 2.0.0)
115+
fastlane-sirp (1.0.0)
116+
sysrandom (~> 1.0)
113117
gh_inspector (1.1.3)
114118
google-apis-androidpublisher_v3 (0.54.0)
115119
google-apis-core (>= 0.11.0, < 2.a)
@@ -148,34 +152,34 @@ GEM
148152
os (>= 0.9, < 2.0)
149153
signet (>= 0.16, < 2.a)
150154
highline (2.0.3)
151-
http-cookie (1.0.7)
155+
http-cookie (1.0.8)
152156
domain_name (~> 0.5)
153157
httpclient (2.8.3)
154158
jmespath (1.6.2)
155-
json (2.7.2)
156-
jwt (2.8.2)
159+
json (2.7.6)
160+
jwt (2.10.1)
157161
base64
158162
mini_magick (4.13.2)
159163
mini_mime (1.1.5)
160164
multi_json (1.15.0)
161165
multipart-post (2.4.1)
162-
nanaimo (0.3.0)
166+
nanaimo (0.4.0)
163167
naturally (2.2.1)
164168
nkf (0.2.0)
165-
optparse (0.5.0)
169+
optparse (0.6.0)
166170
os (1.1.4)
167-
plist (3.7.1)
171+
plist (3.7.2)
168172
public_suffix (5.1.1)
169173
rake (13.2.1)
170174
representable (3.2.0)
171175
declarative (< 0.1.0)
172176
trailblazer-option (>= 0.1.1, < 0.2.0)
173177
uber (< 0.2.0)
174178
retriable (3.1.2)
175-
rexml (3.3.9)
176-
rouge (2.0.7)
179+
rexml (3.4.0)
180+
rouge (3.28.0)
177181
ruby2_keywords (0.0.5)
178-
rubyzip (2.3.2)
182+
rubyzip (2.4.1)
179183
security (0.1.5)
180184
signet (0.18.0)
181185
addressable (~> 2.8)
@@ -185,6 +189,7 @@ GEM
185189
simctl (1.6.10)
186190
CFPropertyList
187191
naturally
192+
sysrandom (1.0.5)
188193
terminal-notifier (2.0.0)
189194
terminal-table (3.0.2)
190195
unicode-display_width (>= 1.1.1, < 3)
@@ -195,17 +200,17 @@ GEM
195200
tty-cursor (~> 0.7)
196201
uber (0.1.0)
197202
unf (0.2.0)
198-
unicode-display_width (2.5.0)
203+
unicode-display_width (2.6.0)
199204
word_wrap (1.0.0)
200-
xcodeproj (1.25.0)
205+
xcodeproj (1.27.0)
201206
CFPropertyList (>= 2.3.3, < 4.0)
202207
atomos (~> 0.1.3)
203208
claide (>= 1.0.2, < 2.0)
204209
colored2 (~> 3.1)
205-
nanaimo (~> 0.3.0)
206-
rexml (>= 3.3.2, < 4.0)
207-
xcpretty (0.3.0)
208-
rouge (~> 2.0.7)
210+
nanaimo (~> 0.4.0)
211+
rexml (>= 3.3.6, < 4.0)
212+
xcpretty (0.4.0)
213+
rouge (~> 3.28.0)
209214
xcpretty-travis-formatter (1.0.1)
210215
xcpretty (~> 0.2, >= 0.0.7)
211216

nightguard WatchKit App/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleVersion</key>
24-
<string>912</string>
24+
<string>913</string>
2525
<key>CLKComplicationPrincipalClass</key>
2626
<string>$(PRODUCT_MODULE_NAME).ComplicationController</string>
2727
<key>NSAppTransportSecurity</key>
Lines changed: 82 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,103 @@
11
//
2-
// SystemSmallView.swift
3-
// nightguard Widget Extension
2+
// Created by Dirk Hermanns on 23.05.2025.
3+
// Copyright © 2025 private. All rights reserved.
44
//
5-
// Created by Philipp Pöml on 26.05.24.
6-
//
7-
8-
import Foundation
95
import SwiftUI
106
import WidgetKit
117

12-
struct SystemSmallView : View {
13-
8+
struct SystemSmallView: View {
149
var entry: NightscoutDataEntry
15-
10+
1611
var body: some View {
17-
VStack {
18-
Image ("WidgetImageBlack")
19-
.resizable()
20-
.aspectRatio(contentMode: .fit)
12+
ZStack {
13+
Color.black
14+
15+
VStack {
2116
HStack {
22-
VStack {
23-
ForEach(entry.lastBGValues, id: \.self.id) { bgEntry in
24-
//Text("\(calculateAgeInMinutes(from:NSNumber(value: bgEntry.timestamp)))m")
25-
if (entry.lastBGValues.first?.id == bgEntry.id) {
26-
Text(Date.now.addingTimeInterval(-(Date.now.timeIntervalSince1970 - (bgEntry.timestamp / 1000))), style: .timer)
27-
.foregroundColor(Color(entry.sgvColor))
28-
.frame(maxWidth: .infinity, alignment: .trailing)
29-
.monospacedDigit()
30-
.multilineTextAlignment(.trailing)
31-
} else {
32-
Text("+\(calculateAgeInMinutes(from:NSNumber(value: Date.now.timeIntervalSince1970 * 1000 + bgEntry.timestamp - (entry.lastBGValues.first?.timestamp ?? 0))))m")
33-
.foregroundColor(Color(entry.sgvColor))
34-
.frame(maxWidth: .infinity, alignment: .trailing)
35-
}
36-
}
37-
}
38-
.padding(.trailing, 20)
39-
VStack {
40-
ForEach(entry.lastBGValues, id: \.self.id) { bgEntry in
41-
//Text("\(String(bgEntry.value)) \(bgEntry.delta)")
17+
Image("WidgetImageBlack") // Custom owl logo
18+
.resizable()
19+
.aspectRatio(contentMode: ContentMode.fit)
20+
.frame(width: 30, height: 30)
21+
.padding(.top, 5)
22+
Spacer()
23+
}
24+
Spacer()
25+
}
26+
27+
28+
VStack {
29+
// Header with time
30+
HStack {
31+
Spacer()
32+
Text(entry.entryDate, style: .time)
33+
.foregroundColor(.white)
34+
.font(.caption2)
35+
}
36+
37+
// Central glucose value
38+
if let latest = entry.lastBGValues.first {
39+
Text("\(String(latest.value))")
40+
.foregroundColor(Color(entry.sgvColor))
41+
.font(.system(size: 60, weight: .bold))
42+
.frame(height: 50)
43+
} else {
44+
Text("---")
45+
.font(.system(size: 60, weight: .bold))
46+
.foregroundColor(.gray)
47+
}
48+
49+
// Current delta and arrow
50+
if let latest = entry.lastBGValues.first {
51+
Text("\(latest.delta) \(latest.arrow)")
52+
.foregroundColor(Color(entry.sgvColor))
53+
.font(.caption)
54+
}
55+
56+
Divider()
57+
.background(Color.white)
58+
59+
// Two previous entries
60+
if entry.lastBGValues.count > 1 {
61+
ForEach(Array(entry.lastBGValues.dropFirst()), id: \.self.id) { bgEntry in
62+
HStack {
63+
Text("+\(calculateAgeInMinutes(from:NSNumber(value: Date.now.timeIntervalSince1970 * 1000 + bgEntry.timestamp - (entry.lastBGValues.first?.timestamp ?? 0))))m")
64+
.foregroundColor(Color(entry.sgvColor))
65+
.font(.caption2)
4266
Text("\(String(bgEntry.value)) \(bgEntry.delta) \(bgEntry.arrow)")
4367
.foregroundColor(Color(entry.sgvColor))
44-
.frame(maxWidth: .infinity, alignment: .leading)
45-
}
46-
.padding(.leading, -20)
47-
}
48-
if entry.lastBGValues.isEmpty {
49-
VStack {
50-
Text("--- --- ---")
68+
.font(.caption2)
5169
}
5270
}
5371
}
72+
73+
// Optional error message
5474
if !entry.errorMessage.isEmpty {
55-
Text("\(entry.errorMessage)")
75+
Text(entry.errorMessage)
5676
.font(.system(size: 6))
77+
.foregroundColor(.white)
78+
.padding(.top, 2)
5779
}
58-
//Text(entry.entryDate, style: .time)
59-
//Text("\(snoozedForMinutes(snoozeTimestamp: entry.snoozedUntilTimestamp))min Snoozed")
6080
}
61-
.widgetAccentable(true)
62-
.unredacted()
81+
}
6382
}
64-
65-
func snoozedForMinutes(snoozeTimestamp: TimeInterval) -> Int {
66-
let currentTimestamp = Date().timeIntervalSince1970
67-
let snoozedMinutes = Int((snoozeTimestamp - currentTimestamp) / 60)
68-
if snoozedMinutes < 0 {
69-
return 0
83+
84+
// Helper: Time difference in minutes
85+
func calculateAgeInMinutes(from timestamp: NSNumber) -> Int {
86+
let timeDiff = Date().timeIntervalSince1970 - (timestamp.doubleValue / 1000)
87+
return Int(timeDiff / 60)
88+
}
89+
90+
// Helper: Match string arrow to SF Symbol
91+
func symbolForArrow(_ arrow: String) -> String {
92+
switch arrow {
93+
case "DoubleUp": return "arrow.up.to.line"
94+
case "SingleUp": return "arrow.up"
95+
case "FortyFiveUp": return "arrow.up.right"
96+
case "Flat": return "arrow.right"
97+
case "FortyFiveDown": return "arrow.down.right"
98+
case "SingleDown": return "arrow.down"
99+
case "DoubleDown": return "arrow.down.to.line"
100+
default: return "minus"
70101
}
71-
return snoozedMinutes
72102
}
73103
}

nightguard Widget Extension/nightguard_Widget_Extension.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ struct NightguardEntryView : View {
105105

106106
var body: some View {
107107
switch widgetFamily {
108-
case .systemSmall:
109-
SystemSmallView(entry: entry)
110-
.widgetBackground(backgroundView: Color.black)
108+
case .systemSmall:
109+
SystemSmallView(entry: entry)
110+
.widgetBackground(backgroundView: Color.black)
111111
case .accessoryCircular:
112112
AccessoryCircularView(entry: entry)
113113
.widgetBackground(backgroundView: background())

0 commit comments

Comments
 (0)