CCOfflinePageContent.m 31 KB

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