Skip to content
This repository has been archived by the owner on Jan 4, 2024. It is now read-only.

Commit

Permalink
Add link detection in text (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
ExTBH authored Nov 30, 2022
1 parent 0ff8dec commit 4ac3570
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 22 deletions.
4 changes: 4 additions & 0 deletions Theos/Classes/Exts.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
@interface NSUserDefaults (Colors)
- (void)setColor:(UIColor*)color forKey:(NSString*)key;
- (UIColor*)colorForKey:(NSString*)key;
@end

@interface UIView (FindUIViewController)
- (UIViewController *) firstAvailableUIViewController;
@end
14 changes: 14 additions & 0 deletions Theos/Classes/Exts.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,18 @@ - (UIColor*)colorForKey:(NSString*)key{
}
return nil;
}
@end

@implementation UIView (FindUIViewController)
- (UIViewController *) firstAvailableUIViewController {
UIResponder *responder = [self nextResponder];
while (responder != nil) {
if ([responder isKindOfClass:[UIViewController class]]) {
return (UIViewController *)responder;
}
responder = [responder nextResponder];
}
return nil;
}

@end
11 changes: 10 additions & 1 deletion Theos/Classes/JDESettingsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ - (NSDictionary*)cellInfoForPath:(NSIndexPath*)indexPath{
case 6:
info = @{
@"title": [self localizedStringForKey:@"screenshot_protection"],
@"desc": [self localizedStringForKey:@"screenshot_protection_desc"],
@"image": [UIImage systemImageNamed:@"bell.slash"]
}; break;
case 7:
info = @{
@"title": [self localizedStringForKey:@"detect_links"],
@"image": [UIImage systemImageNamed:@"link"]
}; break;
}
break;
case 1:
Expand All @@ -105,6 +109,11 @@ - (NSDictionary*)cellInfoForPath:(NSIndexPath*)indexPath{
@"title": [self localizedStringForKey:@"logs"],
@"image": [UIImage systemImageNamed:@"doc.text"]
}; break;
case 3:
info = @{
@"title": @"Theming",
@"image": [UIImage systemImageNamed:@"scribble"]
}; break;
}
}
return info;
Expand Down
36 changes: 36 additions & 0 deletions Theos/Headers/ZSWTappableLabel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// ZSWTappableLabel.h
// ZSWTappableLabel
//
// Copyright (c) 2019 Zachary West. All rights reserved.
//
// MIT License
// https://github.com/zacwest/ZSWTappableLabel
//

#import <UIKit/UIKit.h>



NS_ASSUME_NONNULL_BEGIN
@interface ZSWTappableLabel : UILabel
@end
#pragma mark - Attributes you include in strings

NSAttributedStringKey const ZSWTappableLabelHighlightedBackgroundAttributeName
NS_SWIFT_NAME(tappableHighlightedBackgroundColor) = @"ZSWTappableLabelHighlightedBackgroundAttributeName";

NSAttributedStringKey const ZSWTappableLabelHighlightedForegroundAttributeName
NS_SWIFT_NAME(tappableHighlightedForegroundColor) = @"ZSWTappableLabelHighlightedForegroundAttributeName";

NSAttributedStringKey const ZSWTappableLabelTappableRegionAttributeName
NS_SWIFT_NAME(tappableRegion) = @"ZSWTappableLabelTappableRegionAttributeName";

@protocol ZSWTappableLabelTapDelegate

- (void)tappableLabel:(ZSWTappableLabel *)tappableLabel
tappedAtIndex:(NSInteger)idx
withAttributes:(NSDictionary<NSAttributedStringKey, id> *)attributes;
@end

NS_ASSUME_NONNULL_END
6 changes: 1 addition & 5 deletions Theos/JDEViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ - (void)openLinkForIndexPath:(NSIndexPath*)indexPath{
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 2; }

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(section == 0){ return 7;}
if(section == 0){ return 8;}
return 4;
}

Expand Down Expand Up @@ -195,10 +195,6 @@ - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForR
UIImage *icon = [UIImage resizeImageFromImage:infoDict[@"image"] withSize:CGSizeMake(25, 25)];
cell.imageView.image = icon;
}
else if (indexPath.row == 3) {
cell.imageView.image = [UIImage systemImageNamed:@"scribble"];
cell.textLabel.text = @"Theming";
}
}

[NSLayoutConstraint activateConstraints:consts];
Expand Down
10 changes: 9 additions & 1 deletion Theos/Tweak.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#import <PhotosUI/PhotosUI.h>
#import "JDEViewController.h"
#import "Headers/AppHaptic.h"
#import "Headers/ZSWTappableLabel.h"
#import <SafariServices/SafariServices.h>

@interface PictureFeedViewController : UIViewController
@property (weak, nonatomic, readwrite) UIButton *addReactionButton;
Expand All @@ -25,7 +27,8 @@
@interface JDLFeedTableViewSource <UITableViewDataSource, UITableViewDelegate> //Its both delegate and dataSource. BLKFlexibleHeightBar forwards calls to it
@end

@interface JDLPostDetailsPostCellV2 : UITableViewCell
@interface JDLPostDetailsPostCell : UITableViewCell

- (id)contentLabel;
- (void)setContentLabel:(id)contentLabel;
@end
Expand All @@ -45,3 +48,8 @@
- (void)upvoteTap:(id)sender;
- (UIViewController *) firstAvailableUIViewController:(UIView*)view; //Getting the VC to show an alert
@end

