CCDetail.m 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  1. //
  2. // CCDetail.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 16/01/15.
  6. // Copyright (c) 2017 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  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 "CCDetail.h"
  24. #import "AppDelegate.h"
  25. #import "CCMain.h"
  26. #import "NCUchardet.h"
  27. #import "NCBridgeSwift.h"
  28. #import "NCBridgeSwift.h"
  29. #define TOOLBAR_HEIGHT 49.0f
  30. #define alertRequestPasswordPDF 1
  31. @interface CCDetail () <NCTextDelegate, UIDocumentInteractionControllerDelegate>
  32. {
  33. AppDelegate *appDelegate;
  34. UIDocumentInteractionController *docController;
  35. UIBarButtonItem *buttonModifyTxt;
  36. UIBarButtonItem *buttonShare;
  37. UIBarButtonItem *buttonDelete;
  38. NSInteger indexNowVisible;
  39. NSString *ocIdNowVisible;
  40. NSString *fileNameExtension;
  41. }
  42. @end
  43. @implementation CCDetail
  44. #pragma --------------------------------------------------------------------------------------------
  45. #pragma mark ===== init =====
  46. #pragma --------------------------------------------------------------------------------------------
  47. - (id)initWithCoder:(NSCoder *)aDecoder
  48. {
  49. if (self = [super initWithCoder:aDecoder]) {
  50. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  51. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  52. self.metadataDetail = [[tableMetadata alloc] init];
  53. self.photos = [[NSMutableArray alloc] init];
  54. self.photoDataSource = [NSMutableArray new];
  55. indexNowVisible = -1;
  56. ocIdNowVisible = nil;
  57. appDelegate.activeDetail = self;
  58. }
  59. return self;
  60. }
  61. #pragma --------------------------------------------------------------------------------------------
  62. #pragma mark ===== View =====
  63. #pragma --------------------------------------------------------------------------------------------
  64. - (void)viewDidLoad
  65. {
  66. [super viewDidLoad];
  67. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(insertGeocoderLocation:) name:@"insertGeocoderLocation" object:nil];
  68. [self changeTheming];
  69. // Open View
  70. if ([self.metadataDetail.fileNameView length] > 0 || [self.metadataDetail.serverUrl length] > 0 || [self.metadataDetail.ocId length] > 0) {
  71. [self viewFile];
  72. }
  73. }
  74. - (void)viewWillAppear:(BOOL)animated
  75. {
  76. [super viewWillAppear:animated];
  77. self.tabBarController.tabBar.hidden = YES;
  78. }
  79. - (void)viewWillDisappear:(BOOL)animated
  80. {
  81. [super viewWillDisappear:animated];
  82. self.navigationController.navigationBarHidden = NO;
  83. self.tabBarController.tabBar.hidden = NO;
  84. }
  85. - (void)viewDidDisappear:(BOOL)animated
  86. {
  87. [super viewDidDisappear:animated];
  88. // If AVPlayer in play -> Stop
  89. if (appDelegate.player != nil && appDelegate.player.rate != 0) {
  90. [appDelegate.player pause];
  91. }
  92. // remove Observer AVPlayer
  93. if (self.isMediaObserver) {
  94. self.isMediaObserver = NO;
  95. @try{
  96. [[NCViewerMedia sharedInstance] removeObserver];
  97. }@catch(id anException) { }
  98. }
  99. }
  100. - (void)changeTheming
  101. {
  102. [appDelegate changeTheming:self tableView:nil collectionView:nil form:false];
  103. if (self.toolbar) {
  104. self.toolbar.barTintColor = NCBrandColor.sharedInstance.tabBar;
  105. self.toolbar.tintColor = NCBrandColor.sharedInstance.brandElement;
  106. }
  107. // Logo
  108. self.imageBackground.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"logo"] multiplier:2 color:[NCBrandColor.sharedInstance.brand colorWithAlphaComponent:0.4]];
  109. // reload image
  110. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_image]) {
  111. self.edgesForExtendedLayout = UIRectEdgeAll;
  112. [self viewImage];
  113. }
  114. }
  115. - (void)changeToDisplayMode
  116. {
  117. if (_readerPDFViewController) {
  118. [self.readerPDFViewController updateContentViews];
  119. }
  120. }
  121. #pragma --------------------------------------------------------------------------------------------
  122. #pragma mark ===== View File =====
  123. #pragma --------------------------------------------------------------------------------------------
  124. - (void)viewFile
  125. {
  126. // Remove all subview except ..
  127. //for (UIView *view in self.view.superview.subviews) {
  128. // NSInteger tag = view.tag;
  129. //}
  130. // Title
  131. self.navigationController.navigationBar.topItem.title = _metadataDetail.fileNameView;
  132. // verifico se esiste l'icona e se la posso creare
  133. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconOcId:self.metadataDetail.ocId fileNameView:self.metadataDetail.fileNameView]] == NO) {
  134. [CCGraphics createNewImageFrom:self.metadataDetail.fileNameView ocId:self.metadataDetail.ocId extension:[self.metadataDetail.fileNameView pathExtension] filterGrayScale:NO typeFile:self.metadataDetail.typeFile writeImage:YES];
  135. }
  136. // remove Observer AVPlayer
  137. if (self.isMediaObserver) {
  138. self.isMediaObserver = NO;
  139. [[NCViewerMedia sharedInstance] removeObserver];
  140. }
  141. // IMAGE
  142. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_image]) {
  143. self.edgesForExtendedLayout = UIRectEdgeAll;
  144. [self viewImage];
  145. }
  146. // AUDIO VIDEO
  147. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_video] || [self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_audio]) {
  148. self.edgesForExtendedLayout = UIRectEdgeAll;
  149. [self createToolbar];
  150. [[NCViewerMedia sharedInstance] viewMedia:self.metadataDetail detail:self];
  151. }
  152. // DOCUMENT - INTERNAL VIEWER
  153. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_document] && [self.selectorDetail isEqualToString:selectorLoadFileInternalView]) {
  154. self.edgesForExtendedLayout = UIRectEdgeBottom;
  155. [self createToolbar];
  156. [[NCViewerDocumentWeb sharedInstance] viewDocumentWebAt:self.metadataDetail detail:self];
  157. return;
  158. }
  159. // DOCUMENT
  160. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_document]) {
  161. fileNameExtension = [[self.metadataDetail.fileNameView pathExtension] uppercaseString];
  162. if ([fileNameExtension isEqualToString:@"PDF"]) {
  163. self.edgesForExtendedLayout = UIRectEdgeBottom;
  164. [self createToolbar];
  165. [self viewPDF:@""];
  166. return;
  167. }
  168. // Direct Editing
  169. if ([[NCUtility sharedInstance] isDirectEditing:self.metadataDetail] != nil && appDelegate.reachability.isReachable) {
  170. NSString *editor = [[NCUtility sharedInstance] isDirectEditing:self.metadataDetail];
  171. if ([editor.lowercaseString isEqualToString:@"nextcloud text"]) {
  172. [[NCUtility sharedInstance] startActivityIndicatorWithView:self.view bottom:0];
  173. NSString *fileNamePath = [CCUtility returnFileNamePathFromFileName:self.metadataDetail.fileName serverUrl:self.metadataDetail.serverUrl activeUrl:appDelegate.activeUrl];
  174. [[NCCommunication sharedInstance] NCTextOpenFileWithUrlString:appDelegate.activeUrl fileNamePath:fileNamePath editor: @"text" account:self.metadataDetail.account completionHandler:^(NSString *account, NSString *url, NSInteger errorCode, NSString *errorMessage) {
  175. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  176. } else {
  177. if (errorCode != 0) {
  178. [appDelegate messageNotification:@"_error_" description:errorMessage visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  179. } else {
  180. NSLog(@"[LOG] It has been changed user during networking process, error.");
  181. }
  182. [self.navigationController popViewControllerAnimated:YES];
  183. }
  184. }];
  185. } else {
  186. }
  187. return;
  188. }
  189. // RichDocument
  190. if ([[NCUtility sharedInstance] isRichDocument:self.metadataDetail] && appDelegate.reachability.isReachable) {
  191. [[NCUtility sharedInstance] startActivityIndicatorWithView:self.view bottom:0];
  192. if ([self.metadataDetail.url isEqualToString:@""]) {
  193. [[OCNetworking sharedManager] createLinkRichdocumentsWithAccount:appDelegate.activeAccount fileId:self.metadataDetail.fileId completion:^(NSString *account, NSString *link, NSString *message, NSInteger errorCode) {
  194. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  195. self.richDocument = [[NCViewerRichdocument alloc] initWithFrame:self.view.bounds configuration:[WKWebViewConfiguration new]];
  196. [self.view addSubview:self.richDocument];
  197. [self.richDocument viewRichDocumentAt:link detail:self metadata:self.metadataDetail];
  198. } else {
  199. [[NCUtility sharedInstance] stopActivityIndicator];
  200. if (errorCode != 0) {
  201. [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  202. } else {
  203. NSLog(@"[LOG] It has been changed user during networking process, error.");
  204. }
  205. [self.navigationController popViewControllerAnimated:YES];
  206. }
  207. }];
  208. } else {
  209. self.richDocument = [[NCViewerRichdocument alloc] initWithFrame:self.view.bounds configuration:[WKWebViewConfiguration new]];
  210. [self.view addSubview:self.richDocument];
  211. [self.richDocument viewRichDocumentAt:self.metadataDetail.url detail:self metadata:self.metadataDetail];
  212. }
  213. return;
  214. }
  215. self.edgesForExtendedLayout = UIRectEdgeBottom;
  216. [self createToolbar];
  217. [[NCViewerDocumentWeb sharedInstance] viewDocumentWebAt:self.metadataDetail detail:self];
  218. }
  219. }
  220. #pragma --------------------------------------------------------------------------------------------
  221. #pragma mark ===== Toolbar =====
  222. #pragma --------------------------------------------------------------------------------------------
  223. - (void)createToolbar
  224. {
  225. CGFloat safeAreaBottom = 0;
  226. if (@available(iOS 11, *)) {
  227. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  228. }
  229. self.toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom, self.view.bounds.size.width, TOOLBAR_HEIGHT)];
  230. UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
  231. UIBarButtonItem *fixedSpaceMini = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
  232. fixedSpaceMini.width = 25;
  233. buttonModifyTxt = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetModify"] style:UIBarButtonItemStylePlain target:self action:@selector(modifyTxtButtonPressed:)];
  234. if (![NCBrandOptions sharedInstance].disable_openin_file) {
  235. self.buttonAction = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"openFile"] style:UIBarButtonItemStylePlain target:self action:@selector(actionButtonPressed:)];
  236. }
  237. buttonShare = [[UIBarButtonItem alloc] initWithImage:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"share"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] style:UIBarButtonItemStylePlain target:self action:@selector(shareButtonPressed:)];
  238. buttonDelete = [[UIBarButtonItem alloc] initWithImage:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"trash"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] style:UIBarButtonItemStylePlain target:self action:@selector(deleteButtonPressed:)];
  239. if ([CCUtility isDocumentModifiableExtension:fileNameExtension]) {
  240. if ([CCUtility isFolderEncrypted:_metadataDetail.serverUrl account:appDelegate.activeAccount]) // E2EE
  241. [self.toolbar setItems:[NSArray arrayWithObjects: buttonModifyTxt, flexible, buttonDelete, fixedSpaceMini, self.buttonAction, nil]];
  242. else
  243. [self.toolbar setItems:[NSArray arrayWithObjects: buttonModifyTxt, flexible, buttonDelete, fixedSpaceMini, buttonShare, fixedSpaceMini, self.buttonAction, nil]];
  244. } else {
  245. if ([CCUtility isFolderEncrypted:_metadataDetail.serverUrl account:appDelegate.activeAccount]) // E2EE
  246. [self.toolbar setItems:[NSArray arrayWithObjects: flexible, buttonDelete, fixedSpaceMini, self.buttonAction, nil]];
  247. else
  248. [self.toolbar setItems:[NSArray arrayWithObjects: flexible, buttonDelete, fixedSpaceMini, buttonShare, fixedSpaceMini, self.buttonAction, nil]];
  249. }
  250. [self.toolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  251. self.toolbar.barTintColor = NCBrandColor.sharedInstance.tabBar;
  252. self.toolbar.tintColor = NCBrandColor.sharedInstance.brandElement;
  253. [self.view addSubview:self.toolbar];
  254. }
  255. #pragma --------------------------------------------------------------------------------------------
  256. #pragma mark ===== View Image =====
  257. #pragma --------------------------------------------------------------------------------------------
  258. - (void)viewImage
  259. {
  260. self.photoBrowser = [[MWPhotoBrowser alloc] initWithDelegate:self];
  261. indexNowVisible = -1;
  262. ocIdNowVisible = nil;
  263. [self.photos removeAllObjects];
  264. // if not images, exit
  265. if ([self.photoDataSource count] == 0)
  266. return;
  267. NSUInteger index = 0;
  268. for (tableMetadata *metadata in self.photoDataSource) {
  269. // start from here ?
  270. if (self.metadataDetail.ocId && [metadata.ocId isEqualToString:self.metadataDetail.ocId])
  271. [self.photoBrowser setCurrentPhotoIndex:index];
  272. [self.photos addObject:[MWPhoto photoWithImage:nil]];
  273. // add directory
  274. index++;
  275. }
  276. // PhotoBrowser
  277. if ([NCBrandOptions sharedInstance].disable_openin_file) {
  278. self.photoBrowser.displayActionButton = NO;
  279. } else {
  280. self.photoBrowser.displayActionButton = YES;
  281. }
  282. self.photoBrowser.displayDeleteButton = YES;
  283. if ([CCUtility isFolderEncrypted:_metadataDetail.serverUrl account:appDelegate.activeAccount]) // E2EE
  284. self.photoBrowser.displayShareButton = NO;
  285. else
  286. self.photoBrowser.displayShareButton = YES;
  287. self.photoBrowser.displayNavArrows = YES;
  288. self.photoBrowser.displaySelectionButtons = NO;
  289. self.photoBrowser.alwaysShowControls = NO;
  290. self.photoBrowser.zoomPhotosToFill = NO;
  291. self.photoBrowser.autoPlayOnAppear = NO;
  292. self.photoBrowser.delayToHideElements = 15;
  293. if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
  294. self.photoBrowser.enableSwipeToDismiss = NO;
  295. if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
  296. [self addChildViewController:self.photoBrowser];
  297. [self.view addSubview:self.photoBrowser.view];
  298. [self.photoBrowser didMoveToParentViewController:self];
  299. } else {
  300. [self.navigationController pushViewController:self.photoBrowser animated:NO];
  301. }
  302. self.navigationController.navigationBar.topItem.title = _metadataDetail.fileNameView;
  303. }
  304. - (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser
  305. {
  306. return [self.photoDataSource count];
  307. }
  308. - (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index
  309. {
  310. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  311. NSString *titleDir = metadata.fileNameView;
  312. self.title = titleDir;
  313. return titleDir;
  314. }
  315. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index
  316. {
  317. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  318. indexNowVisible = index;
  319. ocIdNowVisible = metadata.ocId;
  320. photoBrowser.toolbar.hidden = NO;
  321. // Download image ?
  322. if (metadata) {
  323. NSInteger status;
  324. tableMetadata *metadataDB = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadata.ocId]];
  325. if (metadataDB) {
  326. status = metadataDB.status;
  327. } else {
  328. status = k_metadataStatusNormal;
  329. }
  330. if ([CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView] == NO && status == k_metadataStatusNormal) {
  331. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:metadata.fileNameView]] == NO && metadata.hasPreview) {
  332. [CCGraphics addImageToTitle:NSLocalizedString(@"_...loading..._", nil) colorTitle:NCBrandColor.sharedInstance.brandText imageTitle:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"load"] multiplier:2 color:NCBrandColor.sharedInstance.brandText] imageRight:NO navigationItem:self.navigationItem];
  333. CGFloat width = [[NCUtility sharedInstance] getScreenWidthForPreview];
  334. CGFloat height = [[NCUtility sharedInstance] getScreenHeightForPreview];
  335. [[OCNetworking sharedManager] downloadPreviewWithAccount:appDelegate.activeAccount metadata:metadata withWidth:width andHeight:height completion:^(NSString *account, UIImage *image, NSString *message, NSInteger errorCode) {
  336. self.navigationItem.titleView = nil;
  337. self.title = metadata.fileNameView;
  338. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  339. [self.photoBrowser reloadData];
  340. }
  341. }];
  342. } else {
  343. [self downloadPhotoBrowser:metadata];
  344. }
  345. }
  346. }
  347. // Title
  348. if (metadata)
  349. self.title = metadata.fileNameView;
  350. }
  351. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index
  352. {
  353. UIImage *image;
  354. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  355. if (index < self.photos.count) {
  356. if (metadata.ocId) {
  357. UIImage *imagePreview = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:metadata.fileNameView]];
  358. // if (!imagePreview) imagePreview = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"file_photo"] multiplier:3 color:[NCBrandColor.sharedInstance icon]];
  359. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
  360. NSString *fileImage = [CCUtility getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileNameView];
  361. NSString *ext = [CCUtility getExtension:metadata.fileNameView];
  362. if ([ext isEqualToString:@"GIF"]) image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  363. else image = [UIImage imageWithContentsOfFile:fileImage];
  364. if (image) {
  365. MWPhoto *photo = [MWPhoto photoWithImage:image];
  366. // Location ??
  367. [self setLocationCaptionPhoto:photo ocId:metadata.ocId];
  368. [self.photos replaceObjectAtIndex:index withObject:photo];
  369. } else {
  370. if (metadata.status == k_metadataStatusDownloadError) {
  371. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  372. } else {
  373. if (imagePreview)
  374. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:imagePreview]];
  375. }
  376. }
  377. }
  378. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
  379. if ([CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView]) {
  380. NSURL *url = [NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileNameView]];
  381. MWPhoto *video = [MWPhoto photoWithImage:[CCGraphics thumbnailImageForVideo:url atTime:1.0]];
  382. video.videoURL = url;
  383. [self.photos replaceObjectAtIndex:index withObject:video];
  384. } else {
  385. if (metadata.status == k_metadataStatusDownloadError) {
  386. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  387. } else {
  388. if (imagePreview)
  389. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:imagePreview]];
  390. }
  391. }
  392. }
  393. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_audio]) {
  394. if ([CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView]) {
  395. MWPhoto *audio;
  396. UIImage *audioImage;
  397. NSURL *url = [NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileNameView]];
  398. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:metadata.fileNameView]]) {
  399. audioImage = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:metadata.fileNameView]];
  400. } else {
  401. audioImage = [UIImage imageNamed:@"notaMusic"]; //[CCGraphics scaleImage:[UIImage imageNamed:@"notaMusic"] toSize:CGSizeMake(200, 200) isAspectRation:YES];
  402. }
  403. audio = [MWPhoto photoWithImage:audioImage];
  404. audio.videoURL = url;
  405. [self.photos replaceObjectAtIndex:index withObject:audio];
  406. } else {
  407. if (metadata.status == k_metadataStatusDownloadError) {
  408. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  409. } else {
  410. if (imagePreview)
  411. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:imagePreview]];
  412. }
  413. }
  414. }
  415. }
  416. // energy saving memory
  417. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  418. int iPrev = (int)index - 2;
  419. if (iPrev >= 0) {
  420. if ([self.photos objectAtIndex:iPrev] != nil)
  421. [self.photos replaceObjectAtIndex:iPrev withObject:[MWPhoto photoWithImage:nil]];
  422. }
  423. int iNext = (int)index + 2;
  424. if (iNext < _photos.count) {
  425. if ([self.photos objectAtIndex:iNext] != nil)
  426. [self.photos replaceObjectAtIndex:iNext withObject:[MWPhoto photoWithImage:nil]];
  427. }
  428. });
  429. return [self.photos objectAtIndex:index];
  430. }
  431. return nil;
  432. }
  433. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser actionButtonPressedForPhotoAtIndex:(NSUInteger)index
  434. {
  435. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  436. if (metadata == nil) return;
  437. docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileNameView]]];
  438. docController.delegate = self;
  439. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  440. [docController presentOptionsMenuFromRect:photoBrowser.view.frame inView:photoBrowser.view animated:YES];
  441. [docController presentOptionsMenuFromBarButtonItem:photoBrowser.actionButton animated:YES];
  442. }
  443. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser shareButtonPressedForPhotoAtIndex:(NSUInteger)index
  444. {
  445. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  446. [[NCMainCommon sharedInstance] openShareWithViewController:self metadata:metadata indexPage:2];
  447. }
  448. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser deleteButtonPressedForPhotoAtIndex:(NSUInteger)index deleteButton:(UIBarButtonItem *)deleteButton
  449. {
  450. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  451. if (metadata == nil || [CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView] == NO) {
  452. [appDelegate messageNotification:@"_info_" description:@"_file_not_found_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  453. return;
  454. }
  455. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  456. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  457. style:UIAlertActionStyleDestructive
  458. handler:^(UIAlertAction *action) {
  459. [self deleteFile:metadata];
  460. }]];
  461. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  462. style:UIAlertActionStyleCancel
  463. handler:^(UIAlertAction *action) {
  464. }]];
  465. alertController.popoverPresentationController.barButtonItem = deleteButton;
  466. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  467. [alertController.view layoutIfNeeded];
  468. [self.parentViewController presentViewController:alertController animated:YES completion:NULL];
  469. }
  470. - (void)photoBrowserDidFinishPresentation:(MWPhotoBrowser *)photoBrowser
  471. {
  472. [self.navigationController popViewControllerAnimated:YES];
  473. }
  474. - (void)downloadPhotoBrowserSuccessFailure:(tableMetadata *)metadata selector:(NSString *)selector errorCode:(NSInteger)errorCode
  475. {
  476. // if a message for a directory of these
  477. if (![metadata.ocId isEqualToString:ocIdNowVisible])
  478. return;
  479. // Title
  480. self.navigationItem.titleView = nil;
  481. self.title = metadata.fileNameView;
  482. if (errorCode == 0) {
  483. // verifico se esiste l'icona e se la posso creare
  484. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:metadata.fileNameView]] == NO) {
  485. [CCGraphics createNewImageFrom:metadata.fileNameView ocId:metadata.ocId extension:[metadata.fileNameView pathExtension] filterGrayScale:NO typeFile:metadata.typeFile writeImage:YES];
  486. }
  487. [self.photoBrowser reloadData];
  488. } else {
  489. [appDelegate messageNotification:@"_download_selected_files_" description:@"_error_download_photobrowser_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  490. [self.navigationController popViewControllerAnimated:YES];
  491. }
  492. }
  493. - (void)downloadPhotoBrowser:(tableMetadata *)metadata
  494. {
  495. tableMetadata *metadataForDownload = [[NCManageDatabase sharedInstance] initNewMetadata:metadata];
  496. metadataForDownload.session = k_download_session;
  497. metadataForDownload.sessionError = @"";
  498. metadataForDownload.sessionSelector = selectorLoadViewImage;
  499. metadataForDownload.status = k_metadataStatusWaitDownload;
  500. // Add Metadata for Download
  501. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForDownload];
  502. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadata.serverUrl ocId:metadataForDownload.ocId action:k_action_MOD];
  503. [appDelegate startLoadAutoDownloadUpload];
  504. [CCGraphics addImageToTitle:NSLocalizedString(@"_...loading..._", nil) colorTitle:NCBrandColor.sharedInstance.brandText imageTitle:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"load"] multiplier:2 color:NCBrandColor.sharedInstance.brandText] imageRight:NO navigationItem:self.navigationItem];
  505. }
  506. - (void)insertGeocoderLocation:(NSNotification *)notification
  507. {
  508. if (notification.userInfo.count == 0)
  509. return;
  510. NSString *ocId = [[notification.userInfo allKeys] objectAtIndex:0];
  511. //NSDate *date = [[notification.userInfo allValues] objectAtIndex:0];
  512. // test [Chrash V 1.14,15]
  513. if (indexNowVisible >= [self.photos count])
  514. return;
  515. if ([ocId isEqualToString:ocIdNowVisible]) {
  516. MWPhoto *photo = [self.photos objectAtIndex:indexNowVisible];
  517. [self setLocationCaptionPhoto:photo ocId:ocId];
  518. [self.photoBrowser reloadData];
  519. }
  520. }
  521. - (void)setLocationCaptionPhoto:(MWPhoto *)photo ocId:(NSString *)ocId
  522. {
  523. tableLocalFile *localFile;
  524. // read Geocoder
  525. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocId]];
  526. if ([localFile.exifLatitude doubleValue] != 0 || [localFile.exifLongitude doubleValue] != 0) {
  527. // Fix BUG Geo latitude & longitude
  528. if ([localFile.exifLatitude doubleValue] == 9999 || [localFile.exifLongitude doubleValue] == 9999) {
  529. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocId]];
  530. if (metadata) {
  531. [[CCExifGeo sharedInstance] setExifLocalTableEtag:metadata];
  532. }
  533. }
  534. [[CCExifGeo sharedInstance] setGeocoderEtag:ocId exifDate:localFile.exifDate latitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  535. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocId]];
  536. if ([localFile.exifLatitude floatValue] != 0 || [localFile.exifLongitude floatValue] != 0) {
  537. NSString *location = [[NCManageDatabase sharedInstance] getLocationFromGeoLatitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  538. if ([localFile.exifDate isEqualToDate:[NSDate distantPast]] == NO && location) {
  539. NSString *localizedDateTime = [NSDateFormatter localizedStringFromDate:localFile.exifDate dateStyle:NSDateFormatterFullStyle timeStyle:NSDateFormatterMediumStyle];
  540. photo.caption = [NSString stringWithFormat:NSLocalizedString(@"%@\n%@", nil), localizedDateTime, location];
  541. }
  542. }
  543. }
  544. }
  545. #pragma --------------------------------------------------------------------------------------------
  546. #pragma mark ===== View PDF =====
  547. #pragma --------------------------------------------------------------------------------------------
  548. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  549. {
  550. [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
  551. [[alertView textFieldAtIndex:0] resignFirstResponder];
  552. if (alertView.tag == alertRequestPasswordPDF) [self performSelector:@selector(viewPDF:) withObject:[alertView textFieldAtIndex:0].text afterDelay:0.3];
  553. }
  554. - (void)viewPDF:(NSString *)password
  555. {
  556. // remove cache PDF
  557. NSString *filePlistReader = [NSString stringWithFormat:@"%@/%@.plist", [CCUtility getDirectoryReaderMetadata], self.metadataDetail.fileNameView.stringByDeletingPathExtension];
  558. [CCUtility removeFileAtPath:filePlistReader];
  559. NSString *fileNamePath = [CCUtility getDirectoryProviderStorageOcId:self.metadataDetail.ocId fileNameView:self.metadataDetail.fileNameView];
  560. if ([CCUtility fileProviderStorageExists:self.metadataDetail.ocId fileNameView:self.metadataDetail.fileNameView] == NO) {
  561. // read file error
  562. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  563. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  564. [alertController addAction:okAction];
  565. [self presentViewController:alertController animated:YES completion:nil];
  566. }
  567. CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:fileNamePath]);
  568. if (pdf) {
  569. // Encrypted
  570. if (CGPDFDocumentIsEncrypted(pdf) == YES) {
  571. // Try a blank password first, per Apple's Quartz PDF example
  572. if (CGPDFDocumentUnlockWithPassword(pdf, "") == YES) {
  573. // blank password
  574. [self readerPDF:fileNamePath password:@""];
  575. } else {
  576. if ([password length] == 0) {
  577. // password request
  578. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_insert_password_pfd_",nil) message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  579. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  580. alertView.tag = alertRequestPasswordPDF;
  581. [alertView show];
  582. } else {
  583. const char *key = [password UTF8String];
  584. // failure
  585. if (CGPDFDocumentUnlockWithPassword(pdf, key) == NO) {
  586. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_password_pdf_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  587. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  588. [alertController addAction:okAction];
  589. [self presentViewController:alertController animated:YES completion:nil];
  590. } else {
  591. // pdf with password
  592. [self readerPDF:fileNamePath password:password];
  593. }
  594. }
  595. }
  596. } else{
  597. // No password
  598. [self readerPDF:fileNamePath password:@""];
  599. }
  600. } else {
  601. // read file error
  602. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  603. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  604. [alertController addAction:okAction];
  605. [self presentViewController:alertController animated:YES completion:nil];
  606. }
  607. }
  608. - (void)readerPDF:(NSString *)fileName password:(NSString *)password
  609. {
  610. ReaderDocument *documentPDF = [ReaderDocument withDocumentFilePath:fileName password:password];
  611. CGFloat safeAreaBottom = 0;
  612. if (@available(iOS 11, *)) {
  613. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  614. }
  615. if (documentPDF != nil) {
  616. self.readerPDFViewController = [[ReaderViewController alloc] initWithReaderDocument:documentPDF];
  617. self.readerPDFViewController.delegate = self;
  618. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom);
  619. [self.readerPDFViewController updateContentViews];
  620. [self addChildViewController:self.readerPDFViewController];
  621. [self.view addSubview:self.readerPDFViewController.view];
  622. [self.readerPDFViewController didMoveToParentViewController:self];
  623. } else {
  624. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  625. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  626. [alertController addAction:okAction];
  627. [self presentViewController:alertController animated:YES completion:nil];
  628. }
  629. }
  630. - (void)handleSingleTapReader
  631. {
  632. UILayoutGuide *layoutGuide;
  633. CGFloat safeAreaTop = 0;
  634. CGFloat safeAreaBottom = 0;
  635. if (@available(iOS 11, *)) {
  636. layoutGuide = [UIApplication sharedApplication].delegate.window.safeAreaLayoutGuide;
  637. safeAreaTop = [UIApplication sharedApplication].delegate.window.safeAreaInsets.top;
  638. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  639. }
  640. self.navigationController.navigationBarHidden = !self.navigationController.navigationBarHidden;
  641. self.toolbar.hidden = !self.toolbar.isHidden;
  642. if (self.toolbar.isHidden) {
  643. self.readerPDFViewController.view.frame = CGRectMake(0, safeAreaTop, self.view.bounds.size.width, self.view.bounds.size.height - safeAreaTop - safeAreaBottom);
  644. } else {
  645. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom);
  646. }
  647. [self.readerPDFViewController updateContentViews];
  648. }
  649. - (void)handleSwipeUpDown
  650. {
  651. // REMOVE IT'S UNUSABLE
  652. /*
  653. self.navigationController.navigationBarHidden = false; // iOS App is unusable after swipe up or down with PDF in fullscreen #526
  654. [self removeAllView];
  655. [self.navigationController popViewControllerAnimated:YES];
  656. */
  657. }
  658. #pragma --------------------------------------------------------------------------------------------
  659. #pragma mark ===== Delete =====
  660. #pragma --------------------------------------------------------------------------------------------
  661. - (void)deleteFile:(tableMetadata *)metadata
  662. {
  663. tableDirectory *tableDirectory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND e2eEncrypted == 1 AND serverUrl == %@", appDelegate.activeAccount, metadata.serverUrl]];
  664. [[NCMainCommon sharedInstance ] deleteFileWithMetadatas:[[NSArray alloc] initWithObjects:metadata, nil] e2ee:tableDirectory.e2eEncrypted serverUrl:tableDirectory.serverUrl folderocId:tableDirectory.ocId completion:^(NSInteger errorCode, NSString *message) {
  665. if (errorCode == 0) {
  666. // reload data source
  667. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:tableDirectory.serverUrl ocId:metadata.ocId action:k_action_DEL];
  668. // Not image
  669. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_image] == NO) {
  670. // exit
  671. [self.navigationController popViewControllerAnimated:YES];
  672. } else {
  673. for (NSUInteger index=0; index < [self.photoDataSource count] && _photoBrowser; index++ ) {
  674. tableMetadata *metadataTemp = [self.photoDataSource objectAtIndex:index];
  675. if ([metadata isInvalidated] || [metadataTemp.ocId isEqualToString:metadata.ocId]) {
  676. [self.photoDataSource removeObjectAtIndex:index];
  677. [self.photos removeObjectAtIndex:index];
  678. [self.photoBrowser reloadData];
  679. // exit
  680. if ([self.photoDataSource count] == 0) {
  681. [self.navigationController popViewControllerAnimated:YES];
  682. }
  683. }
  684. }
  685. }
  686. } else {
  687. NSLog(@"[LOG] DeleteFileOrFolder failure error %d, %@", (int)errorCode, message);
  688. }
  689. }];
  690. }
  691. #pragma --------------------------------------------------------------------------------------------
  692. #pragma mark ===== ButtonPressed =====
  693. #pragma --------------------------------------------------------------------------------------------
  694. - (void)dismissTextView
  695. {
  696. if (self.webView) {
  697. NSString *fileNamePath = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileNameView];
  698. [[NSFileManager defaultManager] removeItemAtPath:fileNamePath error:nil];
  699. [[NSFileManager defaultManager] linkItemAtPath:[CCUtility getDirectoryProviderStorageOcId:self.metadataDetail.ocId fileNameView:self.metadataDetail.fileNameView] toPath:fileNamePath error:nil];
  700. [self.webView reload];
  701. }
  702. }
  703. - (void)modifyTxtButtonPressed:(UIBarButtonItem *)sender
  704. {
  705. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", self.metadataDetail.ocId]];
  706. if (metadata) {
  707. UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"NCText" bundle:nil] instantiateViewControllerWithIdentifier:@"NCText"];
  708. NCText *viewController = (NCText *)navigationController.topViewController;
  709. viewController.metadata = metadata;
  710. viewController.delegate = self;
  711. navigationController.modalPresentationStyle = UIModalPresentationPageSheet;
  712. navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  713. [self presentViewController:navigationController animated:YES completion:nil];
  714. }
  715. }
  716. - (void)actionButtonPressed:(UIBarButtonItem *)sender
  717. {
  718. if ([self.metadataDetail.fileNameView length] == 0) return;
  719. NSString *filePath = [CCUtility getDirectoryProviderStorageOcId:self.metadataDetail.ocId fileNameView:self.metadataDetail.fileNameView];
  720. docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  721. docController.delegate = self;
  722. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  723. [docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  724. else
  725. [docController presentOptionsMenuFromBarButtonItem:sender animated:YES];
  726. }
  727. - (void)shareButtonPressed:(UIBarButtonItem *)sender
  728. {
  729. [[NCMainCommon sharedInstance] openShareWithViewController:self metadata:self.metadataDetail indexPage:2];
  730. }
  731. - (void)deleteButtonPressed:(UIBarButtonItem *)sender
  732. {
  733. if ([self.metadataDetail.fileNameView length] == 0) return;
  734. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  735. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  736. style:UIAlertActionStyleDestructive
  737. handler:^(UIAlertAction *action) {
  738. [self deleteFile:self.metadataDetail];
  739. }]];
  740. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  741. style:UIAlertActionStyleCancel
  742. handler:^(UIAlertAction *action) {
  743. [alertController dismissViewControllerAnimated:YES completion:nil];
  744. }]];
  745. alertController.popoverPresentationController.barButtonItem = buttonDelete;
  746. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  747. [alertController.view layoutIfNeeded];
  748. [self presentViewController:alertController animated:YES completion:NULL];
  749. }
  750. @end