-
Notifications
You must be signed in to change notification settings - Fork 37
/
FeedFilterSettingsViewController.x
227 lines (217 loc) · 9.4 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#import "FeedFilterSettingsViewController.h"
extern NSBundle *redditFilterBundle;
extern UIImage *iconWithName(NSString *iconName);
extern Class CoreClass(NSString *name);
#define LOC(x, d) [redditFilterBundle localizedStringForKey:x value:d table:nil]
%subclass FeedFilterSettingsViewController : BaseTableViewController
%new
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
switch (section) {
case 0:
return 7;
default:
return 0;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *mainLabelText;
NSString *detailLabelText;
NSArray *iconNames;
ToggleImageTableViewCell *toggleCell;
ImageLabelTableViewCell *cell;
switch (indexPath.section) {
case 0: {
toggleCell = [tableView dequeueReusableCellWithIdentifier:kToggleCellID
forIndexPath:indexPath];
switch (indexPath.row) {
case 0:
mainLabelText = LOC(@"filter.settings.promoted.title", @"Promoted");
iconNames = @[ @"icon_tag" ];
toggleCell.accessorySwitch.on =
![NSUserDefaults.standardUserDefaults boolForKey:kRedditFilterPromoted];
[toggleCell.accessorySwitch addTarget:self
action:@selector(didTogglePromotedSwitch:)
forControlEvents:UIControlEventValueChanged];
break;
case 1:
mainLabelText = LOC(@"filter.settings.recommended.title", @"Recommended");
iconNames = @[ @"icon_spam" ];
toggleCell.accessorySwitch.on =
![NSUserDefaults.standardUserDefaults boolForKey:kRedditFilterRecommended];
[toggleCell.accessorySwitch addTarget:self
action:@selector(didToggleRecommendedSwitch:)
forControlEvents:UIControlEventValueChanged];
break;
case 2:
mainLabelText = LOC(@"filter.settings.livestreams.title", @"Livestreams");
iconNames = @[ @"icon_videocamera", @"icon_video_camera" ];
toggleCell.accessorySwitch.on =
![NSUserDefaults.standardUserDefaults boolForKey:kRedditFilterLivestreams];
[toggleCell.accessorySwitch addTarget:self
action:@selector(didToggleLivestreamsSwitch:)
forControlEvents:UIControlEventValueChanged];
break;
case 3:
mainLabelText = LOC(@"filter.settings.nsfw.title", @"NSFW");
iconNames = @[ @"icon_nsfw_outline", @"icon_nsfw" ];
toggleCell.accessorySwitch.on =
![NSUserDefaults.standardUserDefaults boolForKey:kRedditFilterNSFW];
[toggleCell.accessorySwitch addTarget:self
action:@selector(didToggleNsfwSwitch:)
forControlEvents:UIControlEventValueChanged];
break;
case 4:
mainLabelText = LOC(@"filter.settings.awards.title", @"Awards");
detailLabelText =
LOC(@"filter.settings.awards.subtitle", @"Show awards on posts and comments");
iconNames = @[ @"icon_gift_fill", @"icon_award", @"icon-award-outline" ];
toggleCell.accessorySwitch.on =
![NSUserDefaults.standardUserDefaults boolForKey:kRedditFilterAwards];
[toggleCell.accessorySwitch addTarget:self
action:@selector(didToggleAwardsSwitch:)
forControlEvents:UIControlEventValueChanged];
break;
case 5:
mainLabelText = LOC(@"filter.settings.scores.title", @"Scores");
detailLabelText =
LOC(@"filter.settings.scores.subtitle", @"Show vote count on posts and comments");
iconNames = @[ @"icon_upvote" ];
toggleCell.accessorySwitch.on =
![NSUserDefaults.standardUserDefaults boolForKey:kRedditFilterScores];
[toggleCell.accessorySwitch addTarget:self
action:@selector(didToggleScoresSwitch:)
forControlEvents:UIControlEventValueChanged];
break;
case 6:
mainLabelText = LOC(@"filter.settings.automod.title", @"AutoMod");
detailLabelText =
LOC(@"filter.settings.automod.subtitle", @"Auto collapse AutoMod comments");
iconNames = @[ @"icon_mod" ];
toggleCell.accessorySwitch.on =
[NSUserDefaults.standardUserDefaults boolForKey:kRedditFilterAutoCollapseAutoMod];
[toggleCell.accessorySwitch addTarget:self
action:@selector(didToggleAutoCollapseAutoModSwitch:)
forControlEvents:UIControlEventValueChanged];
break;
default:
return nil;
}
cell = toggleCell;
break;
}
default:
return nil;
}
([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)];
switch (section) {
case 0:
label.text = [LOC(@"filter.settings.header", @"Filters") uppercaseString];
break;
default:
return nil;
}
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)];
switch (section) {
case 0:
label.text = LOC(@"filter.settings.footer", @"Filter specific types of posts from your feed");
break;
default:
return nil;
}
return footerView;
}
%new
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 40.0;
}
- (void)viewDidLoad {
%orig;
self.title = LOC(@"filter.settings.title", @"Feed filter");
[self.tableView registerClass:CoreClass(@"ToggleImageTableViewCell")
forCellReuseIdentifier:kToggleCellID];
[self.tableView registerClass:CoreClass(@"ImageLabelTableViewCell")
forCellReuseIdentifier:kLabelCellID];
}
%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