CCOfflinePageContent.m 32 KB

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