CCPeekPop.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account];
  58. [[CCNetworking sharedNetworking] downloadFile:_metadata.etag serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorOpenIn selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self.delegate];
  59. }];
  60. return @[previewAction1];
  61. }
  62. #pragma --------------------------------------------------------------------------------------------
  63. #pragma mark ==== Download Thumbnail ====
  64. #pragma --------------------------------------------------------------------------------------------
  65. - (void)downloadThumbnailSuccess:(CCMetadataNet *)metadataNet
  66. {
  67. UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.pvw",app.directoryUser, _metadata.etag]];
  68. _imagePreview.image = image;
  69. _imagePreview.contentMode = UIViewContentModeScaleToFill;
  70. self.preferredContentSize = CGSizeMake(image.size.width, image.size.height);
  71. }
  72. - (void)downloadThumbnailFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  73. {
  74. [app messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  75. [self dismissViewControllerAnimated:YES completion:nil];
  76. }
  77. - (void)downloadThumbnail:(tableMetadata *)metadata
  78. {
  79. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  80. NSString *serverUrl = app.activeMain.serverUrl;
  81. metadataNet.action = actionDownloadThumbnail;
  82. metadataNet.etag = metadata.etag;
  83. metadataNet.fileName = [self returnFileNamePathFromFileName:metadata.fileName serverUrl:serverUrl];
  84. metadataNet.fileNameLocal = metadata.etag;
  85. metadataNet.fileNamePrint = metadata.fileNamePrint;
  86. metadataNet.options = @"l";
  87. metadataNet.priority = NSOperationQueuePriorityLow;
  88. metadataNet.selector = selectorDownloadThumbnail;
  89. metadataNet.serverUrl = serverUrl;
  90. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  91. }
  92. - (NSString *)returnFileNamePathFromFileName:(NSString *)metadataFileName serverUrl:(NSString *)serverUrl
  93. {
  94. NSString *fileName = [NSString stringWithFormat:@"%@/%@", [serverUrl stringByReplacingOccurrencesOfString:[CCUtility getHomeServerUrlActiveUrl:app.activeUrl] withString:@""], metadataFileName];
  95. if ([fileName hasPrefix:@"/"]) fileName = [fileName substringFromIndex:1];
  96. return fileName;
  97. }
  98. @end