Browse Source

Optomize & Clean Up Code

master
Matthew Matter 7 years ago
parent
commit
e696020a1f
1 changed files with 38 additions and 204 deletions
  1. +38
    -204
      Tweak.xm

+ 38
- 204
Tweak.xm View File

@property (assign, nonatomic) UIImageView *imageView; @property (assign, nonatomic) UIImageView *imageView;
@end @end


%hook FLHubPhotoViewController
@interface FLPhotoDetailViewController : UIViewController
@property (assign, nonatomic) FLImageView *photoView;
@end


-(void)viewDidLoad
{
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 1.5;
[self.view addGestureRecognizer:longPress];
%orig;
}


%new
-(void)handleLongPress:(UILongPressGestureRecognizer *)sender
{
// Save Image with UIImage and the Controller
inline void requestSaveImage(UIImage *snapshot, UIViewController *sender) {

UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];


[actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { [actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

// Cancel button tappped.
[self dismissViewControllerAnimated:YES completion:^{
}];
}]];
[sender dismissViewControllerAnimated:YES completion:^{ }]; }]];


[actionSheet addAction:[UIAlertAction actionWithTitle:@"Save Image" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [actionSheet addAction:[UIAlertAction actionWithTitle:@"Save Image" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

UIImage *snapshot = self.imageView.originalImage;

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^ [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^
{ {
PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:snapshot]; PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:snapshot];
} }
}]; }];


[self dismissViewControllerAnimated:YES completion:^{
[sender dismissViewControllerAnimated:YES completion:^{
}]; }];
}]]; }]];

// Present action sheet.
[self presentViewController:actionSheet animated:YES completion:nil];
[sender presentViewController:actionSheet animated:YES completion:nil];
} }


%end

#define SETUP_LONGPRESS_ONCONTROLLER UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; longPress.minimumPressDuration = 1.5; [self.view addGestureRecognizer:longPress];


@interface FLPhotoDetailViewController : UIViewController
@property (assign, nonatomic) FLImageView *photoView;
@end

%hook FLPhotoDetailViewController
// Media tab images
%hook FLHubPhotoViewController


-(void)viewDidLoad -(void)viewDidLoad
{ {
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 1.5;
[self.view addGestureRecognizer:longPress];
SETUP_LONGPRESS_ONCONTROLLER
%orig; %orig;
} }



%new %new
-(void)handleLongPress:(UILongPressGestureRecognizer *)sender -(void)handleLongPress:(UILongPressGestureRecognizer *)sender
{ {
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

[actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

// Cancel button tappped.
[self dismissViewControllerAnimated:YES completion:^{
}];
}]];

[actionSheet addAction:[UIAlertAction actionWithTitle:@"Save Image" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
requestSaveImage(self.imageView.originalImage, self);
}


UIImage *snapshot = [self.photoView image];
%end


[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^
{
PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:snapshot];
changeRequest.creationDate = [NSDate date];
}
completionHandler:^(BOOL success, NSError *error)
{
if (success)
{
NSLog(@"successfully saved");
}
else
{
NSLog(@"error saving to photos: %@", error);
}
}];
//Normal Timeline Photos
%hook FLPhotoDetailViewController


[self dismissViewControllerAnimated:YES completion:^{
}];
}]];
-(void)viewDidLoad
{
SETUP_LONGPRESS_ONCONTROLLER
%orig;
}


// Present action sheet.
[self presentViewController:actionSheet animated:YES completion:nil];
%new
-(void)handleLongPress:(UILongPressGestureRecognizer *)sender
{
requestSaveImage([self.photoView image], self);
} }


%end %end


//Collage Photos
%hook FLCollageSinglePhotoViewController %hook FLCollageSinglePhotoViewController


-(void)viewDidLoad -(void)viewDidLoad
{ {
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 1.5;
[self.view addGestureRecognizer:longPress];
SETUP_LONGPRESS_ONCONTROLLER
%orig; %orig;
} }