@interface TappableLabel : UILabel
@end
@interface FeedCellTappableLabelDelegate : NSObject <ZSWTappableLabelTapDelegate>
@end
48 changes: 44 additions & 4 deletions Theos/Tweak.x
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@
//Copying for sub posts
else if([cellClass isEqualToString:@"Jodel.JDLPostDetailsPostCell"]){
//Change cell type to access methods interfaced methods
JDLPostDetailsPostCellV2 *cell = [tableView cellForRowAtIndexPath:indexPath];
JDLPostDetailsPostCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIPasteboard.generalPasteboard.string = [[cell contentLabel] text];
[[JDESettingsManager sharedInstance] logString:[NSString stringWithFormat:@"Successfully copied for (%@)", cellClass]];
}
Expand All @@ -329,8 +329,46 @@
}
%end

%hook TappableLabel
-(void)setAttributedText:(NSAttributedString *)arg1{
NSMutableAttributedString *newAttributedString = [[NSMutableAttributedString alloc] initWithAttributedString:arg1];
if([[JDESettingsManager sharedInstance] featureStateForTag:7]){
NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
[detector enumerateMatchesInString:arg1.string options:0 range:NSMakeRange(0, arg1.string.length)
usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
attributes[ZSWTappableLabelTappableRegionAttributeName] = @YES;
attributes[ZSWTappableLabelHighlightedBackgroundAttributeName] = UIColor.lightGrayColor;
attributes[ZSWTappableLabelHighlightedForegroundAttributeName] = UIColor.whiteColor;
attributes[NSUnderlineStyleAttributeName] = @(NSUnderlineStyleSingle);
attributes[@"NSTextCheckingResult"] = result;
[newAttributedString addAttributes:attributes range:result.range];
}];
}

%orig(newAttributedString);

}
%end

%hook FeedCellTappableLabelDelegate
- (void)tappableLabel:(ZSWTappableLabel *)tappableLabel tappedAtIndex:(NSInteger)idx withAttributes:(NSDictionary<NSAttributedStringKey, id> *)attributes{
if([[JDESettingsManager sharedInstance] featureStateForTag:7]){
NSTextCheckingResult *result = attributes[@"NSTextCheckingResult"];
if(result.resultType == NSTextCheckingTypeLink){
UIViewController *presentationController = [tappableLabel firstAvailableUIViewController];
if (presentationController != nil){
SFSafariViewController *inApp = [[SFSafariViewController alloc] initWithURL:result.URL];
[presentationController presentViewController:inApp animated:YES completion:nil];
}
}
}
%orig;
}
%end

//DON'T DELETE WILL BREAK ABOVE METHOD
%hook JDLPostDetailsPostCellV2
%hook JDLPostDetailsPostCell
%end

%hook UIColor
Expand All @@ -350,10 +388,12 @@
PictureFeedViewController=objc_getClass("Jodel.PictureFeedViewController"),
ScreenshotService=objc_getClass("Jodel.ScreenshotService"),
FeedCellVoteView=objc_getClass("Jodel.JDLFeedCellVoteView"),
JDLPostDetailsPostCellV2=objc_getClass("Jodel.JDLPostDetailsPostCellV2"),
JDLPostDetailsPostCell=objc_getClass("Jodel.JDLPostDetailsPostCell"),
ChatboxViewController=objc_getClass("Jodel.ChatboxViewController"),
JDLFeedTableViewSource=objc_getClass("Jodel.JDLFeedTableViewSource"),
MainFeedViewController=objc_getClass("Jodel.MainFeedViewController"),
ImageCaptureViewController=objc_getClass("Jodel.ImageCaptureViewController"));
ImageCaptureViewController=objc_getClass("Jodel.ImageCaptureViewController"),
TappableLabel=objc_getClass("Jodel.TappableLabel"),
FeedCellTappableLabelDelegate=objc_getClass("Jodel.FeedCellTappableLabelDelegate"));
}

2 changes: 1 addition & 1 deletion Theos/layout/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: dev.extbh.jodelemproved
Name: Jodel EMPROVED
Version: 1.1.4-1
Version: 1.1.5
Architecture: iphoneos-arm
Description: Customizing the Jodel app
Depiction: https://repo.depiction.extbh.dev/dev.extbh.jodelemproved/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,13 @@
"confirm_replies" = "تأكيد الردود";
"screenshot_protection" = "حماية تصوير الشاشة";
"tracking_protection" = "حماية التتبع";
"detect_links" = "فتح الروابط";

///More Section
"source_code" = "السورس كود";
"twitter" = "ExTBH";
"logs" = "لوقات الاداه";

//Settings description
"copy_paste_desc" = "تتفعل بالضفط المطول, تحتاج إلى ريستارت للتغيير";
"screenshot_protection_desc" = "أخذ صور للشاشة بدون تنبيه";
"tracking_protection_desc" = "إيقاف التتبع للخصوصية";

//Confirm Alerts
"confirm_reply_title" = "تأكيد الرد";
"confirm_reply_ok" = "أرسل";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,13 @@
"confirm_replies" = "Confirm Replies";
"screenshot_protection" = "Screenshot Protection";
"tracking_protection" = "Tracking Protection";
"detect_links" = "Detect Links in text";

///More Section
"source_code" = "Source Code";
"twitter" = "ExTBH";
"logs" = "Tweak Logs";

//Settings description
"copy_paste_desc" = "Activates by long press, needs restart for changes";
"screenshot_protection_desc" = "Takes screenshot without anyone knowing";
"tracking_protection_desc" = "No more tracking";

//Confirm Alerts
"confirm_reply_title" = "Confirm Reply";
"confirm_reply_ok" = "Reply";
Expand Down

0 comments on commit 4ac3570

Please sign in to comment.