Skip to content

Commit c262b64

Browse files
committed
Merge complications changes back into dev (they were accidentally merged to master)
1 parent f1e4342 commit c262b64

File tree

10 files changed

+153
-81
lines changed

10 files changed

+153
-81
lines changed

Loop.xcodeproj/project.pbxproj

Lines changed: 22 additions & 27 deletions
Large diffs are not rendered by default.

Loop/Managers/StatusExtensionDataManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ extension StatusExtensionDataManager: CustomDebugStringConvertible {
109109
var debugDescription: String {
110110
return [
111111
"## StatusExtensionDataManager",
112+
"appGroupName: \(Bundle.main.appGroupSuiteName)",
112113
"statusExtensionContext: \(String(reflecting: defaults?.statusExtensionContext))"
113114
].joined(separator: "\n")
114115
}

Loop/gallery.ckcomplication/A307227B-6EFF-4242-A538-2C9AC617E041.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

Loop/gallery.ckcomplication/Base.lproj/ckcomplication.strings

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,10 @@
77
*/
88

99
/* The complication template example unit string */
10-
"mg/dL" = "mg/dL"
10+
"120↘︎" = "120↘︎";
11+
12+
/* Utilitarian small flat format string (1: Glucose & Trend symbol) (2: Time) */
13+
"UtilitarianSmallFlat" = "%1@ %2@";
14+
15+
/* Utilitarian small flat format string (1: Glucose & Trend symbol) (2: Eventual Glucose) (3: Time) */
16+
"UtilitarianLargeFlat" = "%1@%2@ %3@";
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{
22
"supported complication families" : {
3-
"0" : "A307227B-6EFF-4242-A538-2C9AC617E041.json"
3+
"3" : "CFB33AC2-7CD0-43A0-804F-F9A0EEC37480.json",
4+
"6" : "E87B02EB-57B2-4E9D-B371-E0BA2DD55C19.json",
5+
"4" : "B922BD0B-9601-45C9-B84D-ECB9C8235322.json",
6+
"0" : "69B78E1F-415D-4E9E-8E56-E486517658FC.json",
7+
"7" : "AB5AF86D-FF8F-493B-A738-4BB590C8A45E.json"
48
},
59
"client ID" : "com.loudnate.Loop.watchkitapp.watchkitextension"
610
}

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ Bluetooth LE communication with Minimed pumps is enabled by the [RileyLink](http
9292

9393
[Sign up for the Loop Users announcement list](https://groups.google.com/forum/#!forum/loop-ios-users) to stay informed of critical issues that may arise.
9494

95-
[Please visit the Wiki for a "Guide to Loop" setup, installation, FAQs, and use.](https://github.com/LoopKit/Loop/wiki)
95+
Please use the [Guide to Loop](https://github.com/LoopKit/Loop/wiki/Guide) for building, installation, and configuration instructions.
96+
97+
For FAQs and other tips, refer to the [Wiki](https://github.com/LoopKit/Loop/wiki)
9698

9799
(Note: there is also a tab for the Wiki at the top of this page)
98100

WatchApp Extension/Base.lproj/ckcomplication.strings

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,10 @@
77
*/
88

99
/* The complication template example unit string */
10-
"mg/dL" = "mg/dL"
10+
"120↘︎" = "120↘︎";
11+
12+
/* Utilitarian small flat format string (1: Glucose & Trend symbol) (2: Time) */
13+
"UtilitarianSmallFlat" = "%1@ %2@";
14+
15+
/* Utilitarian small flat format string (1: Glucose & Trend symbol) (2: Eventual Glucose) (3: Time) */
16+
"UtilitarianLargeFlat" = "%1@%2@ %3@";

WatchApp Extension/ComplicationController.swift

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

WatchApp Extension/Extensions/CLKComplicationTemplate.swift

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,69 @@ import ClockKit
1010
import Foundation
1111

1212

13-
extension CLKComplicationTemplateModularSmallStackText {
13+
extension CLKComplicationTemplate {
1414

15-
convenience init?(line1: String?, date: Date?) {
16-
guard let line1 = line1, let date = date else {
15+
static func templateForFamily(_ family: CLKComplicationFamily, from context: WatchContext) -> CLKComplicationTemplate? {
16+
17+
guard let glucose = context.glucose,
18+
let unit = context.preferredGlucoseUnit
19+
else {
1720
return nil
1821
}
1922

20-
self.init()
23+
let formatter = NumberFormatter.glucoseFormatter(for: unit)
2124

22-
line1TextProvider = CLKSimpleTextProvider(text: line1)
23-
line2TextProvider = CLKTimeTextProvider(date: date)
24-
}
25+
guard let glucoseString = formatter.string(from: NSNumber(value: glucose.doubleValue(for: unit))),
26+
let date = context.glucoseDate else
27+
{
28+
return nil
29+
}
30+
31+
var glucoseStrings = [glucoseString]
32+
var accessibilityStrings = [glucoseString]
33+
var eventualGlucoseText: CLKSimpleTextProvider?
34+
35+
if let trend = context.glucoseTrend {
36+
glucoseStrings.append(trend.symbol)
37+
accessibilityStrings.append(trend.localizedDescription)
38+
}
2539

40+
if let eventualGlucose = context.eventualGlucose,
41+
let eventualGlucoseString = formatter.string(from: NSNumber(value: eventualGlucose.doubleValue(for: unit)))
42+
{
43+
eventualGlucoseText = CLKSimpleTextProvider(text: eventualGlucoseString)
44+
}
45+
46+
let glucoseText = CLKSimpleTextProvider(text: glucoseStrings.joined(), shortText: glucoseString, accessibilityLabel: accessibilityStrings.joined(separator: ", "))
47+
let timeText = CLKTimeTextProvider(date: date)
48+
49+
switch family {
50+
case .modularSmall:
51+
let template = CLKComplicationTemplateModularSmallStackText()
52+
template.line1TextProvider = glucoseText
53+
template.line2TextProvider = timeText
54+
return template
55+
case .circularSmall:
56+
let template = CLKComplicationTemplateCircularSmallSimpleText()
57+
template.textProvider = glucoseText
58+
return template
59+
case .extraLarge:
60+
let template = CLKComplicationTemplateExtraLargeStackText()
61+
template.line1TextProvider = glucoseText
62+
template.line2TextProvider = timeText
63+
return template
64+
case .utilitarianSmallFlat:
65+
let template = CLKComplicationTemplateUtilitarianSmallFlat()
66+
template.textProvider = CLKSimpleTextProvider.localizableTextProvider(withStringsFileFormatKey: "UtilitarianSmallFlat", textProviders: [glucoseText, timeText])
67+
return template
68+
case .utilitarianLarge:
69+
let template = CLKComplicationTemplateUtilitarianLargeFlat()
70+
let providers: [CLKTextProvider?] = [glucoseText, eventualGlucoseText, timeText]
71+
72+
template.textProvider = CLKSimpleTextProvider.localizableTextProvider(withStringsFileFormatKey: "UtilitarianLargeFlat", textProviders: providers.flatMap({ $0 }))
73+
return template
74+
default:
75+
return nil
76+
}
77+
}
2678
}

WatchApp Extension/Info.plist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
<key>CLKComplicationSupportedFamilies</key>
2828
<array>
2929
<string>CLKComplicationFamilyModularSmall</string>
30+
<string>CLKComplicationFamilyCircularSmall</string>
31+
<string>CLKComplicationFamilyExtraLarge</string>
32+
<string>CLKComplicationFamilyUtilitarianSmallFlat</string>
33+
<string>CLKComplicationFamilyUtilitarianLarge</string>
3034
</array>
3135
<key>NSExtension</key>
3236
<dict>

0 commit comments

Comments
 (0)