CCPeekPop.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // CCPeekPop.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 26/08/16.
  6. // Copyright (c) 2017 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 "CCGraphics.h"
  26. #import "NCBridgeSwift.h"
  27. @interface CCPeekPop ()
  28. {
  29. AppDelegate *appDelegate;
  30. NSInteger highLabelFileName;
  31. }
  32. @end
  33. @implementation CCPeekPop
  34. - (void)viewDidLoad
  35. {
  36. [super viewDidLoad];
  37. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  38. UIImage *image = self.imageFile;
  39. self.fileName.text = self.metadata.fileNameView;
  40. self.fileName.textColor = NCBrandColor.sharedInstance.textView;
  41. highLabelFileName = self.fileName.bounds.size.height + 5;
  42. if (self.metadata.hasPreview) {
  43. if ([CCUtility fileProviderStorageIconExists:self.metadata.ocId fileNameView:self.metadata.fileNameView]) {
  44. UIImage *fullImage = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageOcId:self.metadata.ocId fileNameView:self.metadata.fileNameView]];
  45. if (fullImage != nil) {
  46. image = fullImage;
  47. }
  48. } else {
  49. [self downloadThumbnail];
  50. }
  51. }
  52. self.view.backgroundColor = NCBrandColor.sharedInstance.backgroundMenu;
  53. self.imagePreview.image = [CCGraphics scaleImage:image toSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height) isAspectRation:true];
  54. self.preferredContentSize = CGSizeMake(self.imagePreview.image.size.width, self.imagePreview.image.size.height + highLabelFileName);
  55. }
  56. - (NSArray<id<UIPreviewActionItem>> *)previewActionItems
  57. {
  58. NSMutableArray *items = [NSMutableArray new];
  59. if (self.showOpenIn && !self.metadata.directory) {
  60. UIPreviewAction *openIn = [UIPreviewAction actionWithTitle:NSLocalizedString(@"_open_in_", nil) style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action, UIViewController *previewViewController) {
  61. [[NCMainCommon sharedInstance] downloadOpenInMetadata:self.metadata];
  62. }];
  63. [items addObject:openIn];
  64. }
  65. if (self.showShare) {
  66. UIPreviewAction *share = [UIPreviewAction actionWithTitle:NSLocalizedString(@"_share_", nil) style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action, UIViewController *previewViewController) {
  67. [[NCMainCommon sharedInstance] openShareWithViewController:appDelegate.activeMain metadata:self.metadata indexPage:2];
  68. }];
  69. [items addObject:share];
  70. }
  71. return items;
  72. }
  73. #pragma --------------------------------------------------------------------------------------------
  74. #pragma mark ==== Download Thumbnail ====
  75. #pragma --------------------------------------------------------------------------------------------
  76. - (void)downloadThumbnail
  77. {
  78. CGFloat width = [[NCUtility sharedInstance] getScreenWidthForPreview];
  79. CGFloat height = [[NCUtility sharedInstance] getScreenHeightForPreview];
  80. [[OCNetworking sharedManager] downloadPreviewWithAccount:appDelegate.activeAccount metadata:self.metadata withWidth:width andHeight:height completion:^(NSString *account, UIImage *image, NSString *message, NSInteger errorCode) {
  81. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  82. self.imagePreview.image = [CCGraphics scaleImage:image toSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height) isAspectRation:true];
  83. self.preferredContentSize = CGSizeMake(self.imagePreview.image.size.width, self.imagePreview.image.size.height + highLabelFileName);
  84. }
  85. }];
  86. }
  87. @end