Skip to content

Commit 2c249d5

Browse files
authored
Merge pull request #5 from apabari/Watch4-Complications
Watch4 complications
2 parents a5bc15a + 6a6d45c commit 2c249d5

3 files changed

Lines changed: 70 additions & 5 deletions

File tree

WatchApp Extension/ComplicationController.swift

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,30 @@ final class ComplicationController: NSObject, CLKComplicationDataSource {
9292
let timeText = CLKRelativeDateTextProvider(date: Date(), style: .natural, units: .minute)
9393

9494
switch complication.family {
95-
case .graphicCorner, .graphicCircular, .graphicRectangular, .graphicBezel:
95+
96+
case .graphicCorner:
97+
if #available(watchOSApplicationExtension 5.0, *) {
98+
let cornerTemplate = CLKComplicationTemplateGraphicCornerStackText()
99+
cornerTemplate.outerTextProvider = glucoseText
100+
cornerTemplate.innerTextProvider = timeText
101+
cornerTemplate.outerTextProvider.tintColor = .green
102+
template = cornerTemplate
103+
} else {
104+
// Fallback on earlier versions
105+
template = nil
106+
}
107+
case .graphicCircular:
108+
if #available(watchOSApplicationExtension 5.0, *) {
109+
let circularTemplate = CLKComplicationTemplateGraphicCircularOpenGaugeSimpleText()
110+
circularTemplate.gaugeProvider = CLKSimpleGaugeProvider(style: .fill, gaugeColor: .green, fillFraction: 1)
111+
circularTemplate.centerTextProvider = CLKSimpleTextProvider(text: "120")
112+
circularTemplate.bottomTextProvider = CLKSimpleTextProvider(text: "↘︎")
113+
template = circularTemplate
114+
} else {
115+
// Fallback on earlier versions
116+
template = nil
117+
}
118+
case .graphicRectangular, .graphicBezel:
96119
template = nil
97120
case .modularSmall:
98121
let modularSmall = CLKComplicationTemplateModularSmallStackText()
@@ -126,5 +149,6 @@ final class ComplicationController: NSObject, CLKComplicationDataSource {
126149

127150
template?.tintColor = UIColor.tintColor
128151
handler(template)
152+
129153
}
130154
}

WatchApp Extension/Extensions/CLKComplicationTemplate.swift

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,45 @@ extension CLKComplicationTemplate {
4646
timeFormatter.dateStyle = .none
4747
timeFormatter.timeStyle = .short
4848

49+
4950
switch family {
50-
case .graphicCorner, .graphicCircular, .graphicRectangular, .graphicBezel:
51+
case .graphicCorner:
52+
// ***************************************
53+
// ** Apple Watch Series 4 Complication **
54+
// ***************************************
55+
// Corner Text
56+
// Outer Text: Current Glucose and Trend
57+
// Inner Text: timeText
58+
59+
if #available(watchOSApplicationExtension 5.0, *) {
60+
let cornerTemplate = CLKComplicationTemplateGraphicCornerStackText()
61+
cornerTemplate.outerTextProvider = glucoseAndTrendText
62+
cornerTemplate.outerTextProvider.tintColor = .green
63+
cornerTemplate.innerTextProvider = timeText
64+
return cornerTemplate
65+
} else {
66+
// Fallback on earlier versions
67+
return nil
68+
}
69+
case .graphicCircular:
70+
// ***************************************
71+
// ** Apple Watch Series 4 Complication **
72+
// ***************************************
73+
// Circular Gauge
74+
// Full Ring
75+
// Current Glucose in Center, Trend Arrow Below
76+
// * future enhancement - update gauge colors to reflect loop status, or time in range for the day
77+
if #available(watchOSApplicationExtension 5.0, *) {
78+
let circularTemplate = CLKComplicationTemplateGraphicCircularOpenGaugeSimpleText()
79+
circularTemplate.gaugeProvider = CLKSimpleGaugeProvider(style: .fill, gaugeColor: .green, fillFraction: 1)
80+
circularTemplate.centerTextProvider = CLKSimpleTextProvider(text: glucoseString)
81+
circularTemplate.bottomTextProvider = CLKSimpleTextProvider(text: (trend?.symbol ?? " "))
82+
return circularTemplate
83+
} else {
84+
// Fallback on earlier versions
85+
return nil
86+
}
87+
case .graphicRectangular, .graphicBezel:
5188
return nil
5289
case .modularSmall:
5390
let template = CLKComplicationTemplateModularSmallStackText()

WatchApp Extension/Info.plist

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@
2626
<string>$(PRODUCT_MODULE_NAME).ComplicationController</string>
2727
<key>CLKComplicationSupportedFamilies</key>
2828
<array>
29-
<string>CLKComplicationFamilyModularSmall</string>
3029
<string>CLKComplicationFamilyCircularSmall</string>
3130
<string>CLKComplicationFamilyExtraLarge</string>
32-
<string>CLKComplicationFamilyUtilitarianSmallFlat</string>
33-
<string>CLKComplicationFamilyUtilitarianLarge</string>
31+
<string>CLKComplicationFamilyGraphicBezel</string>
32+
<string>CLKComplicationFamilyGraphicCircular</string>
33+
<string>CLKComplicationFamilyGraphicCorner</string>
34+
<string>CLKComplicationFamilyGraphicRectangular</string>
3435
<string>CLKComplicationFamilyModularLarge</string>
36+
<string>CLKComplicationFamilyModularSmall</string>
37+
<string>CLKComplicationFamilyUtilitarianLarge</string>
3538
<string>CLKComplicationFamilyUtilitarianSmall</string>
39+
<string>CLKComplicationFamilyUtilitarianSmallFlat</string>
3640
</array>
3741
<key>NSExtension</key>
3842
<dict>

0 commit comments

Comments
 (0)