Skip to content

Commit

Permalink
Update 2.9.6
Browse files Browse the repository at this point in the history
- New feature: Save tweets as images.
- Fix Padlock feature issues.
- Fix Tweet confirm option.
  • Loading branch information
BandarHL committed Jun 25, 2022
1 parent 1d874dc commit 8a01948
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 68 deletions.
1 change: 1 addition & 0 deletions BHTwitter/BHTManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@
+ (BOOL)disableSensitiveTweetWarnings;
+ (BOOL)TwitterCircle;
+ (BOOL)CopyProfileInfo;
+ (BOOL)tweetToImage;
@end

13 changes: 12 additions & 1 deletion BHTwitter/BHTManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ + (BOOL)TwitterCircle {
+ (BOOL)CopyProfileInfo {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"CopyProfileInfo"];
}
+ (BOOL)tweetToImage {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"TweetToImage"];
}
+ (UIViewController *)BHTSettings {
HBPreferences *pref = [[HBPreferences alloc] initTableWithTableStyle:UITableViewStyleInsetGrouped title:@"BHTwitter" SeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
HBSection *mainSection = [HBSection sectionWithTitle:@"BHTwitter Preferences" footer:nil];
Expand Down Expand Up @@ -378,6 +381,14 @@ + (UIViewController *)BHTSettings {
}
}];

HBSwitchCell *tweetToImage = [[HBSwitchCell alloc] initSwitchCellWithImage:nil Title:@"Save tweet as image" DetailTitle:@"You can export tweets as image, by long pressing on the Tweet Share button" switchKey:@"TweetToImage" withBlock:^(UISwitch *weakSender) {
if (weakSender.isOn) {
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"TweetToImage"];
} else {
[[NSUserDefaults standardUserDefaults] setBool:false forKey:@"TweetToImage"];
}
}];

HBViewControllerCell *fontsPicker = [[HBViewControllerCell alloc] initCellWithTitle:@"Font" detail:[[NSUserDefaults standardUserDefaults] objectForKey:@"bhtwitter_font_1"] action:^UIViewController *{
UIFontPickerViewControllerConfiguration *configuration = [[UIFontPickerViewControllerConfiguration alloc] init];
[configuration setFilteredTraits:UIFontDescriptorClassMask];
Expand Down Expand Up @@ -439,7 +450,7 @@ + (UIViewController *)BHTSettings {
HBGithubCell *sourceCode = [[HBGithubCell alloc] initGithubCellWithTitle:@"BHTwitter" detailTitle:@"Code source of BHTwitter" GithubURL:@"https://github.com/BandarHL/BHTwitter/"];


[mainSection addCells:@[download, hide_ads, hide_topics, disable_VODCaptions, direct_save, voice, voice_in_replay, UndoTweet, ReaderMode, ReplyLater, VideoZoom, NoHistory, BioTranslate, like_confirm, tweet_confirm, follow_confirm, padlock, DmModularSearch, autoHighestLoad, disableSensitiveTweetWarnings, copyProfileInfo, trustedFriends]];
[mainSection addCells:@[download, hide_ads, hide_topics, disable_VODCaptions, direct_save, voice, voice_in_replay, UndoTweet, ReaderMode, ReplyLater, VideoZoom, NoHistory, BioTranslate, like_confirm, tweet_confirm, follow_confirm, padlock, DmModularSearch, autoHighestLoad, disableSensitiveTweetWarnings, copyProfileInfo, trustedFriends, tweetToImage]];

[layoutSection addCells:@[oldTweetStyle, dwbLayout, font]];
if ([BHTManager changeFont]) {
Expand Down
74 changes: 55 additions & 19 deletions BHTwitter/BHTwitter.xm
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
[image setContentMode:UIViewContentModeCenter];
[self.window addSubview:image];
}
if ([BHTManager FLEX]) {
[[FLEXManager sharedManager] showExplorer];
}
}
%end

Expand Down Expand Up @@ -313,11 +316,42 @@
}
%end

// MARK: Save tweet as image
%hook T1StatusInlineShareButton
- (void)didLongPressActionButton:(UILongPressGestureRecognizer *)gestureRecognizer {
if ([BHTManager tweetToImage]) {
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
T1StatusInlineActionsView *actionsView = self.delegate;
UIView *tweetView;

// it supposed the T1StatusInlineShareButton class only exist in Tweet view, but just to make sure we are working in tweet. :)
if ([actionsView.superview isKindOfClass:%c(T1StandardStatusView)]) { // normal tweet in the time line
tweetView = actionsView.superview;
} else if ([actionsView.superview isKindOfClass:%c(T1TweetDetailsFocalStatusView)]) { // Focus tweet
tweetView = actionsView.superview;
} else {
return;
}

UIImage *tweetImage = imageFromView(tweetView);
UIActivityViewController *acVC = [[UIActivityViewController alloc] initWithActivityItems:@[tweetImage] applicationActivities:nil];
if (is_iPad()) {
acVC.popoverPresentationController.sourceView = self;
acVC.popoverPresentationController.sourceRect = self.frame;
}
[topMostController() presentViewController:acVC animated:true completion:nil];
return;
}
}
return %orig;
}
%end

