Skip to content

Commit

Permalink
Merge pull request #16 from castdrian/v1
Browse files Browse the repository at this point in the history
feat!: v1
  • Loading branch information
castdrian authored Dec 24, 2024
2 parents e0433c9 + bafaaf2 commit f3bbf36
Show file tree
Hide file tree
Showing 9 changed files with 497 additions and 372 deletions.
98 changes: 67 additions & 31 deletions Settings.x
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,15 @@
return NO;
}]];

for (NSString *videoTitle in blockedVideos) {
for (NSDictionary *videoInfo in blockedVideos) {
[rows
addObject:
[%c(YTSettingsSectionItem)
itemWithTitle:@""
titleDescription:videoTitle
itemWithTitle:videoInfo[@"channel"] ?: @"Unknown Channel"
titleDescription:videoInfo[@"title"] ?: @"Unknown Title"
accessibilityIdentifier:nil
detailTextBlock:nil
selectBlock:^BOOL(YTSettingsCell *cell,
NSUInteger sectionItemIndex) {
selectBlock:^BOOL(YTSettingsCell *cell, NSUInteger arg1) {
YTSettingsViewController *settingsVC =
[self valueForKey:@"_settingsViewControllerDelegate"];
UIAlertController *alertController = [UIAlertController
Expand All @@ -248,7 +247,7 @@
stringWithFormat:
@"Are you sure you want "
@"to delete '%@'?",
videoTitle]
videoInfo[@"title"]]
preferredStyle:UIAlertControllerStyleAlert];

[alertController
Expand All @@ -258,7 +257,8 @@
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action) {
[[VideoManager sharedInstance]
removeBlockedVideo:videoTitle];
removeBlockedVideo:videoInfo
[@"id"]];
[self reloadGonerinoSection];

UIImpactFeedbackGenerator *generator =
Expand All @@ -270,9 +270,10 @@

[[%c(YTToastResponderEvent)
eventWithMessage:
[NSString stringWithFormat:
@"Deleted %@",
videoTitle]
[NSString
stringWithFormat:
@"Deleted %@",
videoInfo[@"title"]]
firstResponder:settingsVC] send];
}]];

Expand Down Expand Up @@ -639,35 +640,70 @@
return;
}

void (^continueImport)(void) = ^{
NSArray *words = settings[@"blockedWords"];
if (words) {
[[WordManager sharedInstance] setBlockedWords:words];
}

NSNumber *peopleWatched = settings[@"blockPeopleWatched"];
if (peopleWatched) {
[[NSUserDefaults standardUserDefaults] setBool:[peopleWatched boolValue]
forKey:@"GonerinoPeopleWatched"];
}

NSNumber *mightLike = settings[@"blockMightLike"];
if (mightLike) {
[[NSUserDefaults standardUserDefaults] setBool:[mightLike boolValue] forKey:@"GonerinoMightLike"];
}

[[NSUserDefaults standardUserDefaults] synchronize];
[self reloadGonerinoSection];
[[%c(YTToastResponderEvent) eventWithMessage:@"Settings imported successfully"
firstResponder:settingsVC] send];
};

NSArray *channels = settings[@"blockedChannels"];
if (channels) {
[[ChannelManager sharedInstance] setBlockedChannels:[NSMutableArray arrayWithArray:channels]];
}

NSArray *videos = settings[@"blockedVideos"];
if (videos) {
[[VideoManager sharedInstance] setBlockedVideos:videos];
}

NSArray *words = settings[@"blockedWords"];
if (words) {
[[WordManager sharedInstance] setBlockedWords:words];
}

NSNumber *peopleWatched = settings[@"blockPeopleWatched"];
if (peopleWatched) {
[[NSUserDefaults standardUserDefaults] setBool:[peopleWatched boolValue] forKey:@"GonerinoPeopleWatched"];
}

