CCLocalStorage.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. //
  2. // CCLocalStorage.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 16/01/17.
  6. // Copyright (c) 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCLocalStorage.h"
  24. #import "AppDelegate.h"
  25. @interface CCLocalStorage ()
  26. {
  27. NSArray *dataSource;
  28. }
  29. @end
  30. @implementation CCLocalStorage
  31. - (void)viewDidLoad
  32. {
  33. [super viewDidLoad];
  34. // Custom Cell
  35. [self.tableView registerNib:[UINib nibWithNibName:@"CCLocalStorageCell" bundle:nil] forCellReuseIdentifier:@"Cell"];
  36. // dataSource
  37. dataSource = [NSMutableArray new];
  38. // Metadata
  39. _metadata = [CCMetadata new];
  40. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 1)];
  41. self.tableView.separatorColor = COLOR_SEPARATOR_TABLE;
  42. self.tableView.emptyDataSetDelegate = self;
  43. self.tableView.emptyDataSetSource = self;
  44. self.tableView.allowsMultipleSelectionDuringEditing = NO;
  45. // ServerUrl
  46. if (!_serverUrl)
  47. _serverUrl = [CCUtility getDirectoryLocal];
  48. // Title
  49. if (_titleViewControl)
  50. self.title = _titleViewControl;
  51. else
  52. self.title = NSLocalizedString(@"_local_storage_", nil);
  53. }
  54. // Apparirà
  55. - (void)viewWillAppear:(BOOL)animated
  56. {
  57. [super viewWillAppear:animated];
  58. // Color
  59. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  60. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  61. // Plus Button
  62. [app plusButtonVisibile:true];
  63. [self reloadDatasource];
  64. }
  65. // E' arrivato
  66. - (void)viewDidAppear:(BOOL)animated
  67. {
  68. [super viewDidAppear:animated];
  69. // update Badge
  70. [app updateApplicationIconBadgeNumber];
  71. }
  72. - (void)didReceiveMemoryWarning {
  73. [super didReceiveMemoryWarning];
  74. }
  75. #pragma --------------------------------------------------------------------------------------------
  76. #pragma mark ==== DZNEmptyDataSetSource ====
  77. #pragma --------------------------------------------------------------------------------------------
  78. - (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView
  79. {
  80. // only for root
  81. if ([_serverUrl isEqualToString:[CCUtility getDirectoryLocal]])
  82. return YES;
  83. else
  84. return NO;
  85. }
  86. - (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView
  87. {
  88. return 0.0f;
  89. }
  90. - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
  91. {
  92. return [UIColor whiteColor];
  93. }
  94. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
  95. {
  96. return [UIImage imageNamed:image_brandBackgroundLite];
  97. }
  98. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
  99. {
  100. NSString *text = [NSString stringWithFormat:@"%@", @""];
  101. NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:COLOR_BRAND};
  102. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  103. }
  104. - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
  105. {
  106. NSString *text = [NSString stringWithFormat:@"\n%@", NSLocalizedString(@"_tutorial_local_view_", nil)];
  107. NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
  108. paragraph.lineBreakMode = NSLineBreakByWordWrapping;
  109. paragraph.alignment = NSTextAlignmentCenter;
  110. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph};
  111. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  112. }
  113. #pragma --------------------------------------------------------------------------------------------
  114. #pragma mark ===== UIDocumentInteractionController <delegate> =====
  115. #pragma --------------------------------------------------------------------------------------------
  116. - (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *)controller
  117. {
  118. // evitiamo il rimando della eventuale photo e/o video
  119. if ([CCCoreData getCameraUploadActiveAccount:app.activeAccount]) {
  120. [CCCoreData setCameraUploadDatePhoto:[NSDate date]];
  121. [CCCoreData setCameraUploadDateVideo:[NSDate date]];
  122. }
  123. }
  124. #pragma --------------------------------------------------------------------------------------------
  125. #pragma mark ===== menu =====
  126. #pragma--------------------------------------------------------------------------------------------
  127. - (void)openModel:(CCMetadata *)metadata
  128. {
  129. UIViewController *viewController;
  130. BOOL isLocal = YES;
  131. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:app.activeAccount];
  132. if ([metadata.model isEqualToString:@"cartadicredito"])
  133. viewController = [[CCCartaDiCredito alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:isLocal serverUrl:serverUrl];
  134. if ([metadata.model isEqualToString:@"bancomat"])
  135. viewController = [[CCBancomat alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:isLocal serverUrl:serverUrl];
  136. if ([metadata.model isEqualToString:@"contocorrente"])
  137. viewController = [[CCContoCorrente alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:isLocal serverUrl:serverUrl];
  138. if ([metadata.model isEqualToString:@"accountweb"])
  139. viewController = [[CCAccountWeb alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:isLocal serverUrl:serverUrl];
  140. if ([metadata.model isEqualToString:@"patenteguida"])
  141. viewController = [[CCPatenteGuida alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:isLocal serverUrl:serverUrl];
  142. if ([metadata.model isEqualToString:@"cartaidentita"])
  143. viewController = [[CCCartaIdentita alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:isLocal serverUrl:serverUrl];
  144. if ([metadata.model isEqualToString:@"passaporto"])
  145. viewController = [[CCPassaporto alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:isLocal serverUrl:serverUrl];
  146. if ([metadata.model isEqualToString:@"note"]) {
  147. viewController = [[CCNote alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:isLocal serverUrl:serverUrl];
  148. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  149. [self presentViewController:navigationController animated:YES completion:nil];
  150. } else {
  151. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  152. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  153. [self presentViewController:navigationController animated:YES completion:nil];
  154. }
  155. }
  156. - (void)openWith:(CCMetadata *)metadata
  157. {
  158. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", _serverUrl, metadata.fileNameData];
  159. if ([[NSFileManager defaultManager] fileExistsAtPath:fileNamePath]) {
  160. [[NSFileManager defaultManager] removeItemAtPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint] error:nil];
  161. [[NSFileManager defaultManager] linkItemAtPath:fileNamePath toPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint] error:nil];
  162. NSURL *url = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint]];
  163. _docController = [UIDocumentInteractionController interactionControllerWithURL:url];
  164. _docController.delegate = self;
  165. [_docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  166. }
  167. }
  168. - (void)requestDeleteMetadata:(CCMetadata *)metadata indexPath:(NSIndexPath *)indexPath
  169. {
  170. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  171. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  172. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", _serverUrl, metadata.fileNameData];
  173. NSString *iconPath = [NSString stringWithFormat:@"%@/.%@.ico", _serverUrl, metadata.fileNameData];
  174. [[NSFileManager defaultManager] removeItemAtPath:fileNamePath error:nil];
  175. [[NSFileManager defaultManager] removeItemAtPath:iconPath error:nil];
  176. [self reloadDatasource];
  177. }]];
  178. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  179. }]];
  180. alertController.popoverPresentationController.sourceView = self.view;
  181. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  182. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  183. [alertController.view layoutIfNeeded];
  184. [self presentViewController:alertController animated:YES completion:nil];
  185. }
  186. -(void)cellButtonDownWasTapped:(id)sender
  187. {
  188. CGPoint touchPoint = [sender convertPoint:CGPointZero toView:self.tableView];
  189. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touchPoint];
  190. CCMetadata *metadata = [CCMetadata new];
  191. UIImage *iconHeader;
  192. NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  193. NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl];
  194. metadata = [CCUtility insertFileSystemInMetadata:[dataSource objectAtIndex:indexPath.row] directory:_serverUrl activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
  195. AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.view title:nil];
  196. actionSheet.animationDuration = 0.2;
  197. actionSheet.blurRadius = 0.0f;
  198. actionSheet.blurTintColor = [UIColor colorWithWhite:0.0f alpha:0.50f];
  199. actionSheet.buttonHeight = 50.0;
  200. actionSheet.cancelButtonHeight = 50.0f;
  201. actionSheet.separatorHeight = 5.0f;
  202. actionSheet.automaticallyTintButtonImages = @(NO);
  203. actionSheet.encryptedButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:COLOR_CRYPTOCLOUD };
  204. actionSheet.buttonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:COLOR_TEXT_ANTHRACITE };
  205. actionSheet.cancelButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:COLOR_BRAND };
  206. actionSheet.disableButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:COLOR_TEXT_ANTHRACITE };
  207. actionSheet.separatorColor = COLOR_SEPARATOR_TABLE;
  208. actionSheet.cancelButtonTitle = NSLocalizedString(@"_cancel_",nil);
  209. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  210. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]])
  211. iconHeader = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
  212. else
  213. iconHeader = [UIImage imageNamed:metadata.iconName];
  214. [actionSheet addButtonWithTitle: metadata.fileNamePrint
  215. image: iconHeader
  216. backgroundColor: COLOR_TABBAR
  217. height: 50.0
  218. type: AHKActionSheetButtonTypeDisabled
  219. handler: nil
  220. ];
  221. // Remove file/folder offline
  222. if (_serverUrl == nil) {
  223. [actionSheet addButtonWithTitle:NSLocalizedString(@"_remove_offline_", nil) image:[UIImage imageNamed:image_actionSheetOffline] backgroundColor:[UIColor whiteColor] height: 50.0 type:AHKActionSheetButtonTypeDefault handler:^(AHKActionSheet *as) {
  224. if (metadata.directory) {
  225. // remove tag offline for all folder/subfolder/file
  226. NSString *relativeRoot = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:app.activeAccount];
  227. NSString *dirServerUrl = [CCUtility stringAppendServerUrl:relativeRoot addFileName:metadata.fileNameData];
  228. NSArray *directories = [CCCoreData getOfflineDirectoryActiveAccount:app.activeAccount];
  229. for (TableDirectory *directory in directories)
  230. if ([directory.serverUrl containsString:dirServerUrl]) {
  231. [CCCoreData setOfflineDirectoryServerUrl:directory.serverUrl offline:NO activeAccount:app.activeAccount];
  232. [CCCoreData removeOfflineAllFileFromServerUrl:directory.serverUrl activeAccount:app.activeAccount];
  233. }
  234. } else {
  235. [CCCoreData setOfflineLocalFileID:metadata.fileID offline:NO activeAccount:app.activeAccount];
  236. }
  237. [self.tableView setEditing:NO animated:YES];
  238. [self reloadDatasource];
  239. }];
  240. }
  241. // NO Directory - NO Template
  242. if (metadata.directory == NO && [metadata.type isEqualToString:k_metadataType_template] == NO) {
  243. [actionSheet addButtonWithTitle:NSLocalizedString(@"_open_in_", nil) image:[UIImage imageNamed:image_actionSheetOpenIn] backgroundColor:[UIColor whiteColor] height: 50.0 type:AHKActionSheetButtonTypeDefault handler:^(AHKActionSheet *as) {
  244. [self.tableView setEditing:NO animated:YES];
  245. [self openWith:metadata];
  246. }];
  247. }
  248. [actionSheet addButtonWithTitle:NSLocalizedString(@"_delete_", nil) image:[UIImage imageNamed:image_delete] backgroundColor:[UIColor whiteColor] height: 50.0 type:AHKActionSheetButtonTypeDestructive handler:^(AHKActionSheet *as) {
  249. [self requestDeleteMetadata:metadata indexPath:indexPath];
  250. }];
  251. [actionSheet show];
  252. }
  253. #pragma --------------------------------------------------------------------------------------------
  254. #pragma mark ==== Table ====
  255. #pragma --------------------------------------------------------------------------------------------
  256. - (CCMetadata *)setSelfMetadataFromIndexPath:(NSIndexPath *)indexPath
  257. {
  258. NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  259. NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl];
  260. return [CCUtility insertFileSystemInMetadata:[dataSource objectAtIndex:indexPath.row] directory:_serverUrl activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
  261. }
  262. - (void)readFolderWithForced:(BOOL)forced serverUrl:(NSString *)serverUrl
  263. {
  264. [self reloadDatasource];
  265. }
  266. - (void)reloadDatasource
  267. {
  268. NSArray *subpaths = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:_serverUrl error:nil];
  269. NSMutableArray *metadatas = [NSMutableArray new];
  270. for (NSString *subpath in subpaths)
  271. if (![[subpath lastPathComponent] hasPrefix:@"."])
  272. [metadatas addObject:subpath];
  273. dataSource = [NSArray arrayWithArray:metadatas];
  274. [self.tableView reloadData];
  275. }
  276. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  277. {
  278. return 60;
  279. }
  280. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  281. {
  282. return 1;
  283. }
  284. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  285. {
  286. return [dataSource count];
  287. }
  288. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  289. {
  290. CCLocalStorageCell *cell = (CCLocalStorageCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
  291. CCMetadata *metadata;
  292. // separator
  293. cell.separatorInset = UIEdgeInsetsMake(0.f, 60.f, 0.f, 0.f);
  294. // Initialize
  295. cell.statusImageView.image = nil;
  296. cell.offlineImageView.image = nil;
  297. // change color selection
  298. UIView *selectionColor = [[UIView alloc] init];
  299. selectionColor.backgroundColor = COLOR_SELECT_BACKGROUND;
  300. cell.selectedBackgroundView = selectionColor;
  301. NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  302. NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl];
  303. metadata = [CCUtility insertFileSystemInMetadata:[dataSource objectAtIndex:indexPath.row] directory:_serverUrl activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
  304. cell.fileImageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/.%@.ico", _serverUrl, metadata.fileNamePrint]];
  305. if (!cell.fileImageView.image) {
  306. UIImage *icon = [CCGraphics createNewImageFrom:metadata.fileID directoryUser:_serverUrl fileNameTo:metadata.fileID fileNamePrint:metadata.fileNamePrint size:@"m" imageForUpload:NO typeFile:metadata.typeFile writePreview:NO optimizedFileName:[CCUtility getOptimizedPhoto]];
  307. if (icon) {
  308. [CCGraphics saveIcoWithFileID:metadata.fileNamePrint image:icon writeToFile:[NSString stringWithFormat:@"%@/.%@.ico", _serverUrl, metadata.fileNamePrint] copy:NO move:NO fromPath:nil toPath:nil];
  309. cell.fileImageView.image = icon;
  310. }
  311. }
  312. // ButtonDown Tapped
  313. [cell.buttonDown addTarget:self action:@selector(cellButtonDownWasTapped:) forControlEvents:UIControlEventTouchUpInside];
  314. // encrypted color
  315. if (metadata.cryptated) {
  316. cell.labelTitle.textColor = COLOR_CRYPTOCLOUD;
  317. } else {
  318. cell.labelTitle.textColor = [UIColor blackColor];
  319. }
  320. // File name
  321. cell.labelTitle.text = metadata.fileNamePrint;
  322. cell.labelInfoFile.text = @"";
  323. // Immagine del file, se non c'è l'anteprima mettiamo quella standard
  324. if (cell.fileImageView.image == nil)
  325. cell.fileImageView.image = [UIImage imageNamed:metadata.iconName];
  326. // it's encrypted ???
  327. if (metadata.cryptated && [metadata.type isEqualToString: k_metadataType_template] == NO)
  328. cell.statusImageView.image = [UIImage imageNamed:image_lock];
  329. // text and length
  330. if (metadata.directory) {
  331. cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
  332. cell.accessoryType = UITableViewCellAccessoryNone;
  333. //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  334. } else {
  335. NSString *date = [CCUtility dateDiff:metadata.date];
  336. NSString *length = [CCUtility transformedSize:metadata.size];
  337. if ([metadata.type isEqualToString: k_metadataType_template])
  338. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", date];
  339. if ([metadata.type isEqualToString: k_metadataType_file] || [metadata.type isEqualToString: k_metadataType_local])
  340. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ • %@", date, length];
  341. cell.accessoryType = UITableViewCellAccessoryNone;
  342. }
  343. return cell;
  344. }
  345. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  346. {
  347. // deselect row
  348. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  349. _metadata = [self setSelfMetadataFromIndexPath:indexPath];
  350. // if is in download [do not touch]
  351. if ([_metadata.session length] > 0 && [_metadata.session containsString:@"download"])
  352. return;
  353. // File
  354. if (([_metadata.type isEqualToString: k_metadataType_file] || [_metadata.type isEqualToString: k_metadataType_local]) && _metadata.directory == NO) {
  355. if ([_metadata.typeFile isEqualToString: k_metadataTypeFile_unknown] || [_metadata.typeFile isEqualToString: k_metadataTypeFile_compress]) {
  356. [self openWith:_metadata];
  357. } else {
  358. if ([self shouldPerformSegue])
  359. [self performSegueWithIdentifier:@"segueDetail" sender:self];
  360. }
  361. }
  362. // Model
  363. if ([self.metadata.type isEqualToString: k_metadataType_template])
  364. [self openModel:_metadata];
  365. // Directory
  366. if (_metadata.directory)
  367. [self performSegueDirectoryWithControlPasscode];
  368. }
  369. -(void)performSegueDirectoryWithControlPasscode
  370. {
  371. CCLocalStorage *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCLocalStorage"];
  372. vc.serverUrl = [CCUtility stringAppendServerUrl:_serverUrl addFileName:_metadata.fileNameData];
  373. vc.titleViewControl = _metadata.fileNamePrint;
  374. [self.navigationController pushViewController:vc animated:YES];
  375. }
  376. #pragma --------------------------------------------------------------------------------------------
  377. #pragma mark ===== Navigation ====
  378. #pragma --------------------------------------------------------------------------------------------
  379. - (BOOL)shouldPerformSegue
  380. {
  381. // if i am in background -> exit
  382. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return NO;
  383. // if i am not window -> exit
  384. if (self.view.window == NO)
  385. return NO;
  386. // Collapsed but i am in detail -> exit
  387. if (self.splitViewController.isCollapsed)
  388. if (self.detailViewController.isViewLoaded && self.detailViewController.view.window) return NO;
  389. // Video in run -> exit
  390. if (self.detailViewController.photoBrowser.currentVideoPlayerViewController.isViewLoaded && self.detailViewController.photoBrowser.currentVideoPlayerViewController.view.window) return NO;
  391. return YES;
  392. }
  393. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  394. {
  395. id viewController = segue.destinationViewController;
  396. if ([viewController isKindOfClass:[UINavigationController class]]) {
  397. UINavigationController *nav = viewController;
  398. _detailViewController = (CCDetail *)nav.topViewController;
  399. } else {
  400. _detailViewController = segue.destinationViewController;
  401. }
  402. NSMutableArray *allRecordsDataSourceImagesVideos = [NSMutableArray new];
  403. NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  404. NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl];
  405. for (NSString *fileName in dataSource) {
  406. CCMetadata *metadata = [CCMetadata new];
  407. metadata = [CCUtility insertFileSystemInMetadata:fileName directory:_serverUrl activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
  408. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] || [metadata.typeFile isEqualToString: k_metadataTypeFile_video])
  409. [allRecordsDataSourceImagesVideos addObject:metadata];
  410. }
  411. _detailViewController.sourceDirectoryLocal = YES;
  412. _detailViewController.metadataDetail = _metadata;
  413. _detailViewController.dateFilterQuery = nil;
  414. _detailViewController.isCameraUpload = NO;
  415. _detailViewController.dataSourceImagesVideos = allRecordsDataSourceImagesVideos;
  416. [_detailViewController setTitle:_metadata.fileNamePrint];
  417. }
  418. @end