Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion FeedFilterSettingsViewController.x
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#import <CoreFoundation/CoreFoundation.h>
#import "FeedFilterSettingsViewController.h"
#import "DebugMenu.h"

Expand All @@ -6,6 +7,11 @@ extern UIImage *iconWithName(NSString *iconName);
extern Class CoreClass(NSString *name);
#define LOC(x, d) (localizedString(x, nil) ?: d)

// Helper to broadcast preferences update
static void postPrefsUpdatedNotification() {
CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), CFSTR("com.level3tjg.redditfilter/prefsUpdated"), NULL, NULL, true);
}

#if REDDITFILTER_DEBUG
// Visible declarations for the debug-only helpers so the direct call site in
// -cellForRowAtIndexPath: and the @selector(...) references are fully typed.
Expand Down Expand Up @@ -51,6 +57,10 @@ extern Class CoreClass(NSString *name);
case 0: {
toggleCell = [tableView dequeueReusableCellWithIdentifier:kToggleCellID
forIndexPath:indexPath];

// Fixed Switch Handler Accumulation
[toggleCell.accessorySwitch removeTarget:nil action:NULL forControlEvents:UIControlEventAllEvents];

switch (indexPath.row) {
case 0:
mainLabelText = LOC(@"filter.settings.promoted.title", @"Promoted");
Expand Down Expand Up @@ -132,6 +142,7 @@ extern Class CoreClass(NSString *name);
([cell respondsToSelector:@selector(detailLabel)] ? cell.detailLabel
: cell.imageLabelView.detailLabel)
.text = detailLabelText;

UIImage *iconImage;
for (NSString *iconName in iconNames) {
iconImage = iconWithName(iconName);
Expand All @@ -157,11 +168,14 @@ extern Class CoreClass(NSString *name);
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];
Expand Down Expand Up @@ -190,11 +204,14 @@ extern Class CoreClass(NSString *name);
footerHeight);
[label associatePropertySetter:@selector(setTextColor:)
withThemePropertyGetter:@selector(metaTextColor)];

BaseTableReusableView *footerView = [[%c(BaseTableReusableView) alloc]
initWithFrame:CGRectMake(0, 0, tableView.frameWidth, footerHeight)];
[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");
Expand Down Expand Up @@ -230,35 +247,44 @@ extern Class CoreClass(NSString *name);
forCellReuseIdentifier:kToggleCellID];
[self.tableView registerClass:labelCellClass
forCellReuseIdentifier:kLabelCellID];

#if REDDITFILTER_DEBUG
// Debug rows carry multi-line detail text, so let them self-size.
self.tableView.estimatedRowHeight = 60.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
#endif
}

// Emitting notifications across tweak processes allows updates without querying
%new
- (void)didTogglePromotedSwitch:(UISwitch *)sender {
[NSUserDefaults.standardUserDefaults setBool:!sender.on forKey:kRedditFilterPromoted];
postPrefsUpdatedNotification();
}
%new
- (void)didToggleRecommendedSwitch:(UISwitch *)sender {
[NSUserDefaults.standardUserDefaults setBool:!sender.on forKey:kRedditFilterRecommended];
postPrefsUpdatedNotification();
}
%new
- (void)didToggleNsfwSwitch:(UISwitch *)sender {
[NSUserDefaults.standardUserDefaults setBool:!sender.on forKey:kRedditFilterNSFW];
postPrefsUpdatedNotification();
}
%new
- (void)didToggleAwardsSwitch:(UISwitch *)sender {
[NSUserDefaults.standardUserDefaults setBool:!sender.on forKey:kRedditFilterAwards];
postPrefsUpdatedNotification();
}
%new
- (void)didToggleScoresSwitch:(UISwitch *)sender {
[NSUserDefaults.standardUserDefaults setBool:!sender.on forKey:kRedditFilterScores];
postPrefsUpdatedNotification();
}
%new
- (void)didToggleAutoCollapseAutoModSwitch:(UISwitch *)sender {
[NSUserDefaults.standardUserDefaults setBool:sender.on forKey:kRedditFilterAutoCollapseAutoMod];
postPrefsUpdatedNotification();
}

// ---------------------------------------------------------------------------
Expand All @@ -274,6 +300,7 @@ extern Class CoreClass(NSString *name);
- (UITableViewCell *)debugCellForRow:(NSInteger)row inTableView:(UITableView *)tableView {
#if REDDITFILTER_DEBUG
static NSString *const kRFDebugCellID = @"RFSchemaDebugCell";

// Deliberately a plain UIKit cell, not a Reddit class: the whole point of
// this screen is to keep working when Reddit's own classes/schema change.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kRFDebugCellID];
Expand All @@ -289,7 +316,7 @@ extern Class CoreClass(NSString *name);
cell.selectionStyle = UITableViewCellSelectionStyleNone;

NSArray<NSDictionary *> *snapshot = [[RFSchemaDebug shared] snapshot];

// Trailing "reset" row.
if (row >= (NSInteger)snapshot.count) {
cell.textLabel.textColor = [UIColor systemBlueColor];
Expand Down
2 changes: 1 addition & 1 deletion 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.2.3
PACKAGE_VERSION = 1.2.5
ifdef APP_VERSION
PACKAGE_VERSION := $(APP_VERSION)-$(PACKAGE_VERSION)
endif
Expand Down
Loading
Loading