NSNumber *mightLike = settings[@"blockMightLike"];
if (mightLike) {
[[NSUserDefaults standardUserDefaults] setBool:[mightLike boolValue] forKey:@"GonerinoMightLike"];
if ([videos isKindOfClass:[NSArray class]]) {
BOOL isValidFormat = YES;
for (id videoEntry in videos) {
if (![videoEntry isKindOfClass:[NSDictionary class]] ||
![videoEntry[@"id"] isKindOfClass:[NSString class]] ||
![videoEntry[@"title"] isKindOfClass:[NSString class]] ||
![videoEntry[@"channel"] isKindOfClass:[NSString class]] || [videoEntry count] != 3) {
isValidFormat = NO;
break;
}
}

if (isValidFormat) {
[[VideoManager sharedInstance] setBlockedVideos:videos];
continueImport();
} else {
[[%c(YTToastResponderEvent)
eventWithMessage:@"Format outdated, blocked videos will not be imported"
firstResponder:settingsVC] send];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{ continueImport(); });
}
} else {
[[%c(YTToastResponderEvent)
eventWithMessage:@"Format outdated, blocked videos will not be imported"
firstResponder:settingsVC] send];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{ continueImport(); });
}
} else {
continueImport();
}

[[NSUserDefaults standardUserDefaults] synchronize];
[self reloadGonerinoSection];
[[%c(YTToastResponderEvent) eventWithMessage:@"Settings imported successfully"
firstResponder:settingsVC] send];
} else {
NSMutableDictionary *settings = [NSMutableDictionary dictionary];
settings[@"blockedChannels"] = [[ChannelManager sharedInstance] blockedChannels];
Expand Down
45 changes: 40 additions & 5 deletions Tweak.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#import "Util.h"

#import "ChannelManager.h"
#import "VideoManager.h"
#import "WordManager.h"

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
Expand Down Expand Up @@ -32,10 +33,6 @@ NS_ASSUME_NONNULL_BEGIN

- (void)removeOffendingCells;

- (BOOL)nodeContainsBlockedChannelName:(id)node;

- (BOOL)nodeContainsBlockedVideo:(id)node;

@end

@interface _ASCollectionViewCell : UICollectionViewCell
Expand Down Expand Up @@ -84,6 +81,7 @@ NS_ASSUME_NONNULL_BEGIN
- (UIViewController *)findViewControllerForView:(UIView *)view;
- (void)extractChannelNameFromNode:(id)node completion:(void (^)(NSString *channelName))completion;
- (nullable NSString *)extractVideoTitleFromNode:(id)node;
- (NSArray<YTActionSheetAction *> *)actions; // Added this line
@end

@interface YTActionSheetAction : NSObject
Expand Down Expand Up @@ -121,4 +119,41 @@ NS_ASSUME_NONNULL_BEGIN
settingItemId:(NSUInteger)settingItemId;
@end

@interface YTICommand : NSObject
@property(copy, nonatomic) NSString *description;
@end

@interface YTInlinePlaybackPlayerDescriptor : NSObject
@property(retain, nonatomic) id navigationEndpoint;
@end

@interface YTASDPlayableEntry : NSObject
@property(retain, nonatomic) YTICommand *navigationEndpoint;
@property(nonatomic) BOOL hasNavigationEndpoint;
@property(copy, nonatomic) NSString *description;
@end

@interface YTElementsInlineMutedPlaybackView : NSObject
@property(retain, nonatomic) YTASDPlayableEntry *asdPlayableEntry;
@end

@interface ELMContext : NSObject
- (id)elementForKey:(NSString *)key;
@end

@interface ELMElement : NSObject
@property(retain, nonatomic) id properties;
@property(retain, nonatomic) ELMContext *context;
- (id)propertyForKey:(NSString *)key;
- (NSDictionary *)allProperties;
- (id)valueForKey:(NSString *)key;
@end

@interface YTInlinePlaybackPlayerNode : ASDisplayNode
@property(nonatomic, readonly) id playbackView;
@property(nonatomic, readonly) ELMElement *element;
@property(nonatomic, readonly) ELMContext *context;
- (id)playbackView;
@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit f3bbf36

Please sign in to comment.