CCPeekPop.m 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // CCPeekPop.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 26/08/16.
  6. // Copyright (c) 2016 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCPeekPop.h"
  24. #import "AppDelegate.h"
  25. #import "NCBridgeSwift.h"
  26. @interface CCPeekPop ()
  27. {
  28. AppDelegate *appDelegate;
  29. NSInteger highLabelFileName;
  30. }
  31. @end
  32. @implementation CCPeekPop
  33. - (void)viewDidLoad
  34. {
  35. [super viewDidLoad];
  36. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  37. UIImage *image = self.imageFile;
  38. self.fileName.text = self.metadata.fileNameView;
  39. self.fileName.textColor = NCBrandColor.shared.textView;
  40. highLabelFileName = self.fileName.bounds.size.height + 5;
  41. if (self.metadata.hasPreview) {
  42. if ([CCUtility fileProviderStoragePreviewIconExists:self.metadata.ocId etag:self.metadata.etag]) {
  43. UIImage *fullImage = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageOcId:self.metadata.ocId fileNameView:self.metadata.fileNameView]];
  44. if (fullImage != nil) {
  45. image = fullImage;
  46. }
  47. } else {
  48. [self downloadThumbnail];
  49. }
  50. }
  51. self.view.backgroundColor = NCBrandColor.shared.backgroundForm;
  52. self.imagePreview.image = [image resizeImageWithSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height) isAspectRation:true];
  53. self.preferredContentSize = CGSizeMake(self.imagePreview.image.size.width, self.imagePreview.image.size.height + highLabelFileName);
  54. }
  55. - (NSArray<id<UIPreviewActionItem>> *)previewActionItems
  56. {
  57. NSMutableArray *items = [NSMutableArray new];
  58. if (self.showOpenIn && !self.metadata.directory) {
  59. UIPreviewAction *item = [UIPreviewAction actionWithTitle:NSLocalizedString(@"_open_in_", nil) style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action, UIViewController *previewViewController) {
  60. [[NCNetworkingNotificationCenter shared] downloadOpenWithMetadata:self.metadata selector:NCBrandGlobal.shared.selectorOpenIn];
  61. }];
  62. [items addObject:item];
  63. }
  64. if (self.showOpenQuickLook) {
  65. UIPreviewAction *item = [UIPreviewAction actionWithTitle:NSLocalizedString(@"_open_quicklook_", nil) style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action, UIViewController *previewViewController) {
  66. [[NCNetworkingNotificationCenter shared] downloadOpenWithMetadata:self.metadata selector:NCBrandGlobal.shared.selectorLoadFileQuickLook];
  67. }];
  68. [items addObject:item];
  69. }
  70. if (self.showShare) {
  71. UIPreviewAction *item = [UIPreviewAction actionWithTitle:NSLocalizedString(@"_share_", nil) style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action, UIViewController *previewViewController) {
  72. [[NCNetworkingNotificationCenter shared] openShareWithViewController:appDelegate.activeFiles metadata:self.metadata indexPage:2];
  73. }];
  74. [items addObject:item];
  75. }
  76. return items;
  77. }
  78. #pragma --------------------------------------------------------------------------------------------
  79. #pragma mark ==== Download Thumbnail ====
  80. #pragma --------------------------------------------------------------------------------------------
  81. - (void)downloadThumbnail
  82. {
  83. NSString *fileNamePath = [CCUtility returnFileNamePathFromFileName:self.metadata.fileName serverUrl:self.metadata.serverUrl urlBase:appDelegate.urlBase account:appDelegate.account];
  84. NSString *fileNamePreviewLocalPath = [CCUtility getDirectoryProviderStoragePreviewOcId:self.metadata.ocId etag:self.metadata.etag];
  85. NSString *fileNameIconLocalPath = [CCUtility getDirectoryProviderStorageIconOcId:self.metadata.ocId etag:self.metadata.etag];
  86. [[NCCommunication shared] downloadPreviewWithFileNamePathOrFileId:fileNamePath fileNamePreviewLocalPath:fileNamePreviewLocalPath widthPreview:NCBrandGlobal.shared.sizePreview heightPreview:NCBrandGlobal.shared.sizePreview fileNameIconLocalPath:fileNameIconLocalPath sizeIcon:NCBrandGlobal.shared.sizeIcon customUserAgent:nil addCustomHeaders:nil endpointTrashbin:false useInternalEndpoint:true completionHandler:^(NSString *account, UIImage *imagePreview, UIImage *imageIcon, NSInteger errorCode, NSString *errorDescription) {
  87. if (errorCode == 0 && imagePreview != nil) {
  88. self.imagePreview.image = [imagePreview resizeImageWithSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height) isAspectRation:true];
  89. self.preferredContentSize = CGSizeMake(self.imagePreview.image.size.width, self.imagePreview.image.size.height + highLabelFileName);
  90. }
  91. }];
  92. }
  93. @end