CCDetail.m 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042
  1. //
  2. // CCDetail.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 16/01/15.
  6. // Copyright (c) 2017 TWS. 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. #define TOOLBAR_HEIGHT 49.0f
  29. #define alertRequestPasswordPDF 1
  30. @interface CCDetail () <CCActionsDeleteDelegate>
  31. {
  32. AppDelegate *appDelegate;
  33. UIToolbar *_toolbar;
  34. UIBarButtonItem *_buttonModifyTxt;
  35. UIBarButtonItem *_buttonAction;
  36. UIBarButtonItem *_buttonShare;
  37. UIBarButtonItem *_buttonDelete;
  38. NSInteger _indexNowVisible;
  39. NSString *_fileIDNowVisible;
  40. BOOL _reload;
  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. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
  53. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  54. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backNavigationController) name:@"detailBack" object:nil];
  55. self.metadataDetail = [[tableMetadata alloc] init];
  56. self.photos = [[NSMutableArray alloc] init];
  57. self.thumbs = [[NSMutableArray alloc] init];
  58. self.dataSourceImagesVideos = [[NSMutableArray alloc] init];
  59. _dataSourceDirectoryID = [[NSMutableOrderedSet alloc] init];
  60. _indexNowVisible = -1;
  61. _fileIDNowVisible = nil;
  62. app.activeDetail = self;
  63. }
  64. return self;
  65. }
  66. #pragma --------------------------------------------------------------------------------------------
  67. #pragma mark ===== View =====
  68. #pragma --------------------------------------------------------------------------------------------
  69. - (void)viewDidLoad
  70. {
  71. [super viewDidLoad];
  72. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  73. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(insertGeocoderLocation:) name:@"insertGeocoderLocation" object:nil];
  74. self.imageBackground.image = [UIImage imageNamed:@"backgroundDetail"];
  75. if ([self.metadataDetail.fileName length] > 0 || [self.metadataDetail.directoryID length] > 0 || [self.metadataDetail.fileID length] > 0) {
  76. // open view
  77. [self viewFile];
  78. }
  79. }
  80. // Apparirà
  81. - (void)viewWillAppear:(BOOL)animated
  82. {
  83. [super viewWillAppear:animated];
  84. if (self.splitViewController.isCollapsed) {
  85. self.tabBarController.tabBar.hidden = YES;
  86. self.tabBarController.tabBar.translucent = YES;
  87. }
  88. if (self.splitViewController.isCollapsed)
  89. [app plusButtonVisibile:false];
  90. }
  91. // E' scomparso
  92. - (void)viewDidDisappear:(BOOL)animated
  93. {
  94. [super viewDidDisappear:animated];
  95. // remove all
  96. if (self.isMovingFromParentViewController)
  97. [self removeAllView];
  98. }
  99. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  100. {
  101. [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
  102. }];
  103. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  104. }
  105. // remove all view
  106. - (void)removeAllView
  107. {
  108. // Document
  109. if (_webView) {
  110. [_webView removeFromSuperview];
  111. _webView = nil;
  112. }
  113. // PDF
  114. if (_readerPDFViewController) {
  115. [_readerPDFViewController.view removeFromSuperview];
  116. _readerPDFViewController.delegate = nil;
  117. _readerPDFViewController = nil;
  118. }
  119. // Photo-Video-Audio
  120. if (_photoBrowser) {
  121. [_photos removeAllObjects];
  122. [_thumbs removeAllObjects];
  123. _photoBrowser.delegate = nil;
  124. _photoBrowser = nil;
  125. }
  126. // ToolBar
  127. if (_toolbar) {
  128. [_toolbar removeFromSuperview];
  129. _toolbar = nil;
  130. }
  131. // Title
  132. self.title = nil;
  133. }
  134. - (void)backNavigationController
  135. {
  136. [self removeAllView];
  137. [self.navigationController popViewControllerAnimated:NO];
  138. }
  139. - (void)changeToDisplayMode
  140. {
  141. if (_readerPDFViewController)
  142. [self.readerPDFViewController updateContentViews];
  143. }
  144. - (void)createToolbar
  145. {
  146. CGFloat safeAreaBottom = 0;
  147. if (@available(iOS 11, *)) {
  148. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  149. }
  150. _toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom, self.view.bounds.size.width, TOOLBAR_HEIGHT)];
  151. UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
  152. UIBarButtonItem *fixedSpaceMini = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
  153. fixedSpaceMini.width = 25;
  154. _buttonModifyTxt = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetModify"] style:UIBarButtonItemStylePlain target:self action:@selector(modifyTxtButtonPressed:)];
  155. _buttonAction = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetOpenIn"] style:UIBarButtonItemStylePlain target:self action:@selector(actionButtonPressed:)];
  156. _buttonShare = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetShare"] style:UIBarButtonItemStylePlain target:self action:@selector(shareButtonPressed:)];
  157. _buttonDelete = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteButtonPressed:)];
  158. if ([_fileNameExtension isEqualToString:@"TXT"])
  159. [_toolbar setItems:[NSArray arrayWithObjects: _buttonModifyTxt, flexible, _buttonDelete, fixedSpaceMini, _buttonShare, fixedSpaceMini, _buttonAction, nil]];
  160. else
  161. [_toolbar setItems:[NSArray arrayWithObjects: flexible, _buttonDelete, fixedSpaceMini, _buttonShare, fixedSpaceMini, _buttonAction, nil]];
  162. [_toolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  163. _toolbar.barTintColor = [NCBrandColor sharedInstance].tabBar;
  164. _toolbar.tintColor = [NCBrandColor sharedInstance].brand;
  165. [self.view addSubview:_toolbar];
  166. }
  167. - (void)changeTheming
  168. {
  169. [app changeTheming:self];
  170. if (_toolbar) {
  171. _toolbar.barTintColor = [NCBrandColor sharedInstance].tabBar;
  172. _toolbar.tintColor = [NCBrandColor sharedInstance].brand;
  173. }
  174. }
  175. #pragma --------------------------------------------------------------------------------------------
  176. #pragma mark ===== View File =====
  177. #pragma --------------------------------------------------------------------------------------------
  178. - (void)viewFile
  179. {
  180. // verifico se esiste l'icona e se la posso creare
  181. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, self.metadataDetail.fileID]] == NO) {
  182. [CCGraphics createNewImageFrom:self.metadataDetail.fileID directoryUser:app.directoryUser fileNameTo:self.metadataDetail.fileID extension:[self.metadataDetail.fileName pathExtension] size:@"m" imageForUpload:NO typeFile:self.metadataDetail.typeFile writePreview:YES optimizedFileName:[CCUtility getOptimizedPhoto]];
  183. }
  184. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_image] || [self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_video] || [self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_audio]) {
  185. self.edgesForExtendedLayout = UIRectEdgeAll;
  186. [self viewImageVideoAudio];
  187. }
  188. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_document]) {
  189. _fileNameExtension = [[self.metadataDetail.fileName pathExtension] uppercaseString];
  190. if ([_fileNameExtension isEqualToString:@"PDF"]) {
  191. self.edgesForExtendedLayout = UIRectEdgeBottom;
  192. [self viewPDF:@""];
  193. [self createToolbar];
  194. [app aspectNavigationControllerBar:self.navigationController.navigationBar online:[app.reachability isReachable] hidden:NO];
  195. } else {
  196. self.edgesForExtendedLayout = UIRectEdgeBottom;
  197. [self viewDocument];
  198. [self createToolbar];
  199. [app aspectNavigationControllerBar:self.navigationController.navigationBar online:[app.reachability isReachable] hidden:NO];
  200. }
  201. }
  202. }
  203. #pragma --------------------------------------------------------------------------------------------
  204. #pragma mark ===== View Document =====
  205. #pragma --------------------------------------------------------------------------------------------
  206. - (void)viewDocument
  207. {
  208. NSString *fileName;
  209. CGFloat safeAreaBottom = 0;
  210. if (@available(iOS 11, *)) {
  211. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  212. }
  213. fileName = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileName];
  214. [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
  215. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
  216. if ([[NSFileManager defaultManager] fileExistsAtPath:fileName] == NO) {
  217. [self backNavigationController];
  218. return;
  219. }
  220. NSURL *url = [NSURL fileURLWithPath:fileName];
  221. WKPreferences *wkPreferences = [[WKPreferences alloc] init];
  222. wkPreferences.javaScriptEnabled = true;
  223. WKWebViewConfiguration *wkConfig = [[WKWebViewConfiguration alloc] init];
  224. wkConfig.preferences = wkPreferences;
  225. self.webView = [[WKWebView alloc] initWithFrame:(CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom)) configuration:wkConfig];
  226. self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  227. [self.webView setBackgroundColor:[UIColor whiteColor]];
  228. [self.webView setOpaque:NO];
  229. if ( [_fileNameExtension isEqualToString:@"CSS"] || [_fileNameExtension isEqualToString:@"PY"] || [_fileNameExtension isEqualToString:@"XML"] || [_fileNameExtension isEqualToString:@"JS"] ) {
  230. NSString *dataFile = [[NSString alloc] initWithData:[NSData dataWithContentsOfURL:url] encoding:NSASCIIStringEncoding];
  231. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  232. [self.webView loadHTMLString:[NSString stringWithFormat:@"<div style='font-size:%@;font-family:%@;'><pre>%@",@"40",@"Sans-Serif",dataFile] baseURL:nil];
  233. }else{
  234. [self.webView loadHTMLString:[NSString stringWithFormat:@"<div style='font-size:%@;font-family:%@;'><pre>%@",@"20",@"Sans-Serif",dataFile] baseURL:nil];
  235. }
  236. } else if ([_fileNameExtension isEqualToString:@"TXT"]) {
  237. NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
  238. NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:nil delegateQueue:nil];
  239. NSMutableURLRequest *headRequest = [NSMutableURLRequest requestWithURL:url];
  240. [headRequest setHTTPMethod:@"HEAD"];
  241. NSURLSessionDataTask *task = [session dataTaskWithRequest:headRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
  242. NSString *encodingName = [[NCUchardet sharedNUCharDet] encodingStringDetectWithData:data];
  243. [self.webView loadData:[NSData dataWithContentsOfURL: url] MIMEType:response.MIMEType characterEncodingName:encodingName baseURL:url];
  244. }];
  245. [task resume];
  246. } else {
  247. [self.webView loadRequest:[NSMutableURLRequest requestWithURL:url]];
  248. }
  249. [self.view addSubview:self.webView];
  250. }
  251. #pragma --------------------------------------------------------------------------------------------
  252. #pragma mark ===== View Image =====
  253. #pragma --------------------------------------------------------------------------------------------
  254. - (void)viewImageVideoAudio
  255. {
  256. self.photoBrowser = [[MWPhotoBrowser alloc] initWithDelegate:self];
  257. _reload = NO;
  258. _indexNowVisible = -1;
  259. _fileIDNowVisible = nil;
  260. [self.photos removeAllObjects];
  261. [self.thumbs removeAllObjects];
  262. [_dataSourceDirectoryID removeAllObjects];
  263. // if not images, exit
  264. if ([self.dataSourceImagesVideos count] == 0) return;
  265. NSUInteger index = 0;
  266. for (tableMetadata *metadata in self.dataSourceImagesVideos) {
  267. // start from here ?
  268. if (self.metadataDetail.fileID && [metadata.fileID isEqualToString:self.metadataDetail.fileID])
  269. [self.photoBrowser setCurrentPhotoIndex:index];
  270. [self.photos addObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewDownload"]]];
  271. MWPhoto *thumb = [MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewDownload"]];
  272. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video] || [metadata.typeFile isEqualToString: k_metadataTypeFile_audio]) thumb.isVideo = YES;
  273. [self.thumbs addObject:thumb];
  274. // add directory
  275. [_dataSourceDirectoryID addObject:metadata.directoryID];
  276. index++;
  277. }
  278. // PhotoBrowser
  279. self.photoBrowser.displayActionButton = YES;
  280. self.photoBrowser.displayDeleteButton = YES;
  281. self.photoBrowser.displayNavArrows = YES;
  282. self.photoBrowser.displaySelectionButtons = NO;
  283. self.photoBrowser.alwaysShowControls = NO;
  284. self.photoBrowser.zoomPhotosToFill = NO;
  285. self.photoBrowser.autoPlayOnAppear = NO;
  286. self.photoBrowser.delayToHideElements = 15;
  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.dataSourceImagesVideos count];
  298. }
  299. - (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index
  300. {
  301. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  302. NSString *titleDir = metadata.fileName;
  303. self.title = titleDir;
  304. return titleDir;
  305. }
  306. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index
  307. {
  308. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  309. _indexNowVisible = index;
  310. _fileIDNowVisible = metadata.fileID;
  311. photoBrowser.toolbar.hidden = NO;
  312. // Download image ?
  313. if (metadata) {
  314. tableMetadata *metadataDB = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadata.fileID]];
  315. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]] == NO && [metadataDB.session length] == 0)
  316. [self downloadPhotoBrowser:metadata];
  317. }
  318. // Title
  319. if (metadata)
  320. self.title = metadata.fileName;
  321. if (_reload) {
  322. [self.photoBrowser performSelector:@selector(reloadData) withObject:nil];
  323. _reload = NO;
  324. }
  325. }
  326. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index
  327. {
  328. UIImage *image;
  329. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  330. if (index < self.photos.count) {
  331. if (metadata.fileID) {
  332. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
  333. NSString *fileImage = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID];
  334. NSString *ext = [CCUtility getExtension:metadata.fileName];
  335. if ([ext isEqualToString:@"GIF"]) image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  336. else image = [UIImage imageWithContentsOfFile:fileImage];
  337. if (image) {
  338. MWPhoto *photo = [MWPhoto photoWithImage:image];
  339. // Location ??
  340. [self setLocationCaptionPhoto:photo fileID:metadata.fileID];
  341. [self.photos replaceObjectAtIndex:index withObject:photo];
  342. } else {
  343. if ([metadata.sessionError length] > 0 ) {
  344. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  345. } else {
  346. image = [CCGraphics drawText:[NSLocalizedString(@"_loading_", nil) stringByAppendingString:@"..."] inImage:[UIImage imageNamed:@"button1000x200"] colorText:[UIColor darkGrayColor] sizeOfFont:50];
  347. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:image]];
  348. }
  349. }
  350. }
  351. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
  352. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]]) {
  353. // remove and make the simbolic link in temp
  354. NSString *toPath = [NSTemporaryDirectory() stringByAppendingString:metadata.fileName];
  355. [[NSFileManager defaultManager] removeItemAtPath:toPath error:nil];
  356. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] toPath:toPath error:nil];
  357. NSURL *url = [NSURL fileURLWithPath:toPath];
  358. MWPhoto *video = [MWPhoto photoWithImage:[CCGraphics thumbnailImageForVideo:url atTime:1.0]];
  359. video.videoURL = url;
  360. [self.photos replaceObjectAtIndex:index withObject:video];
  361. } else {
  362. if ([metadata.sessionError length] > 0 ) {
  363. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  364. } else {
  365. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[CCGraphics drawText:[NSLocalizedString(@"_loading_", nil) stringByAppendingString:@"..."] inImage:[UIImage imageNamed:@"button1000x200"] colorText:[UIColor darkGrayColor] sizeOfFont:50]]];
  366. }
  367. }
  368. }
  369. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_audio]) {
  370. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]]) {
  371. MWPhoto *audio;
  372. UIImage *audioImage;
  373. // remove and make the simbolic link in temp
  374. NSString *toPath = [NSTemporaryDirectory() stringByAppendingString:metadata.fileName];
  375. [[NSFileManager defaultManager] removeItemAtPath:toPath error:nil];
  376. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] toPath:toPath error:nil];
  377. NSURL *url = [NSURL fileURLWithPath:toPath];
  378. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]]) {
  379. audioImage = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
  380. } else {
  381. audioImage = [UIImage imageNamed:@"notaMusic"]; //[CCGraphics scaleImage:[UIImage imageNamed:@"notaMusic"] toSize:CGSizeMake(200, 200) isAspectRation:YES];
  382. }
  383. audio = [MWPhoto photoWithImage:audioImage];
  384. audio.videoURL = url;
  385. [self.photos replaceObjectAtIndex:index withObject:audio];
  386. } else {
  387. if ([metadata.sessionError length] > 0 ) {
  388. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  389. } else {
  390. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[CCGraphics drawText:[NSLocalizedString(@"_loading_", nil) stringByAppendingString:@"..."] inImage:[UIImage imageNamed:@"button1000x200"] colorText:[UIColor darkGrayColor] sizeOfFont:50]]];
  391. }
  392. }
  393. }
  394. }
  395. // energy saving memory
  396. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  397. int iPrev = (int)index - 2;
  398. if (iPrev >= 0) {
  399. if ([self.photos objectAtIndex:iPrev] != nil)
  400. [self.photos replaceObjectAtIndex:iPrev withObject:[MWPhoto photoWithImage:nil]];
  401. }
  402. int iNext = (int)index + 2;
  403. if (iNext < _photos.count) {
  404. if ([self.photos objectAtIndex:iNext] != nil)
  405. [self.photos replaceObjectAtIndex:iNext withObject:[MWPhoto photoWithImage:nil]];
  406. }
  407. });
  408. return [self.photos objectAtIndex:index];
  409. }
  410. return nil;
  411. }
  412. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser thumbPhotoAtIndex:(NSUInteger)index
  413. {
  414. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  415. if (index < self.thumbs.count) {
  416. if (metadata.fileID) {
  417. NSString *fileImage = [NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID];
  418. UIImage *image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  419. if (image) {
  420. MWPhoto *thumb = [MWPhoto photoWithImage:image];
  421. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) thumb.isVideo = YES;
  422. [self.thumbs replaceObjectAtIndex:index withObject:thumb];
  423. }
  424. }
  425. return [self.thumbs objectAtIndex:index];
  426. }
  427. return nil;
  428. }
  429. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser actionButtonPressedForPhotoAtIndex:(NSUInteger)index
  430. {
  431. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  432. if (metadata == nil) return;
  433. NSString *filePath = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileName];
  434. [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
  435. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] toPath:filePath error:nil];
  436. self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  437. self.docController.delegate = self;
  438. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  439. [self.docController presentOptionsMenuFromRect:photoBrowser.view.frame inView:photoBrowser.view animated:YES];
  440. [self.docController presentOptionsMenuFromBarButtonItem:photoBrowser.actionButton animated:YES];
  441. }
  442. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser shareButtonPressedForPhotoAtIndex:(NSUInteger)index
  443. {
  444. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  445. [app.activeMain openWindowShare:metadata];
  446. }
  447. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser deleteButtonPressedForPhotoAtIndex:(NSUInteger)index deleteButton:(UIBarButtonItem *)deleteButton
  448. {
  449. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  450. if (metadata == nil || [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]] == NO) {
  451. [app messageNotification:@"_info_" description:@"_file_not_found_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  452. return;
  453. }
  454. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  455. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  456. style:UIAlertActionStyleDestructive
  457. handler:^(UIAlertAction *action) {
  458. [[CCActions sharedInstance] deleteFileOrFolder:metadata delegate:self];
  459. }]];
  460. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  461. style:UIAlertActionStyleCancel
  462. handler:^(UIAlertAction *action) {
  463. [alertController dismissViewControllerAnimated:YES completion:nil];
  464. }]];
  465. alertController.popoverPresentationController.barButtonItem = deleteButton;
  466. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  467. [alertController.view layoutIfNeeded];
  468. [self.parentViewController presentViewController:alertController animated:YES completion:NULL];
  469. }
  470. - (void)triggerProgressTask:(NSNotification *)notification
  471. {
  472. //NSDictionary *dict = notification.userInfo;
  473. //float progress = [[dict valueForKey:@"progress"] floatValue];
  474. }
  475. - (void)downloadPhotoBrowserFailure:(NSInteger)errorCode
  476. {
  477. [app messageNotification:@"_download_selected_files_" description:@"_error_download_photobrowser_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  478. [self.photoBrowser reloadData];
  479. }
  480. - (void)downloadPhotoBrowserSuccess:(tableMetadata *)metadataVar selector:(NSString *)selector
  481. {
  482. NSUInteger index = 0;
  483. // if a message for a directory of these
  484. if (![_dataSourceDirectoryID containsObject:metadataVar.directoryID])
  485. return;
  486. for (NSUInteger i=0; i < [self.dataSourceImagesVideos count]; i++ ) {
  487. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:i];
  488. // search index
  489. if ([metadataVar.fileID isEqualToString:metadata.fileID]) {
  490. index = i;
  491. break;
  492. }
  493. }
  494. if ([metadataVar.fileID isEqualToString:_fileIDNowVisible]) {
  495. [self.photoBrowser reloadData];
  496. _reload = NO;
  497. } else {
  498. _reload = YES;
  499. }
  500. // verifico se esiste l'icona e se la posso creare
  501. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadataVar.fileID]] == NO) {
  502. [CCGraphics createNewImageFrom:metadataVar.fileID directoryUser:app.directoryUser fileNameTo:metadataVar.fileID extension:[metadataVar.fileName pathExtension] size:@"m" imageForUpload:NO typeFile:metadataVar.typeFile writePreview:YES optimizedFileName:[CCUtility getOptimizedPhoto]];
  503. }
  504. }
  505. - (void)downloadPhotoBrowser:(tableMetadata *)metadata
  506. {
  507. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  508. if (serverUrl)
  509. [[CCNetworking sharedNetworking] downloadFile:metadata.fileID serverUrl:serverUrl selector:selectorLoadViewImage selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:app.activeMain];
  510. }
  511. - (void)insertGeocoderLocation:(NSNotification *)notification
  512. {
  513. if (notification.userInfo.count == 0)
  514. return;
  515. NSString *fileID = [[notification.userInfo allKeys] objectAtIndex:0];
  516. //NSDate *date = [[notification.userInfo allValues] objectAtIndex:0];
  517. // test [Chrash V 1.14,15]
  518. if (_indexNowVisible >= [self.photos count])
  519. return;
  520. if ([fileID isEqualToString:_fileIDNowVisible]) {
  521. MWPhoto *photo = [self.photos objectAtIndex:_indexNowVisible];
  522. [self setLocationCaptionPhoto:photo fileID:fileID];
  523. }
  524. }
  525. - (void)setLocationCaptionPhoto:(MWPhoto *)photo fileID:(NSString *)fileID
  526. {
  527. tableLocalFile *localFile;
  528. // read Geocoder
  529. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  530. if ([localFile.exifLatitude doubleValue] != 0 || [localFile.exifLongitude doubleValue] != 0) {
  531. // Fix BUG Geo latitude & longitude
  532. if ([localFile.exifLatitude doubleValue] == 9999 || [localFile.exifLongitude doubleValue] == 9999) {
  533. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  534. if (metadata) {
  535. [[CCExifGeo sharedInstance] setExifLocalTableEtag:metadata directoryUser:app.directoryUser activeAccount:app.activeAccount];
  536. }
  537. }
  538. [[CCExifGeo sharedInstance] setGeocoderEtag:fileID exifDate:localFile.exifDate latitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  539. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  540. if ([localFile.exifLatitude floatValue] != 0 || [localFile.exifLongitude floatValue] != 0) {
  541. NSString *location = [[NCManageDatabase sharedInstance] getLocationFromGeoLatitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  542. if ([localFile.exifDate isEqualToDate:[NSDate distantPast]] == NO && location) {
  543. NSString *localizedDateTime = [NSDateFormatter localizedStringFromDate:localFile.exifDate dateStyle:NSDateFormatterFullStyle timeStyle:NSDateFormatterMediumStyle];
  544. photo.caption = [NSString stringWithFormat:NSLocalizedString(@"%@\n%@", nil), localizedDateTime, location];
  545. }
  546. }
  547. }
  548. }
  549. #pragma --------------------------------------------------------------------------------------------
  550. #pragma mark ===== View PDF =====
  551. #pragma --------------------------------------------------------------------------------------------
  552. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  553. {
  554. [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
  555. [[alertView textFieldAtIndex:0] resignFirstResponder];
  556. if (alertView.tag == alertRequestPasswordPDF) [self performSelector:@selector(viewPDF:) withObject:[alertView textFieldAtIndex:0].text afterDelay:0.3];
  557. }
  558. - (void)viewPDF:(NSString *)password
  559. {
  560. NSString *fileName = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileName];
  561. [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
  562. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
  563. if ([[NSFileManager defaultManager] fileExistsAtPath:fileName isDirectory:nil] == NO) {
  564. // read file error
  565. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  566. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  567. [alertController addAction:okAction];
  568. [self presentViewController:alertController animated:YES completion:nil];
  569. }
  570. CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:fileName]);
  571. if (pdf) {
  572. // Encrypted
  573. if (CGPDFDocumentIsEncrypted(pdf) == YES) {
  574. // Try a blank password first, per Apple's Quartz PDF example
  575. if (CGPDFDocumentUnlockWithPassword(pdf, "") == YES) {
  576. // blank password
  577. [self readerPDF:fileName password:@""];
  578. } else {
  579. if ([password length] == 0) {
  580. // password request
  581. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_insert_password_pfd_",nil) message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  582. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  583. alertView.tag = alertRequestPasswordPDF;
  584. [alertView show];
  585. } else {
  586. const char *key = [password UTF8String];
  587. // failure
  588. if (CGPDFDocumentUnlockWithPassword(pdf, key) == NO) {
  589. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_password_pdf_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  590. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  591. [alertController addAction:okAction];
  592. [self presentViewController:alertController animated:YES completion:nil];
  593. } else {
  594. // pdf with password
  595. [self readerPDF:fileName password:password];
  596. }
  597. }
  598. }
  599. } else{
  600. // No password
  601. [self readerPDF:fileName password:@""];
  602. }
  603. } else {
  604. // read file error
  605. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  606. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  607. [alertController addAction:okAction];
  608. [self presentViewController:alertController animated:YES completion:nil];
  609. }
  610. }
  611. - (void)readerPDF:(NSString *)fileName password:(NSString *)password
  612. {
  613. ReaderDocument *documentPDF = [ReaderDocument withDocumentFilePath:fileName password:password];
  614. CGFloat safeAreaBottom = 0;
  615. if (@available(iOS 11, *)) {
  616. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  617. }
  618. if (documentPDF != nil) {
  619. self.readerPDFViewController = [[ReaderViewController alloc] initWithReaderDocument:documentPDF];
  620. self.readerPDFViewController.delegate = self;
  621. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom);
  622. [self.readerPDFViewController updateContentViews];
  623. [self addChildViewController:self.readerPDFViewController];
  624. [self.view addSubview:self.readerPDFViewController.view];
  625. [self.readerPDFViewController didMoveToParentViewController:self];
  626. } else {
  627. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  628. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  629. [alertController addAction:okAction];
  630. [self presentViewController:alertController animated:YES completion:nil];
  631. }
  632. }
  633. - (void)handleSingleTapReader
  634. {
  635. UILayoutGuide *layoutGuide;
  636. CGFloat safeAreaTop = 0;
  637. CGFloat safeAreaBottom = 0;
  638. if (@available(iOS 11, *)) {
  639. layoutGuide = [UIApplication sharedApplication].delegate.window.safeAreaLayoutGuide;
  640. safeAreaTop = [UIApplication sharedApplication].delegate.window.safeAreaInsets.top;
  641. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  642. }
  643. self.navigationController.navigationBarHidden = !self.navigationController.navigationBarHidden;
  644. _toolbar.hidden = !_toolbar.isHidden;
  645. if (_toolbar.isHidden) {
  646. self.readerPDFViewController.view.frame = CGRectMake(0, safeAreaTop, self.view.bounds.size.width, self.view.bounds.size.height - safeAreaTop - safeAreaBottom);
  647. } else {
  648. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom);
  649. }
  650. [self.readerPDFViewController updateContentViews];
  651. }
  652. #pragma --------------------------------------------------------------------------------------------
  653. #pragma mark ===== Delete =====
  654. #pragma --------------------------------------------------------------------------------------------
  655. - (void)deleteFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  656. {
  657. NSLog(@"[LOG] DeleteFileOrFolder failure error %lu, %@", (long)errorCode, message);
  658. }
  659. - (void)deleteFileOrFolderSuccess:(CCMetadataNet *)metadataNet
  660. {
  661. // reload Main
  662. [app.activeMain reloadDatasource];
  663. // If removed document (web) or PDF close
  664. if (_webView || _readerPDFViewController)
  665. [self removeAllView];
  666. // if a message for a directory of these
  667. if (![_dataSourceDirectoryID containsObject:metadataNet.directoryID])
  668. return;
  669. // if we are not in browserPhoto and it's removed photo/video in preview then "< Back"
  670. if (!self.photoBrowser && [self.metadataDetail.fileID isEqualToString:metadataNet.fileID]) {
  671. NSArray *viewsToRemove = [self.view subviews];
  672. for (id element in viewsToRemove) {
  673. if ([element isMemberOfClass:[UIView class]] || [element isMemberOfClass:[UIToolbar class]])
  674. [element removeFromSuperview];
  675. }
  676. self.title = @"";
  677. [self.navigationController popViewControllerAnimated:YES];
  678. } else {
  679. // only photoBrowser if exists
  680. for (NSUInteger index=0; index < [self.dataSourceImagesVideos count] && _photoBrowser; index++ ) {
  681. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  682. // ricerca index
  683. if ([metadata.fileID isEqualToString:metadataNet.fileID]) {
  684. [self.dataSourceImagesVideos removeObjectAtIndex:index];
  685. [self.photos removeObjectAtIndex:index];
  686. [self.thumbs removeObjectAtIndex:index];
  687. [self.photoBrowser reloadData];
  688. // Title
  689. if ([self.dataSourceImagesVideos count] == 0) {
  690. self.title = @"";
  691. [self.navigationController popViewControllerAnimated:YES];
  692. }
  693. break;
  694. }
  695. }
  696. }
  697. }
  698. #pragma --------------------------------------------------------------------------------------------
  699. #pragma mark ===== ButtonPressed =====
  700. #pragma --------------------------------------------------------------------------------------------
  701. - (void)modifyTxtButtonPressed:(UIBarButtonItem *)sender
  702. {
  703. UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"NCText" bundle:nil] instantiateViewControllerWithIdentifier:@"NCText"];
  704. NCText *viewController = (NCText *)navigationController.topViewController;
  705. viewController.metadata = self.metadataDetail;
  706. navigationController.modalPresentationStyle = UIModalPresentationPageSheet;
  707. navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  708. [self presentViewController:navigationController animated:YES completion:nil];
  709. }
  710. - (void)actionButtonPressed:(UIBarButtonItem *)sender
  711. {
  712. if ([self.metadataDetail.fileName length] == 0) return;
  713. NSString *filePath = [NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), self.metadataDetail.fileName];
  714. self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  715. self.docController.delegate = self;
  716. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  717. [self.docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  718. [self.docController presentOptionsMenuFromBarButtonItem:sender animated:YES];
  719. }
  720. - (void)shareButtonPressed:(UIBarButtonItem *)sender
  721. {
  722. [app.activeMain openWindowShare:self.metadataDetail];
  723. }
  724. - (void)deleteButtonPressed:(UIBarButtonItem *)sender
  725. {
  726. if ([self.metadataDetail.fileName length] == 0) return;
  727. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  728. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  729. style:UIAlertActionStyleDestructive
  730. handler:^(UIAlertAction *action) {
  731. [[CCActions sharedInstance] deleteFileOrFolder:self.metadataDetail delegate:self];
  732. }]];
  733. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  734. style:UIAlertActionStyleCancel
  735. handler:^(UIAlertAction *action) {
  736. [alertController dismissViewControllerAnimated:YES completion:nil];
  737. }]];
  738. alertController.popoverPresentationController.barButtonItem = _buttonDelete;
  739. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  740. [alertController.view layoutIfNeeded];
  741. [self presentViewController:alertController animated:YES completion:NULL];
  742. }
  743. @end