CCLocalStorage.m 25 KB

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