CCLocalStorage.m 25 KB

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