-
Notifications
You must be signed in to change notification settings - Fork 1
/
ClockKit+Convenience.m
147 lines (122 loc) · 6.97 KB
/
ClockKit+Convenience.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//
// ClockKit+Convenience.m
// Sleep Diary
//
// Created by Alexander Ivanov on 12.10.16.
// Copyright © 2016 Alexander Ivanov. All rights reserved.
//
#import "ClockKit+Convenience.h"
@implementation CLKComplicationTemplate (Convenience)
- (void)setText:(CLKTextProvider *)value {
cls(CLKComplicationTemplateCircularSmallRingText, self).textProvider = value;
cls(CLKComplicationTemplateCircularSmallStackImage, self).line2TextProvider = value;
cls(CLKComplicationTemplateModularSmallRingText, self).textProvider = value;
cls(CLKComplicationTemplateModularSmallStackImage, self).line2TextProvider = value;
cls(CLKComplicationTemplateUtilitarianSmallRingText, self).textProvider = value;
cls(CLKComplicationTemplateUtilitarianSmallFlat, self).textProvider = value;
cls(CLKComplicationTemplateUtilitarianLargeFlat, self).textProvider = value;
cls(CLKComplicationTemplateGraphicCircularClosedGaugeText, self).centerTextProvider = value;
cls(CLKComplicationTemplateGraphicCircularStackImage, self).line2TextProvider = value;
cls(CLKComplicationTemplateGraphicCircularStackText, self).line2TextProvider = value;
}
- (void)setRing:(CLKComplicationRingStyle)value {
cls(CLKComplicationTemplateCircularSmallRingText, self).ringStyle = value;
cls(CLKComplicationTemplateModularSmallRingText, self).ringStyle = value;
cls(CLKComplicationTemplateUtilitarianSmallRingText, self).ringStyle = value;
}
- (void)setFill:(float)value tintColor:(UIColor *)color {
cls(CLKComplicationTemplateCircularSmallRingText, self).fillFraction = value;
cls(CLKComplicationTemplateModularSmallRingText, self).fillFraction = value;
cls(CLKComplicationTemplateUtilitarianSmallRingText, self).fillFraction = value;
CLKSimpleGaugeProvider *gauge = [CLKSimpleGaugeProvider gaugeProviderWithStyle:CLKGaugeProviderStyleRing gaugeColor:color ?: [UIColor whiteColor] fillFraction:fminf(value, 1.0)];
cls(CLKComplicationTemplateGraphicCircularClosedGaugeImage, self).gaugeProvider = gauge;
cls(CLKComplicationTemplateGraphicCircularClosedGaugeText, self).gaugeProvider = gauge;
}
- (void)setFill:(float)value {
[self setFill:value tintColor:[UIColor whiteColor]];
}
- (void)setImage:(UIImage *)value tintColor:(UIColor *)color {
CLKImageProvider *image = [CLKImageProvider imageProviderWithOnePieceImage:value];
image.tintColor = color;
cls(CLKComplicationTemplateCircularSmallStackImage, self).line1ImageProvider = image;
cls(CLKComplicationTemplateModularSmallStackImage, self).line1ImageProvider = image;
cls(CLKComplicationTemplateUtilitarianSmallFlat, self).imageProvider = image;
cls(CLKComplicationTemplateUtilitarianLargeFlat, self).imageProvider = image;
CLKFullColorImageProvider *fcImage = [CLKFullColorImageProvider providerWithFullColorImage:value tintedImageProvider:image];
cls(CLKComplicationTemplateGraphicCircularImage, self).imageProvider = fcImage;
cls(CLKComplicationTemplateGraphicCircularStackImage, self).line1ImageProvider = fcImage;
cls(CLKComplicationTemplateGraphicCircularClosedGaugeImage, self).imageProvider = fcImage;
}
- (void)setImage:(UIImage *)value {
[self setImage:value tintColor:Nil];
}
- (void)setText:(NSString *)value shortText:(NSString *)text {
[self setText:[CLKSimpleTextProvider textProviderWithText:value shortText:text]];
}
+ (CLKComplicationTemplate *)createWithFamily:(CLKComplicationFamily)family member:(CLKComplicationFamilyMember)member {
switch (family) {
case CLKComplicationFamilyModularSmall:
return member == CLKComplicationFamilyMemberRingImage ? [CLKComplicationTemplateModularSmallRingImage new]
: member == CLKComplicationFamilyMemberRingText ? [CLKComplicationTemplateModularSmallRingText new]
: member == CLKComplicationFamilyMemberSimpleImage ? [CLKComplicationTemplateModularSmallSimpleImage new]
: member == CLKComplicationFamilyMemberSimpleText ? [CLKComplicationTemplateModularSmallSimpleText new]
: member == CLKComplicationFamilyMemberStackImage ? [CLKComplicationTemplateModularSmallStackImage new]
: member == CLKComplicationFamilyMemberStackText ? [CLKComplicationTemplateModularSmallStackText new]
: Nil;
case CLKComplicationFamilyModularLarge:
return Nil;
case CLKComplicationFamilyUtilitarianSmall:
return member == CLKComplicationFamilyMemberRingImage ? [CLKComplicationTemplateUtilitarianSmallRingImage new]
: member == CLKComplicationFamilyMemberRingText ? [CLKComplicationTemplateUtilitarianSmallRingText new]
: member == CLKComplicationFamilyMemberSimpleImage ? [CLKComplicationTemplateUtilitarianSmallSquare new]
: member == CLKComplicationFamilyMemberStackImage ? [CLKComplicationTemplateUtilitarianSmallFlat new]
: Nil;
case CLKComplicationFamilyUtilitarianSmallFlat: // 3.0
return Nil;
case CLKComplicationFamilyUtilitarianLarge:
return [CLKComplicationTemplateUtilitarianLargeFlat new];
case CLKComplicationFamilyCircularSmall:
return member == CLKComplicationFamilyMemberRingImage ? [CLKComplicationTemplateCircularSmallRingImage new]
: member == CLKComplicationFamilyMemberRingText ? [CLKComplicationTemplateCircularSmallRingText new]
: member == CLKComplicationFamilyMemberSimpleImage ? [CLKComplicationTemplateCircularSmallSimpleImage new]
: member == CLKComplicationFamilyMemberSimpleText ? [CLKComplicationTemplateCircularSmallSimpleText new]
: member == CLKComplicationFamilyMemberStackImage ? [CLKComplicationTemplateCircularSmallStackImage new]
: member == CLKComplicationFamilyMemberStackText ? [CLKComplicationTemplateCircularSmallStackText new]
: Nil;
case CLKComplicationFamilyExtraLarge: // 3.0
return Nil;
// 5.0
case CLKComplicationFamilyGraphicCorner:
return Nil;
case CLKComplicationFamilyGraphicBezel:
return Nil;
case CLKComplicationFamilyGraphicCircular:
return member == CLKComplicationFamilyMemberRingImage ? [CLKComplicationTemplateGraphicCircularClosedGaugeImage new] // gauge + image
: member == CLKComplicationFamilyMemberRingText ? [CLKComplicationTemplateGraphicCircularClosedGaugeText new] // gauge + text
: member == CLKComplicationFamilyMemberSimpleImage ? [CLKComplicationTemplateGraphicCircularImage new] // image
: member == CLKComplicationFamilyMemberStackImage ? [CLKComplicationTemplateGraphicCircularStackImage new] // image + text
: member == CLKComplicationFamilyMemberStackText ? [CLKComplicationTemplateGraphicCircularStackText new] // text + text
: Nil;
case CLKComplicationFamilyGraphicRectangular:
return Nil;
default:
return Nil;
}
}
@end
@implementation CLKComplicationServer (Convenience)
- (void)extendTimeline:(CLKComplication *)complication {
if (complication)
[self extendTimelineForComplication:complication];
else
for (CLKComplication *activeComplication in self.activeComplications)
[self extendTimelineForComplication:activeComplication];
}
- (void)reloadTimeline:(CLKComplication *)complication {
if (complication)
[self reloadTimelineForComplication:complication];
else
for (CLKComplication *activeComplication in self.activeComplications)
[self reloadTimelineForComplication:activeComplication];
}
@end