CCDetail.m 46 KB

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