CCPeekPop.m 5.1 KB

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