Skip to content

Commit e8b207e

Browse files
walker0ps2
authored andcommitted
Add mmol watchapp units support. Add modularLarge complication. Change complication time to relative time. (#379)
* Adds support for mmol in watch app. Changes complication time to relative. Adds modularLarge complication. * Fix gallery and tabs
1 parent c92e780 commit e8b207e

File tree

7 files changed

+39
-22
lines changed

7 files changed

+39
-22
lines changed

Loop.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
437CEEE41CDE5C0A003C8C80 /* UIImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 437CEEE31CDE5C0A003C8C80 /* UIImage.swift */; };
6565
437D9BA31D7BC977007245E8 /* PredictionTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 437D9BA21D7BC977007245E8 /* PredictionTableViewController.swift */; };
6666
43846AD51D8FA67800799272 /* Base.lproj in Resources */ = {isa = PBXBuildFile; fileRef = 43846AD41D8FA67800799272 /* Base.lproj */; };
67-
43846AD91D8FA84B00799272 /* gallery.ckcomplication in Resources */ = {isa = PBXBuildFile; fileRef = 43846AD81D8FA84B00799272 /* gallery.ckcomplication */; };
6867
43846ADB1D91057000799272 /* ContextUpdatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43846ADA1D91057000799272 /* ContextUpdatable.swift */; };
6968
43880F951D9CD54A009061A8 /* ChartPointsScatterDownTrianglesLayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 43880F941D9CD54A009061A8 /* ChartPointsScatterDownTrianglesLayer.swift */; };
7069
438849EA1D297CB6003B3F23 /* NightscoutService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 438849E91D297CB6003B3F23 /* NightscoutService.swift */; };
@@ -200,6 +199,7 @@
200199
C1C73F021DE3D0250022FC89 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = C1C73F041DE3D0250022FC89 /* Localizable.strings */; };
201200
C1C73F081DE3D0260022FC89 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = C1C73F0A1DE3D0260022FC89 /* InfoPlist.strings */; };
202201
C1C73F0D1DE3D0270022FC89 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = C1C73F0F1DE3D0270022FC89 /* InfoPlist.strings */; };
202+
C9886AE51E5B2FAD00473BB8 /* gallery.ckcomplication in Resources */ = {isa = PBXBuildFile; fileRef = C9886AE41E5B2FAD00473BB8 /* gallery.ckcomplication */; };
203203
/* End PBXBuildFile section */
204204

205205
/* Begin PBXContainerItemProxy section */
@@ -380,7 +380,6 @@
380380
437D9BA11D7B5203007245E8 /* Loop.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Loop.xcconfig; sourceTree = "<group>"; };
381381
437D9BA21D7BC977007245E8 /* PredictionTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PredictionTableViewController.swift; sourceTree = "<group>"; };
382382
43846AD41D8FA67800799272 /* Base.lproj */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Base.lproj; sourceTree = "<group>"; };
383-
43846AD81D8FA84B00799272 /* gallery.ckcomplication */ = {isa = PBXFileReference; lastKnownFileType = folder; path = gallery.ckcomplication; sourceTree = "<group>"; };
384383
43846ADA1D91057000799272 /* ContextUpdatable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContextUpdatable.swift; sourceTree = "<group>"; };
385384
43880F941D9CD54A009061A8 /* ChartPointsScatterDownTrianglesLayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChartPointsScatterDownTrianglesLayer.swift; sourceTree = "<group>"; };
386385
438849E91D297CB6003B3F23 /* NightscoutService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NightscoutService.swift; sourceTree = "<group>"; };
@@ -499,6 +498,7 @@
499498
C1C73F031DE3D0250022FC89 /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/Localizable.strings; sourceTree = "<group>"; };
500499
C1C73F091DE3D0260022FC89 /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/InfoPlist.strings; sourceTree = "<group>"; };
501500
C1C73F0E1DE3D0270022FC89 /* it */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/InfoPlist.strings; sourceTree = "<group>"; };
501+
C9886AE41E5B2FAD00473BB8 /* gallery.ckcomplication */ = {isa = PBXFileReference; lastKnownFileType = folder; path = gallery.ckcomplication; sourceTree = "<group>"; };
502502
/* End PBXFileReference section */
503503

504504
/* Begin PBXFrameworksBuildPhase section */
@@ -656,7 +656,7 @@
656656
43776F8E1B8022E90074EA36 /* Loop */ = {
657657
isa = PBXGroup;
658658
children = (
659-
43846AD81D8FA84B00799272 /* gallery.ckcomplication */,
659+
C9886AE41E5B2FAD00473BB8 /* gallery.ckcomplication */,
660660
43EDEE6B1CF2E12A00393BE3 /* Loop.entitlements */,
661661
43F5C2D41B92A4A6003EB13D /* Info.plist */,
662662
43776F8F1B8022E90074EA36 /* AppDelegate.swift */,
@@ -1219,7 +1219,7 @@
12191219
434F54591D28805E002A9274 /* ButtonTableViewCell.xib in Resources */,
12201220
C1C73F021DE3D0250022FC89 /* Localizable.strings in Resources */,
12211221
43776F971B8022E90074EA36 /* Main.storyboard in Resources */,
1222-
43846AD91D8FA84B00799272 /* gallery.ckcomplication in Resources */,
1222+
C9886AE51E5B2FAD00473BB8 /* gallery.ckcomplication in Resources */,
12231223
434F545B1D2880D4002A9274 /* AuthenticationTableViewCell.xib in Resources */,
12241224
);
12251225
runOnlyForDeploymentPostprocessing = 0;

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

100644100755
File mode changed.
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"supported complication families" : {
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"
3+
"3" : "7F209C4B-314F-4875-9072-3CFD6C18AE3A.json",
4+
"1" : "0912322A-F7BA-487C-B910-60ADD3B22910.json",
5+
"6" : "E5D4D16F-B048-454F-BAD4-A1D92E65F650.json",
6+
"4" : "2F588D19-9780-4727-B5CB-DFE7945469E4.json",
7+
"0" : "2A9C2659-183D-468D-A20D-704A6D9F7875.json",
8+
"7" : "1163D5A6-1BB9-41D4-B6A0-60DCDFD52EC3.json"
89
},
9-
"client ID" : "com.loudnate.Loop.watchkitapp.watchkitextension"
10+
"client ID" : "com.loopkit.Loop.watchkitapp.watchkitextension"
1011
}

