CCDetail.m 48 KB

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