Skip to content

Watch4 complications #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion WatchApp Extension/ComplicationController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,30 @@ final class ComplicationController: NSObject, CLKComplicationDataSource {
let timeText = CLKRelativeDateTextProvider(date: Date(), style: .natural, units: .minute)

switch complication.family {
case .graphicCorner, .graphicCircular, .graphicRectangular, .graphicBezel:

case .graphicCorner:
if #available(watchOSApplicationExtension 5.0, *) {
let cornerTemplate = CLKComplicationTemplateGraphicCornerStackText()
cornerTemplate.outerTextProvider = glucoseText
cornerTemplate.innerTextProvider = timeText
cornerTemplate.outerTextProvider.tintColor = .green
template = cornerTemplate
} else {
// Fallback on earlier versions
template = nil
}
case .graphicCircular:
if #available(watchOSApplicationExtension 5.0, *) {
let circularTemplate = CLKComplicationTemplateGraphicCircularOpenGaugeSimpleText()
circularTemplate.gaugeProvider = CLKSimpleGaugeProvider(style: .fill, gaugeColor: .green, fillFraction: 1)
circularTemplate.centerTextProvider = CLKSimpleTextProvider(text: "120")
circularTemplate.bottomTextProvider = CLKSimpleTextProvider(text: "↘︎")
template = circularTemplate
} else {
// Fallback on earlier versions
template = nil
}
case .graphicRectangular, .graphicBezel:
template = nil
case .modularSmall:
let modularSmall = CLKComplicationTemplateModularSmallStackText()
Expand Down Expand Up @@ -126,5 +149,6 @@ final class ComplicationController: NSObject, CLKComplicationDataSource {

template?.tintColor = UIColor.tintColor
handler(template)

}
}
39 changes: 38 additions & 1 deletion WatchApp Extension/Extensions/CLKComplicationTemplate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,45 @@ extension CLKComplicationTemplate {
timeFormatter.dateStyle = .none
timeFormatter.timeStyle = .short


switch family {
case .graphicCorner, .graphicCircular, .graphicRectangular, .graphicBezel:
case .graphicCorner:
// ***************************************
// ** Apple Watch Series 4 Complication **
// ***************************************
// Corner Text
// Outer Text: Current Glucose and Trend
// Inner Text: timeText

if #available(watchOSApplicationExtension 5.0, *) {
let cornerTemplate = CLKComplicationTemplateGraphicCornerStackText()
cornerTemplate.outerTextProvider = glucoseAndTrendText
cornerTemplate.outerTextProvider.tintColor = .green
cornerTemplate.innerTextProvider = timeText
return cornerTemplate
} else {
// Fallback on earlier versions
return nil
}
case .graphicCircular:
// ***************************************
// ** Apple Watch Series 4 Complication **
// ***************************************
// Circular Gauge
// Full Ring
// Current Glucose in Center, Trend Arrow Below
// * future enhancement - update gauge colors to reflect loop status, or time in range for the day
if #available(watchOSApplicationExtension 5.0, *) {
let circularTemplate = CLKComplicationTemplateGraphicCircularOpenGaugeSimpleText()
circularTemplate.gaugeProvider = CLKSimpleGaugeProvider(style: .fill, gaugeColor: .green, fillFraction: 1)
circularTemplate.centerTextProvider = CLKSimpleTextProvider(text: glucoseString)
circularTemplate.bottomTextProvider = CLKSimpleTextProvider(text: (trend?.symbol ?? " "))
return circularTemplate
} else {
// Fallback on earlier versions
return nil
}
case .graphicRectangular, .graphicBezel:
return nil
case .modularSmall:
let template = CLKComplicationTemplateModularSmallStackText()
Expand Down
10 changes: 7 additions & 3 deletions WatchApp Extension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@
<string>$(PRODUCT_MODULE_NAME).ComplicationController</string>
<key>CLKComplicationSupportedFamilies</key>
<array>
<string>CLKComplicationFamilyModularSmall</string>
<string>CLKComplicationFamilyCircularSmall</string>
<string>CLKComplicationFamilyExtraLarge</string>
<string>CLKComplicationFamilyUtilitarianSmallFlat</string>
<string>CLKComplicationFamilyUtilitarianLarge</string>
<string>CLKComplicationFamilyGraphicBezel</string>
<string>CLKComplicationFamilyGraphicCircular</string>
<string>CLKComplicationFamilyGraphicCorner</string>
<string>CLKComplicationFamilyGraphicRectangular</string>
<string>CLKComplicationFamilyModularLarge</string>
<string>CLKComplicationFamilyModularSmall</string>
<string>CLKComplicationFamilyUtilitarianLarge</string>
<string>CLKComplicationFamilyUtilitarianSmall</string>
<string>CLKComplicationFamilyUtilitarianSmallFlat</string>
</array>
<key>NSExtension</key>
<dict>
Expand Down