CCDetail.m 48 KB

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