-
Notifications
You must be signed in to change notification settings - Fork 37
/
Settings.x
75 lines (70 loc) · 3.29 KB
/
Settings.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
#import <AppSettingsViewController.h>
#import "FeedFilterSettingsViewController.h"
NSBundle *redditFilterBundle;
extern UIImage *iconWithName(NSString *iconName);
extern NSString *localizedString(NSString *key, NSString *table);
@interface AppSettingsViewController ()
@property(nonatomic, assign) NSInteger feedFilterSectionIndex;
@end
%hook AppSettingsViewController
%property(nonatomic, assign) NSInteger feedFilterSectionIndex;
- (void)viewDidLoad {
%orig;
for (int section = 0; section < [self numberOfSectionsInTableView:self.tableView]; section++) {
BaseTableReusableView *headerView = (BaseTableReusableView *)[self tableView:self.tableView
viewForHeaderInSection:section];
if (!headerView) continue;
BaseLabel *label = headerView.contentView.subviews[0];
for (NSString *key in @[ @"drawer.settings.feedOptions", @"drawer.settings.viewOptions" ]) {
if ([label.text isEqualToString:[localizedString(key, @"user") uppercaseString]]) {
self.feedFilterSectionIndex = section;
return;
}
}
}
self.feedFilterSectionIndex = 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSInteger result = %orig;
if (section == self.feedFilterSectionIndex) result++;
return result;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == self.feedFilterSectionIndex &&
indexPath.row == [self tableView:tableView numberOfRowsInSection:indexPath.section] - 1) {
UIImage *iconImage = [iconWithName(@"icon_filter") imageScaledToSize:CGSizeMake(20, 20)];
UIImage *accessoryIconImage =
[iconWithName(@"icon_forward") imageScaledToSize:CGSizeMake(20, 20)];
ImageLabelTableViewCell *cell = [self
dequeueSettingsCellForTableView:tableView
indexPath:indexPath
leadingImage:iconImage
text:[redditFilterBundle localizedStringForKey:@"filter.settings.title"
value:@"Feed filter"
table:nil]];
[cell setCustomAccessoryImage:accessoryIconImage];
return cell;
}
return %orig;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == self.feedFilterSectionIndex &&
indexPath.row == [self tableView:tableView numberOfRowsInSection:indexPath.section] - 1) {
[self.navigationController
pushViewController:[(FeedFilterSettingsViewController *)[objc_getClass(
"FeedFilterSettingsViewController") alloc]
initWithStyle:UITableViewStyleGrouped]
animated:YES];
return;
}
%orig;
}
%end
%ctor {
redditFilterBundle = [NSBundle bundleWithPath:[NSBundle.mainBundle pathForResource:@"RedditFilter"
ofType:@"bundle"]];
if (!redditFilterBundle)
redditFilterBundle = [NSBundle bundleWithPath:@THEOS_PACKAGE_INSTALL_PREFIX
@"/Library/Application Support/RedditFilter.bundle"];
}