CCDetail.m 45 KB

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