// MARK: Timeline download
// THIS SOLUTION WAS TAKEN FROM Translomatic AFTER DISASSEMBLING THE DYLIB
// SO THANKS: @foxfortmobile
%hook T1StatusInlineActionsView
+ (NSArray *)_t1_inlineActionViewClassesForViewModel:(id)arg1 options:(unsigned long long)arg2 displayType:(unsigned long long)arg3 account:(id)arg4 {
+ (NSArray *)_t1_inlineActionViewClassesForViewModel:(id)arg1 options:(NSUInteger)arg2 displayType:(NSUInteger)arg3 account:(id)arg4 {
NSArray *_orig = %orig;
NSMutableArray *newOrig = [_orig mutableCopy];

Expand All @@ -329,8 +363,6 @@
}
%end

// MARK: always Open Safari
// thanks: @CrazyMind90
%hook TFSTwitterEntityURL
- (NSString *)url {
// https://github.com/haoict/twitter-no-ads/blob/master/Tweak.xm#L195
Expand Down Expand Up @@ -389,9 +421,9 @@
}
- (id)_t1_loadHighQualityActionItemWithTitle:(id)arg1 forImageDisplayView:(id)arg2 highestQuality:(_Bool)arg3 {
if ([BHTManager autoHighestLoad]) {
return %orig(arg1, arg2, true);
arg3 = true;
}
return %orig(arg1, arg2, arg3);
return %orig;
}
%end

Expand Down Expand Up @@ -420,15 +452,6 @@
%end

// MARK: Voice feature
%hook TFNTwitterComposition
- (BOOL)isReply {
if ([BHTManager voice_in_replay]) {
return false;
}
return %orig;
}
%end

%hook TFSTwitterAPICommandAccountStateProvider
- (_Bool)allowPromotedContent {
if ([BHTManager HidePromoted]) {
Expand Down Expand Up @@ -538,9 +561,9 @@
}
%end
%hook TFNTwitterComposition
- (BOOL)hasVoiceRecordingAttachment {
if ([BHTManager VoiceFeature]) {
return true;
- (BOOL)isReply {
if ([BHTManager voice_in_replay]) {
return false;
}
return %orig;
}
Expand Down Expand Up @@ -578,6 +601,19 @@

// MARK: Tweet confirm
%hook T1TweetComposeViewController
- (void)_t1_didTapSendButton:(UIButton *)tweetButton {
if ([BHTManager TweetConfirm]) {
[FLEXAlert makeAlert:^(FLEXAlert *make) {
make.message(@"Are you sure?");
make.button(@"Yes").handler(^(NSArray<NSString *> *strings) {
%orig;
});
make.button(@"No").cancelStyle();
} showFrom:self];
} else {
return %orig;
}
}
- (void)_t1_handleTweet {
if ([BHTManager TweetConfirm]) {
[FLEXAlert makeAlert:^(FLEXAlert *make) {
Expand Down Expand Up @@ -688,15 +724,15 @@

// MARK: BHTwitter settings
%hook TFNActionItem
%new + (id)actionItemWithTitle:(NSString *)arg1 systemImageName:(NSString *)arg2 action:(void (^)(void))arg3 {
%new + (instancetype)actionItemWithTitle:(NSString *)arg1 systemImageName:(NSString *)arg2 action:(void (^)(void))arg3 {
TFNActionItem *_self = [%c(TFNActionItem) actionItemWithTitle:arg1 imageName:nil action:arg3];
[_self setValue:[UIImage systemImageNamed:arg2] forKey:@"_image"];
return _self;
}
%end

%hook TFNSettingsNavigationItem
%new - (id)initWithTitle:(NSString *)arg1 detail:(NSString *)arg2 systemIconName:(NSString *)arg3 controllerFactory:(UIViewController* (^)(void))arg4 {
%new - (instancetype)initWithTitle:(NSString *)arg1 detail:(NSString *)arg2 systemIconName:(NSString *)arg3 controllerFactory:(UIViewController* (^)(void))arg4 {
TFNSettingsNavigationItem *_self = [[%c(TFNSettingsNavigationItem) alloc] initWithTitle:arg1 detail:arg2 iconName:arg3 controllerFactory:arg4];
[_self setValue:[UIImage systemImageNamed:arg3] forKey:@"_icon"];
return _self;
Expand Down
2 changes: 1 addition & 1 deletion BHTwitter/Package/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: com.bandarhl.BHTwitter
Name: BHTwitter
Version: 2.9.5-2
Version: 2.9.6
Description: Awesome tweak for Twitter
Section: Tweaks
Depends: firmware (>= 13.0), mobilesubstrate
Expand Down
6 changes: 5 additions & 1 deletion BHTwitter/SAMKeychain/AuthViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ @implementation AuthViewController
- (void)viewDidLoad {
[super viewDidLoad];
LAContext *context = [[LAContext alloc] init];
if ([context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil]) {
if ([self canEvaluateBiometrics]) {
[context evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:@"Touch ID or Face ID is required to use Twitter" reply:^(BOOL success, NSError * _Nullable error) {
if (success) {
[[keychain shared] saveDictionary:@{@"isAuthenticated": @YES}];
Expand Down Expand Up @@ -47,4 +47,8 @@ - (void)viewDidLoad {
}
}

- (BOOL)canEvaluateBiometrics {
NSMutableDictionary *infoPlistDict = [NSMutableDictionary dictionaryWithDictionary:[[NSBundle mainBundle] infoDictionary]];
return [infoPlistDict objectForKey:@"NSFaceIDUsageDescription"] != nil ? true : false;
}
@end
97 changes: 51 additions & 46 deletions BHTwitter/TWHeaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,36 +67,38 @@
@end

@interface TAEStandardFontGroup : NSObject
+ (id)sharedFontGroup;
+ (instancetype)sharedFontGroup;
- (UIFont *)fixedLargeBoldFont;
@end

@interface TFNActionItem : NSObject
+ (id)cancelActionItemWithAction:(void (^)(void))arg1;
+ (id)cancelActionItemWithTitle:(NSString *)arg1;
+ (id)actionItemWithTitle:(NSString *)arg1 action:(void (^)(void))arg2;
+ (id)actionItemWithTitle:(NSString *)arg1 imageName:(NSString *)arg2 action:(void (^)(void))arg3;
+ (id)actionItemWithTitle:(NSString *)arg1 subtitle:(NSString *)arg2 imageName:(NSString *)arg3 action:(void (^) (void))arg4;
+ (id)actionItemWithTitle:(NSString *)arg1 systemImageName:(NSString *)arg2 action:(void (^)(void))arg3;
+ (instancetype)cancelActionItemWithAction:(void (^)(void))arg1;
+ (instancetype)cancelActionItemWithTitle:(NSString *)arg1;
+ (instancetype)actionItemWithTitle:(NSString *)arg1 action:(void (^)(void))arg2;
+ (instancetype)actionItemWithTitle:(NSString *)arg1 imageName:(NSString *)arg2 action:(void (^)(void))arg3;
+ (instancetype)actionItemWithTitle:(NSString *)arg1 subtitle:(NSString *)arg2 imageName:(NSString *)arg3 action:(void (^) (void))arg4;
+ (instancetype)actionItemWithTitle:(NSString *)arg1 systemImageName:(NSString *)arg2 action:(void (^)(void))arg3;
@end

@interface TFNMenuSheetCenteredIconItem : NSObject
- (id)initWithIconImageName:(id)imageName height:(CGFloat)arg1 fillColor:(id)Color;
- (instancetype)initWithIconImageName:(id)imageName height:(CGFloat)arg1 fillColor:(id)Color;
@end

@interface TFNAttributedTextModel : NSObject
- (id)initWithAttributedString:(NSMutableAttributedString *)arg;
- (instancetype)initWithAttributedString:(NSMutableAttributedString *)arg;
@end

@interface TFNActiveTextItem : NSObject
- (id)initWithTextModel:(id)arg activeRanges:(id)arg1;
- (instancetype)initWithTextModel:(id)arg activeRanges:(id)arg1;
@end

@interface TFNMenuSheetViewController : TFNItemsDataViewController
@property(nonatomic, assign, readwrite) BOOL shouldPresentAsMenu;
- (id)initWithTitle:(id)arg1 actionItems:(id)arg2;
- (id)initWithMessage:(id)arg1 actionItems:(id)arg2;
- (id)initWithActionItems:(id)arg1;
@property(retain, nonatomic) UIView *sourceView;
- (instancetype)initWithTitle:(NSString *)sheetTitle actionItems:(NSArray *)actionItems;
- (instancetype)initWithMessage:(NSString *)sheetMessage actionItems:(NSArray *)actionItems;
- (instancetype)initWithActionItems:(NSArray *)actionItems;
- (instancetype)initWithTitle:(NSString *)sheetTitle titleStyle:(long long)sheetTitleStyle message:(NSString *)sheetMessage messageIconName:(id)sheetMessageIconName actionItemSections:(NSArray *)actionItemSections;
- (void)tfnPresentedCustomPresentFromViewController:(id)arg1 animated:(BOOL)arg2 completion:(void (^) (void))arg3;
@end

Expand All @@ -105,18 +107,10 @@
@property (nonatomic, strong) NSArray *sections;
@end

@interface TFSTwitterEntityURL : NSObject
@property(readonly, copy, nonatomic) NSString *expandedURL;
@end

@interface T1SafariViewController : UIViewController
@property (readonly, nonatomic) NSURL *rootURL;
@end

@interface TFNSettingsNavigationItem : NSObject
- (id)initWithTitle:(NSString *)arg1 detail:(NSString *)arg2 iconName:(NSString *)arg3 controllerFactory:(UIViewController* (^)(void))arg4;
- (id)initWithTitle:(NSString *)arg1 detail:(NSString *)arg2 systemIconName:(NSString *)arg3 controllerFactory:(UIViewController* (^)(void))arg4;
- (id)initWithTitle:(NSString *)arg1 detail:(NSString *)arg2 controllerFactory:(UIViewController* (^)(void))arg4;
- (instancetype)initWithTitle:(NSString *)arg1 detail:(NSString *)arg2 iconName:(NSString *)arg3 controllerFactory:(UIViewController* (^)(void))arg4;
- (instancetype)initWithTitle:(NSString *)arg1 detail:(NSString *)arg2 systemIconName:(NSString *)arg3 controllerFactory:(UIViewController* (^)(void))arg4;
- (instancetype)initWithTitle:(NSString *)arg1 detail:(NSString *)arg2 controllerFactory:(UIViewController* (^)(void))arg4;
@end

@interface TFNTextCell: UITableViewCell
Expand Down Expand Up @@ -152,14 +146,11 @@
@property(retain, nonatomic) T1ProfileUserViewModel *viewModel;
@end

@interface T1StatusInlineActionButton : UIView
{
TFNAnimatableButton *_modernButton;
UIButton *_button;
}
@property (nonatomic, assign, readwrite) UIEdgeInsets touchInsets;
@property(readonly, nonatomic) TFNLegacyButtonAnimator *animator;
- (id)initWithOptions:(unsigned long long)arg1 overrideSize:(id)arg2 account:(id)arg3;
@protocol T1StatusInlineActionButtonDelegate <NSObject>
@end

@interface T1StatusInlineShareButton : UIView
@property(nonatomic) __weak id <T1StatusInlineActionButtonDelegate> delegate;
@end

@interface TFSTwitterEntityMediaVideoVariant : NSObject
Expand All @@ -185,17 +176,17 @@
@property(nonatomic, readonly) TFSTwitterEntitySet *entities;
@end

@interface T1SlideshowStatusView: NSObject
@end

@interface T1StatusInlineActionsView : UIView
@interface T1StatusInlineActionsView : UIView <T1StatusInlineActionButtonDelegate>
@property(readonly, nonatomic) id <T1StatusViewModel> viewModel;
@end

@interface T1StandardStatusView : UIView
@property(readonly, nonatomic) UIView *visibleInlineActionsView;
@end

@interface T1TweetDetailsFocalStatusView : UIView
@end

@interface TFNButtonBarView : UIView
@property(nonatomic) double trailingViewsSpacing;
@property(nonatomic) double leadingViewsSpacing;
Expand Down Expand Up @@ -252,7 +243,7 @@
- (_Bool)accessibilityActivate;
- (void)dealloc;
- (void)layoutSubviews;
- (id)initWithFrame:(struct CGRect)arg1;
- (instancetype)initWithFrame:(struct CGRect)arg1;
- (void)DownloadHandler;
@end

Expand Down Expand Up @@ -280,20 +271,34 @@
@property(readonly, nonatomic) NSString *mediaScribeContentID;
@end

@interface TFSTwitterEntityURL : NSObject
@property(readonly, copy, nonatomic) NSString *expandedURL;
@end

@interface T1StatusBodyTextView : UIView
@property(readonly, nonatomic) id viewModel; // @synthesize viewModel=_viewModel;
@end

static BOOL BH_canOpenURL(NSURL *url) {
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"openInBrowser"]) {
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
return true;
}
return false;
}
return false;
@interface TAETwitterColorPaletteSettingInfo : NSObject
@property(readonly, nonatomic) _Bool isDark;
@end

@interface TAEColorSettings : NSObject
@property(retain, nonatomic) TAETwitterColorPaletteSettingInfo *currentColorPalette;
+ (instancetype)sharedSettings;
@end

static UIImage *imageFromView(UIView *view) {
TAEColorSettings *colorSettings = [objc_getClass("TAEColorSettings") sharedSettings];
bool opaque = [colorSettings.currentColorPalette isDark] ? true : false;
UIGraphicsBeginImageContextWithOptions(view.layer.frame.size, opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return img;
}

static BOOL isDeviceLanguageRTL() {
return ([NSLocale characterDirectionForLanguage:[[NSLocale preferredLanguages] objectAtIndex:0]] == NSLocaleLanguageDirectionRightToLeft);
}
Expand Down

0 comments on commit 8a01948

Please sign in to comment.