CCLocalStorage.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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. }
  70. - (void)didReceiveMemoryWarning {
  71. [super didReceiveMemoryWarning];
  72. }
  73. #pragma --------------------------------------------------------------------------------------------
  74. #pragma mark ==== DZNEmptyDataSetSource ====
  75. #pragma --------------------------------------------------------------------------------------------
  76. - (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView
  77. {
  78. // only for root
  79. if ([_serverUrl isEqualToString:[CCUtility getDirectoryLocal]])
  80. return YES;
  81. else
  82. return NO;
  83. }
  84. - (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView
  85. {
  86. return 0.0f;
  87. }
  88. - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
  89. {
  90. return [UIColor whiteColor];
  91. }
  92. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
  93. {
  94. return [UIImage imageNamed:image_localStorageNoRecord];
  95. }
  96. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
  97. {
  98. NSString *text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_local_storage_no_record_", nil)];
  99. NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:[UIColor lightGrayColor]};
  100. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  101. }
  102. - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
  103. {
  104. NSString *text = [NSString stringWithFormat:@"\n%@", NSLocalizedString(@"_tutorial_local_view_", nil)];
  105. NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
  106. paragraph.lineBreakMode = NSLineBreakByWordWrapping;
  107. paragraph.alignment = NSTextAlignmentCenter;
  108. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph};
  109. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  110. }
  111. #pragma --------------------------------------------------------------------------------------------
  112. #pragma mark ===== UIDocumentInteractionController <delegate> =====
  113. #pragma --------------------------------------------------------------------------------------------
  114. - (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *)controller
  115. {
  116. // evitiamo il rimando della eventuale photo e/o video
  117. if ([CCCoreData getCameraUploadActiveAccount:app.activeAccount]) {
  118. [CCCoreData setCameraUploadDatePhoto:[NSDate date]];
  119. [CCCoreData setCameraUploadDateVideo:[NSDate date]];
  120. }
  121. }
  122. #pragma --------------------------------------------------------------------------------------------
  123. #pragma mark ===== menu =====
  124. #pragma--------------------------------------------------------------------------------------------
  125. - (void)openModel:(CCMetadata *)metadata
  126. {
  127. UIViewController *viewController;
  128. BOOL isLocal = YES;
  129. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:app.activeAccount];
  130. if ([metadata.model isEqualToString:@"cartadicredito"])
  131. viewController = [[CCCartaDiCredito alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:isLocal serverUrl:serverUrl];
  132. if ([metadata.model isEqualToString:@"bancomat"])
  133. viewController = [[CCBancomat alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:isLocal serverUrl:serverUrl];
  134. if ([metadata.model isEqualToString:@"contocorrente"])
  135. viewController = [[CCContoCorrente alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:isLocal serverUrl:serverUrl];
  136. if ([metadata.model isEqualToString:@"accountweb"])
  137. viewController = [[CCAccountWeb alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:isLocal serverUrl:serverUrl];
  138. if ([metadata.model isEqualToString:@"patenteguida"])
  139. viewController = [[CCPatenteGuida alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:isLocal serverUrl:serverUrl];
  140. if ([metadata.model isEqualToString:@"cartaidentita"])
  141. viewController = [[CCCartaIdentita alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:isLocal serverUrl:serverUrl];
  142. if ([metadata.model isEqualToString:@"passaporto"])
  143. viewController = [[CCPassaporto alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:isLocal serverUrl:serverUrl];
  144. if ([metadata.model isEqualToString:@"note"]) {
  145. viewController = [[CCNote alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:isLocal serverUrl:serverUrl];
  146. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  147. [self presentViewController:navigationController animated:YES completion:nil];
  148. } else {
  149. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  150. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  151. [self presentViewController:navigationController animated:YES completion:nil];
  152. }
  153. }
  154. - (void)openWith:(CCMetadata *)metadata
  155. {
  156. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", _serverUrl, metadata.fileNameData];
  157. if ([[NSFileManager defaultManager] fileExistsAtPath:fileNamePath]) {
  158. [[NSFileManager defaultManager] removeItemAtPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint] error:nil];
  159. [[NSFileManager defaultManager] linkItemAtPath:fileNamePath toPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint] error:nil];
  160. NSURL *url = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint]];
  161. _docController = [UIDocumentInteractionController interactionControllerWithURL:url];
  162. _docController.delegate = self;
  163. [_docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  164. }
  165. }
  166. - (void)requestDeleteMetadata:(CCMetadata *)metadata indexPath:(NSIndexPath *)indexPath
  167. {
  168. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  169. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  170. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", _serverUrl, metadata.fileNameData];
  171. NSString *iconPath = [NSString stringWithFormat:@"%@/.%@.ico", _serverUrl, metadata.fileNameData];
  172. [[NSFileManager defaultManager] removeItemAtPath:fileNamePath error:nil];
  173. [[NSFileManager defaultManager] removeItemAtPath:iconPath error:nil];
  174. [self reloadDatasource];
  175. }]];
  176. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  177. }]];
  178. alertController.popoverPresentationController.sourceView = self.view;
  179. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  180. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  181. [alertController.view layoutIfNeeded];
  182. [self presentViewController:alertController animated:YES completion:nil];
  183. }
  184. -(void)cellButtonDownWasTapped:(id)sender
  185. {
  186. CGPoint touchPoint = [sender convertPoint:CGPointZero toView:self.tableView];
  187. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touchPoint];
  188. CCMetadata *metadata = [CCMetadata new];
  189. UIImage *iconHeader;
  190. NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  191. NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl];
  192. metadata = [CCUtility insertFileSystemInMetadata:[dataSource objectAtIndex:indexPath.row] directory:_serverUrl activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
  193. AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.view title:nil];
  194. actionSheet.animationDuration = 0.2;
  195. actionSheet.blurRadius = 0.0f;
  196. actionSheet.blurTintColor = [UIColor colorWithWhite:0.0f alpha:0.50f];
  197. actionSheet.buttonHeight = 50.0;
  198. actionSheet.cancelButtonHeight = 50.0f;
  199. actionSheet.separatorHeight = 5.0f;
  200. actionSheet.automaticallyTintButtonImages = @(NO);
  201. actionSheet.encryptedButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:COLOR_CRYPTOCLOUD };
  202. actionSheet.buttonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:COLOR_TEXT_ANTHRACITE };
  203. actionSheet.cancelButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:COLOR_BRAND };
  204. actionSheet.disableButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:COLOR_TEXT_ANTHRACITE };
  205. actionSheet.separatorColor = COLOR_SEPARATOR_TABLE;
  206. actionSheet.cancelButtonTitle = NSLocalizedString(@"_cancel_",nil);
  207. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  208. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]])
  209. iconHeader = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
  210. else
  211. iconHeader = [UIImage imageNamed:metadata.iconName];
  212. [actionSheet addButtonWithTitle: metadata.fileNamePrint
  213. image: iconHeader
  214. backgroundColor: COLOR_TABBAR
  215. height: 50.0
  216. type: AHKActionSheetButtonTypeDisabled
  217. handler: nil
  218. ];
  219. // Remove file/folder offline
  220. if (_serverUrl == nil) {
  221. [actionSheet addButtonWithTitle:NSLocalizedString(@"_remove_offline_", nil) image:[UIImage imageNamed:image_actionSheetOffline] backgroundColor:[UIColor whiteColor] height: 50.0 type:AHKActionSheetButtonTypeDefault handler:^(AHKActionSheet *as) {
  222. if (metadata.directory) {
  223. // remove tag offline for all folder/subfolder/file
  224. NSString *relativeRoot = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:app.activeAccount];
  225. NSString *dirServerUrl = [CCUtility stringAppendServerUrl:relativeRoot addFileName:metadata.fileNameData];
  226. NSArray *directories = [CCCoreData getOfflineDirectoryActiveAccount:app.activeAccount];
  227. for (TableDirectory *directory in directories)
  228. if ([directory.serverUrl containsString:dirServerUrl]) {
  229. [CCCoreData setOfflineDirectoryServerUrl:directory.serverUrl offline:NO activeAccount:app.activeAccount];
  230. [CCCoreData removeOfflineAllFileFromServerUrl:directory.serverUrl activeAccount:app.activeAccount];
  231. }
  232. } else {
  233. [CCCoreData setOfflineLocalFileID:metadata.fileID offline:NO activeAccount:app.activeAccount];
  234. }
  235. [self.tableView setEditing:NO animated:YES];
  236. [self reloadDatasource];
  237. }];
  238. }
  239. // NO Directory - NO Template
  240. if (metadata.directory == NO && [metadata.type isEqualToString:k_metadataType_template] == NO) {
  241. [actionSheet addButtonWithTitle:NSLocalizedString(@"_open_in_", nil) image:[UIImage imageNamed:image_actionSheetOpenIn] backgroundColor:[UIColor whiteColor] height: 50.0 type:AHKActionSheetButtonTypeDefault handler:^(AHKActionSheet *as) {
  242. [self.tableView setEditing:NO animated:YES];
  243. [self openWith:metadata];
  244. }];
  245. }
  246. [actionSheet addButtonWithTitle:NSLocalizedString(@"_delete_", nil) image:[UIImage imageNamed:image_delete] backgroundColor:[UIColor whiteColor] height: 50.0 type:AHKActionSheetButtonTypeDestructive handler:^(AHKActionSheet *as) {
  247. [self requestDeleteMetadata:metadata indexPath:indexPath];
  248. }];
  249. [actionSheet show];
  250. }
  251. #pragma --------------------------------------------------------------------------------------------
  252. #pragma mark ==== Table ====
  253. #pragma --------------------------------------------------------------------------------------------
  254. - (CCMetadata *)setSelfMetadataFromIndexPath:(NSIndexPath *)indexPath
  255. {
  256. NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  257. NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl];
  258. return [CCUtility insertFileSystemInMetadata:[dataSource objectAtIndex:indexPath.row] directory:_serverUrl activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
  259. }
  260. - (void)readFolderWithForced:(BOOL)forced serverUrl:(NSString *)serverUrl
  261. {
  262. [self reloadDatasource];
  263. }
  264. - (void)reloadDatasource
  265. {
  266. NSArray *subpaths = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:_serverUrl error:nil];
  267. NSMutableArray *metadatas = [NSMutableArray new];
  268. for (NSString *subpath in subpaths)
  269. if (![[subpath lastPathComponent] hasPrefix:@"."])
  270. [metadatas addObject:subpath];
  271. dataSource = [NSArray arrayWithArray:metadatas];
  272. [self.tableView reloadData];
  273. }
  274. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  275. {
  276. return 60;
  277. }
  278. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  279. {
  280. return 1;
  281. }
  282. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  283. {
  284. return [dataSource count];
  285. }
  286. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  287. {
  288. CCLocalStorageCell *cell = (CCLocalStorageCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
  289. CCMetadata *metadata;
  290. // separator
  291. cell.separatorInset = UIEdgeInsetsMake(0.f, 60.f, 0.f, 0.f);
  292. // Initialize
  293. cell.statusImageView.image = nil;
  294. cell.offlineImageView.image = nil;
  295. // change color selection
  296. UIView *selectionColor = [[UIView alloc] init];
  297. selectionColor.backgroundColor = COLOR_SELECT_BACKGROUND;
  298. cell.selectedBackgroundView = selectionColor;
  299. NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  300. NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl];
  301. metadata = [CCUtility insertFileSystemInMetadata:[dataSource objectAtIndex:indexPath.row] directory:_serverUrl activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
  302. cell.fileImageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/.%@.ico", _serverUrl, metadata.fileNamePrint]];
  303. if (!cell.fileImageView.image) {
  304. 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]];
  305. if (icon) {
  306. [CCGraphics saveIcoWithFileID:metadata.fileNamePrint image:icon writeToFile:[NSString stringWithFormat:@"%@/.%@.ico", _serverUrl, metadata.fileNamePrint] copy:NO move:NO fromPath:nil toPath:nil];
  307. cell.fileImageView.image = icon;
  308. }
  309. }
  310. // ButtonDown Tapped
  311. [cell.buttonDown addTarget:self action:@selector(cellButtonDownWasTapped:) forControlEvents:UIControlEventTouchUpInside];
  312. // encrypted color
  313. if (metadata.cryptated) {
  314. cell.labelTitle.textColor = COLOR_CRYPTOCLOUD;
  315. } else {
  316. cell.labelTitle.textColor = [UIColor blackColor];
  317. }
  318. // File name
  319. cell.labelTitle.text = metadata.fileNamePrint;
  320. cell.labelInfoFile.text = @"";
  321. // Immagine del file, se non c'è l'anteprima mettiamo quella standard
  322. if (cell.fileImageView.image == nil)
  323. cell.fileImageView.image = [UIImage imageNamed:metadata.iconName];
  324. // it's encrypted ???
  325. if (metadata.cryptated && [metadata.type isEqualToString: k_metadataType_template] == NO)
  326. cell.statusImageView.image = [UIImage imageNamed:image_lock];
  327. // text and length
  328. if (metadata.directory) {
  329. cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
  330. cell.accessoryType = UITableViewCellAccessoryNone;
  331. //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  332. } else {
  333. NSString *date = [CCUtility dateDiff:metadata.date];
  334. NSString *length = [CCUtility transformedSize:metadata.size];
  335. if ([metadata.type isEqualToString: k_metadataType_template])
  336. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", date];
  337. if ([metadata.type isEqualToString: k_metadataType_file] || [metadata.type isEqualToString: k_metadataType_local])
  338. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ • %@", date, length];
  339. cell.accessoryType = UITableViewCellAccessoryNone;
  340. }
  341. return cell;
  342. }
  343. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  344. {
  345. // deselect row
  346. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  347. _metadata = [self setSelfMetadataFromIndexPath:indexPath];
  348. // if is in download [do not touch]
  349. if ([_metadata.session length] > 0 && [_metadata.session containsString:@"download"])
  350. return;
  351. // File
  352. if (([_metadata.type isEqualToString: k_metadataType_file] || [_metadata.type isEqualToString: k_metadataType_local]) && _metadata.directory == NO) {
  353. if ([_metadata.typeFile isEqualToString: k_metadataTypeFile_unknown] || [_metadata.typeFile isEqualToString: k_metadataTypeFile_compress]) {
  354. [self openWith:_metadata];
  355. } else {
  356. if ([self shouldPerformSegue])
  357. [self performSegueWithIdentifier:@"segueDetail" sender:self];
  358. }
  359. }
  360. // Model
  361. if ([self.metadata.type isEqualToString: k_metadataType_template])
  362. [self openModel:_metadata];
  363. // Directory
  364. if (_metadata.directory)
  365. [self performSegueDirectoryWithControlPasscode];
  366. }
  367. -(void)performSegueDirectoryWithControlPasscode
  368. {
  369. CCLocalStorage *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCLocalStorage"];
  370. vc.serverUrl = [CCUtility stringAppendServerUrl:_serverUrl addFileName:_metadata.fileNameData];
  371. vc.titleViewControl = _metadata.fileNamePrint;
  372. [self.navigationController pushViewController:vc animated:YES];
  373. }
  374. #pragma --------------------------------------------------------------------------------------------
  375. #pragma mark ===== Navigation ====
  376. #pragma --------------------------------------------------------------------------------------------
  377. - (BOOL)shouldPerformSegue
  378. {
  379. // if i am in background -> exit
  380. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return NO;
  381. // if i am not window -> exit
  382. if (self.view.window == NO)
  383. return NO;
  384. // Collapsed but i am in detail -> exit
  385. if (self.splitViewController.isCollapsed)
  386. if (self.detailViewController.isViewLoaded && self.detailViewController.view.window) return NO;
  387. // Video in run -> exit
  388. if (self.detailViewController.photoBrowser.currentVideoPlayerViewController.isViewLoaded && self.detailViewController.photoBrowser.currentVideoPlayerViewController.view.window) return NO;
  389. return YES;
  390. }
  391. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  392. {
  393. id viewController = segue.destinationViewController;
  394. if ([viewController isKindOfClass:[UINavigationController class]]) {
  395. UINavigationController *nav = viewController;
  396. _detailViewController = (CCDetail *)nav.topViewController;
  397. } else {
  398. _detailViewController = segue.destinationViewController;
  399. }
  400. NSMutableArray *allRecordsDataSourceImagesVideos = [NSMutableArray new];
  401. NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  402. NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl];
  403. for (NSString *fileName in dataSource) {
  404. CCMetadata *metadata = [CCMetadata new];
  405. metadata = [CCUtility insertFileSystemInMetadata:fileName directory:_serverUrl activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
  406. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] || [metadata.typeFile isEqualToString: k_metadataTypeFile_video])
  407. [allRecordsDataSourceImagesVideos addObject:metadata];
  408. }
  409. _detailViewController.sourceDirectoryLocal = YES;
  410. _detailViewController.metadataDetail = _metadata;
  411. _detailViewController.dateFilterQuery = nil;
  412. _detailViewController.isCameraUpload = NO;
  413. _detailViewController.dataSourceImagesVideos = allRecordsDataSourceImagesVideos;
  414. [_detailViewController setTitle:_metadata.fileNamePrint];
  415. }
  416. @end