@@ -43,21 +43,14 @@ final class ComplicationController: NSObject, CLKComplicationDataSource {
4343 private lazy var formatter = NumberFormatter ( )
4444
4545 func getCurrentTimelineEntry( for complication: CLKComplication , withHandler handler: ( @escaping ( CLKComplicationTimelineEntry ? ) -> Void ) ) {
46-
47- switch complication. family {
48- case . modularSmall:
49- if let context = ExtensionDelegate . shared ( ) . lastContext,
50- let glucose = context. glucose,
51- let unit = context. preferredGlucoseUnit,
52- let glucoseString = formatter. string ( from: NSNumber ( value: glucose. doubleValue ( for: unit) ) ) ,
53- let date = context. glucoseDate, date. timeIntervalSinceNow. minutes >= - 15 ,
54- let template = CLKComplicationTemplateModularSmallStackText ( line1: glucoseString, date: date)
55- {
56- handler ( CLKComplicationTimelineEntry ( date: date, complicationTemplate: template) )
57- } else {
58- handler ( nil )
59- }
60- default :
46+ if let context = ExtensionDelegate . shared ( ) . lastContext,
47+ let glucoseDate = context. glucoseDate,
48+ glucoseDate. timeIntervalSinceNow. minutes >= - 15 ,
49+ let template = CLKComplicationTemplate . templateForFamily ( complication. family, from: context)
50+ {
51+ template. tintColor = UIColor . tintColor
52+ handler ( CLKComplicationTimelineEntry ( date: glucoseDate, complicationTemplate: template) )
53+ } else {
6154 handler ( nil )
6255 }
6356 }
@@ -69,13 +62,12 @@ final class ComplicationController: NSObject, CLKComplicationDataSource {
6962
7063 func getTimelineEntries( for complication: CLKComplication , after date: Date , limit: Int , withHandler handler: ( @escaping ( [ CLKComplicationTimelineEntry ] ? ) -> Void ) ) {
7164 // Call the handler with the timeline entries after to the given date
72- if let context = ExtensionDelegate . shared ( ) . lastContext,
73- let glucose = context. glucose,
74- let unit = context. preferredGlucoseUnit,
75- let glucoseString = formatter. string ( from: NSNumber ( value: glucose. doubleValue ( for: unit) ) ) ,
76- let glucoseDate = context. glucoseDate, glucoseDate. timeIntervalSince ( date) > 0 ,
77- let template = CLKComplicationTemplateModularSmallStackText ( line1: glucoseString, date: glucoseDate)
65+ if let context = ExtensionDelegate . shared ( ) . lastContext,
66+ let glucoseDate = context. glucoseDate,
67+ glucoseDate. timeIntervalSince ( date) > 0 ,
68+ let template = CLKComplicationTemplate . templateForFamily ( complication. family, from: context)
7869 {
70+ template. tintColor = UIColor . tintColor
7971 handler ( [ CLKComplicationTimelineEntry ( date: glucoseDate, complicationTemplate: template) ] )
8072 } else {
8173 handler ( nil )
@@ -85,16 +77,41 @@ final class ComplicationController: NSObject, CLKComplicationDataSource {
8577 // MARK: - Placeholder Templates
8678
8779 func getLocalizableSampleTemplate( for complication: CLKComplication , withHandler handler: @escaping ( CLKComplicationTemplate ? ) -> Void ) {
88- switch complication. family {
89- case . modularSmall:
90- let template = CLKComplicationTemplateModularSmallStackText ( )
9180
92- template. line1TextProvider = CLKSimpleTextProvider ( text: " -- " , shortText: " -- " , accessibilityLabel: " No glucose value available " )
93- template. line2TextProvider = CLKSimpleTextProvider . localizableTextProvider ( withStringsFileTextKey: " mg/dL " )
81+ let template : CLKComplicationTemplate ?
82+
83+ let glucoseText = CLKSimpleTextProvider . localizableTextProvider ( withStringsFileTextKey: " 120↘︎ " , shortTextKey: " 120 " )
84+ let timeText = CLKTimeTextProvider ( date: Date ( ) )
9485
95- handler ( template)
86+ switch complication. family {
87+ case . modularSmall:
88+ let modularSmall = CLKComplicationTemplateModularSmallStackText ( )
89+ modularSmall. line1TextProvider = glucoseText
90+ modularSmall. line2TextProvider = timeText
91+ template = modularSmall
92+ case . circularSmall:
93+ let circularSmall = CLKComplicationTemplateCircularSmallSimpleText ( )
94+ circularSmall. textProvider = glucoseText
95+ template = circularSmall
96+ case . extraLarge:
97+ let extraLarge = CLKComplicationTemplateExtraLargeStackText ( )
98+ extraLarge. line1TextProvider = glucoseText
99+ extraLarge. line2TextProvider = timeText
100+ template = extraLarge
101+ case . utilitarianSmallFlat:
102+ let utilitarianSmallFlat = CLKComplicationTemplateUtilitarianSmallFlat ( )
103+ utilitarianSmallFlat. textProvider = CLKSimpleTextProvider . localizableTextProvider ( withStringsFileFormatKey: " UtilitarianSmallFlat " , textProviders: [ glucoseText, timeText] )
104+ template = utilitarianSmallFlat
105+ case . utilitarianLarge:
106+ let utilitarianLarge = CLKComplicationTemplateUtilitarianLargeFlat ( )
107+ let eventualGlucoseText = CLKSimpleTextProvider . localizableTextProvider ( withStringsFileTextKey: " 75 " )
108+ utilitarianLarge. textProvider = CLKSimpleTextProvider . localizableTextProvider ( withStringsFileFormatKey: " UtilitarianLargeFlat " , textProviders: [ glucoseText, eventualGlucoseText, timeText] )
109+ template = utilitarianLarge
96110 default :
97- handler ( nil )
111+ template = nil
98112 }
113+
114+ template? . tintColor = UIColor . tintColor
115+ handler ( template)
99116 }
100117}
0 commit comments