Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Add option to remove news and trending posts
Browse files Browse the repository at this point in the history
  • Loading branch information
haoict committed May 27, 2020
1 parent 1b8e6f0 commit 76299bf
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 8 deletions.
38 changes: 31 additions & 7 deletions Tweak.xm
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
* Load Preferences
*/
BOOL noads;
BOOL hideNewsAndTrending;
BOOL canSaveVideo;

static void reloadPrefs() {
NSDictionary *settings = [[NSMutableDictionary alloc] initWithContentsOfFile:@PLIST_PATH] ?: [@{} mutableCopy];

noads = [[settings objectForKey:@"noads"] ?: @(YES) boolValue];
hideNewsAndTrending = [[settings objectForKey:@"hideNewsAndTrending"] ?: @(YES) boolValue];
canSaveVideo = [[settings objectForKey:@"canSaveVideo"] ?: @(YES) boolValue];
}

Expand Down Expand Up @@ -37,22 +39,46 @@ static void showDownloadPopup(id twStatus, UIViewController *viewController, voi
[viewController presentViewController:alert animated:YES completion:nil];
}

%group NoAds
%group NewsFeedAndPosts
%hook TFNItemsDataViewController
- (id)tableViewCellForItem:(id)arg1 atIndexPath:(id)arg2 {
UITableViewCell *tbvCell = %orig;
id item = [self itemAtIndexPath: arg2];
if ([item respondsToSelector: @selector(isPromoted)] && [item performSelector:@selector(isPromoted)]) {

if (noads && [item respondsToSelector: @selector(isPromoted)] && [item performSelector:@selector(isPromoted)]) {
[tbvCell setHidden: YES];
return tbvCell;
}

if (hideNewsAndTrending) {
NSString *itemClassName = NSStringFromClass([item classForCoder]);
if ([itemClassName isEqualToString:@"T1Twitter.URTTimelineTrendViewModel"]
|| [itemClassName isEqualToString:@"T1Twitter.URTTimelineEventSummaryViewModel"]
|| [itemClassName isEqualToString:@"T1URTTimelineMessageItemViewModel"]) {
[tbvCell setHidden: YES];
return tbvCell;
}
}
return tbvCell;

return tbvCell;
}

- (double)tableView:(id)arg1 heightForRowAtIndexPath:(id)arg2 {
id item = [self itemAtIndexPath: arg2];
if ([item respondsToSelector: @selector(isPromoted)] && [item performSelector:@selector(isPromoted)]) {

if (noads && [item respondsToSelector: @selector(isPromoted)] && [item performSelector:@selector(isPromoted)]) {
return 0;
}

if (hideNewsAndTrending) {
NSString *itemClassName = NSStringFromClass([item classForCoder]);
if ([itemClassName isEqualToString:@"T1Twitter.URTTimelineTrendViewModel"]
|| [itemClassName isEqualToString:@"T1Twitter.URTTimelineEventSummaryViewModel"]
|| [itemClassName isEqualToString:@"T1URTTimelineMessageItemViewModel"]) {
return 0;
}
}

return %orig;
}
%end
Expand Down Expand Up @@ -88,9 +114,7 @@ static void showDownloadPopup(id twStatus, UIViewController *viewController, voi
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback) reloadPrefs, CFSTR(PREF_CHANGED_NOTIF), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
reloadPrefs();

if (noads) {
%init(NoAds);
}
%init(NewsFeedAndPosts);

if (canSaveVideo) {
%init(SaveVideo);
Expand Down
19 changes: 19 additions & 0 deletions pref/Resources/Root.plist
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@
<string>com.haoict.twitternoadspref/PrefChanged</string>
</dict>

<dict>
<key>cell</key>
<string>PSSwitchCell</string>
<key>cellClass</key>
<string>HPSSwitchCell</string>
<key>default</key>
<true/>
<key>defaults</key>
<string>com.haoict.twitternoadspref</string>
<key>key</key>
<string>hideNewsAndTrending</string>
<key>label</key>
<string>REMOVE_NEWS_AND_TRENDING</string>
<key>subtitle</key>
<string>REMOVE_NEWS_AND_TRENDING_POST_ON_SEARCH_TAB</string>
<key>PostNotification</key>
<string>com.haoict.twitternoadspref/PrefChanged</string>
</dict>

<dict>
<key>cell</key>
<string>PSSwitchCell</string>
Expand Down
2 changes: 2 additions & 0 deletions pref/Resources/base.lproj/Root.strings
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"MAIN_PREFERENCES" = "Main Preferences";
"NO_ADS" = "No Ads";
"REMOVE_ADS_IN_NEWS_FEED" = "Remove Ads in News Feed";
"REMOVE_NEWS_AND_TRENDING" = "Remove News And Trending";
"REMOVE_NEWS_AND_TRENDING_POST_ON_SEARCH_TAB" = "Remove News And Trending post on Search tab";
"CAN_SAVE_VIDEO" = "Can Save Video";
"LONG_PRESS_ON_VIDEO_TO_SAVE" = "Long press on video to save";
"OTHER_PREFERENCES" = "Other Preferences";
Expand Down
2 changes: 2 additions & 0 deletions pref/Resources/en.lproj/Root.strings
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"MAIN_PREFERENCES" = "Main Preferences";
"NO_ADS" = "No Ads";
"REMOVE_ADS_IN_NEWS_FEED" = "Remove Ads in News Feed";
"REMOVE_NEWS_AND_TRENDING" = "Remove News And Trending";
"REMOVE_NEWS_AND_TRENDING_POST_ON_SEARCH_TAB" = "Remove News And Trending post on Search tab";
"CAN_SAVE_VIDEO" = "Can Save Video";
"LONG_PRESS_ON_VIDEO_TO_SAVE" = "Long press on video to save";
"OTHER_PREFERENCES" = "Other Preferences";
Expand Down
4 changes: 3 additions & 1 deletion pref/Resources/vi.lproj/Root.strings
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
"DEFAULT" = "Mặc định";
"MAIN_PREFERENCES" = "Tùy chỉnh chính";
"NO_ADS" = "Gỡ quảng cáo";
"REMOVE_ADS_IN_NEWS_FEED" = "Gỡ quảng cáo ở News Feed";
"REMOVE_NEWS_AND_TRENDING" = "Remove News And Trending";
"REMOVE_NEWS_AND_TRENDING_POST_ON_SEARCH_TAB" = "Remove News And Trending post on Search tab";
"CAN_SAVE_VIDEO" = "Có thể tải video";
"LONG_PRESS_ON_VIDEO_TO_SAVE" = "Ấn và giữ video để lưu";
"REMOVE_ADS_IN_NEWS_FEED" = "Gỡ quảng cáo ở News Feed";
"OTHER_PREFERENCES" = "Tùy chỉnh phụ";
"RESET_SETTINGS" = "Đặt lại tùy chỉnh";
"SUPPORT_ME" = "Hỗ trợ tôi";
Expand Down

0 comments on commit 76299bf

Please sign in to comment.