CCFavorites.m 28 KB

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