CCDetail.m 45 KB

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