CCOfflinePageContent.m 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  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. return NSLocalizedString(@"_more_", nil);
  148. }
  149. - (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
  150. {
  151. return NSLocalizedString(@"_delete_", nil);
  152. }
  153. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
  154. {
  155. return YES;
  156. }
  157. - (void)tableView:(UITableView *)tableView swipeAccessoryButtonPushedForRowAtIndexPath:(NSIndexPath *)indexPath
  158. {
  159. [self setSelfMetadataFromIndexPath:indexPath];
  160. AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.view title:nil];
  161. actionSheet.animationDuration = 0.2;
  162. actionSheet.blurRadius = 0.0f;
  163. actionSheet.blurTintColor = [UIColor colorWithWhite:0.0f alpha:0.50f];
  164. actionSheet.buttonHeight = 50.0;
  165. actionSheet.cancelButtonHeight = 50.0f;
  166. actionSheet.separatorHeight = 5.0f;
  167. actionSheet.automaticallyTintButtonImages = @(NO);
  168. actionSheet.encryptedButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSForegroundColorAttributeName:COLOR_ENCRYPTED };
  169. actionSheet.buttonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSForegroundColorAttributeName:COLOR_GRAY };
  170. actionSheet.cancelButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:COLOR_BRAND };
  171. actionSheet.disableButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:12], NSForegroundColorAttributeName:COLOR_GRAY };
  172. actionSheet.separatorColor = COLOR_SEPARATOR_TABLE;
  173. actionSheet.cancelButtonTitle = NSLocalizedString(@"_cancel_",nil);
  174. UIImage *iconHeader;
  175. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  176. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/.%@.ico", _localServerUrl, _metadata.fileNamePrint]])
  177. iconHeader = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/.%@.ico", _localServerUrl, _metadata.fileNamePrint]];
  178. else
  179. iconHeader = [UIImage imageNamed:self.metadata.iconName];
  180. // NO Directory
  181. if (_metadata.directory == NO) {
  182. [actionSheet addButtonWithTitle:NSLocalizedString(@"_open_in_", nil)
  183. image:[UIImage imageNamed:image_actionSheetOpenIn]
  184. backgroundColor:[UIColor whiteColor]
  185. height: 50.0
  186. type:AHKActionSheetButtonTypeDefault
  187. handler:^(AHKActionSheet *as) {
  188. [self.tableView setEditing:NO animated:YES];
  189. [self openWith:_metadata];
  190. }];
  191. }
  192. // ONLY Root Offline : Remove file/folder offline
  193. if (_localServerUrl == nil && [_pageType isEqualToString:pageOfflineOffline]) {
  194. [actionSheet addButtonWithTitle:NSLocalizedString(@"_remove_offline_", nil)
  195. image:[UIImage imageNamed:image_actionSheetOffline]
  196. backgroundColor:[UIColor whiteColor]
  197. height: 50.0
  198. type:AHKActionSheetButtonTypeDefault
  199. handler:^(AHKActionSheet *as) {
  200. if (_metadata.directory) {
  201. // remove tag offline for all folder/subfolder/file
  202. NSString *relativeRoot = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:app.activeAccount];
  203. NSString *dirServerUrl = [CCUtility stringAppendServerUrl:relativeRoot addServerUrl:_metadata.fileNameData];
  204. NSArray *directories = [CCCoreData getOfflineDirectoryActiveAccount:app.activeAccount];
  205. for (TableDirectory *directory in directories)
  206. if ([directory.serverUrl containsString:dirServerUrl]) {
  207. [CCCoreData setOfflineDirectoryServerUrl:directory.serverUrl offline:NO activeAccount:app.activeAccount];
  208. [CCCoreData removeOfflineAllFileFromServerUrl:directory.serverUrl activeAccount:app.activeAccount];
  209. }
  210. } else {
  211. [CCCoreData setOfflineLocalFileID:_metadata.fileID offline:NO activeAccount:app.activeAccount];
  212. }
  213. [self.tableView setEditing:NO animated:YES];
  214. [self reloadTable];
  215. }];
  216. }
  217. [actionSheet show];
  218. }
  219. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
  220. {
  221. [self setSelfMetadataFromIndexPath:indexPath];
  222. if (editingStyle == UITableViewCellEditingStyleDelete) {
  223. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  224. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  225. style:UIAlertActionStyleDestructive
  226. handler:^(UIAlertAction *action) {
  227. if ([_pageType isEqualToString:pageOfflineLocal]) {
  228. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", _localServerUrl, _metadata.fileNameData];
  229. NSString *iconPath = [NSString stringWithFormat:@"%@/.%@.ico", _localServerUrl, _metadata.fileNameData];
  230. [[NSFileManager defaultManager] removeItemAtPath:fileNamePath error:nil];
  231. [[NSFileManager defaultManager] removeItemAtPath:iconPath error:nil];
  232. }
  233. [self reloadTable];
  234. }]];
  235. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  236. style:UIAlertActionStyleCancel
  237. handler:^(UIAlertAction *action) {
  238. }]];
  239. alertController.popoverPresentationController.sourceView = self.view;
  240. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  241. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  242. [alertController.view layoutIfNeeded];
  243. [self presentViewController:alertController animated:YES completion:nil];
  244. }
  245. [self.tableView setEditing:NO animated:YES];
  246. }
  247. #pragma --------------------------------------------------------------------------------------------
  248. #pragma mark ==== Table ====
  249. #pragma --------------------------------------------------------------------------------------------
  250. - (void)setSelfMetadataFromIndexPath:(NSIndexPath *)indexPath
  251. {
  252. if ([_pageType isEqualToString:pageOfflineOffline]) {
  253. NSManagedObject *record = [dataSource objectAtIndex:indexPath.row];
  254. _metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", [record valueForKey:@"fileID"], app.activeAccount] context:nil];
  255. }
  256. if ([_pageType isEqualToString:pageOfflineLocal]) {
  257. NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  258. NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  259. _metadata = [CCUtility insertFileSystemInMetadata:[dataSource objectAtIndex:indexPath.row] directory:_localServerUrl activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
  260. }
  261. }
  262. - (void)reloadTable
  263. {
  264. if ([_pageType isEqualToString:pageOfflineOffline]) {
  265. if (!_localServerUrl) {
  266. dataSource = [CCCoreData getHomeOfflineActiveAccount:app.activeAccount directoryUser:app.directoryUser];
  267. } else {
  268. NSMutableArray *metadatas = [NSMutableArray new];
  269. NSString *directoryID = [CCCoreData getDirectoryIDFromServerUrl:_localServerUrl activeAccount:app.activeAccount];
  270. NSArray *recordsTableMetadata = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@)", app.activeAccount, directoryID] fieldOrder:[CCUtility getOrderSettings] ascending:[CCUtility getAscendingSettings]];
  271. CCSectionDataSource *sectionDataSource = [CCSection creataDataSourseSectionTableMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:nil replaceDateToExifDate:NO activeAccount:app.activeAccount];
  272. for (NSString *key in sectionDataSource.allRecordsDataSource)
  273. [metadatas insertObject:[sectionDataSource.allRecordsDataSource objectForKey:key] atIndex:0 ];
  274. dataSource = [NSArray arrayWithArray:metadatas];
  275. }
  276. }
  277. if ([_pageType isEqualToString:pageOfflineLocal]) {
  278. NSArray *subpaths = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:_localServerUrl error:nil];
  279. NSMutableArray *metadatas = [NSMutableArray new];
  280. for (NSString *subpath in subpaths)
  281. if (![[subpath lastPathComponent] hasPrefix:@"."])
  282. [metadatas addObject:subpath];
  283. dataSource = [NSArray arrayWithArray:metadatas];
  284. }
  285. [self.tableView reloadData];
  286. }
  287. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  288. {
  289. return 60;
  290. }
  291. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  292. {
  293. return 1;
  294. }
  295. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  296. {
  297. return [dataSource count];
  298. }
  299. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  300. {
  301. CCCellOffline *cell = (CCCellOffline *)[tableView dequeueReusableCellWithIdentifier:@"OfflineCell" forIndexPath:indexPath];
  302. CCMetadata *metadata;
  303. // Initialize
  304. cell.statusImageView.image = nil;
  305. cell.offlineImageView.image = nil;
  306. // change color selection
  307. UIView *selectionColor = [[UIView alloc] init];
  308. selectionColor.backgroundColor = COLOR_SELECT_BACKGROUND;
  309. cell.selectedBackgroundView = selectionColor;
  310. // i am in Offline
  311. if ([_pageType isEqualToString:pageOfflineOffline]) {
  312. metadata = [dataSource objectAtIndex:indexPath.row];
  313. cell.fileImageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
  314. if (metadata.cryptated)
  315. cell.offlineImageView.image = [UIImage imageNamed:image_offlinecrypto];
  316. else
  317. cell.offlineImageView.image = [UIImage imageNamed:image_offline];
  318. }
  319. // i am in local
  320. if ([_pageType isEqualToString:pageOfflineLocal]) {
  321. NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  322. NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  323. metadata = [CCUtility insertFileSystemInMetadata:[dataSource objectAtIndex:indexPath.row] directory:_localServerUrl activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
  324. cell.fileImageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/.%@.ico", _localServerUrl, metadata.fileNamePrint]];
  325. if (!cell.fileImageView.image) {
  326. 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]];
  327. if (icon) {
  328. [CCGraphics saveIcoWithFileID:metadata.fileNamePrint image:icon writeToFile:[NSString stringWithFormat:@"%@/.%@.ico", _localServerUrl, metadata.fileNamePrint] copy:NO move:NO fromPath:nil toPath:nil];
  329. cell.fileImageView.image = icon;
  330. }
  331. }
  332. }
  333. // color and font
  334. if (metadata.cryptated) {
  335. cell.labelTitle.textColor = COLOR_ENCRYPTED;
  336. //nameLabel.font = RalewayLight(13.0f);
  337. cell.labelInfoFile.textColor = [UIColor blackColor];
  338. //detailLabel.font = RalewayLight(9.0f);
  339. } else {
  340. cell.labelTitle.textColor = COLOR_CLEAR;
  341. //nameLabel.font = RalewayLight(13.0f);
  342. cell.labelInfoFile.textColor = [UIColor blackColor];
  343. //detailLabel.font = RalewayLight(9.0f);
  344. }
  345. if (metadata.directory) {
  346. cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
  347. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  348. }
  349. // File name
  350. cell.labelTitle.text = metadata.fileNamePrint;
  351. cell.labelInfoFile.text = @"";
  352. // Immagine del file, se non c'è l'anteprima mettiamo quella standard
  353. if (cell.fileImageView.image == nil)
  354. cell.fileImageView.image = [UIImage imageNamed:metadata.iconName];
  355. // it's encrypted ???
  356. if (metadata.cryptated && [metadata.type isEqualToString:metadataType_model] == NO)
  357. cell.statusImageView.image = [UIImage imageNamed:image_lock];
  358. // it's in download mode
  359. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"download"].location != NSNotFound)
  360. cell.statusImageView.image = [UIImage imageNamed:image_attention];
  361. // text and length
  362. if (metadata.directory) {
  363. cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
  364. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  365. } else {
  366. NSString *date = [CCUtility dateDiff:metadata.date];
  367. NSString *length = [CCUtility transformedSize:metadata.size];
  368. if ([metadata.type isEqualToString:metadataType_model])
  369. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", date];
  370. if ([metadata.type isEqualToString:metadataType_file] || [metadata.type isEqualToString:metadataType_local])
  371. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", date, length];
  372. cell.accessoryType = UITableViewCellAccessoryNone;
  373. }
  374. return cell;
  375. }
  376. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  377. {
  378. // deselect row
  379. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  380. [self setSelfMetadataFromIndexPath:indexPath];
  381. // if is in download [do not touch]
  382. if ([_metadata.session length] > 0 && [_metadata.session rangeOfString:@"download"].location != NSNotFound) return;
  383. if (([_metadata.type isEqualToString:metadataType_file] || [_metadata.type isEqualToString:metadataType_local]) && _metadata.directory == NO) {
  384. if ([self shouldPerformSegue])
  385. [self performSegueWithIdentifier:@"segueDetail" sender:self];
  386. }
  387. if ([self.metadata.type isEqualToString:metadataType_model])
  388. [self openModel:self.metadata];
  389. if (_metadata.directory)
  390. [self performSegueDirectoryWithControlPasscode];
  391. }
  392. -(void)performSegueDirectoryWithControlPasscode
  393. {
  394. CCOfflinePageContent *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"OfflinePageContentViewController"];
  395. NSString *serverUrl;
  396. if ([_pageType isEqualToString:pageOfflineOffline] && !_localServerUrl) {
  397. serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:app.activeAccount];
  398. } else {
  399. serverUrl = _localServerUrl;
  400. }
  401. vc.localServerUrl = [CCUtility stringAppendServerUrl:serverUrl addServerUrl:_metadata.fileNameData];
  402. vc.pageType = _pageType;
  403. vc.titleViewControl = _metadata.fileNamePrint;
  404. [self.navigationController pushViewController:vc animated:YES];
  405. }
  406. #pragma --------------------------------------------------------------------------------------------
  407. #pragma mark ===== Navigation ====
  408. #pragma --------------------------------------------------------------------------------------------
  409. - (void)openModel:(CCMetadata *)metadata
  410. {
  411. UIViewController *viewController;
  412. BOOL isLocal = NO;
  413. if ([self.pageType isEqualToString:pageOfflineLocal])
  414. isLocal = YES;
  415. if ([metadata.model isEqualToString:@"cartadicredito"])
  416. viewController = [[CCCartaDiCredito alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:isLocal];
  417. if ([metadata.model isEqualToString:@"bancomat"])
  418. viewController = [[CCBancomat alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:isLocal];
  419. if ([metadata.model isEqualToString:@"contocorrente"])
  420. viewController = [[CCContoCorrente alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:isLocal];
  421. if ([metadata.model isEqualToString:@"accountweb"])
  422. viewController = [[CCAccountWeb alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:isLocal];
  423. if ([metadata.model isEqualToString:@"patenteguida"])
  424. viewController = [[CCPatenteGuida alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:isLocal];
  425. if ([metadata.model isEqualToString:@"cartaidentita"])
  426. viewController = [[CCCartaIdentita alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:isLocal];
  427. if ([metadata.model isEqualToString:@"passaporto"])
  428. viewController = [[CCPassaporto alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:isLocal];
  429. if ([metadata.model isEqualToString:@"note"]) {
  430. viewController = [[CCNote alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid rev:metadata.rev fileID:metadata.fileID modelReadOnly:true isLocal:isLocal];
  431. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  432. [self presentViewController:navigationController animated:YES completion:nil];
  433. } else {
  434. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  435. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  436. [self presentViewController:navigationController animated:YES completion:nil];
  437. }
  438. }
  439. - (void)openWith:(CCMetadata *)metadata
  440. {
  441. NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", _localServerUrl, metadata.fileNamePrint]];
  442. self.docController = [UIDocumentInteractionController interactionControllerWithURL:url];
  443. self.docController.delegate = self;
  444. [self.docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  445. }
  446. - (BOOL)shouldPerformSegue
  447. {
  448. // if i am in background -> exit
  449. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return NO;
  450. // if i am not window -> exit
  451. if (self.view.window == NO)
  452. return NO;
  453. // Collapsed but i am in detail -> exit
  454. if (self.splitViewController.isCollapsed)
  455. if (self.detailViewController.isViewLoaded && self.detailViewController.view.window) return NO;
  456. // Video in run -> exit
  457. if (self.detailViewController.photoBrowser.currentVideoPlayerViewController.isViewLoaded && self.detailViewController.photoBrowser.currentVideoPlayerViewController.view.window) return NO;
  458. return YES;
  459. }
  460. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  461. {
  462. id viewController = segue.destinationViewController;
  463. if ([viewController isKindOfClass:[UINavigationController class]]) {
  464. UINavigationController *nav = viewController;
  465. _detailViewController = (CCDetail *)nav.topViewController;
  466. } else {
  467. _detailViewController = segue.destinationViewController;
  468. }
  469. NSMutableArray *allRecordsDataSourceImagesVideos = [NSMutableArray new];
  470. if ([self.pageType isEqualToString:pageOfflineOffline]) {
  471. for (CCMetadata *metadata in dataSource) {
  472. if ([metadata.typeFile isEqualToString:metadataTypeFile_image] || [metadata.typeFile isEqualToString:metadataTypeFile_video])
  473. [allRecordsDataSourceImagesVideos addObject:metadata];
  474. }
  475. }
  476. if ([self.pageType isEqualToString:pageOfflineLocal]) {
  477. NSString *cameraFolderName = [CCCoreData getCameraUploadFolderNameActiveAccount:app.activeAccount];
  478. NSString *cameraFolderPath = [CCCoreData getCameraUploadFolderPathActiveAccount:app.activeAccount activeUrl:app.activeUrl typeCloud:app.typeCloud];
  479. for (NSString *fileName in dataSource) {
  480. CCMetadata *metadata = [CCMetadata new];
  481. metadata = [CCUtility insertFileSystemInMetadata:fileName directory:_localServerUrl activeAccount:app.activeAccount cameraFolderName:cameraFolderName cameraFolderPath:cameraFolderPath];
  482. if ([metadata.typeFile isEqualToString:metadataTypeFile_image] || [metadata.typeFile isEqualToString:metadataTypeFile_video])
  483. [allRecordsDataSourceImagesVideos addObject:metadata];
  484. }
  485. _detailViewController.sourceDirectoryLocal = YES;
  486. }
  487. _detailViewController.metadataDetail = _metadata;
  488. _detailViewController.dateFilterQuery = nil;
  489. _detailViewController.isCameraUpload = NO;
  490. _detailViewController.dataSourceImagesVideos = allRecordsDataSourceImagesVideos;
  491. [_detailViewController setTitle:_metadata.fileNamePrint];
  492. }
  493. @end