forked from qnblackcat/RedditFilter_Sideloaded
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FeedFilterSettingsViewController.x
189 lines (180 loc) · 7.73 KB
/
FeedFilterSettingsViewController.x
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
#import "FeedFilterSettingsViewController.h"
extern UIImage *iconWithName(NSString *iconName);
extern Class CoreClass(NSString *name);
%subclass FeedFilterSettingsViewController : BaseTableViewController
%new
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 7;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ToggleImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kToggleCellID
forIndexPath:indexPath];
NSString *mainLabelText;
NSString *detailLabelText;
NSArray *iconNames;
switch (indexPath.row) {
case 0:
mainLabelText = @"Promoted";
iconNames = @[ @"icon_tag" ];
cell.accessorySwitch.on =
![NSUserDefaults.standardUserDefaults boolForKey:kRedditFilterPromoted];
[cell.accessorySwitch addTarget:self
action:@selector(didTogglePromotedSwitch:)
forControlEvents:UIControlEventValueChanged];
break;
case 1:
mainLabelText = @"Recommended";
iconNames = @[ @"icon_spam" ];
cell.accessorySwitch.on =
![NSUserDefaults.standardUserDefaults boolForKey:kRedditFilterRecommended];
[cell.accessorySwitch addTarget:self
action:@selector(didToggleRecommendedSwitch:)
forControlEvents:UIControlEventValueChanged];
break;
case 2:
mainLabelText = @"Livestreams";
iconNames = @[ @"icon_videocamera", @"icon_video_camera" ];
cell.accessorySwitch.on =
![NSUserDefaults.standardUserDefaults boolForKey:kRedditFilterLivestreams];
[cell.accessorySwitch addTarget:self
action:@selector(didToggleLivestreamsSwitch:)
forControlEvents:UIControlEventValueChanged];
break;
case 3:
mainLabelText = @"NSFW";
iconNames = @[ @"icon_nsfw" ];
cell.accessorySwitch.on = ![NSUserDefaults.standardUserDefaults boolForKey:kRedditFilterNSFW];
[cell.accessorySwitch addTarget:self
action:@selector(didToggleNsfwSwitch:)
forControlEvents:UIControlEventValueChanged];
break;
case 4:
mainLabelText = @"Awards";
detailLabelText = @"Show awards on posts and comments";
iconNames = @[ @"icon_gift_fill", @"icon_award" ];
cell.accessorySwitch.on =
![NSUserDefaults.standardUserDefaults boolForKey:kRedditFilterAwards];
[cell.accessorySwitch addTarget:self
action:@selector(didToggleAwardsSwitch:)
forControlEvents:UIControlEventValueChanged];
break;
case 5:
mainLabelText = @"Scores";
detailLabelText = @"Show vote count on posts and comments";
iconNames = @[ @"icon_upvote" ];
cell.accessorySwitch.on =
![NSUserDefaults.standardUserDefaults boolForKey:kRedditFilterScores];
[cell.accessorySwitch addTarget:self
action:@selector(didToggleScoresSwitch:)
forControlEvents:UIControlEventValueChanged];
break;
case 6:
mainLabelText = @"AutoMod";
detailLabelText = @"Auto collapse AutoMod comments";
iconNames = @[ @"icon_mod" ];
cell.accessorySwitch.on =
[NSUserDefaults.standardUserDefaults boolForKey:kRedditFilterAutoCollapseAutoMod];
[cell.accessorySwitch addTarget:self
action:@selector(didToggleAutoCollapseAutoModSwitch:)
forControlEvents:UIControlEventValueChanged];
break;
}
([cell respondsToSelector:@selector(mainLabel)] ? cell.mainLabel : cell.imageLabelView.mainLabel)
.text = mainLabelText;
([cell respondsToSelector:@selector(detailLabel)] ? cell.detailLabel
: cell.imageLabelView.detailLabel)
.text = detailLabelText;
UIImage *iconImage;
for (NSString *iconName in iconNames) {
iconImage = iconWithName(iconName);
if (iconImage) break;
}
if (iconImage) {
UIImage *displayImage = [[iconImage imageScaledToSize:CGSizeMake(20, 20)]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
if ([cell respondsToSelector:@selector(setDisplayImage:)])
cell.displayImage = displayImage;
else
cell.imageLabelView.imageView.image = displayImage;
}
return cell;
}
%new
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
BaseLabel *label = [%c(BaseLabel) labelWithSubheaderFont];
LayoutGuidance *layoutGuidance = [%c(LayoutGuidance) currentGuidance];
label.frame = CGRectMake(layoutGuidance.gridPadding, 0,
layoutGuidance.maxContentWidth - layoutGuidance.gridPaddingDouble, 40.0);
[label associatePropertySetter:@selector(setTextColor:)
withThemePropertyGetter:@selector(metaTextColor)];
BaseTableReusableView *headerView = [[%c(BaseTableReusableView) alloc]
initWithFrame:CGRectMake(0, 0, tableView.frameWidth, 40.0)];
[headerView.contentView addSubview:label];
[headerView associatePropertySetter:@selector(setBackgroundColor:)
withThemePropertyGetter:@selector(canvasColor)];
label.text = [@"Filters" uppercaseString];
return headerView;
}
%new
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 40.0;
}
%new
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
BaseLabel *label = [%c(BaseLabel) labelWithSubheaderFont];
LayoutGuidance *layoutGuidance = [%c(LayoutGuidance) currentGuidance];
label.frame = CGRectMake(layoutGuidance.gridPadding, 0,
layoutGuidance.maxContentWidth - layoutGuidance.gridPaddingDouble, 40.0);
[label associatePropertySetter:@selector(setTextColor:)
withThemePropertyGetter:@selector(metaTextColor)];
BaseTableReusableView *footerView = [[%c(BaseTableReusableView) alloc]
initWithFrame:CGRectMake(0, 0, tableView.frameWidth, 40.0)];
[footerView.contentView addSubview:label];
[footerView associatePropertySetter:@selector(setBackgroundColor:)
withThemePropertyGetter:@selector(canvasColor)];
label.text = @"Filter specific types of posts from your feed.";
return footerView;
}
%new
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 40.0;
}
- (void)viewDidLoad {
%orig;
self.title = @"Feed filter";
[self.tableView registerClass:CoreClass(@"ToggleImageTableViewCell")
forCellReuseIdentifier:kToggleCellID];
}
%new
- (void)didTogglePromotedSwitch:(UISwitch *)sender {
[NSUserDefaults.standardUserDefaults setBool:!sender.on forKey:kRedditFilterPromoted];
}
%new
- (void)didToggleRecommendedSwitch:(UISwitch *)sender {
[NSUserDefaults.standardUserDefaults setBool:!sender.on forKey:kRedditFilterRecommended];
}
%new
- (void)didToggleLivestreamsSwitch:(UISwitch *)sender {
[NSUserDefaults.standardUserDefaults setBool:!sender.on forKey:kRedditFilterLivestreams];
}
%new
- (void)didToggleNsfwSwitch:(UISwitch *)sender {
[NSUserDefaults.standardUserDefaults setBool:!sender.on forKey:kRedditFilterNSFW];
}
%new
- (void)didToggleAwardsSwitch:(UISwitch *)sender {
[NSUserDefaults.standardUserDefaults setBool:!sender.on forKey:kRedditFilterAwards];
}
%new
- (void)didToggleScoresSwitch:(UISwitch *)sender {
[NSUserDefaults.standardUserDefaults setBool:!sender.on forKey:kRedditFilterScores];
}
%new
- (void)didToggleAutoCollapseAutoModSwitch:(UISwitch *)sender {
[NSUserDefaults.standardUserDefaults setBool:sender.on forKey:kRedditFilterAutoCollapseAutoMod];
}
%end