-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathITXNCGroupBackgroundView.m
More file actions
209 lines (175 loc) · 6.71 KB
/
ITXNCGroupBackgroundView.m
File metadata and controls
209 lines (175 loc) · 6.71 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#import <Intelix/ITXNCGroupBackgroundView.h>
#import <UIKit/UICollectionView+Private.h>
#import <UIKit/UICollectionReusableView+Private.h>
#import <Intelix/NCNotificationListCell.h>
#import <ColorBanners2/CBRColoringInfo.h>
#import <Intelix/ITXNCGroupFooterView.h>
#import <Intelix/NCNotificationShortLookView.h>
#import <Intelix/NCNotificationListSectionHeaderView.h>
static CGFloat headerHeight = 20;
@implementation ITXNCGroupBackgroundView
- (id)initWithFrame:(CGRect)frame {
// HBLogInfo(@"Method #120");
self = [super initWithFrame:frame];
if (self) {
_topView = [[ITXAnimatedSeperatedCornersView alloc] init];
_bottomView = [[ITXAnimatedSeperatedCornersView alloc] init];
_containerView = [[UIView alloc] init];
[_containerView addSubview:_topView];
[_containerView addSubview:_bottomView];
_backdropView = [NSClassFromString(@"MTMaterialView") materialViewWithRecipe:1 options:2];
_backdropView.maskView = _containerView;
_backdropView.groupName = @"NCNotificationListCombinedListViewController.blur";
// _backdropView.allowsInPlaceFiltering = YES;
// _backdropView.backgroundColor = [UIColor redColor];
[self addSubview:_backdropView];
_middleFrame = CGRectNull;
_forcedFrame = self.frame;
_configuration = [ITXNCGroupBackgroundConfiguration defaultConfiguration];
[self _resetRevealOverrides];
}
return self;
}
- (void)setMiddleFrame:(CGRect)frame {
// HBLogInfo(@"Method #121");
if (!CGRectEqualToRect(frame, _middleFrame)) {
_middleFrame = frame;
_previousFrame = CGRectZero;
[self layoutSubviews];
}
}
- (void)setForcedFrame:(CGRect)frame {
// HBLogInfo(@"Method #122");
if (!CGRectEqualToRect(frame, _forcedFrame)) {
_forcedFrame = frame;
[self layoutSubviews];
}
}
- (void)setFrame:(CGRect)frame {
// HBLogInfo(@"Method #123");
[super setFrame:frame];
[self layoutSubviews];
}
- (void)doConfigUpdate {
CGRect bounds = CGRectMake(0,0,self.bounds.size.width,self.bounds.size.height);
_backdropView.frame = bounds;
_containerView.frame = bounds;
ITXNCGroupBackgroundConfiguration *config = _configuration;
_topView.topCornerRadius = config.topRadius;
_topView.bottomCornerRadius = config.middleTopRadius;
_topView.bottomInset = config.middleTopInset;
_bottomView.topCornerRadius = config.middleBottomRadius;
_bottomView.bottomCornerRadius = config.bottomRadius;
_bottomView.topInset = config.middleBottomInset;
CGRect middleFrame = _middleFrame;
if (CGRectIsNull(middleFrame)) middleFrame = CGRectMake(0, bounds.size.height*0.5, bounds.size.width, 0);
_topView.frame = CGRectMake(0, 0 + (_isSectionBackground ? headerHeight : 0), bounds.size.width, middleFrame.origin.y - (_isSectionBackground ? headerHeight : 0));
CGFloat bottomY = middleFrame.origin.y + middleFrame.size.height;
_bottomView.frame = CGRectMake(0, bottomY, bounds.size.width, bounds.size.height - bottomY);
[_topView layoutSubviews];
[_bottomView layoutSubviews];
_previousFrame = self.frame;
if (NSClassFromString(@"CBRPrefsManager") && NSClassFromString(@"CBRColoringInfo")) {
if ([self superview] && [[self superview] isKindOfClass:NSClassFromString(@"NCNotificationShortLookView")]) {
NCNotificationShortLookView *shortLookView = (NCNotificationShortLookView *)[self superview];
id coloringInfo = [shortLookView cbr_coloringInfo];
if (coloringInfo) [self cbr_setColoringInfo:coloringInfo];
if (_coloringInfo) {
if (_backdropView && [_backdropView respondsToSelector:@selector(cbr_colorize:)]) {
[_backdropView cbr_colorize:_coloringInfo];
}
}
} else {
UICollectionView *collectionView = self.collectionView;
UICollectionViewLayoutAttributes *layoutAttributes = self.layoutAttributes;
if (layoutAttributes && collectionView) {
NSIndexPath *path = layoutAttributes.indexPath;
if (path) {
NCNotificationListCell *cell = [collectionView _visibleCellForIndexPath:path];
if (cell) {
id coloringInfo = [cell cbr_coloringInfo];
if (coloringInfo) {
[self cbr_setColoringInfo:coloringInfo];
CBRColoringInfo *info = (CBRColoringInfo *)_coloringInfo;
ITXNCGroupFooterView *footerView = [collectionView _visibleSupplementaryViewOfKind:@"UICollectionElementKindSectionFooter" atIndexPath:path];
if (footerView && [footerView isKindOfClass:NSClassFromString(@"ITXNCGroupFooterView")]) {
[footerView setTextColor:info.contrastColorForLookType];
}
NCNotificationListSectionHeaderView *headerView = [collectionView _visibleSupplementaryViewOfKind:@"UICollectionElementKindSectionHeader" atIndexPath:path];
if (headerView && [headerView isKindOfClass:NSClassFromString(@"NCNotificationListSectionHeaderView")]) {
[headerView cbr_setColoringInfo:_coloringInfo];
}
if (_backdropView && [_backdropView respondsToSelector:@selector(cbr_colorize:)]) {
[_backdropView cbr_colorize:_coloringInfo];
}
}
}
}
}
}
// if (_coloringInfo) {
// CBRColoringInfo *info = (CBRColoringInfo *)_coloringInfo;
// }
// if (_coloringInfo) {
// [self cbr_colorize]
// }
}
}
- (void)layoutSubviews {
// HBLogInfo(@"Method #124");
[super layoutSubviews];
//_isSectionBackground = NO;
// Andy Remove this after testing
//_forcedFrame = self.frame;
// if (!CGRectIsNull(_forcedFrame))
//CGRect forcedFrame = _forcedFrame;
//self.frame = _forcedFrame;
if (_previousFrame.size.width != self.frame.size.width || _previousFrame.size.height != self.frame.size.height || _backdropView.bounds.size.height != self.frame.size.height) {
[self doConfigUpdate];
}
}
+ (NSString *)elementKind {
return @"ITXNCGroupBackgroundView";
}
- (void)setOverrideAlpha:(CGFloat)alpha {
// HBLogInfo(@"Method #125");
_overrideAlpha = alpha;
if (!self.isTopSection) self.alpha = _overrideAlpha;
}
- (void)setOverrideCenter:(CGPoint)center {
// HBLogInfo(@"Method #126");
_overrideCenter = center;
if (!self.isTopSection) self.center = _overrideCenter;
}
- (void)prepareForReuse {
// HBLogInfo(@"Method #127");
_isSectionBackground = NO;
_isTopSection = NO;
[super prepareForReuse];
[self _resetRevealOverrides];
}
- (void)_resetRevealOverrides {
// HBLogInfo(@"Method #128");
_overrideAlpha = CGFLOAT_MAX;
_overrideCenter = CGPointMake(CGFLOAT_MAX, CGFLOAT_MAX);
_shouldOverrideForReveal = NO;
}
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)attributes {
// HBLogInfo(@"Method #129");
[super applyLayoutAttributes:attributes];
if (_shouldOverrideForReveal && !self.isTopSection) {
if (_overrideAlpha != CGFLOAT_MAX) {
[self setAlpha:_overrideAlpha];
}
if (_overrideCenter.x != CGFLOAT_MAX && _overrideCenter.y != CGFLOAT_MAX) {
[self setCenter:_overrideCenter];
}
}
}
- (void)cbr_setColoringInfo:(id)info {
_coloringInfo = info;
}
- (id)cbr_coloringInfo {
return _coloringInfo;
}
@end