123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- #import "CCPeekPop.h"
- #import "AppDelegate.h"
- #import "CCGraphics.h"
- #import "NCBridgeSwift.h"
- @interface CCPeekPop ()
- {
- AppDelegate *appDelegate;
- NSInteger highLabelFileName;
- }
- @end
- @implementation CCPeekPop
- - (void)setMetadata:(tableMetadata *)newMetadata
- {
- if (_metadata != newMetadata)
- _metadata = newMetadata;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
- UIImage *image = self.imageFile;
- self.fileName.text = self.metadata.fileNameView;
- highLabelFileName = self.fileName.bounds.size.height + 5;
-
- if (self.metadata.hasPreview) {
-
- if ([CCUtility fileProviderStorageIconExists:self.metadata.fileID fileNameView:self.metadata.fileNameView]) {
-
- UIImage *fullImage = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageFileID:self.metadata.fileID fileNameView:self.metadata.fileNameView]];
- if (fullImage != nil) {
- image = fullImage;
- }
-
- } else {
-
- [self downloadThumbnail];
- }
- }
-
- self.imagePreview.image = [CCGraphics scaleImage:image toSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height) isAspectRation:true];
- self.preferredContentSize = CGSizeMake(self.imagePreview.image.size.width, self.imagePreview.image.size.height + highLabelFileName);
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- }
- - (NSArray<id<UIPreviewActionItem>> *)previewActionItems
- {
- UIPreviewAction *openIn = [UIPreviewAction actionWithTitle:NSLocalizedString(@"_open_in_", nil) style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action, UIViewController *previewViewController){
-
- [[NCMainCommon sharedInstance] downloadOpenInMetadata:_metadata];
- }];
-
- UIPreviewAction *share = [UIPreviewAction actionWithTitle:NSLocalizedString(@"_share_", nil) style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action, UIViewController *previewViewController){
-
- [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount openWindow:YES metadata:self.metadata];
- }];
-
- if (self.showShare == true) {
- return @[openIn, share];
- } else {
- return @[openIn];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== Download Thumbnail ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)downloadThumbnail
- {
- CGFloat width = [[NCUtility sharedInstance] getScreenWidthForPreview];
- CGFloat height = [[NCUtility sharedInstance] getScreenHeightForPreview];
-
- [[OCNetworking sharedManager] downloadPreviewWithAccount:appDelegate.activeAccount metadata:_metadata withWidth:width andHeight:height completion:^(NSString *account, UIImage *image, NSString *message, NSInteger errorCode) {
-
- if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
- self.imagePreview.image = [CCGraphics scaleImage:image toSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height) isAspectRation:true];
- self.preferredContentSize = CGSizeMake(self.imagePreview.image.size.width, self.imagePreview.image.size.height + highLabelFileName);
- }
- }];
- }
- @end
|