%new %new
-(void)handleLongPress:(UILongPressGestureRecognizer *)sender -(void)handleLongPress:(UILongPressGestureRecognizer *)sender
{ {
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

[actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

// Cancel button tappped.
[self dismissViewControllerAnimated:YES completion:^{
}];
}]];

[actionSheet addAction:[UIAlertAction actionWithTitle:@"Save Image" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

UIImage *snapshot = self.photoView.photoView.originalImage;

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^
{
PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:snapshot];
changeRequest.creationDate = [NSDate date];
}
completionHandler:^(BOOL success, NSError *error)
{
if (success)
{
NSLog(@"successfully saved");
}
else
{
NSLog(@"error saving to photos: %@", error);
}
}];

[self dismissViewControllerAnimated:YES completion:^{
}];
}]];

// Present action sheet.
[self presentViewController:actionSheet animated:YES completion:nil];
requestSaveImage(self.photoView.photoView.originalImage, self);
} }


%end %end


//Poll Images
%hook FLPollSinglePhotoViewController %hook FLPollSinglePhotoViewController


-(void)viewDidLoad -(void)viewDidLoad
{ {
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 1.5;
[self.view addGestureRecognizer:longPress];
SETUP_LONGPRESS_ONCONTROLLER
%orig; %orig;
} }


%new %new
-(void)handleLongPress:(UILongPressGestureRecognizer *)sender -(void)handleLongPress:(UILongPressGestureRecognizer *)sender
{ {
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

[actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

// Cancel button tappped.
[self dismissViewControllerAnimated:YES completion:^{
}];
}]];

[actionSheet addAction:[UIAlertAction actionWithTitle:@"Save Image" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

UIImage *snapshot = self.photoView.originalImage;

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^
{
PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:snapshot];
changeRequest.creationDate = [NSDate date];
}
completionHandler:^(BOOL success, NSError *error)
{
if (success)
{
NSLog(@"successfully saved");
}
else
{
NSLog(@"error saving to photos: %@", error);
}
}];

[self dismissViewControllerAnimated:YES completion:^{
}];
}]];

// Present action sheet.
[self presentViewController:actionSheet animated:YES completion:nil];
requestSaveImage(self.photoView.originalImage, self);
} }


%end %end


//Profile Pictures
%hook FLFullScreenPhotoViewController %hook FLFullScreenPhotoViewController


-(void)viewDidLoad -(void)viewDidLoad
{ {
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 1.5;
[self.view addGestureRecognizer:longPress];
SETUP_LONGPRESS_ONCONTROLLER
%orig; %orig;
} }


%new %new
-(void)handleLongPress:(UILongPressGestureRecognizer *)sender -(void)handleLongPress:(UILongPressGestureRecognizer *)sender
{ {
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

[actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

// Cancel button tappped.
[self dismissViewControllerAnimated:YES completion:^{
}];
}]];

[actionSheet addAction:[UIAlertAction actionWithTitle:@"Save Image" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

UIImage *snapshot = self.imageView.image;

[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^
{
PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:snapshot];
changeRequest.creationDate = [NSDate date];
}
completionHandler:^(BOOL success, NSError *error)
{
if (success)
{
NSLog(@"successfully saved");
}
else
{
NSLog(@"error saving to photos: %@", error);
}
}];

[self dismissViewControllerAnimated:YES completion:^{
}];
}]];

// Present action sheet.
[self presentViewController:actionSheet animated:YES completion:nil];
requestSaveImage(self.imageView.image, self);
} }


%end %end


// IGNORE ABOVE. SAVES IMAGES
//FLAVPlayerLayerView
//FLHubVideoCollection
//FLVideoContentHolderVIew


//Saves Videos
%hook FLPostCollectionViewCell %hook FLPostCollectionViewCell


-(void)setPostView:(FLBaseContentHolderView *)holderView -(void)setPostView:(FLBaseContentHolderView *)holderView
[[[UIApplication sharedApplication] keyWindow].rootViewController presentViewController:actionSheet animated:YES completion:nil]; [[[UIApplication sharedApplication] keyWindow].rootViewController presentViewController:actionSheet animated:YES completion:nil];
} }


%end
%end

Loading…
Cancel
Save