WatchApp Extension/ComplicationController.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,19 @@ final class ComplicationController: NSObject, CLKComplicationDataSource {
8181
let template: CLKComplicationTemplate?
8282

8383
let glucoseText = CLKSimpleTextProvider.localizableTextProvider(withStringsFileTextKey: "120↘︎", shortTextKey: "120")
84-
let timeText = CLKTimeTextProvider(date: Date())
84+
let timeText = CLKRelativeDateTextProvider(date: Date(), style: .natural, units: .minute)
8585

8686
switch complication.family {
8787
case .modularSmall:
8888
let modularSmall = CLKComplicationTemplateModularSmallStackText()
8989
modularSmall.line1TextProvider = glucoseText
9090
modularSmall.line2TextProvider = timeText
9191
template = modularSmall
92+
case .modularLarge:
93+
let modularSmall = CLKComplicationTemplateModularLargeTallBody()
94+
modularSmall.bodyTextProvider = glucoseText
95+
modularSmall.headerTextProvider = timeText
96+
template = modularSmall
9297
case .circularSmall:
9398
let circularSmall = CLKComplicationTemplateCircularSmallSimpleText()
9499
circularSmall.textProvider = glucoseText

WatchApp Extension/Controllers/StatusInterfaceController.swift

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,33 @@ final class StatusInterfaceController: WKInterfaceController, ContextUpdatable {
4545
loopTimer.setHidden(true)
4646
loopHUDImage.setLoopImage(.Unknown)
4747
}
48+
49+
guard let glucose = context?.glucose,
50+
let unit = context?.preferredGlucoseUnit
51+
else {
52+
glucoseLabel.setHidden(true)
53+
eventualGlucoseLabel.setHidden(true)
54+
return
55+
}
4856

49-
let numberFormatter = NumberFormatter()
57+
let formatter = NumberFormatter.glucoseFormatter(for: unit)
5058

51-
if let glucose = context?.glucose, let unit = context?.preferredGlucoseUnit {
52-
let glucoseValue = glucose.doubleValue(for: unit)
59+
if let glucoseValue = formatter.string(from: NSNumber(value: glucose.doubleValue(for: unit))){
5360
let trend = context?.glucoseTrend?.symbol ?? ""
54-
55-
self.glucoseLabel.setText((numberFormatter.string(from: NSNumber(value: glucoseValue)) ?? "") + trend)
61+
self.glucoseLabel.setText(glucoseValue + trend)
5662
self.glucoseLabel.setHidden(false)
5763
} else {
5864
glucoseLabel.setHidden(true)
5965
}
6066

61-
if let eventualGlucose = context?.eventualGlucose, let unit = context?.preferredGlucoseUnit {
62-
let glucoseValue = eventualGlucose.doubleValue(for: unit)
63-
64-
self.eventualGlucoseLabel.setText(numberFormatter.string(from: NSNumber(value: glucoseValue)))
67+
if let eventualGlucose = context?.eventualGlucose {
68+
let glucoseValue = formatter.string(from: NSNumber(value: eventualGlucose.doubleValue(for: unit)))
69+
self.eventualGlucoseLabel.setText(glucoseValue)
6570
self.eventualGlucoseLabel.setHidden(false)
6671
} else {
6772
eventualGlucoseLabel.setHidden(true)
6873
}
69-
74+
7075
// TODO: Other elements
7176
statusLabel.setHidden(true)
7277
graphImage.setHidden(true)

WatchApp Extension/Extensions/CLKComplicationTemplate.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,19 @@ extension CLKComplicationTemplate {
4444
}
4545

4646
let glucoseText = CLKSimpleTextProvider(text: glucoseStrings.joined(), shortText: glucoseString, accessibilityLabel: accessibilityStrings.joined(separator: ", "))
47-
let timeText = CLKTimeTextProvider(date: date)
47+
let timeText = CLKRelativeDateTextProvider(date: date, style: .natural, units: .minute)
4848

4949
switch family {
5050
case .modularSmall:
5151
let template = CLKComplicationTemplateModularSmallStackText()
5252
template.line1TextProvider = glucoseText
5353
template.line2TextProvider = timeText
5454
return template
55+
case .modularLarge:
56+
let template = CLKComplicationTemplateModularLargeTallBody()
57+
template.bodyTextProvider = glucoseText
58+
template.headerTextProvider = timeText
59+
return template
5560
case .circularSmall:
5661
let template = CLKComplicationTemplateCircularSmallSimpleText()
5762
template.textProvider = glucoseText

WatchApp Extension/Info.plist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<string>CLKComplicationFamilyExtraLarge</string>
3232
<string>CLKComplicationFamilyUtilitarianSmallFlat</string>
3333
<string>CLKComplicationFamilyUtilitarianLarge</string>
34+
<string>CLKComplicationFamilyModularLarge</string>
3435
</array>
3536
<key>NSExtension</key>
3637
<dict>

0 commit comments

Comments
 (0)