CCFavorites.m 28 KB

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