CCFavorites.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. //
  2. // CCFavorites.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 "CCFavorites.h"
  24. #import "AppDelegate.h"
  25. #ifdef CUSTOM_BUILD
  26. #import "CustomSwift.h"
  27. #else
  28. #import "Nextcloud-Swift.h"
  29. #endif
  30. @interface CCFavorites () <CCActionsDeleteDelegate, CCActionsSettingFavoriteDelegate>
  31. {
  32. NSArray *dataSource;
  33. BOOL _reloadDataSource;
  34. }
  35. @end
  36. @implementation CCFavorites
  37. #pragma --------------------------------------------------------------------------------------------
  38. #pragma mark ===== Init =====
  39. #pragma --------------------------------------------------------------------------------------------
  40. - (id)initWithCoder:(NSCoder *)aDecoder
  41. {
  42. if (self = [super initWithCoder:aDecoder]) {
  43. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
  44. }
  45. return self;
  46. }
  47. - (void)viewDidLoad
  48. {
  49. [super viewDidLoad];
  50. // Custom Cell
  51. [self.tableView registerNib:[UINib nibWithNibName:@"CCFavoritesCell" bundle:nil] forCellReuseIdentifier:@"Cell"];
  52. // dataSource
  53. dataSource = [NSMutableArray new];
  54. // Metadata
  55. _metadata = [CCMetadata new];
  56. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 1)];
  57. self.tableView.separatorColor = COLOR_SEPARATOR_TABLE;
  58. self.tableView.emptyDataSetDelegate = self;
  59. self.tableView.emptyDataSetSource = self;
  60. self.tableView.allowsMultipleSelectionDuringEditing = NO;
  61. // calculate _serverUrl
  62. if (!_serverUrl)
  63. _serverUrl = nil;
  64. // Title
  65. if (_titleViewControl)
  66. self.title = _titleViewControl;
  67. else
  68. self.title = NSLocalizedString(@"_favorites_", nil);
  69. }
  70. // Apparirà
  71. - (void)viewWillAppear:(BOOL)animated
  72. {
  73. [super viewWillAppear:animated];
  74. // Color
  75. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  76. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  77. // Plus Button
  78. [app plusButtonVisibile:true];
  79. [self reloadDatasource];
  80. }
  81. // E' arrivato
  82. - (void)viewDidAppear:(BOOL)animated
  83. {
  84. [super viewDidAppear:animated];
  85. // update Badge
  86. [app updateApplicationIconBadgeNumber];
  87. }
  88. - (void)didReceiveMemoryWarning {
  89. [super didReceiveMemoryWarning];
  90. }
  91. - (void)triggerProgressTask:(NSNotification *)notification
  92. {
  93. NSDictionary *dict = notification.userInfo;
  94. float progress = [[dict valueForKey:@"progress"] floatValue];
  95. if (progress == 0)
  96. [self.navigationController cancelCCProgress];
  97. else
  98. [self.navigationController setCCProgressPercentage:progress*100 andTintColor:COLOR_NAVIGATIONBAR_PROGRESS];
  99. }
  100. #pragma --------------------------------------------------------------------------------------------
  101. #pragma mark ==== DZNEmptyDataSetSource ====
  102. #pragma --------------------------------------------------------------------------------------------
  103. - (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView
  104. {
  105. // only for root
  106. if (!_serverUrl)
  107. return YES;
  108. else
  109. return NO;
  110. }
  111. - (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView
  112. {
  113. return 0.0f;
  114. }
  115. - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
  116. {
  117. return [UIColor whiteColor];
  118. }
  119. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
  120. {
  121. return [UIImage imageNamed:image_brandBackgroundLite];
  122. }
  123. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
  124. {
  125. NSString *text = [NSString stringWithFormat:@"%@", @""];
  126. NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:COLOR_BRAND};
  127. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  128. }
  129. - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
  130. {
  131. NSString *text = [NSString stringWithFormat:@"\n%@", NSLocalizedString(@"_tutorial_favorite_view_", nil)];
  132. NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
  133. paragraph.lineBreakMode = NSLineBreakByWordWrapping;
  134. paragraph.alignment = NSTextAlignmentCenter;
  135. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph};
  136. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  137. }
  138. #pragma --------------------------------------------------------------------------------------------
  139. #pragma mark ===== UIDocumentInteractionController <delegate> =====
  140. #pragma --------------------------------------------------------------------------------------------
  141. - (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *)controller
  142. {
  143. // evitiamo il rimando della eventuale photo e/o video
  144. if ([CCCoreData getCameraUploadActiveAccount:app.activeAccount]) {
  145. [CCCoreData setCameraUploadDatePhoto:[NSDate date]];
  146. [CCCoreData setCameraUploadDateVideo:[NSDate date]];
  147. }
  148. }
  149. #pragma --------------------------------------------------------------------------------------------
  150. #pragma mark ===== Delete <delegate> =====
  151. #pragma--------------------------------------------------------------------------------------------
  152. - (void)deleteFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  153. {
  154. NSLog(@"[LOG] Delete error %@", message);
  155. }
  156. - (void)deleteFileOrFolderSuccess:(CCMetadataNet *)metadataNet
  157. {
  158. [self reloadDatasource];
  159. }
  160. #pragma --------------------------------------------------------------------------------------------
  161. #pragma mark ===== Favorite <delegate> =====
  162. #pragma--------------------------------------------------------------------------------------------
  163. - (void)settingFavoriteFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  164. {
  165. NSLog(@"[LOG] Remove Favorite error %@", message);
  166. }
  167. - (void)settingFavoriteSuccess:(CCMetadataNet *)metadataNet
  168. {
  169. [CCCoreData setMetadataFavoriteFileID:metadataNet.fileID favorite:[metadataNet.options boolValue] activeAccount:app.activeAccount context:nil];
  170. [self reloadDatasource];
  171. }
  172. #pragma --------------------------------------------------------------------------------------------
  173. #pragma mark ==== Download Thumbnail <Delegate> ====
  174. #pragma --------------------------------------------------------------------------------------------
  175. - (void)downloadThumbnailSuccess:(CCMetadataNet *)metadataNet
  176. {
  177. [self reloadDatasource];
  178. }
  179. #pragma --------------------------------------------------------------------------------------------
  180. #pragma mark ==== Download <Delegate> ====
  181. #pragma --------------------------------------------------------------------------------------------
  182. - (void)downloadFileFailure:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector message:(NSString *)message errorCode:(NSInteger)errorCode
  183. {
  184. [app messageNotification:@"_download_file_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  185. [app updateApplicationIconBadgeNumber];
  186. }
  187. - (void)downloadFileSuccess:(NSString *)fileID serverUrl:(NSString *)serverUrl selector:(NSString *)selector selectorPost:(NSString *)selectorPost
  188. {
  189. _metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, app.activeAccount] context:nil];
  190. // File exists
  191. if ([self shouldPerformSegue])
  192. [self performSegueWithIdentifier:@"segueDetail" sender:self];
  193. [app updateApplicationIconBadgeNumber];
  194. }
  195. #pragma --------------------------------------------------------------------------------------------
  196. #pragma mark ===== menu =====
  197. #pragma--------------------------------------------------------------------------------------------
  198. - (void)openModel:(CCMetadata *)metadata
  199. {
  200. UIViewController *viewController;
  201. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:app.activeAccount];
  202. if ([metadata.model isEqualToString:@"cartadicredito"])
  203. viewController = [[CCCartaDiCredito alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:NO serverUrl:serverUrl];
  204. if ([metadata.model isEqualToString:@"bancomat"])
  205. viewController = [[CCBancomat alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:NO serverUrl:serverUrl];
  206. if ([metadata.model isEqualToString:@"contocorrente"])
  207. viewController = [[CCContoCorrente alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:NO serverUrl:serverUrl];
  208. if ([metadata.model isEqualToString:@"accountweb"])
  209. viewController = [[CCAccountWeb alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:NO serverUrl:serverUrl];
  210. if ([metadata.model isEqualToString:@"patenteguida"])
  211. viewController = [[CCPatenteGuida alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:NO serverUrl:serverUrl];
  212. if ([metadata.model isEqualToString:@"cartaidentita"])
  213. viewController = [[CCCartaIdentita alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:NO serverUrl:serverUrl];
  214. if ([metadata.model isEqualToString:@"passaporto"])
  215. viewController = [[CCPassaporto alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:NO serverUrl:serverUrl];
  216. if ([metadata.model isEqualToString:@"note"]) {
  217. viewController = [[CCNote alloc] initWithDelegate:self fileName:metadata.fileName uuid:metadata.uuid fileID:metadata.fileID isLocal:NO serverUrl:serverUrl];
  218. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  219. [self presentViewController:navigationController animated:YES completion:nil];
  220. } else {
  221. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  222. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  223. [self presentViewController:navigationController animated:YES completion:nil];
  224. }
  225. }
  226. - (void)openWith:(CCMetadata *)metadata
  227. {
  228. NSString *fileNamePath = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID];
  229. if ([[NSFileManager defaultManager] fileExistsAtPath:fileNamePath]) {
  230. [[NSFileManager defaultManager] removeItemAtPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint] error:nil];
  231. [[NSFileManager defaultManager] linkItemAtPath:fileNamePath toPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint] error:nil];
  232. NSURL *url = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint]];
  233. _docController = [UIDocumentInteractionController interactionControllerWithURL:url];
  234. _docController.delegate = self;
  235. [_docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  236. }
  237. }
  238. - (void)requestDeleteMetadata:(CCMetadata *)metadata indexPath:(NSIndexPath *)indexPath
  239. {
  240. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  241. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  242. [[CCActions sharedInstance] deleteFileOrFolder:metadata delegate:self];
  243. [self reloadDatasource];
  244. }]];
  245. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  246. }]];
  247. alertController.popoverPresentationController.sourceView = self.view;
  248. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  249. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  250. [alertController.view layoutIfNeeded];
  251. [self presentViewController:alertController animated:YES completion:nil];
  252. }
  253. -(void)cellButtonDownWasTapped:(id)sender
  254. {
  255. CGPoint touchPoint = [sender convertPoint:CGPointZero toView:self.tableView];
  256. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touchPoint];
  257. CCMetadata *metadata = [CCMetadata new];
  258. UIImage *iconHeader;
  259. metadata = [dataSource objectAtIndex:indexPath.row];
  260. AHKActionSheet *actionSheet = [[AHKActionSheet alloc] initWithView:self.view title:nil];
  261. actionSheet.animationDuration = 0.2;
  262. actionSheet.blurRadius = 0.0f;
  263. actionSheet.blurTintColor = [UIColor colorWithWhite:0.0f alpha:0.50f];
  264. actionSheet.buttonHeight = 50.0;
  265. actionSheet.cancelButtonHeight = 50.0f;
  266. actionSheet.separatorHeight = 5.0f;
  267. actionSheet.automaticallyTintButtonImages = @(NO);
  268. actionSheet.encryptedButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:COLOR_CRYPTOCLOUD };
  269. actionSheet.buttonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:COLOR_TEXT_ANTHRACITE };
  270. actionSheet.cancelButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:COLOR_BRAND };
  271. actionSheet.disableButtonTextAttributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:16], NSForegroundColorAttributeName:COLOR_TEXT_ANTHRACITE };
  272. actionSheet.separatorColor = COLOR_SEPARATOR_TABLE;
  273. actionSheet.cancelButtonTitle = NSLocalizedString(@"_cancel_",nil);
  274. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  275. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]])
  276. iconHeader = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
  277. else
  278. iconHeader = [UIImage imageNamed:metadata.iconName];
  279. [actionSheet addButtonWithTitle: metadata.fileNamePrint
  280. image: iconHeader
  281. backgroundColor: COLOR_TABBAR
  282. height: 50.0
  283. type: AHKActionSheetButtonTypeDisabled
  284. handler: nil
  285. ];
  286. // ONLY Root Favorites : Remove file/folder Favorites
  287. if (_serverUrl == nil) {
  288. [actionSheet addButtonWithTitle:NSLocalizedString(@"_remove_favorites_", nil) image:[UIImage imageNamed:image_actionSheetOffline] backgroundColor:[UIColor whiteColor] height: 50.0 type:AHKActionSheetButtonTypeDefault handler:^(AHKActionSheet *as) {
  289. [self.tableView setEditing:NO animated:YES];
  290. [[CCActions sharedInstance] settingFavorite:metadata favorite:NO delegate:self];
  291. }];
  292. }
  293. // Share
  294. if (_metadata.cryptated == NO && app.hasServerShareSupport) {
  295. [actionSheet addButtonWithTitle:NSLocalizedString(@"_share_", nil)
  296. image:[UIImage imageNamed:image_actionSheetShare]
  297. backgroundColor:[UIColor whiteColor]
  298. height: 50.0
  299. type:AHKActionSheetButtonTypeDefault
  300. handler:^(AHKActionSheet *as) {
  301. // close swipe
  302. [self setEditing:NO animated:YES];
  303. [app.activeMain openWindowShare:metadata];
  304. }];
  305. }
  306. // NO Directory - NO Template
  307. if (metadata.directory == NO && [metadata.type isEqualToString:k_metadataType_template] == NO) {
  308. [actionSheet addButtonWithTitle:NSLocalizedString(@"_open_in_", nil) image:[UIImage imageNamed:image_actionSheetOpenIn] backgroundColor:[UIColor whiteColor] height: 50.0 type:AHKActionSheetButtonTypeDefault handler:^(AHKActionSheet *as) {
  309. [self.tableView setEditing:NO animated:YES];
  310. [self openWith:metadata];
  311. }];
  312. }
  313. [actionSheet addButtonWithTitle:NSLocalizedString(@"_delete_", nil) image:[UIImage imageNamed:image_delete] backgroundColor:[UIColor whiteColor] height: 50.0 type:AHKActionSheetButtonTypeDestructive handler:^(AHKActionSheet *as) {
  314. [self requestDeleteMetadata:metadata indexPath:indexPath];
  315. }];
  316. [actionSheet show];
  317. }
  318. #pragma --------------------------------------------------------------------------------------------
  319. #pragma mark ==== Table ====
  320. #pragma --------------------------------------------------------------------------------------------
  321. - (CCMetadata *)setSelfMetadataFromIndexPath:(NSIndexPath *)indexPath
  322. {
  323. CCMetadata *metadata;
  324. NSManagedObject *record = [dataSource objectAtIndex:indexPath.row];
  325. metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", [record valueForKey:@"fileID"], app.activeAccount] context:nil];
  326. return metadata;
  327. }
  328. - (void)readFolderWithForced:(BOOL)forced serverUrl:(NSString *)serverUrl
  329. {
  330. [self reloadDatasource];
  331. }
  332. - (void)reloadDatasource
  333. {
  334. NSMutableArray *metadatas = [NSMutableArray new];
  335. NSArray *recordsTableMetadata ;
  336. if (!_serverUrl) {
  337. recordsTableMetadata = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (favorite == 1)", app.activeAccount] context:nil];
  338. } else {
  339. NSString *directoryID = [CCCoreData getDirectoryIDFromServerUrl:_serverUrl activeAccount:app.activeAccount];
  340. recordsTableMetadata = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (directoryID == %@)", app.activeAccount, directoryID] fieldOrder:[CCUtility getOrderSettings] ascending:[CCUtility getAscendingSettings]];
  341. }
  342. CCSectionDataSourceMetadata *sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:nil replaceDateToExifDate:NO activeAccount:app.activeAccount];
  343. NSArray *fileIDs = [sectionDataSource.sectionArrayRow objectForKey:@"_none_"];
  344. for (NSString *fileID in fileIDs)
  345. [metadatas addObject:[sectionDataSource.allRecordsDataSource objectForKey:fileID]];
  346. dataSource = [NSArray arrayWithArray:metadatas];
  347. [self.tableView reloadData];
  348. }
  349. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  350. {
  351. return 60;
  352. }
  353. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  354. {
  355. return 1;
  356. }
  357. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  358. {
  359. return [dataSource count];
  360. }
  361. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  362. {
  363. CCFavoritesCell *cell = (CCFavoritesCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
  364. CCMetadata *metadata;
  365. // separator
  366. cell.separatorInset = UIEdgeInsetsMake(0.f, 60.f, 0.f, 0.f);
  367. // Initialize
  368. cell.statusImageView.image = nil;
  369. cell.offlineImageView.image = nil;
  370. // change color selection
  371. UIView *selectionColor = [[UIView alloc] init];
  372. selectionColor.backgroundColor = COLOR_SELECT_BACKGROUND;
  373. cell.selectedBackgroundView = selectionColor;
  374. metadata = [dataSource objectAtIndex:indexPath.row];
  375. cell.fileImageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
  376. if (_serverUrl == nil)
  377. cell.offlineImageView.image = [UIImage imageNamed:image_favorite];
  378. if (cell.fileImageView.image == nil && metadata.thumbnailExists)
  379. [[CCActions sharedInstance] downloadTumbnail:metadata delegate:self];
  380. // ButtonDown Tapped
  381. [cell.buttonDown addTarget:self action:@selector(cellButtonDownWasTapped:) forControlEvents:UIControlEventTouchUpInside];
  382. // encrypted color
  383. if (metadata.cryptated) {
  384. cell.labelTitle.textColor = COLOR_CRYPTOCLOUD;
  385. } else {
  386. cell.labelTitle.textColor = [UIColor blackColor];
  387. }
  388. // File name
  389. cell.labelTitle.text = metadata.fileNamePrint;
  390. cell.labelInfoFile.text = @"";
  391. // Immagine del file, se non c'è l'anteprima mettiamo quella standard
  392. if (cell.fileImageView.image == nil)
  393. cell.fileImageView.image = [UIImage imageNamed:metadata.iconName];
  394. // it's encrypted ???
  395. if (metadata.cryptated && [metadata.type isEqualToString: k_metadataType_template] == NO)
  396. cell.statusImageView.image = [UIImage imageNamed:image_lock];
  397. // text and length
  398. if (metadata.directory) {
  399. cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
  400. cell.accessoryType = UITableViewCellAccessoryNone;
  401. //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  402. } else {
  403. NSString *date = [CCUtility dateDiff:metadata.date];
  404. NSString *length = [CCUtility transformedSize:metadata.size];
  405. if ([metadata.type isEqualToString: k_metadataType_template])
  406. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", date];
  407. if ([metadata.type isEqualToString: k_metadataType_file] || [metadata.type isEqualToString: k_metadataType_local]) {
  408. BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]];
  409. if (fileExists)
  410. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ • %@", date, length];
  411. else
  412. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ ◦ %@", date, length];
  413. }
  414. cell.accessoryType = UITableViewCellAccessoryNone;
  415. }
  416. return cell;
  417. }
  418. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  419. {
  420. // deselect row
  421. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  422. _metadata = [self setSelfMetadataFromIndexPath:indexPath];
  423. // if is in download [do not touch]
  424. if ([_metadata.session length] > 0 && [_metadata.session containsString:@"download"])
  425. return;
  426. // File
  427. if (([_metadata.type isEqualToString: k_metadataType_file] || [_metadata.type isEqualToString: k_metadataType_local]) && _metadata.directory == NO) {
  428. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, _metadata.fileID]]) {
  429. // File exists
  430. if ([self shouldPerformSegue])
  431. [self performSegueWithIdentifier:@"segueDetail" sender:self];
  432. } else {
  433. // File do not exists
  434. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:_metadata.account];
  435. [[CCNetworking sharedNetworking] downloadFile:_metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorLoadFileView selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:self];
  436. }
  437. }
  438. // Model
  439. if ([self.metadata.type isEqualToString: k_metadataType_template])
  440. [self openModel:self.metadata];
  441. // Directory
  442. if (_metadata.directory)
  443. [self performSegueDirectoryWithControlPasscode];
  444. }
  445. -(void)performSegueDirectoryWithControlPasscode
  446. {
  447. CCFavorites *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCFavorites"];
  448. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:_metadata.directoryID activeAccount:app.activeAccount];
  449. vc.serverUrl = [CCUtility stringAppendServerUrl:serverUrl addFileName:_metadata.fileNameData];
  450. vc.titleViewControl = _metadata.fileNamePrint;
  451. [self.navigationController pushViewController:vc animated:YES];
  452. }
  453. #pragma --------------------------------------------------------------------------------------------
  454. #pragma mark ===== Navigation ====
  455. #pragma --------------------------------------------------------------------------------------------
  456. - (BOOL)shouldPerformSegue
  457. {
  458. // if i am in background -> exit
  459. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return NO;
  460. // if i am not window -> exit
  461. if (self.view.window == NO)
  462. return NO;
  463. // Collapsed but i am in detail -> exit
  464. if (self.splitViewController.isCollapsed)
  465. if (self.detailViewController.isViewLoaded && self.detailViewController.view.window) return NO;
  466. // Video in run -> exit
  467. if (self.detailViewController.photoBrowser.currentVideoPlayerViewController.isViewLoaded && self.detailViewController.photoBrowser.currentVideoPlayerViewController.view.window) return NO;
  468. return YES;
  469. }
  470. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  471. {
  472. id viewController = segue.destinationViewController;
  473. if ([viewController isKindOfClass:[UINavigationController class]]) {
  474. UINavigationController *nav = viewController;
  475. _detailViewController = (CCDetail *)nav.topViewController;
  476. } else {
  477. _detailViewController = segue.destinationViewController;
  478. }
  479. NSMutableArray *allRecordsDataSourceImagesVideos = [NSMutableArray new];
  480. for (CCMetadata *metadata in dataSource) {
  481. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] || [metadata.typeFile isEqualToString: k_metadataTypeFile_video])
  482. [allRecordsDataSourceImagesVideos addObject:metadata];
  483. }
  484. _detailViewController.metadataDetail = _metadata;
  485. _detailViewController.dateFilterQuery = nil;
  486. _detailViewController.isCameraUpload = NO;
  487. _detailViewController.dataSourceImagesVideos = allRecordsDataSourceImagesVideos;
  488. [_detailViewController setTitle:_metadata.fileNamePrint];
  489. }
  490. @end