CCPeekPop.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //
  2. // CCPeekPop.m
  3. // Crypto Cloud Technology Nextcloud
  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. @end
  29. @implementation CCPeekPop
  30. - (void)setMetadata:(tableMetadata *)newMetadata
  31. {
  32. if (_metadata != newMetadata)
  33. _metadata = newMetadata;
  34. }
  35. - (void)viewDidLoad
  36. {
  37. [super viewDidLoad];
  38. self.preferredContentSize = CGSizeMake(640, 640);
  39. //detailVC?.preferredContentSize = CGSize(width: 0, height: 380)
  40. NSURL *url = [[NSBundle mainBundle] URLForResource:@"loading" withExtension:@"gif"];
  41. _imagePreview.image = [UIImage animatedImageWithAnimatedGIFURL:url];
  42. _imagePreview.contentMode = UIViewContentModeCenter;
  43. [self downloadThumbnail:_metadata];
  44. }
  45. // E' apparso
  46. -(void) viewDidAppear:(BOOL)animated{
  47. [super viewDidAppear:animated];
  48. }
  49. - (void)didReceiveMemoryWarning
  50. {
  51. [super didReceiveMemoryWarning];
  52. }
  53. - (NSArray<id<UIPreviewActionItem>> *)previewActionItems
  54. {
  55. //__weak typeof(self) weakSelf = self;
  56. UIPreviewAction *previewAction1 = [UIPreviewAction actionWithTitle:NSLocalizedString(@"_open_in_", nil) style:UIPreviewActionStyleDefault handler:^(UIPreviewAction *action, UIViewController *previewViewController){
  57. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadata.directoryID];
  58. if (serverUrl)
  59. [[CCNetworking sharedNetworking] downloadFile:_metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorOpenIn selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self.delegate];
  60. }];
  61. return @[previewAction1];
  62. }
  63. #pragma --------------------------------------------------------------------------------------------
  64. #pragma mark ==== Download Thumbnail ====
  65. #pragma --------------------------------------------------------------------------------------------
  66. - (void)downloadThumbnailSuccess:(CCMetadataNet *)metadataNet
  67. {
  68. UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.pvw",app.directoryUser, _metadata.fileID]];
  69. _imagePreview.image = image;
  70. _imagePreview.contentMode = UIViewContentModeScaleToFill;
  71. self.preferredContentSize = CGSizeMake(image.size.width, image.size.height);
  72. }
  73. - (void)downloadThumbnailFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  74. {
  75. [app messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  76. [self dismissViewControllerAnimated:YES completion:nil];
  77. }
  78. - (void)downloadThumbnail:(tableMetadata *)metadata
  79. {
  80. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  81. NSString *serverUrl = app.activeMain.serverUrl;
  82. metadataNet.action = actionDownloadThumbnail;
  83. metadataNet.fileID = metadata.fileID;
  84. metadataNet.fileName = [self returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl];
  85. metadataNet.fileNameLocal = metadata.fileID;
  86. metadataNet.fileNamePrint = metadata.fileNamePrint;
  87. metadataNet.options = @"l";
  88. metadataNet.priority = NSOperationQueuePriorityLow;
  89. metadataNet.selector = selectorDownloadThumbnail;
  90. metadataNet.serverUrl = serverUrl;
  91. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  92. }
  93. - (NSString *)returnFileNamePathFromFileName:(NSString *)metadataFileName serverUrl:(NSString *)serverUrl
  94. {
  95. NSString *fileName = [NSString stringWithFormat:@"%@/%@", [serverUrl stringByReplacingOccurrencesOfString:[CCUtility getHomeServerUrlActiveUrl:app.activeUrl] withString:@""], metadataFileName];
  96. if ([fileName hasPrefix:@"/"]) fileName = [fileName substringFromIndex:1];
  97. return fileName;
  98. }
  99. @end