Skip to content
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ INSTALL_TARGET_PROCESSES = RedditApp Reddit

ARCHS = arm64

PACKAGE_VERSION = 1.1.8
PACKAGE_VERSION = 1.2.0
ifdef APP_VERSION
PACKAGE_VERSION := $(APP_VERSION)-$(PACKAGE_VERSION)
endif
Expand All @@ -28,4 +28,11 @@ ifeq ($(SIDELOADED),1)
include $(THEOS_MAKE_PATH)/aggregate.mk
endif

include $(THEOS_MAKE_PATH)/tweak.mk
include $(THEOS_MAKE_PATH)/tweak.mk

# Copy preference bundle resources to staging directory
after-stage::
$(ECHO_NOTHING)mkdir -p $(THEOS_STAGING_DIR)/Library/PreferenceBundles/RedditFilter.bundle/en.lproj$(ECHO_END)
$(ECHO_NOTHING)if [ -d "layout/Library/Application Support/RedditFilter.bundle" ]; then \
cp -r "layout/Library/Application Support/RedditFilter.bundle"/* "$(THEOS_STAGING_DIR)/Library/PreferenceBundles/RedditFilter.bundle/"; \
fi$(ECHO_END)
115 changes: 54 additions & 61 deletions Settings.x
Original file line number Diff line number Diff line change
Expand Up @@ -7,87 +7,36 @@ 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

// We keep this just in case the side menu still works, as it provides a backup entry point.
%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];

UIImage *icon = iconWithName(@"rpl3/filter") ?: iconWithName(@"icon_filter") ?: iconWithName(@"icon-filter-outline");
if (icon) {
cell.imageView.image = [[icon imageScaledToSize:CGSizeMake(20, 20)] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
}
return cell;
}
return %orig;
}

%new
- (void)navigateToRedditFilterSettings {
[self dismissViewControllerAnimated:YES completion:nil];
Expand All @@ -96,6 +45,7 @@ extern NSString *localizedString(NSString *key, NSString *table);
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) {
Expand All @@ -105,6 +55,49 @@ extern NSString *localizedString(NSString *key, NSString *table);
}
%end

%hook UIViewController

- (void)viewWillAppear:(BOOL)animated {
%orig;

NSString *name = NSStringFromClass([self class]);

if ([name containsString:@"RedditSliceKit"] &&
[name containsString:@"AppSettingsView"] &&
[name containsString:@"HostingController"]) {

if (self.navigationItem.rightBarButtonItems) {
for (UIBarButtonItem *item in self.navigationItem.rightBarButtonItems) {
if (item.tag == 1337) return;
}
}

UIBarButtonItem *filterButton = [[UIBarButtonItem alloc] initWithTitle:@"RedditFilter"
style:UIBarButtonItemStylePlain
target:self
action:@selector(openRedditFilterFromNav)];
filterButton.tag = 1337; // Tag to identify our button

[filterButton setTitlePositionAdjustment:UIOffsetMake(0, 3.5) forBarMetrics:UIBarMetricsDefault];

// 5. Add it to the Navigation Bar
NSMutableArray *items = [self.navigationItem.rightBarButtonItems mutableCopy];
if (!items) items = [NSMutableArray array];
[items insertObject:filterButton atIndex:0]; // Add to the start of the list (right side)

self.navigationItem.rightBarButtonItems = items;
}
}

%new
- (void)openRedditFilterFromNav {
// Launch the Tweak Settings
FeedFilterSettingsViewController *vc = [(FeedFilterSettingsViewController *)[objc_getClass("FeedFilterSettingsViewController") alloc] initWithStyle:UITableViewStyleGrouped];
[self.navigationController pushViewController:vc animated:YES];
}

%end

%ctor {
redditFilterBundle = [NSBundle bundleWithPath:[NSBundle.mainBundle pathForResource:@"RedditFilter"
ofType:@"bundle"]];
Expand Down
Loading