-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathnightguard_Complication.swift
213 lines (181 loc) · 7.58 KB
/
nightguard_Complication.swift
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
//
// nightguard_Complication_Extension.swift
// nightguard Complication Extension
//
// Created by Dirk Hermanns on 02.04.23.
// Copyright © 2023 private. All rights reserved.
//
import WidgetKit
import SwiftUI
import Intents
extension View {
func widgetBackground(backgroundView: some View) -> some View {
if #available(watchOS 10.0, *) {
return containerBackground(for: .widget) {
backgroundView
}
} else {
return background(backgroundView)
}
}
}
@main
struct NightguardWidgetsBundle: WidgetBundle {
var body: some Widget {
NightguardDefaultWidgets()
NightguardTimestampWidgets()
NightguardGaugeWidgets()
}
}
struct NightguardDefaultWidgets: Widget {
var provider = NightguardTimelineProvider(displayName:
NSLocalizedString("BG Text", comment: "Text Widget Display Name"))
var body: some WidgetConfiguration {
StaticConfiguration(
kind: "org.duckdns.dhe.nightguard.NightguardDefaultWidgets",
provider: provider
) { entry in
NightguardEntryView(entry: entry)
}
.configurationDisplayName(
NSLocalizedString("BG Values as Text", comment: "Widget Configuration Display Name"))
.description(provider.displayName)
.supportedFamilies([
.accessoryInline,
.accessoryCorner,
.accessoryCircular,
.accessoryRectangular
])
}
}
struct NightguardTimestampWidgets: Widget {
var provider = NightguardTimelineProvider(displayName:
NSLocalizedString("BG Text", comment: "Text Widget Timestamp Display"))
var body: some WidgetConfiguration {
StaticConfiguration(
kind: "org.duckdns.dhe.nightguard.NightguardTimestampWidgets",
provider: provider
) { entry in
NightguardTimestampEntryView(entry: entry)
}
.configurationDisplayName(
NSLocalizedString("BG with absolute Time", comment: "Widget Configuration Display Name"))
.description(provider.displayName)
.supportedFamilies([
.accessoryRectangular
])
}
}
struct NightguardGaugeWidgets: Widget {
var provider = NightguardTimelineProvider(displayName:
NSLocalizedString("BG Gauge", comment: "Gauge Widget Display Name"))
var body: some WidgetConfiguration {
StaticConfiguration(
kind: "org.duckdns.dhe.nightguard.NightguardGaugeWidgets",
provider: provider
) { entry in
NightguardGaugeEntryView(entry: entry)
}
.configurationDisplayName(
NSLocalizedString("BG Values as Gauge", comment: "Gauge Widget Configuration Display Name"))
.description(provider.displayName)
.supportedFamilies([
.accessoryCorner,
.accessoryCircular
])
}
}
struct nightguard_Complication_Extension_Previews: PreviewProvider {
static var previews: some View {
NightguardEntryView(entry: NightscoutDataEntry.previewValues)
.previewContext(WidgetPreviewContext(family: .accessoryRectangular))
.previewDisplayName("Acc_Rect")
NightguardEntryView(entry: NightscoutDataEntry.previewValues)
.previewContext(WidgetPreviewContext(family: .accessoryInline))
.previewDisplayName("Acc_Inline")
NightguardEntryView(entry: NightscoutDataEntry.previewValues)
.previewContext(WidgetPreviewContext(family: .accessoryCorner))
.previewDisplayName("Acc_Corner")
NightguardEntryView(entry: NightscoutDataEntry.previewValues)
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
.previewDisplayName("Acc_Circ")
NightguardGaugeEntryView(entry: NightscoutDataEntry.previewValues)
.previewContext(WidgetPreviewContext(family: .accessoryCorner))
.previewDisplayName("Gauge_Acc_Corner")
NightguardGaugeEntryView(entry: NightscoutDataEntry.previewValues)
.previewContext(WidgetPreviewContext(family: .accessoryCircular))
.previewDisplayName("Gauge_Acc_Circ")
}
}
struct NightguardEntryView : View {
@Environment(\.widgetFamily) var widgetFamily
var entry: NightscoutDataEntry
var body: some View {
switch widgetFamily {
case .accessoryCorner:
AccessoryCornerView(entry: entry)
.widgetBackground(backgroundView: background())
case .accessoryCircular:
AccessoryCircularView(entry: entry)
.widgetBackground(backgroundView: background())
case .accessoryInline:
AccessoryInlineView(entry: entry)
case .accessoryRectangular:
AccessoryRectangularView(entry: entry)
.widgetBackground(backgroundView: background())
@unknown default:
//mandatory as there are more widget families as in lockscreen widgets etc
Text(NSLocalizedString("Not an implemented widget yet", comment: "Gauge Widget Not Implemented Error Message"))
}
}
}
struct NightguardTimestampEntryView : View {
@Environment(\.widgetFamily) var widgetFamily
var entry: NightscoutDataEntry
var body: some View {
switch widgetFamily {
case .accessoryRectangular:
AccessoryRectangularTimestampView(entry: entry)
.widgetBackground(backgroundView: background())
case .accessoryCorner, .accessoryCircular, .accessoryInline:
//mandatory as there are more widget families as in lockscreen widgets etc
Text(NSLocalizedString("Not an implemented widget yet", comment: "Timestmap Widget Not Implemented Error Message"))
@unknown default:
//mandatory as there are more widget families as in lockscreen widgets etc
Text(NSLocalizedString("Not an implemented widget yet", comment: "Timestmap Widget Not Implemented Error Message"))
}
}
}
struct NightguardGaugeEntryView : View {
@Environment(\.widgetFamily) var widgetFamily
var entry: NightscoutDataEntry
var body: some View {
switch widgetFamily {
case .accessoryCorner:
AccessoryCornerGaugeView(entry: entry)
.widgetBackground(backgroundView: background())
case .accessoryCircular:
AccessoryCircularGaugeView(entry: entry)
.widgetBackground(backgroundView: background())
default:
//mandatory as there are more widget families as in lockscreen widgets etc
Text(NSLocalizedString("No Gauge Support for this widget!", comment: "Gauge Widget Not Supported Error Message"))
}
}
}
//struct NightguardGaugePreviews: PreviewProvider {
// static var previews: some View {
//
// NightguardEntryView(entry: NightscoutDataEntry.previewValues)
// .previewContext(WidgetPreviewContext(family: .accessoryRectangular))
//
// NightguardEntryView(entry: NightscoutDataEntry.previewValues)
// .previewContext(WidgetPreviewContext(family: .accessoryCircular))
//
// NightguardEntryView(entry: NightscoutDataEntry.previewValues)
// .previewContext(WidgetPreviewContext(family: .accessoryCorner))
//
// NightguardEntryView(entry: NightscoutDataEntry.previewValues)
// .previewContext(WidgetPreviewContext(family: .accessoryInline))
// }
//}