CCLocalStorage.m 25 KB

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