CCFavorites.m 28 KB

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