CCDetail.m 45 KB

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