mirror of
https://github.com/lint/TFDidThatSay
synced 2025-07-04 08:36:45 +00:00
Add Slide post support
This commit is contained in:
@ -15,6 +15,21 @@
|
|||||||
-(void) addUndeleteButtonToMenu;
|
-(void) addUndeleteButtonToMenu;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
/* -- Post Interfaces -- */
|
||||||
|
|
||||||
|
@interface RSubmission
|
||||||
|
@property(assign, nonatomic) BOOL isSelf;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@interface CommentViewController : UIViewController
|
||||||
|
-(void) refresh:(id) arg1;
|
||||||
|
|
||||||
|
//custom elements
|
||||||
|
@property(strong, nonatomic) UIButton *undeleteButton;
|
||||||
|
-(void) addUndeleteButtonToToolbar;
|
||||||
|
-(BOOL) shouldAddUndeleteButtonToToolbar;
|
||||||
|
@end
|
||||||
|
|
||||||
/* -- Utility Interfaces -- */
|
/* -- Utility Interfaces -- */
|
||||||
|
|
||||||
@interface UIColor ()
|
@interface UIColor ()
|
||||||
|
135
tweak/Slide.xm
135
tweak/Slide.xm
@ -9,6 +9,10 @@ static CGFloat pushshiftRequestTimeoutValue;
|
|||||||
|
|
||||||
%group Slide
|
%group Slide
|
||||||
|
|
||||||
|
BOOL shouldSlideOverridePostInfo = NO;
|
||||||
|
NSString *slidePostOverrideAuthor;
|
||||||
|
NSString *slidePostOverrideBodyHtml;
|
||||||
|
|
||||||
@implementation FontGenerator
|
@implementation FontGenerator
|
||||||
|
|
||||||
+(UIFont *) fontOfSize:(CGFloat) size submission:(BOOL) isSubmission willOffset:(BOOL) willOffset{
|
+(UIFont *) fontOfSize:(CGFloat) size submission:(BOOL) isSubmission willOffset:(BOOL) willOffset{
|
||||||
@ -209,11 +213,6 @@ static UIButton * createUndeleteButton(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//because it wont compile without this
|
|
||||||
%hook RComment
|
|
||||||
%end
|
|
||||||
|
|
||||||
|
|
||||||
%hook UIColor
|
%hook UIColor
|
||||||
|
|
||||||
%new
|
%new
|
||||||
@ -399,6 +398,130 @@ static UIButton * createUndeleteButton(){
|
|||||||
|
|
||||||
%end
|
%end
|
||||||
|
|
||||||
|
|
||||||
|
%hook RSubmission
|
||||||
|
|
||||||
|
-(id) author{
|
||||||
|
if (shouldSlideOverridePostInfo){
|
||||||
|
return slidePostOverrideAuthor;
|
||||||
|
} else {
|
||||||
|
return %orig;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-(id) htmlBody{
|
||||||
|
if (shouldSlideOverridePostInfo){
|
||||||
|
return slidePostOverrideBodyHtml;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return %orig;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%end
|
||||||
|
|
||||||
|
|
||||||
|
%hook CommentViewController
|
||||||
|
%property(strong, nonatomic) UIButton *undeleteButton;
|
||||||
|
|
||||||
|
-(void) viewDidLoad {
|
||||||
|
%orig;
|
||||||
|
|
||||||
|
shouldSlideOverridePostInfo = NO;
|
||||||
|
slidePostOverrideAuthor = nil;
|
||||||
|
slidePostOverrideBodyHtml = nil;
|
||||||
|
|
||||||
|
UIButton *undeleteButton = createUndeleteButton();
|
||||||
|
[undeleteButton setImage:[[undeleteButton currentImage] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
|
||||||
|
[undeleteButton addTarget:self action:@selector(handleUndeletePost:) forControlEvents:UIControlEventTouchUpInside];
|
||||||
|
[self setUndeleteButton:undeleteButton];
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void) viewDidLayoutSubviews{
|
||||||
|
%orig;
|
||||||
|
|
||||||
|
if ([self undeleteButton]){
|
||||||
|
if ([self shouldAddUndeleteButtonToToolbar]){
|
||||||
|
[self addUndeleteButtonToToolbar];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void) loadAll:(id) arg1{
|
||||||
|
%orig;
|
||||||
|
|
||||||
|
if ([self undeleteButton]){
|
||||||
|
if ([self shouldAddUndeleteButtonToToolbar]){
|
||||||
|
[self addUndeleteButtonToToolbar];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%new
|
||||||
|
-(BOOL) shouldAddUndeleteButtonToToolbar{
|
||||||
|
id post = MSHookIvar<id>(self, "submission");
|
||||||
|
|
||||||
|
if ([post isSelf]){
|
||||||
|
|
||||||
|
NSString *postBody = [post body];
|
||||||
|
|
||||||
|
if ((isTFDeletedOnly && ([postBody isEqualToString:@"[deleted]"] || [postBody isEqualToString:@"[removed]"])) || !isTFDeletedOnly){
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
%new
|
||||||
|
-(void) addUndeleteButtonToToolbar{
|
||||||
|
UIToolbar *toolbar = [[self navigationController] toolbar];
|
||||||
|
NSMutableArray *toolbarItems = [[toolbar items] mutableCopy];
|
||||||
|
UIView *firstView = [toolbarItems[0] customView];
|
||||||
|
|
||||||
|
if (firstView){
|
||||||
|
UIColor *tintColor = [toolbar tintColor];
|
||||||
|
|
||||||
|
UIButton *undeleteButton = [self undeleteButton];
|
||||||
|
[undeleteButton setTintColor:tintColor];
|
||||||
|
|
||||||
|
if ([firstView isMemberOfClass:[UIView class]]){
|
||||||
|
if (![undeleteButton isDescendantOfView:firstView]){
|
||||||
|
[firstView addSubview:undeleteButton];
|
||||||
|
[undeleteButton setFrame:firstView.bounds];
|
||||||
|
}
|
||||||
|
} else if ([firstView isMemberOfClass:[UIButton class]] && undeleteButton != firstView){
|
||||||
|
UIBarButtonItem *undeleteItem = [[UIBarButtonItem alloc] initWithCustomView:undeleteButton];
|
||||||
|
|
||||||
|
[toolbarItems insertObject:toolbarItems[1] atIndex:0];
|
||||||
|
[toolbarItems insertObject:undeleteItem atIndex:0];
|
||||||
|
[toolbar setItems:toolbarItems animated:NO];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%new
|
||||||
|
-(void) handleUndeletePost:(id) sender{
|
||||||
|
shouldSlideOverridePostInfo = YES;
|
||||||
|
|
||||||
|
[sender setEnabled:NO];
|
||||||
|
|
||||||
|
[%c(TFHelper) getUndeleteDataWithID:[MSHookIvar<id>(self, "submission") name] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
|
||||||
|
}
|
||||||
|
|
||||||
|
%new
|
||||||
|
-(void) completeUndeletePostAction:(NSDictionary *) data{
|
||||||
|
|
||||||
|
slidePostOverrideAuthor = data[@"author"];
|
||||||
|
slidePostOverrideBodyHtml = [%c(MMMarkdown) HTMLStringWithMarkdown:data[@"body"] extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
|
||||||
|
|
||||||
|
[self refresh:nil];
|
||||||
|
|
||||||
|
[data[@"sender"] setEnabled:YES];
|
||||||
|
}
|
||||||
|
|
||||||
|
%end
|
||||||
|
|
||||||
%end
|
%end
|
||||||
|
|
||||||
|
|
||||||
@ -447,7 +570,7 @@ static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStrin
|
|||||||
|
|
||||||
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
|
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
|
||||||
|
|
||||||
%init(Slide, CommentDepthCell = objc_getClass("Slide_for_Reddit.CommentDepthCell"), RComment = objc_getClass("Slide_for_Reddit.RSubmission"));
|
%init(Slide, CommentDepthCell = objc_getClass("Slide_for_Reddit.CommentDepthCell"), RSubmission = objc_getClass("Slide_for_Reddit.RSubmission"), CommentViewController = objc_getClass("Slide_for_Reddit.CommentViewController"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user