CCPeekPop.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // CCPeekPop.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 26/08/16.
  6. // Copyright (c) 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  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.preferredContentSize = CGSizeMake(640, 640);
  43. //detailVC?.preferredContentSize = CGSize(width: 0, height: 380)
  44. NSURL *url = [[NSBundle mainBundle] URLForResource:@"loading" withExtension:@"gif"];
  45. _imagePreview.image = [UIImage animatedImageWithAnimatedGIFURL:url];
  46. _imagePreview.contentMode = UIViewContentModeCenter;
  47. [self downloadThumbnail:_metadata];
  48. }
  49. // E' apparso
  50. -(void) viewDidAppear:(BOOL)animated{
  51. [super viewDidAppear:animated];
  52. }
  53. - (void)didReceiveMemoryWarning
  54. {
  55. [super didReceiveMemoryWarning];
  56. }
  57. - (NSArray<id<UIPreviewActionItem>> *)previewActionItems
  58. {
  59. //__weak typeof(self) weakSelf = self;
  60. UIPreviewAction *previewAction1 = [UIPreviewAction actionWithTitle:NSLocalizedString(@"_open_in_", nil) style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action, UIViewController *previewViewController){
  61. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
  62. if (serverUrl) {
  63. _metadata.session = k_download_session;
  64. _metadata.sessionError = @"";
  65. _metadata.sessionSelector = selectorOpenIn;
  66. _metadata.sessionSelectorPost = @"";
  67. _metadata.status = k_metadataStatusWaitDownload;
  68. // Add Metadata for Download
  69. (void)[[NCManageDatabase sharedInstance] addMetadata:_metadata];
  70. [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
  71. }
  72. }];
  73. return @[previewAction1];
  74. }
  75. #pragma --------------------------------------------------------------------------------------------
  76. #pragma mark ==== Download Thumbnail ====
  77. #pragma --------------------------------------------------------------------------------------------
  78. - (void)downloadThumbnailSuccessFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  79. {
  80. // Check Active Account
  81. if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
  82. return;
  83. if (errorCode == 0) {
  84. UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.pvw",appDelegate.directoryUser, _metadata.fileID]];
  85. _imagePreview.image = image;
  86. _imagePreview.contentMode = UIViewContentModeScaleToFill;
  87. self.preferredContentSize = CGSizeMake(image.size.width, image.size.height);
  88. } else {
  89. [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  90. [self dismissViewControllerAnimated:YES completion:nil];
  91. }
  92. }
  93. - (void)downloadThumbnail:(tableMetadata *)metadata
  94. {
  95. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:appDelegate.activeAccount];
  96. NSString *serverUrl = appDelegate.activeMain.serverUrl;
  97. metadataNet.action = actionDownloadThumbnail;
  98. metadataNet.fileID = metadata.fileID;
  99. metadataNet.fileName = [self returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl];
  100. metadataNet.optionAny = @"l";
  101. metadataNet.priority = NSOperationQueuePriorityLow;
  102. metadataNet.selector = selectorDownloadThumbnail;
  103. metadataNet.serverUrl = serverUrl;
  104. [appDelegate addNetworkingOperationQueue:appDelegate.netQueue delegate:self metadataNet:metadataNet];
  105. }
  106. - (NSString *)returnFileNamePathFromFileName:(NSString *)metadataFileName serverUrl:(NSString *)serverUrl
  107. {
  108. NSString *fileName = [NSString stringWithFormat:@"%@/%@", [serverUrl stringByReplacingOccurrencesOfString:[CCUtility getHomeServerUrlActiveUrl:appDelegate.activeUrl] withString:@""], metadataFileName];
  109. if ([fileName hasPrefix:@"/"]) fileName = [fileName substringFromIndex:1];
  110. return fileName;
  111. }
  112. @end