CCPeekPop.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // CCPeekPop.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 26/08/16.
  6. // Copyright (c) 2014 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. [[CCNetworking sharedNetworking] downloadFile:_metadata serverUrl:_serverUrl downloadData:YES downloadPlist:NO selector:selectorOpenIn selectorPost:nil session:download_session taskStatus:taskStatusResume delegate:self.delegate];
  57. }];
  58. return @[previewAction1];
  59. }
  60. #pragma --------------------------------------------------------------------------------------------
  61. #pragma mark ==== Download Thumbnail ====
  62. #pragma --------------------------------------------------------------------------------------------
  63. - (void)downloadThumbnailSuccess:(CCMetadataNet *)metadataNet
  64. {
  65. UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.pvw",app.directoryUser, _metadata.fileID]];
  66. _imagePreview.image = image;
  67. _imagePreview.contentMode = UIViewContentModeScaleToFill;
  68. self.preferredContentSize = CGSizeMake(image.size.width, image.size.height);
  69. }
  70. - (void)downloadThumbnailFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  71. {
  72. [app messageNotification:@"_error_" description:message visible:YES delay:dismissAfterSecond type:TWMessageBarMessageTypeError];
  73. [self dismissViewControllerAnimated:YES completion:nil];
  74. }
  75. - (void)downloadThumbnail:(CCMetadata *)metadata
  76. {
  77. CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
  78. metadataNet.action = actionDownloadThumbnail;
  79. metadataNet.fileID = metadata.fileID;
  80. if ([metadata.typeCloud isEqualToString:typeCloudOwnCloud] || [metadata.typeCloud isEqualToString:typeCloudNextcloud])
  81. metadataNet.fileName = [self returnFileNamePathFromFileName:metadata.fileName serverUrl:app.serverUrl];
  82. metadataNet.fileNameLocal = metadata.fileID;
  83. metadataNet.fileNamePrint = metadata.fileNamePrint;
  84. metadataNet.options = @"l";
  85. metadataNet.priority = NSOperationQueuePriorityLow;
  86. metadataNet.selector = selectorDownloadThumbnail;
  87. metadataNet.serverUrl = app.serverUrl;
  88. [app addNetworkingOperationQueue:app.netQueue delegate:self metadataNet:metadataNet];
  89. }
  90. - (NSString *)returnFileNamePathFromFileName:(NSString *)metadataFileName serverUrl:(NSString *)serverUrl
  91. {
  92. NSString *fileName = [NSString stringWithFormat:@"%@/%@", [serverUrl stringByReplacingOccurrencesOfString:[CCUtility getHomeServerUrlActiveUrl:app.activeUrl typeCloud:app.typeCloud] withString:@""], metadataFileName];
  93. if ([fileName hasPrefix:@"/"]) fileName = [fileName substringFromIndex:1];
  94. return fileName;
  95. }
  96. @end