CCOfflinePageContent.m 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. //
  2. // CCOfflinePageContent.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 "CCOfflinePageContent.h"
  24. #import "AppDelegate.h"
  25. @interface CCOfflinePageContent ()
  26. {
  27. NSArray *dataSource;
  28. BOOL _reloadDataSource;
  29. }
  30. @end
  31. @implementation CCOfflinePageContent
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. // Custom Cell
  35. [self.tableView registerNib:[UINib nibWithNibName:@"CCCellOffline" bundle:nil] forCellReuseIdentifier:@"OfflineCell"];
  36. // dataSource
  37. dataSource = [NSMutableArray new];
  38. // Metadata
  39. _metadata = [CCMetadata new];
  40. self.tableView.tableFooterView = [UIView new];
  41. self.tableView.separatorColor = COLOR_SEPARATOR_TABLE;
  42. self.tableView.emptyDataSetDelegate = self;
  43. self.tableView.emptyDataSetSource = self;
  44. self.tableView.allowsMultipleSelectionDuringEditing = NO;
  45. // calculate _localServerUrl
  46. if ([self.pageType isEqualToString:pageOfflineOffline] && !_localServerUrl) {
  47. _localServerUrl = nil;
  48. }
  49. if ([self.pageType isEqualToString:pageOfflineLocal] && !_localServerUrl) {
  50. _localServerUrl = [CCUtility getDirectoryLocal];
  51. }
  52. // Title
  53. self.title = _titleViewControl;
  54. }
  55. // Apparirà
  56. - (void)viewWillAppear:(BOOL)animated
  57. {
  58. [super viewWillAppear:animated];
  59. // Color
  60. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar hidden:NO];
  61. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  62. // Plus Button
  63. [app plusButtonVisibile:true];
  64. [self reloadTable];
  65. }
  66. // E' arrivato
  67. - (void)viewDidAppear:(BOOL)animated
  68. {
  69. [super viewDidAppear:animated];
  70. // cancell Progress
  71. [self.navigationController cancelCCProgress];
  72. }
  73. - (void)didReceiveMemoryWarning {
  74. [super didReceiveMemoryWarning];
  75. }
  76. #pragma --------------------------------------------------------------------------------------------
  77. #pragma mark ==== DZNEmptyDataSetSource Methods ====
  78. #pragma --------------------------------------------------------------------------------------------
  79. - (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView
  80. {
  81. // only for root
  82. if (!_localServerUrl || [_localServerUrl isEqualToString:[CCUtility getDirectoryLocal]])
  83. return YES;
  84. else
  85. return NO;
  86. }
  87. - (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView
  88. {
  89. return 0.0f;
  90. }
  91. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView
  92. {
  93. return - self.navigationController.navigationBar.frame.size.height;
  94. }
  95. - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
  96. {
  97. return [UIColor whiteColor];
  98. }
  99. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
  100. {
  101. if ([self.pageType isEqualToString:pageOfflineOffline])
  102. return [UIImage imageNamed:image_brandOffline];
  103. if ([self.pageType isEqualToString:pageOfflineLocal])
  104. return [UIImage imageNamed:image_brandLocal];
  105. return nil;
  106. }
  107. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
  108. {
  109. NSString *text;
  110. if ([self.pageType isEqualToString:pageOfflineOffline])
  111. text = NSLocalizedString(@"_no_files_uploaded_", nil);
  112. if ([self.pageType isEqualToString:pageOfflineLocal])
  113. text = NSLocalizedString(@"_no_files_uploaded_", nil);
  114. NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:COLOR_BRAND};
  115. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  116. }
  117. - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
  118. {
  119. NSString *text;
  120. if ([self.pageType isEqualToString:pageOfflineOffline])
  121. text = NSLocalizedString(@"_tutorial_offline_view_", nil);
  122. if ([self.pageType isEqualToString:pageOfflineLocal])
  123. text = NSLocalizedString(@"_tutorial_local_view_", nil);
  124. NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
  125. paragraph.lineBreakMode = NSLineBreakByWordWrapping;
  126. paragraph.alignment = NSTextAlignmentCenter;
  127. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph};
  128. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  129. }
  130. #pragma --------------------------------------------------------------------------------------------
  131. #pragma mark ===== UIDocumentInteractionControllerDelegate =====
  132. #pragma --------------------------------------------------------------------------------------------
  133. - (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *)controller
  134. {
  135. // evitiamo il rimando della eventuale photo e/o video
  136. if ([CCCoreData getCameraUploadActiveAccount:app.activeAccount]) {
  137. [CCCoreData setCameraUploadDatePhoto:[NSDate date]];
  138. [CCCoreData setCameraUploadDateVideo:[NSDate date]];
  139. }
  140. }
  141. #pragma --------------------------------------------------------------------------------------------
  142. #pragma mark ===== Swipe Table -> menu =====
  143. #pragma--------------------------------------------------------------------------------------------
  144. // more
  145. - (NSString *)tableView:(UITableView *)tableView titleForSwipeAccessoryButtonForRowAtIndexPath:(NSIndexPath *)indexPath
  146. {
  147. // No Local
  148. if ([_pageType isEqualToString:pageOfflineLocal])
  149. return nil;
  150. // Root
  151. if (_localServerUrl == nil)
  152. return NSLocalizedString(@"_more_", nil);
  153. // No Root
  154. CCMetadata *metadata = [self setSelfMetadataFromIndexPath:indexPath];
  155. if (metadata.directory)
  156. return nil;
  157. else
  158. return NSLocalizedString(@"_more_", nil);
  159. }
  160. - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
  161. {
  162. return NSLocalizedString(@"_delete_", nil);
  163. }
  164. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  165. {
  166. return YES;
  167. }
  168. - (void)tableView:(UITableView *)tableView swipeAccessoryButtonPushedForRowAtIndexPath:(NSIndexPath *)indexPath
  169. {
  170. _metadata = [self setSelfMetadataFromIndexPath:indexPath];
  171. AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.view title:nil];
  172. actionSheet.animationDuration = 0.2;
  173. actionSheet.blurRadius = 0.0f;
  174. actionSheet.blurTintColor = [UIColor colorWithWhite:0.0f alpha:0.50f];
  175. actionSheet.buttonHeight = 50.0;
  176. actionSheet.cancelButtonHeight = 50.0f;
  177. actionSheet.separatorHeight = 5.0f;
  178. actionSheet.automaticallyTintButtonImages = @(NO);
  179. actionSheet.encryptedButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSForegroundColorAttributeName:COLOR_ENCRYPTED };
  180. actionSheet.buttonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSForegroundColorAttributeName:COLOR_GRAY };
  181. actionSheet.cancelButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:COLOR_BRAND };
  182. actionSheet.disableButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName:COLOR_GRAY };
  183. actionSheet.separatorColor = COLOR_SEPARATOR_TABLE;
  184. actionSheet.cancelButtonTitle = NSLocalizedString(@"_cancel_",nil);
  185. UIImage *iconHeader;
  186. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  187. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/.%@.ico", _localServerUrl, _metadata.fileNamePrint]])
  188. iconHeader = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/.%@.ico", _localServerUrl, _metadata.fileNamePrint]];
  189. else
  190. iconHeader = [UIImage imageNamed:self.metadata.iconName];
  191. // NO Directory
  192. if (_metadata.directory == NO) {
  193. [actionSheet addButtonWithTitle:NSLocalizedString(@"_open_in_", nil)
  194. image:[UIImage imageNamed:image_actionSheetOpenIn]
  195. backgroundColor:[UIColor whiteColor]
  196. height: 50.0
  197. type:AHKActionSheetButtonTypeDefault
  198. handler:^(AHKActionSheet *as) {
  199. [self.tableView setEditing:NO animated:YES];
  200. [self openWith:_metadata];
  201. }];
  202. }
  203. // ONLY Root Offline : Remove file/folder offline
  204. if (_localServerUrl == nil && [_pageType isEqualToString:pageOfflineOffline]) {
  205. [actionSheet addButtonWithTitle:NSLocalizedString(@"_remove_offline_", nil)
  206. image:[UIImage imageNamed:image_actionSheetOffline]
  207. backgroundColor:[UIColor whiteColor]
  208. height: 50.0
  209. type:AHKActionSheetButtonTypeDefault
  210. handler:^(AHKActionSheet *as) {
  211. if (_metadata.directory) {
  212. // remove tag offline for all folder/subfolder/file
  213. NSString *relativeRoot = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:app.activeAccount];
  214. NSString *dirServerUrl = [CCUtility stringAppendServerUrl:relativeRoot addServerUrl:_metadata.fileNameData];
  215. NSArray *directories = [CCCoreData getOfflineDirectoryActiveAccount:app.activeAccount];
  216. for (TableDirectory *directory in directories)
  217. if ([directory.serverUrl containsString:dirServerUrl]) {
  218. [CCCoreData setOfflineDirectoryServerUrl:directory.serverUrl offline:NO activeAccount:app.activeAccount];
  219. [CCCoreData removeOfflineAllFileFromServerUrl:directory.serverUrl activeAccount:app.activeAccount];
  220. }
  221. } else {
  222. [CCCoreData setOfflineLocalFileID:_metadata.fileID offline:NO activeAccount:app.activeAccount];
  223. }
  224. [self.tableView setEditing:NO animated:YES];
  225. [self reloadTable];
  226. }];
  227. }
  228. [actionSheet show];
  229. }
  230. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  231. {
  232. _metadata = [self setSelfMetadataFromIndexPath:indexPath];
  233. if (editingStyle == UITableViewCellEditingStyleDelete) {
  234. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  235. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  236. style:UIAlertActionStyleDestructive
  237. handler:^(UIAlertAction *action) {
  238. if ([_pageType isEqualToString:pageOfflineLocal]) {
  239. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", _localServerUrl, _metadata.fileNameData];
  240. NSString *iconPath = [NSString stringWithFormat:@"%@/.%@.ico", _localServerUrl, _metadata.fileNameData];
  241. [[NSFileManager defaultManager] removeItemAtPath:fileNamePath error:nil];
  242. [[NSFileManager defaultManager] removeItemAtPath:iconPath error:nil];
  243. }
  244. [self reloadTable];
  245. }]];
  246. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  247. style:UIAlertActionStyleCancel
  248. handler:^(UIAlertAction *action) {
  249. }]];
  250. alertController.popoverPresentationController.sourceView = self.view;
  251. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  252. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  253. [alertController.view layoutIfNeeded];
  254. [self presentViewController:alertController animated:YES completion:nil];
  255. }
  256. [self.tableView setEditing:NO animated:YES];
  257. }
  258. #pragma --------------------------------------------------------------------------------------------
  259. #pragma mark ==== Table ====
  260. #pragma --------------------------------------------------------------------------------------------
  261. - (CCMetadata *)setSelfMetadataFromIndexPath:(NSIndexPath *)indexPath
  262. {
  263. CCMetadata *metadata;
  264. if ([_pageType isEqualToString:pageOfflineOffline]) {
  265. NSManagedObject *record = [dataSource objectAtIndex:indexPath.row];
  266. metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", [record valueForKey:@"fileID"], app.activeAccount] context:nil];
  267. }
  268. if ([_pageType isEqualToString:pageOfflineLocal]) {
  269. NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  270. NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  271. metadata = [CCUtility insertFileSystemInMetadata:[dataSource objectAtIndex:indexPath.row] directory:_localServerUrl activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
  272. }
  273. return metadata;
  274. }
  275. - (void)reloadTable
  276. {
  277. if ([_pageType isEqualToString:pageOfflineOffline]) {
  278. NSMutableArray *metadatas = [NSMutableArray new];
  279. NSArray *recordsTableMetadata ;
  280. if (!_localServerUrl) {
  281. recordsTableMetadata = [CCCoreData getHomeOfflineActiveAccount:app.activeAccount directoryUser:app.directoryUser fieldOrder:[CCUtility getOrderSettings] ascending:[CCUtility getAscendingSettings]];
  282. } else {
  283. NSString *directoryID = [CCCoreData getDirectoryIDFromServerUrl:_localServerUrl activeAccount:app.activeAccount];
  284. recordsTableMetadata = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@)", app.activeAccount, directoryID] fieldOrder:[CCUtility getOrderSettings] ascending:[CCUtility getAscendingSettings]];
  285. }
  286. CCSectionDataSource *sectionDataSource = [CCSection creataDataSourseSectionTableMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:nil replaceDateToExifDate:NO activeAccount:app.activeAccount];
  287. NSArray *fileIDs = [sectionDataSource.sectionArrayRow objectForKey:@"_none_"];
  288. for (NSString *fileID in fileIDs)
  289. [metadatas addObject:[sectionDataSource.allRecordsDataSource objectForKey:fileID]];
  290. dataSource = [NSArray arrayWithArray:metadatas];
  291. }
  292. if ([_pageType isEqualToString:pageOfflineLocal]) {
  293. NSArray *subpaths = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:_localServerUrl error:nil];
  294. NSMutableArray *metadatas = [NSMutableArray new];
  295. for (NSString *subpath in subpaths)
  296. if (![[subpath lastPathComponent] hasPrefix:@"."])
  297. [metadatas addObject:subpath];
  298. dataSource = [NSArray arrayWithArray:metadatas];
  299. }
  300. [self.tableView reloadData];
  301. }
  302. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  303. {
  304. return 60;
  305. }
  306. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  307. {
  308. return 1;
  309. }
  310. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  311. {
  312. return [dataSource count];
  313. }
  314. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  315. {
  316. CCCellOffline *cell = (CCCellOffline *)[tableView dequeueReusableCellWithIdentifier:@"OfflineCell" forIndexPath:indexPath];
  317. CCMetadata *metadata;
  318. // Initialize
  319. cell.statusImageView.image = nil;
  320. cell.offlineImageView.image = nil;
  321. // change color selection
  322. UIView *selectionColor = [[UIView alloc] init];
  323. selectionColor.backgroundColor = COLOR_SELECT_BACKGROUND;
  324. cell.selectedBackgroundView = selectionColor;
  325. // i am in Offline
  326. if ([_pageType isEqualToString:pageOfflineOffline]) {
  327. metadata = [dataSource objectAtIndex:indexPath.row];
  328. cell.fileImageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
  329. if (metadata.cryptated)
  330. cell.offlineImageView.image = [UIImage imageNamed:image_offlinecrypto];
  331. else
  332. cell.offlineImageView.image = [UIImage imageNamed:image_offline];
  333. }
  334. // i am in local
  335. if ([_pageType isEqualToString:pageOfflineLocal]) {
  336. NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  337. NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  338. metadata = [CCUtility insertFileSystemInMetadata:[dataSource objectAtIndex:indexPath.row] directory:_localServerUrl activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
  339. cell.fileImageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/.%@.ico", _localServerUrl, metadata.fileNamePrint]];
  340. if (!cell.fileImageView.image) {
  341. UIImage *icon = [CCGraphics createNewImageFrom:metadata.fileID directoryUser:_localServerUrl fileNameTo:metadata.fileID fileNamePrint:metadata.fileNamePrint size:@"m" imageForUpload:NO typeFile:metadata.typeFile writePreview:NO optimizedFileName:[CCUtility getOptimizedPhoto]];
  342. if (icon) {
  343. [CCGraphics saveIcoWithFileID:metadata.fileNamePrint image:icon writeToFile:[NSString stringWithFormat:@"%@/.%@.ico", _localServerUrl, metadata.fileNamePrint] copy:NO move:NO fromPath:nil toPath:nil];
  344. cell.fileImageView.image = icon;
  345. }
  346. }
  347. }
  348. // color and font
  349. if (metadata.cryptated) {
  350. cell.labelTitle.textColor = COLOR_ENCRYPTED;
  351. //nameLabel.font = RalewayLight(13.0f);
  352. cell.labelInfoFile.textColor = [UIColor blackColor];
  353. //detailLabel.font = RalewayLight(9.0f);
  354. } else {
  355. cell.labelTitle.textColor = COLOR_CLEAR;
  356. //nameLabel.font = RalewayLight(13.0f);
  357. cell.labelInfoFile.textColor = [UIColor blackColor];
  358. //detailLabel.font = RalewayLight(9.0f);
  359. }
  360. if (metadata.directory) {
  361. cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
  362. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  363. }
  364. // File name
  365. cell.labelTitle.text = metadata.fileNamePrint;
  366. cell.labelInfoFile.text = @"";
  367. // Immagine del file, se non c'è l'anteprima mettiamo quella standard
  368. if (cell.fileImageView.image == nil)
  369. cell.fileImageView.image = [UIImage imageNamed:metadata.iconName];
  370. // it's encrypted ???
  371. if (metadata.cryptated && [metadata.type isEqualToString:metadataType_model] == NO)
  372. cell.statusImageView.image = [UIImage imageNamed:image_lock];
  373. // it's in download mode
  374. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"download"].location != NSNotFound)
  375. cell.statusImageView.image = [UIImage imageNamed:image_attention];
  376. // text and length
  377. if (metadata.directory) {
  378. cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
  379. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  380. } else {
  381. NSString *date = [CCUtility dateDiff:metadata.date];
  382. NSString *length = [CCUtility transformedSize:metadata.size];
  383. if ([metadata.type isEqualToString:metadataType_model])
  384. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", date];
  385. if ([metadata.type isEqualToString:metadataType_file] || [metadata.type isEqualToString:metadataType_local])
  386. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", date, length];
  387. cell.accessoryType = UITableViewCellAccessoryNone;
  388. }
  389. return cell;
  390. }
  391. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  392. {
  393. // deselect row
  394. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  395. _metadata = [self setSelfMetadataFromIndexPath:indexPath];
  396. // if is in download [do not touch]
  397. if ([_metadata.session length] > 0 && [_metadata.session rangeOfString:@"download"].location != NSNotFound) return;
  398. if (([_metadata.type isEqualToString:metadataType_file] || [_metadata.type isEqualToString:metadataType_local]) && _metadata.directory == NO) {
  399. if ([self shouldPerformSegue])
  400. [self performSegueWithIdentifier:@"segueDetail" sender:self];
  401. }
  402. if ([self.metadata.type isEqualToString:metadataType_model])
  403. [self openModel:self.metadata];
  404. if (_metadata.directory)
  405. [self performSegueDirectoryWithControlPasscode];
  406. }
  407. -(void)performSegueDirectoryWithControlPasscode
  408. {
  409. CCOfflinePageContent *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"OfflinePageContentViewController"];
  410. NSString *serverUrl;
  411. if ([_pageType isEqualToString:pageOfflineOffline] && !_localServerUrl) {
  412. serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:app.activeAccount];
  413. } else {
  414. serverUrl = _localServerUrl;
  415. }
  416. vc.localServerUrl = [CCUtility stringAppendServerUrl:serverUrl addServerUrl:_metadata.fileNameData];
  417. vc.pageType = _pageType;
  418. vc.titleViewControl = _metadata.fileNamePrint;
  419. [self.navigationController pushViewController:vc animated:YES];
  420. }
  421. #pragma --------------------------------------------------------------------------------------------
  422. #pragma mark ===== Navigation ====
  423. #pragma --------------------------------------------------------------------------------------------
  424. - (void)openModel:(CCMetadata *)metadata
  425. {
  426. UIViewController *viewController;
  427. BOOL isLocal = NO;
  428. if ([self.pageType isEqualToString:pageOfflineLocal])
  429. isLocal = YES;
  430. if ([metadata.model isEqualToString:@"cartadicredito"])
  431. viewController = [[CCCartaDiCredito alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:isLocal];
  432. if ([metadata.model isEqualToString:@"bancomat"])
  433. viewController = [[CCBancomat alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:isLocal];
  434. if ([metadata.model isEqualToString:@"contocorrente"])
  435. viewController = [[CCContoCorrente alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:isLocal];
  436. if ([metadata.model isEqualToString:@"accountweb"])
  437. viewController = [[CCAccountWeb alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:isLocal];
  438. if ([metadata.model isEqualToString:@"patenteguida"])
  439. viewController = [[CCPatenteGuida alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:isLocal];
  440. if ([metadata.model isEqualToString:@"cartaidentita"])
  441. viewController = [[CCCartaIdentita alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:isLocal];
  442. if ([metadata.model isEqualToString:@"passaporto"])
  443. viewController = [[CCPassaporto alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:isLocal];
  444. if ([metadata.model isEqualToString:@"note"]) {
  445. viewController = [[CCNote alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:isLocal];
  446. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  447. [self presentViewController:navigationController animated:YES completion:nil];
  448. } else {
  449. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  450. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  451. [self presentViewController:navigationController animated:YES completion:nil];
  452. }
  453. }
  454. - (void)openWith:(CCMetadata *)metadata
  455. {
  456. NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", _localServerUrl, metadata.fileNamePrint]];
  457. self.docController = [UIDocumentInteractionController interactionControllerWithURL:url];
  458. self.docController.delegate = self;
  459. [self.docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  460. }
  461. - (BOOL)shouldPerformSegue
  462. {
  463. // if i am in background -> exit
  464. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return NO;
  465. // if i am not window -> exit
  466. if (self.view.window == NO)
  467. return NO;
  468. // Collapsed but i am in detail -> exit
  469. if (self.splitViewController.isCollapsed)
  470. if (self.detailViewController.isViewLoaded && self.detailViewController.view.window) return NO;
  471. // Video in run -> exit
  472. if (self.detailViewController.photoBrowser.currentVideoPlayerViewController.isViewLoaded && self.detailViewController.photoBrowser.currentVideoPlayerViewController.view.window) return NO;
  473. return YES;
  474. }
  475. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  476. {
  477. id viewController = segue.destinationViewController;
  478. if ([viewController isKindOfClass:[UINavigationController class]]) {
  479. UINavigationController *nav = viewController;
  480. _detailViewController = (CCDetail *)nav.topViewController;
  481. } else {
  482. _detailViewController = segue.destinationViewController;
  483. }
  484. NSMutableArray *allRecordsDataSourceImagesVideos = [NSMutableArray new];
  485. if ([self.pageType isEqualToString:pageOfflineOffline]) {
  486. for (CCMetadata *metadata in dataSource) {
  487. if ([metadata.typeFile isEqualToString:metadataTypeFile_image] || [metadata.typeFile isEqualToString:metadataTypeFile_video])
  488. [allRecordsDataSourceImagesVideos addObject:metadata];
  489. }
  490. }
  491. if ([self.pageType isEqualToString:pageOfflineLocal]) {
  492. NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  493. NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  494. for (NSString *fileName in dataSource) {
  495. CCMetadata *metadata = [CCMetadata new];
  496. metadata = [CCUtility insertFileSystemInMetadata:fileName directory:_localServerUrl activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
  497. if ([metadata.typeFile isEqualToString:metadataTypeFile_image] || [metadata.typeFile isEqualToString:metadataTypeFile_video])
  498. [allRecordsDataSourceImagesVideos addObject:metadata];
  499. }
  500. _detailViewController.sourceDirectoryLocal = YES;
  501. }
  502. _detailViewController.metadataDetail = _metadata;
  503. _detailViewController.dateFilterQuery = nil;
  504. _detailViewController.isCameraUpload = NO;
  505. _detailViewController.dataSourceImagesVideos = allRecordsDataSourceImagesVideos;
  506. [_detailViewController setTitle:_metadata.fileNamePrint];
  507. }
  508. @end