forked from andrewwiik/Intelix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ITXNCGroupFooterView.m
130 lines (112 loc) · 4.14 KB
/
ITXNCGroupFooterView.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
#import <Intelix/ITXHelper.h>
#import <Intelix/ITXNCGroupFooterView.h>
#import <QuartzCore/QuartzCore+Private.h>
#import <Intelix/NCNotificationCombinedListViewController.h>
#import <MaterialKit/MTFontProvider.h>
@implementation ITXNCGroupFooterView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.separatorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, [ITXHelper seperatorHeight])];
self.separatorView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.4];
[self addSubview:self.separatorView];
self.layer.allowsGroupBlending = NO;
self.tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleShowAllNotifications)];
[self addGestureRecognizer:self.tapRecognizer];
self.tapRecognizer.cancelsTouchesInView = NO;
self.tapRecognizer.numberOfTouchesRequired = 1;
self.userInteractionEnabled = YES;
}
return self;
}
- (void)layoutSubviews {
[super layoutSubviews];
self.separatorView.frame = CGRectMake(8, 0, self.bounds.size.width - (8*2), [ITXHelper seperatorHeight]);
// if (_middleLabel) {
// [_middleLabel sizeToFit];
// _middleLabel.center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2);
}
- (void)setupMiddleLabel {
if (!_middleLabel) {
_middleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
_middleLabel.textColor = [UIColor colorWithWhite:0 alpha:0.75];
_middleLabel.font = [[NSClassFromString(@"MTFontProvider") preferredFontProvider] preferredFontForTextStyle:UIFontTextStyleFootnote hiFontStyle:3];
CAFilter *vibrancyFilter = [NSClassFromString(@"CAFilter") filterWithType:@"vibrantLight"];
[vibrancyFilter setValue:[UIColor colorWithWhite:0.4 alpha:1] forKey:@"inputColor0"];
[vibrancyFilter setValue:[UIColor colorWithWhite:0 alpha:0.3] forKey:@"inputColor1"];
[vibrancyFilter setValue:[NSNumber numberWithBool:YES] forKey:@"inputReversed"];
_middleLabel.layer.filters = [NSArray arrayWithObjects:vibrancyFilter, nil];
[self addSubview:_middleLabel];
}
}
- (void)setNumberToShow:(NSInteger)numToShow {
if (numToShow != _numberToShow) {
_numberToShow = numToShow;
if (_isExpanded) {
[self setLabelText:[NSString stringWithFormat:@"Show Less"]];
} else {
[self setLabelText:[NSString stringWithFormat:@"Show %d more", (int)_numberToShow]];
}
//[self setLabelText:[NSString stringWithFormat:@"Show %d more", (int)_numberToShow]];
}
}
- (void)setLabelText:(NSString *)text {
if (!_middleLabel) {
[self setupMiddleLabel];
}
if (text != _middleLabel.text) {
_middleLabel.text = text;
[_middleLabel sizeToFit];
_middleLabel.center = CGPointMake(self.bounds.size.width/2 + 8, self.bounds.size.height/2);
}
}
- (void)setIsExpanded:(BOOL)isExpanded {
if(_isExpanded != isExpanded) {
_isExpanded = isExpanded;
if (_isExpanded) {
[self setLabelText:[NSString stringWithFormat:@"Show Less"]];
} else {
[self setLabelText:[NSString stringWithFormat:@"Show %d more", (int)_numberToShow]];
}
}
}
- (void)toggleShowAllNotifications {
if (self.cellDelegate) {
// self.isExpanded = !self.isExpanded;
[self.cellDelegate sectionFooterView:self didReceiveToggleExpansionActionForSectionIdentifier:self.sectionIdentifier];
}
// if (self.backgroundColor == [UIColor redColor]) {
// self.backgroundColor = [UIColor blueColor];
// } else {
// self.backgroundColor = [UIColor redColor];
// }
}
- (void)setOverrideAlpha:(CGFloat)alpha {
_overrideAlpha = alpha;
self.alpha = _overrideAlpha;
}
- (void)setOverrideCenter:(CGPoint)center {
_overrideCenter = center;
self.center = _overrideCenter;
}
- (void)prepareForReuse {
[super prepareForReuse];
[self _resetRevealOverrides];
}
- (void)_resetRevealOverrides {
_overrideAlpha = CGFLOAT_MAX;
_overrideCenter = CGPointMake(CGFLOAT_MAX, CGFLOAT_MAX);
_shouldOverrideForReveal = NO;
}
- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)attributes {
[super applyLayoutAttributes:attributes];
if (_shouldOverrideForReveal) {
if (_overrideAlpha != CGFLOAT_MAX) {
[self setAlpha:_overrideAlpha];
}
if (_overrideCenter.x != CGFLOAT_MAX && _overrideCenter.y != CGFLOAT_MAX) {
[self setCenter:_overrideCenter];
}
}
}
@end