CCPeekPop.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //
  2. // CCPeekPop.m
  3. // Nextcloud iOS
  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)setMetadata:(tableMetadata *)newMetadata
  35. {
  36. if (_metadata != newMetadata)
  37. _metadata = newMetadata;
  38. }
  39. - (void)viewDidLoad
  40. {
  41. [super viewDidLoad];
  42. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  43. UIImage *image;
  44. self.fileName.text = self.metadata.fileNameView;
  45. highLabelFileName = self.fileName.bounds.size.height + 5;
  46. if (self.metadata.hasPreview) {
  47. if ([CCUtility fileProviderStorageIconExists:self.metadata.fileID fileNameView:self.metadata.fileNameView]) {
  48. image = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconFileID:self.metadata.fileID fileNameView:self.metadata.fileNameView]];
  49. image = [CCGraphics scaleImage:image toSize:CGSizeMake(self.view.bounds.size.width, self.view.bounds.size.height) isAspectRation:true];
  50. self.imagePreview.image = image;
  51. self.imagePreview.contentMode = UIViewContentModeScaleToFill;
  52. self.preferredContentSize = CGSizeMake(image.size.width, image.size.height + highLabelFileName);
  53. } else {
  54. NSURL *url = [[NSBundle mainBundle] URLForResource:@"loading" withExtension:@"gif"];
  55. self.imagePreview.image = [UIImage animatedImageWithAnimatedGIFURL:url];
  56. self.imagePreview.contentMode = UIViewContentModeCenter;
  57. [self downloadThumbnail];
  58. }
  59. } else {
  60. if (self.metadata.directory) {
  61. image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"folder"] multiplier:2 color:[NCBrandColor sharedInstance].brandElement];
  62. } else {
  63. if (self.metadata.iconName.length > 0) {
  64. image = [UIImage imageNamed:self.metadata.iconName];
  65. } else {
  66. image = [UIImage imageNamed:@"file"];
  67. }
  68. }
  69. self.imagePreview.image = image;
  70. self.imagePreview.contentMode = UIViewContentModeCenter;
  71. self.preferredContentSize = CGSizeMake(image.size.width, image.size.height + highLabelFileName);
  72. }
  73. }
  74. - (void)didReceiveMemoryWarning
  75. {
  76. [super didReceiveMemoryWarning];
  77. }
  78. - (NSArray<id<UIPreviewActionItem>> *)previewActionItems
  79. {
  80. if (self.hideAction) {
  81. return @[];
  82. }
  83. UIPreviewAction *openIn = [UIPreviewAction actionWithTitle:NSLocalizedString(@"_open_in_", nil) style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action, UIViewController *previewViewController){
  84. self.metadata.session = k_download_session;
  85. self.metadata.sessionError = @"";
  86. self.metadata.sessionSelector = selectorOpenIn;
  87. self.metadata.status = k_metadataStatusWaitDownload;
  88. // Add Metadata for Download
  89. (void)[[NCManageDatabase sharedInstance] addMetadata:_metadata];
  90. [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
  91. }];
  92. UIPreviewAction *share = [UIPreviewAction actionWithTitle:NSLocalizedString(@"_share_", nil) style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action, UIViewController *previewViewController){
  93. [appDelegate.activeMain readShareWithAccount:appDelegate.activeAccount openWindow:YES metadata:self.metadata];
  94. }];
  95. return @[openIn, share];
  96. }
  97. #pragma --------------------------------------------------------------------------------------------
  98. #pragma mark ==== Download Thumbnail ====
  99. #pragma --------------------------------------------------------------------------------------------
  100. - (void)downloadThumbnail
  101. {
  102. CGFloat width = [[NCUtility sharedInstance] getScreenWidthForPreview];
  103. CGFloat height = [[NCUtility sharedInstance] getScreenHeightForPreview];
  104. [[OCNetworking sharedManager] downloadPreviewWithAccount:appDelegate.activeAccount metadata:_metadata withWidth:width andHeight:height completion:^(NSString *account, UIImage *image, NSString *message, NSInteger errorCode) {
  105. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  106. self.imagePreview.image = image;
  107. self.imagePreview.contentMode = UIViewContentModeScaleToFill;
  108. self.preferredContentSize = CGSizeMake(image.size.width, image.size.height + highLabelFileName);
  109. } else {
  110. if (self.metadata.iconName.length > 0) {
  111. self.imagePreview.image = [UIImage imageNamed:self.metadata.iconName];
  112. } else {
  113. self.imagePreview.image = [UIImage imageNamed:@"file"];
  114. }
  115. self.imagePreview.contentMode = UIViewContentModeCenter;
  116. self.preferredContentSize = CGSizeMake(self.imagePreview.image.size.width, self.imagePreview.image.size.height + highLabelFileName);
  117. }
  118. }];
  119. }
  120. @end