CCFavorites.m 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. //
  2. // CCFavorites.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 16/01/17.
  6. // Copyright (c) 2017 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  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. #import "NCBridgeSwift.h"
  26. @interface CCFavorites ()
  27. {
  28. AppDelegate *appDelegate;
  29. // Automatic Upload Folder
  30. NSString *autoUploadFileName;
  31. NSString *autoUploadDirectory;
  32. UIDocumentInteractionController *docController;
  33. // Datasource
  34. CCSectionDataSourceMetadata *sectionDataSource;
  35. BOOL livePhoto;
  36. }
  37. @end
  38. @implementation CCFavorites
  39. #pragma --------------------------------------------------------------------------------------------
  40. #pragma mark ===== Init =====
  41. #pragma --------------------------------------------------------------------------------------------
  42. - (id)initWithCoder:(NSCoder *)aDecoder
  43. {
  44. if (self = [super initWithCoder:aDecoder]) {
  45. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  46. appDelegate.activeFavorites = self;
  47. }
  48. return self;
  49. }
  50. - (void)viewDidLoad
  51. {
  52. [super viewDidLoad];
  53. [self.tableView registerNib:[UINib nibWithNibName:@"CCCellMain" bundle:nil] forCellReuseIdentifier:@"CellMain"];
  54. [self.tableView registerNib:[UINib nibWithNibName:@"CCCellMainTransfer" bundle:nil] forCellReuseIdentifier:@"CellMainTransfer"];
  55. // Notification
  56. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:k_notificationCenter_progressTask object:nil];
  57. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:k_notificationCenter_changeTheming object:nil];
  58. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadDatasource) name:k_notificationCenter_reloadDataSource object:nil];
  59. // Metadata
  60. self.metadata = [tableMetadata new];
  61. self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 1)];
  62. self.tableView.emptyDataSetDelegate = self;
  63. self.tableView.emptyDataSetSource = self;
  64. self.tableView.delegate = self;
  65. self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 35, 0);
  66. // Register for 3D Touch Previewing if available
  67. if ([self.traitCollection respondsToSelector:@selector(forceTouchCapability)] && (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable))
  68. {
  69. [self registerForPreviewingWithDelegate:self sourceView:self.view];
  70. }
  71. // calculate _serverUrl
  72. if (!_serverUrl) {
  73. _serverUrl = nil;
  74. }
  75. // Title
  76. if (_titleViewControl)
  77. self.title = _titleViewControl;
  78. else
  79. self.title = NSLocalizedString(@"_favorites_", nil);
  80. [self changeTheming];
  81. }
  82. - (void)viewWillAppear:(BOOL)animated
  83. {
  84. [super viewWillAppear:animated];
  85. [self reloadDatasource];
  86. }
  87. - (void)viewDidAppear:(BOOL)animated
  88. {
  89. [super viewDidAppear:animated];
  90. // Active Main
  91. appDelegate.activeFavorites = self;
  92. // test
  93. if (appDelegate.account.length == 0) {
  94. return;
  95. }
  96. if (self.serverUrl == nil) {
  97. [[NCNetworking shared] listingFavoritescompletionWithSelector:(selectorListingFavorite) completion:^(NSString *account, NSArray *metadatas, NSInteger errorCode, NSString *errorDescription) {
  98. for (tableMetadata *metadata in metadatas) {
  99. if (!metadata.directory && CCUtility.getFavoriteOffline) {
  100. tableLocalFile *localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadata.ocId]];
  101. if (localFile == nil || ![localFile.etag isEqualToString:metadata.etag]) {
  102. [[NCOperationQueue shared] downloadWithMetadata:metadata selector:selectorDownloadFile setFavorite:false];
  103. }
  104. }
  105. }
  106. [self reloadDatasource];
  107. }];
  108. } else {
  109. [[NCNetworking shared] readFolderWithServerUrl:self.serverUrl account:appDelegate.account completion:^(NSString *account, tableMetadata *metadataFolder, NSArray *metadatas, NSArray *metadatasUpdate, NSArray *metadatasLocalUpdate, NSInteger errorCode, NSString *errorDescription) {
  110. if (errorCode == 0) {
  111. for (tableMetadata *metadata in metadatas) {
  112. if (!metadata.directory && CCUtility.getFavoriteOffline) {
  113. tableLocalFile *localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadata.ocId]];
  114. if (localFile == nil || ![localFile.etag isEqualToString:metadata.etag]) {
  115. [[NCOperationQueue shared] downloadWithMetadata:metadata selector:selectorDownloadFile setFavorite:false];
  116. }
  117. }
  118. }
  119. [self reloadDatasource];
  120. }
  121. }];
  122. }
  123. }
  124. #pragma --------------------------------------------------------------------------------------------
  125. #pragma mark ==== NotificationCenter ====
  126. #pragma --------------------------------------------------------------------------------------------
  127. - (void)triggerProgressTask:(NSNotification *)notification
  128. {
  129. if (sectionDataSource.ocIdIndexPath != nil) {
  130. [[NCMainCommon sharedInstance] triggerProgressTask:notification sectionDataSourceocIdIndexPath:sectionDataSource.ocIdIndexPath tableView:self.tableView viewController:self serverUrlViewController:self.serverUrl];
  131. }
  132. }
  133. - (void)changeTheming
  134. {
  135. [appDelegate changeTheming:self tableView:self.tableView collectionView:nil form:false];
  136. }
  137. #pragma --------------------------------------------------------------------------------------------
  138. #pragma mark ==== DZNEmptyDataSetSource ====
  139. #pragma --------------------------------------------------------------------------------------------
  140. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView
  141. {
  142. //CGFloat height = self.tabBarController.tabBar.frame.size.height;
  143. return 0;
  144. }
  145. - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
  146. {
  147. return NCBrandColor.sharedInstance.backgroundView;
  148. }
  149. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
  150. {
  151. return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"favorite"] width:300 height:300 color:NCBrandColor.sharedInstance.yellowFavorite];
  152. }
  153. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
  154. {
  155. NSString *text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_favorite_no_files_", nil)];
  156. NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:[UIColor lightGrayColor]};
  157. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  158. }
  159. - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
  160. {
  161. NSString *text = [NSString stringWithFormat:@"\n%@", NSLocalizedString(@"_tutorial_favorite_view_", nil)];
  162. NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
  163. paragraph.lineBreakMode = NSLineBreakByWordWrapping;
  164. paragraph.alignment = NSTextAlignmentCenter;
  165. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph};
  166. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  167. }
  168. - (void)tapActionComment:(UITapGestureRecognizer *)tapGesture
  169. {
  170. CGPoint location = [tapGesture locationInView:self.tableView];
  171. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  172. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  173. if (metadata) {
  174. [[NCMainCommon sharedInstance] openShareWithViewController:self metadata:metadata indexPage:1];
  175. }
  176. }
  177. - (void)tapActionShared:(UITapGestureRecognizer *)tapGesture
  178. {
  179. CGPoint location = [tapGesture locationInView:self.tableView];
  180. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  181. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  182. if (metadata) {
  183. [[NCMainCommon sharedInstance] openShareWithViewController:self metadata:metadata indexPage:2];
  184. }
  185. }
  186. #pragma --------------------------------------------------------------------------------------------
  187. #pragma mark ===== Progress & Task Button =====
  188. #pragma --------------------------------------------------------------------------------------------
  189. - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
  190. {
  191. UITouch *touch = [[event allTouches] anyObject];
  192. CGPoint location = [touch locationInView:self.tableView];
  193. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  194. if ([[NCMainCommon sharedInstance] isValidIndexPath:indexPath view:self.tableView]) {
  195. tableMetadata *metadataSection = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  196. if (metadataSection) {
  197. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadataSection.ocId]];
  198. if (metadata)
  199. [[NCMainCommon sharedInstance] cancelTransferMetadata:metadata reloadDatasource:true uploadStatusForcedStart:false];
  200. }
  201. }
  202. }
  203. - (void)cancelAllTask:(id)sender
  204. {
  205. CGPoint location = [sender locationInView:self.tableView];
  206. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  207. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  208. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_all_task_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  209. [NCUtility.shared startActivityIndicatorWithView:self.view bottom:0];
  210. [[NCMainCommon sharedInstance] cancelAllTransfer];
  211. [NCUtility.shared stopActivityIndicator];
  212. }]];
  213. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]];
  214. alertController.popoverPresentationController.sourceView = self.tableView;
  215. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  216. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  217. [alertController.view layoutIfNeeded];
  218. [self presentViewController:alertController animated:YES completion:nil];
  219. }
  220. #pragma mark -
  221. #pragma --------------------------------------------------------------------------------------------
  222. #pragma mark ===== Peek & Pop =====
  223. #pragma --------------------------------------------------------------------------------------------
  224. - (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
  225. {
  226. CGPoint convertedLocation = [self.view convertPoint:location toView:self.tableView];
  227. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:convertedLocation];
  228. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  229. CCCellMain *cell = [self.tableView cellForRowAtIndexPath:indexPath];
  230. if (cell) {
  231. previewingContext.sourceRect = cell.frame;
  232. CCPeekPop *viewController = [[UIStoryboard storyboardWithName:@"CCPeekPop" bundle:nil] instantiateViewControllerWithIdentifier:@"PeekPopImagePreview"];
  233. viewController.metadata = metadata;
  234. viewController.imageFile = cell.file.image;
  235. viewController.showOpenIn = true;
  236. viewController.showShare = false;
  237. viewController.showOpenQuickLook = [[NCUtility shared] isQuickLookDisplayableWithMetadata:metadata];
  238. return viewController;
  239. }
  240. return nil;
  241. }
  242. - (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit
  243. {
  244. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:previewingContext.sourceRect.origin];
  245. [self tableView:self.tableView didSelectRowAtIndexPath:indexPath];
  246. }
  247. #pragma mark -
  248. #pragma --------------------------------------------------------------------------------------------
  249. #pragma mark ===== menu action : Favorite, More, Delete [swipe] =====
  250. #pragma --------------------------------------------------------------------------------------------
  251. - (BOOL)canOpenMenuAction:(tableMetadata *)metadata
  252. {
  253. return YES;
  254. }
  255. - (BOOL)swipeTableCell:(MGSwipeTableCell *)cell canSwipe:(MGSwipeDirection)direction
  256. {
  257. NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
  258. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  259. return [self canOpenMenuAction:metadata];
  260. }
  261. - (BOOL)swipeTableCell:(MGSwipeTableCell *)cell tappedButtonAtIndex:(NSInteger)index direction:(MGSwipeDirection)direction fromExpansion:(BOOL)fromExpansion
  262. {
  263. NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
  264. if (direction == MGSwipeDirectionRightToLeft) {
  265. [self actionDelete:indexPath];
  266. }
  267. if (direction == MGSwipeDirectionLeftToRight) {
  268. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  269. [[NCNetworking shared] favoriteMetadata:metadata urlBase:appDelegate.urlBase completion:^(NSInteger errorCode, NSString *errorDescription) { }];
  270. }
  271. return YES;
  272. }
  273. - (void)actionDelete:(NSIndexPath *)indexPath
  274. {
  275. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  276. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  277. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  278. [[NCNetworking shared] deleteMetadata:metadata account:appDelegate.account urlBase:appDelegate.urlBase completion:^(NSInteger errorCode, NSString *errorDescription) { }];
  279. }]];
  280. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  281. }]];
  282. alertController.popoverPresentationController.sourceView = self.tableView;
  283. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  284. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  285. [alertController.view layoutIfNeeded];
  286. [self presentViewController:alertController animated:YES completion:nil];
  287. }
  288. - (void)actionMore:(UITapGestureRecognizer *)gestureRecognizer
  289. {
  290. CGPoint touch = [gestureRecognizer locationInView:self.tableView];
  291. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touch];
  292. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  293. [self toggleMoreMenuWithViewController:self.tabBarController indexPath:indexPath metadata:metadata];
  294. }
  295. #pragma --------------------------------------------------------------------------------------------
  296. #pragma mark ==== Table ====
  297. #pragma --------------------------------------------------------------------------------------------
  298. - (tableMetadata *)setSelfMetadataFromIndexPath:(NSIndexPath *)indexPath
  299. {
  300. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  301. return metadata;
  302. }
  303. - (void)reloadDatasource
  304. {
  305. // test
  306. if (appDelegate.account.length == 0) { // || self.view.window == nil) {
  307. return;
  308. }
  309. NSArray *recordsTableMetadata;
  310. NSString *sorted = [CCUtility getOrderSettings];
  311. if ([sorted isEqualToString:@"fileName"]) sorted = @"fileName";
  312. // live photo
  313. livePhoto = [CCUtility getLivePhoto];
  314. // get auto upload folder
  315. autoUploadFileName = [[NCManageDatabase sharedInstance] getAccountAutoUploadFileName];
  316. autoUploadDirectory = [[NCManageDatabase sharedInstance] getAccountAutoUploadDirectoryWithUrlBase:appDelegate.urlBase account:appDelegate.account];
  317. if (!_serverUrl) {
  318. recordsTableMetadata = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND favorite == true", appDelegate.account] page:0 limit:0 sorted:@"fileName" ascending:NO];
  319. } else {
  320. recordsTableMetadata = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.account, self.serverUrl] page:0 limit:0 sorted:@"fileName" ascending:NO];
  321. }
  322. sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:nil groupByField:nil filterTypeFileImage:NO filterTypeFileVideo:NO filterLivePhoto:YES sorted:sorted ascending:[CCUtility getAscendingSettings] account:appDelegate.account];
  323. [self.tableView reloadData];
  324. }
  325. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  326. {
  327. return 60;
  328. }
  329. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  330. {
  331. return [[sectionDataSource.sectionArrayRow allKeys] count];
  332. }
  333. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  334. {
  335. return [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:section]] count];
  336. }
  337. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  338. {
  339. tableShare *shareCell;
  340. tableMetadata *metadataFolder;
  341. tableMetadata *metadata = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  342. if (metadata == nil || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata]) {
  343. return [CCCellMain new];
  344. }
  345. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.account, metadata.serverUrl]];
  346. if (directory != nil) {
  347. metadataFolder = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", directory.ocId]];
  348. }
  349. for (tableShare *share in appDelegate.shares) {
  350. if ([share.serverUrl isEqualToString:metadata.serverUrl] && [share.fileName isEqualToString:metadata.fileName]) {
  351. shareCell = share;
  352. break;
  353. }
  354. }
  355. UITableViewCell *cell = [[NCMainCommon sharedInstance] cellForRowAtIndexPath:indexPath tableView:tableView metadata:metadata metadataFolder:metadataFolder serverUrl:self.serverUrl autoUploadFileName:autoUploadFileName autoUploadDirectory:autoUploadDirectory tableShare:shareCell livePhoto:livePhoto];
  356. // NORMAL - > MAIN
  357. if ([cell isKindOfClass:[CCCellMain class]]) {
  358. // Comment tap
  359. if (metadata.commentsUnread) {
  360. UITapGestureRecognizer *tapComment = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionComment:)];
  361. [tapComment setNumberOfTapsRequired:1];
  362. ((CCCellMain *)cell).comment.userInteractionEnabled = YES;
  363. [((CCCellMain *)cell).comment addGestureRecognizer:tapComment];
  364. }
  365. // Share add Tap
  366. UITapGestureRecognizer *tapShare = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapActionShared:)];
  367. [tapShare setNumberOfTapsRequired:1];
  368. ((CCCellMain *)cell).viewShared.userInteractionEnabled = YES;
  369. [((CCCellMain *)cell).viewShared addGestureRecognizer:tapShare];
  370. // More
  371. if ([self canOpenMenuAction:metadata]) {
  372. UITapGestureRecognizer *tapMore = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionMore:)];
  373. [tapMore setNumberOfTapsRequired:1];
  374. ((CCCellMain *)cell).more.userInteractionEnabled = YES;
  375. [((CCCellMain *)cell).more addGestureRecognizer:tapMore];
  376. }
  377. // MGSwipeButton
  378. ((CCCellMain *)cell).delegate = self;
  379. // LEFT : configure ONLY Root Favorites : Remove file/folder Favorites
  380. if (_serverUrl == nil) {
  381. ((CCCellMain *)cell).leftButtons = @[[MGSwipeButton buttonWithTitle:@"" icon:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"favorite"] width:50 height:50 color:[UIColor whiteColor]] backgroundColor:NCBrandColor.sharedInstance.yellowFavorite padding:25]];
  382. ((CCCellMain *)cell).leftExpansion.buttonIndex = 0;
  383. ((CCCellMain *)cell).leftExpansion.fillOnTrigger = NO;
  384. //centerIconOverText
  385. MGSwipeButton *favoriteButton = (MGSwipeButton *)[((CCCellMain *)cell).leftButtons objectAtIndex:0];
  386. [favoriteButton centerIconOverText];
  387. }
  388. // RIGHT
  389. ((CCCellMain *)cell).rightButtons = @[[MGSwipeButton buttonWithTitle:@"" icon:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"trash"] width:50 height:50 color:[UIColor whiteColor]] backgroundColor:[UIColor redColor] padding:25]];
  390. ((CCCellMain *)cell).rightExpansion.buttonIndex = 0;
  391. ((CCCellMain *)cell).rightExpansion.fillOnTrigger = NO;
  392. //centerIconOverText
  393. MGSwipeButton *deleteButton = (MGSwipeButton *)[((CCCellMain *)cell).rightButtons objectAtIndex:0];
  394. [deleteButton centerIconOverText];
  395. }
  396. // TRANSFER
  397. if ([cell isKindOfClass:[CCCellMainTransfer class]]) {
  398. // gesture Transfer
  399. [((CCCellMainTransfer *)cell).transferButton.stopButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  400. UILongPressGestureRecognizer *stopLongGesture = [UILongPressGestureRecognizer new];
  401. [stopLongGesture addTarget:self action:@selector(cancelAllTask:)];
  402. [((CCCellMainTransfer *)cell).transferButton.stopButton addGestureRecognizer:stopLongGesture];
  403. }
  404. return cell;
  405. }
  406. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  407. {
  408. // deselect row
  409. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  410. self.metadata = [self setSelfMetadataFromIndexPath:indexPath];
  411. if (self.metadata.status != k_metadataStatusNormal && self.metadata.status != k_metadataStatusDownloadError) {
  412. return;
  413. }
  414. // File
  415. if (self.metadata.directory == NO) {
  416. // File do not exists
  417. if ([CCUtility fileProviderStorageExists:self.metadata.ocId fileNameView:self.metadata.fileNameView]) {
  418. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_downloadedFile object:nil userInfo:@{@"metadata": self.metadata, @"selector": selectorLoadFileView, @"errorCode": @(0), @"errorDescription": @""}];
  419. } else {
  420. tableDirectory *tableDirectory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.account, self.metadata.serverUrl]];
  421. if (tableDirectory.e2eEncrypted && ![CCUtility isEndToEndEnabled:appDelegate.account]) {
  422. [[NCContentPresenter shared] messageNotification:@"_info_" description:@"_e2e_goto_settings_for_enable_" delay:k_dismissAfterSecond type:messageTypeInfo errorCode:k_CCErrorInternalError forced:false];
  423. } else {
  424. if (([self.metadata.typeFile isEqualToString: k_metadataTypeFile_video] || [self.metadata.typeFile isEqualToString: k_metadataTypeFile_audio]) && self.metadata.e2eEncrypted == NO) {
  425. [self shouldPerformSegue:self.metadata selector:@""];
  426. } else if ([self.metadata.typeFile isEqualToString: k_metadataTypeFile_document] && [[NCUtility shared] isDirectEditingWithAccount:self.metadata.account contentType:self.metadata.contentType] != nil) {
  427. if (NCCommunication.shared.isNetworkReachable) {
  428. [self shouldPerformSegue:self.metadata selector:@""];
  429. } else {
  430. [[NCContentPresenter shared] messageNotification:@"_info_" description:@"_go_online_" delay:k_dismissAfterSecond type:messageTypeInfo errorCode:k_CCErrorInternalError forced:false];
  431. }
  432. } else if ([self.metadata.typeFile isEqualToString: k_metadataTypeFile_document] && [[NCUtility shared] isRichDocument:self.metadata]) {
  433. if (NCCommunication.shared.isNetworkReachable) {
  434. [self shouldPerformSegue:self.metadata selector:@""];
  435. } else {
  436. [[NCContentPresenter shared] messageNotification:@"_info_" description:@"_go_online_" delay:k_dismissAfterSecond type:messageTypeInfo errorCode:k_CCErrorInternalError forced:false];
  437. }
  438. } else {
  439. if ([self.metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
  440. [self shouldPerformSegue:self.metadata selector:selectorLoadFileView];
  441. }
  442. [[NCNetworking shared] downloadWithMetadata:self.metadata selector:selectorLoadFileViewFavorite setFavorite:false completion:^(NSInteger errorCode) { }];
  443. }
  444. }
  445. }
  446. }
  447. // Directory
  448. if (self.metadata.directory) {
  449. CCFavorites *vc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"CCFavorites"];
  450. vc.serverUrl = [CCUtility stringAppendServerUrl:self.metadata.serverUrl addFileName:self.metadata.fileName];
  451. vc.titleViewControl = self.metadata.fileNameView;
  452. [self.navigationController pushViewController:vc animated:YES];
  453. }
  454. }
  455. #pragma --------------------------------------------------------------------------------------------
  456. #pragma mark ===== Navigation ====
  457. #pragma --------------------------------------------------------------------------------------------
  458. - (void)shouldPerformSegue:(tableMetadata *)metadata selector:(NSString *)selector
  459. {
  460. // if i am in background -> exit
  461. if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) return;
  462. // if i am not window -> exit
  463. if (self.view.window == NO)
  464. return;
  465. // Collapsed but i am in detail -> exit
  466. if (self.splitViewController.isCollapsed) {
  467. if (appDelegate.activeDetail.isViewLoaded && appDelegate.activeDetail.view.window) return;
  468. }
  469. // Metadata for push detail
  470. self.metadataForPushDetail = metadata;
  471. self.selectorForPushDetail = selector;
  472. [self performSegueWithIdentifier:@"segueDetail" sender:self];
  473. }
  474. -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
  475. {
  476. UINavigationController *navigationController = segue.destinationViewController;
  477. NCDetailViewController *detailViewController = (NCDetailViewController *)navigationController.topViewController;
  478. NSMutableArray *photoDataSource = [NSMutableArray new];
  479. for (NSString *ocId in sectionDataSource.allOcId) {
  480. tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:ocId];
  481. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image])
  482. [photoDataSource addObject:metadata];
  483. }
  484. detailViewController.metadata = self.metadataForPushDetail;
  485. detailViewController.selector = self.selectorForPushDetail;
  486. [detailViewController setTitle:self.metadata.fileNameView];
  487. }
  488. @end