-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathSettings.x
More file actions
114 lines (107 loc) · 4.83 KB
/
Settings.x
File metadata and controls
114 lines (107 loc) · 4.83 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
#import <AppSettingsViewController.h>
#import <UserDrawerViewController.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
@interface UserDrawerViewController ()
- (void)navigateToRedditFilterSettings;
@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") ?: iconWithName(@"icon-filter-outline")
imageScaledToSize:CGSizeMake(20, 20)];
UIImage *accessoryIconImage =
[iconWithName(@"icon_forward") imageScaledToSize:CGSizeMake(20, 20)];
ImageLabelTableViewCell *cell = [self dequeueSettingsCellForTableView:tableView
indexPath:indexPath
leadingImage:iconImage
text:@"RedditFilter"];
[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
%hook UserDrawerViewController
- (void)defineAvailableUserActions {
%orig;
[self.availableUserActions addObject:@1337];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([tableView isEqual:self.actionsTableView] &&
self.availableUserActions[indexPath.row].unsignedIntegerValue == 1337) {
UITableViewCell *cell =
[self.actionsTableView dequeueReusableCellWithIdentifier:@"UserDrawerActionTableViewCell"];
cell.textLabel.text = @"RedditFilter";
cell.imageView.image = [[iconWithName(@"rpl3/filter") ?: iconWithName(@"icon_filter") ?: iconWithName(@"icon-filter-outline")
imageScaledToSize:CGSizeMake(20, 20)]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
return cell;
}
return %orig;
}
%new
- (void)navigateToRedditFilterSettings {
[self dismissViewControllerAnimated:YES completion:nil];
FeedFilterSettingsViewController *filterSettingsViewController =
[(FeedFilterSettingsViewController *)[objc_getClass("FeedFilterSettingsViewController") alloc]
initWithStyle:UITableViewStyleGrouped];
[[self currentNavigationController] pushViewController:filterSettingsViewController animated:YES];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([tableView isEqual:self.actionsTableView] &&
self.availableUserActions[indexPath.row].unsignedIntegerValue == 1337) {
return [self navigateToRedditFilterSettings];
}
%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"];
}