CCPeekPop.m 4.6 KB

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