CCLocalStorage.m 26 KB

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