CCDetail.m 44 KB

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