CCTransfers.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. //
  2. // CCTransfers.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 12/04/17.
  6. // Copyright (c) 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCTransfers.h"
  24. #import "AppDelegate.h"
  25. #import "CCMain.h"
  26. #import "CCDetail.h"
  27. #import "CCSection.h"
  28. #import "CCCellMainTransfer.h"
  29. #import "NCBridgeSwift.h"
  30. #define download 1
  31. #define downloadwwan 2
  32. #define upload 3
  33. #define uploadwwan 4
  34. @interface CCTransfers ()
  35. {
  36. AppDelegate *appDelegate;
  37. // Datasource
  38. CCSectionDataSourceMetadata *sectionDataSource;
  39. }
  40. @end
  41. @implementation CCTransfers
  42. #pragma --------------------------------------------------------------------------------------------
  43. #pragma mark ===== Init =====
  44. #pragma --------------------------------------------------------------------------------------------
  45. - (id)initWithCoder:(NSCoder *)aDecoder
  46. {
  47. if (self = [super initWithCoder:aDecoder]) {
  48. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  49. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
  50. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  51. appDelegate.activeTransfers = self;
  52. }
  53. return self;
  54. }
  55. - (void)viewDidLoad {
  56. [super viewDidLoad];
  57. // Custom Cell
  58. [self.tableView registerNib:[UINib nibWithNibName:@"CCCellMainTransfer" bundle:nil] forCellReuseIdentifier:@"CellMainTransfer"];
  59. self.tableView.delegate = self;
  60. self.tableView.dataSource = self;
  61. self.tableView.emptyDataSetDelegate = self;
  62. self.tableView.emptyDataSetSource = self;
  63. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  64. self.tableView.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
  65. self.title = NSLocalizedString(@"_transfers_", nil);
  66. [self reloadDatasource:nil action:k_action_NULL];
  67. }
  68. // Apparirà
  69. - (void)viewWillAppear:(BOOL)animated
  70. {
  71. [super viewWillAppear:animated];
  72. // Color
  73. [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
  74. [appDelegate aspectTabBar:self.tabBarController.tabBar hidden:NO];
  75. [self reloadDatasource:nil action:k_action_NULL];
  76. }
  77. - (void)changeTheming
  78. {
  79. if (self.isViewLoaded && self.view.window)
  80. [appDelegate changeTheming:self];
  81. }
  82. #pragma --------------------------------------------------------------------------------------------
  83. #pragma mark ==== DZNEmptyDataSetSource ====
  84. #pragma --------------------------------------------------------------------------------------------
  85. - (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView
  86. {
  87. return 0.0f;
  88. }
  89. - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
  90. {
  91. return [UIColor whiteColor];
  92. }
  93. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
  94. {
  95. return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"loadNoRecord"] multiplier:2 color:[NCBrandColor sharedInstance].graySoft];
  96. }
  97. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
  98. {
  99. NSString *text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_no_transfer_", nil)];
  100. NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:[UIColor lightGrayColor]};
  101. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  102. }
  103. - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
  104. {
  105. NSString *text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_no_transfer_sub_", nil)];
  106. NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
  107. paragraph.lineBreakMode = NSLineBreakByWordWrapping;
  108. paragraph.alignment = NSTextAlignmentCenter;
  109. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph};
  110. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  111. }
  112. #pragma --------------------------------------------------------------------------------------------
  113. #pragma mark ==== Download Thumbnail ====
  114. #pragma --------------------------------------------------------------------------------------------
  115. - (void)downloadThumbnail:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl indexPath:(NSIndexPath *)indexPath
  116. {
  117. CGFloat width = [[NCUtility sharedInstance] getScreenWidthForPreview];
  118. CGFloat height = [[NCUtility sharedInstance] getScreenHeightForPreview];
  119. OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:appDelegate.activeUser withUserID:appDelegate.activeUserID withPassword:appDelegate.activePassword withUrl:appDelegate.activeUrl];
  120. [ocNetworking downloadPreviewWithMetadata:metadata serverUrl:serverUrl withWidth:width andHeight:height completion:^(NSString *message, NSInteger errorCode) {
  121. if (errorCode == 0 && [[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]] && [[NCMainCommon sharedInstance] isValidIndexPath:indexPath tableView:self.tableView]) {
  122. [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  123. }
  124. }];
  125. }
  126. #pragma --------------------------------------------------------------------------------------------
  127. #pragma mark - ===== Progress & Task Button =====
  128. #pragma --------------------------------------------------------------------------------------------
  129. - (void)triggerProgressTask:(NSNotification *)notification
  130. {
  131. [[NCMainCommon sharedInstance] triggerProgressTask:notification sectionDataSourceFileIDIndexPath:sectionDataSource.fileIDIndexPath tableView:self.tableView];
  132. }
  133. - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
  134. {
  135. UITouch * touch = [[event allTouches] anyObject];
  136. CGPoint location = [touch locationInView:self.tableView];
  137. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  138. if (indexPath) {
  139. NSString *fileID = [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  140. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  141. if (metadata)
  142. [[NCMainCommon sharedInstance] cancelTransferMetadata:metadata reloadDatasource:true];
  143. }
  144. }
  145. - (void)cancelAllTask:(id)sender
  146. {
  147. CGPoint location = [sender locationInView:self.tableView];
  148. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  149. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  150. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_all_task_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  151. [[NCMainCommon sharedInstance] cancelAllTransfer];
  152. }]];
  153. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]];
  154. alertController.popoverPresentationController.sourceView = self.tableView;
  155. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  156. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  157. [alertController.view layoutIfNeeded];
  158. [self presentViewController:alertController animated:YES completion:nil];
  159. }
  160. #pragma --------------------------------------------------------------------------------------------
  161. #pragma mark - ==== Datasource ====
  162. #pragma --------------------------------------------------------------------------------------------
  163. - (void)reloadDatasource:(NSString *)fileID action:(NSInteger)action
  164. {
  165. // test
  166. if (appDelegate.activeAccount.length == 0 || !self.view.window)
  167. return;
  168. NSArray *recordsTableMetadata = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND ((session CONTAINS 'upload') OR (session CONTAINS 'download'))", appDelegate.activeAccount] sorted:@"sessionTaskIdentifier" ascending:NO];
  169. sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:appDelegate.listProgressMetadata groupByField:@"session" filterFileID:appDelegate.filterFileID filterTypeFileImage:NO filterTypeFileVideo:NO activeAccount:appDelegate.activeAccount];
  170. [self.tableView reloadData];
  171. }
  172. #pragma --------------------------------------------------------------------------------------------
  173. #pragma mark - ==== Table ====
  174. #pragma --------------------------------------------------------------------------------------------
  175. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  176. {
  177. return 60;
  178. }
  179. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  180. {
  181. return [[sectionDataSource.sectionArrayRow allKeys] count];
  182. }
  183. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  184. {
  185. return [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:section]] count];
  186. }
  187. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  188. {
  189. return 13.0f;
  190. }
  191. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  192. {
  193. UIVisualEffectView *visualEffectView;
  194. NSString *titleSection, *numberTitle;
  195. NSInteger typeOfSession = 0;
  196. NSInteger queueDownload = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND (session == %@ OR session == %@)", appDelegate.activeAccount, k_download_session, k_download_session_foreground] sorted:nil ascending:NO] count];
  197. NSInteger queueDownloadWWan = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND session == %@", appDelegate.activeAccount, k_download_session_wwan] sorted:nil ascending:NO] count];
  198. NSInteger queueUpload = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND (session == %@ OR session == %@)", appDelegate.activeAccount, k_upload_session, k_upload_session_foreground] sorted:nil ascending:NO] count];
  199. NSInteger queueUploadWWan = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND session == %@", appDelegate.activeAccount, k_upload_session_wwan] sorted:nil ascending:NO] count];
  200. if ([[sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [sectionDataSource.sections objectAtIndex:section];
  201. if ([[sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]]) titleSection = [CCUtility getTitleSectionDate:[sectionDataSource.sections objectAtIndex:section]];
  202. NSArray *metadatas = [sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:section]];
  203. NSUInteger rowsCount = [metadatas count];
  204. visualEffectView = [[UIVisualEffectView alloc] init];
  205. visualEffectView.backgroundColor = [UIColor clearColor];
  206. // title section
  207. if ([titleSection isEqualToString:@"_none_"]) {
  208. titleSection = @"";
  209. } else if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"]) {
  210. typeOfSession = download;
  211. titleSection = NSLocalizedString(@"_title_section_download_",nil);
  212. } else if ([titleSection containsString:@"download"] && [titleSection containsString:@"wwan"]) {
  213. typeOfSession = downloadwwan;
  214. titleSection = [NSLocalizedString(@"_title_section_download_",nil) stringByAppendingString:@" Wi-Fi"];
  215. } else if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"]) {
  216. typeOfSession = upload;
  217. titleSection = NSLocalizedString(@"_title_section_upload_",nil);
  218. } else if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"]) {
  219. typeOfSession = uploadwwan;
  220. titleSection = [NSLocalizedString(@"_title_section_upload_",nil) stringByAppendingString:@" Wi-Fi"];
  221. } else {
  222. titleSection = NSLocalizedString(titleSection,nil);
  223. }
  224. // title label on left
  225. UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(8, 3, 0, 13)];
  226. titleLabel.textColor = [UIColor blackColor];
  227. titleLabel.font = [UIFont systemFontOfSize:9];
  228. titleLabel.textAlignment = NSTextAlignmentLeft;
  229. titleLabel.text = titleSection;
  230. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  231. [visualEffectView.contentView addSubview:titleLabel];
  232. // element (s) on right
  233. UILabel *elementLabel=[[UILabel alloc]initWithFrame:CGRectMake(-8, 3, 0, 13)];
  234. elementLabel.textColor = [UIColor blackColor];
  235. elementLabel.font = [UIFont systemFontOfSize:9];
  236. elementLabel.textAlignment = NSTextAlignmentRight;
  237. elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  238. if ((typeOfSession == download && queueDownload > rowsCount) || (typeOfSession == downloadwwan && queueDownloadWWan > rowsCount) ||
  239. (typeOfSession == upload && queueUpload > rowsCount) || (typeOfSession == uploadwwan && queueUploadWWan > rowsCount)) {
  240. numberTitle = [NSString stringWithFormat:@"%lu+", (unsigned long)rowsCount];
  241. } else {
  242. numberTitle = [NSString stringWithFormat:@"%lu", (unsigned long)rowsCount];
  243. }
  244. if (rowsCount > 1)
  245. elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_elements_",nil)];
  246. else
  247. elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_element_",nil)];
  248. // view
  249. [visualEffectView.contentView addSubview:elementLabel];
  250. return visualEffectView;
  251. }
  252. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  253. {
  254. NSString *titleSection;
  255. NSString *element_s;
  256. if ([[sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [sectionDataSource.sections objectAtIndex:section];
  257. // Prepare view for title in footer
  258. UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
  259. UILabel *titleFooterLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)];
  260. titleFooterLabel.textColor = [UIColor blackColor];
  261. titleFooterLabel.font = [UIFont systemFontOfSize:12];
  262. titleFooterLabel.textAlignment = NSTextAlignmentCenter;
  263. // Footer Download
  264. if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
  265. NSInteger queueDownload = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND (session == %@ OR session == %@)", appDelegate.activeAccount, k_download_session, k_download_session_foreground] sorted:nil ascending:NO] count];
  266. // element or elements ?
  267. if (queueDownload > 1) element_s = NSLocalizedString(@"_elements_",nil);
  268. else element_s = NSLocalizedString(@"_element_",nil);
  269. // Num record to upload
  270. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_download_", nil), queueDownload, element_s]];
  271. titleFooterLabel.attributedText = stringFooter;
  272. [view addSubview:titleFooterLabel];
  273. return view;
  274. }
  275. // Footer Download WWAN
  276. if ([titleSection containsString:@"download"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
  277. NSInteger queueDownloadWWan = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND session == %@", appDelegate.activeAccount, k_download_session_wwan] sorted:nil ascending:NO] count];
  278. // element or elements ?
  279. if (queueDownloadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
  280. else element_s = NSLocalizedString(@"_element_",nil);
  281. // Add the symbol WiFi and Num record
  282. NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
  283. attachment.image = [UIImage imageNamed:@"WiFiSmall"];
  284. NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
  285. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[@" " stringByAppendingString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_download_wwan_", nil), queueDownloadWWan, element_s]]];
  286. [stringFooter insertAttributedString:attachmentString atIndex:0];
  287. titleFooterLabel.attributedText = stringFooter;
  288. [view addSubview:titleFooterLabel];
  289. return view;
  290. }
  291. // Footer Upload
  292. if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
  293. NSInteger queueUpload = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND (session == %@ OR session == %@)", appDelegate.activeAccount, k_upload_session, k_upload_session_foreground] sorted:nil ascending:NO] count];
  294. // element or elements ?
  295. if (queueUpload > 1) element_s = NSLocalizedString(@"_elements_",nil);
  296. else element_s = NSLocalizedString(@"_element_",nil);
  297. // Num record to upload
  298. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_", nil), queueUpload, element_s]];
  299. titleFooterLabel.attributedText = stringFooter;
  300. [view addSubview:titleFooterLabel];
  301. return view;
  302. }
  303. // Footer Upload WWAN
  304. if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
  305. NSInteger queueUploadWWan = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND session == %@", appDelegate.activeAccount, k_upload_session_wwan] sorted:nil ascending:NO] count];
  306. // element or elements ?
  307. if (queueUploadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
  308. else element_s = NSLocalizedString(@"_element_",nil);
  309. // Add the symbol WiFi and Num record
  310. NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
  311. attachment.image = [UIImage imageNamed:@"WiFiSmall"];
  312. NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
  313. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[@" " stringByAppendingString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_wwan_", nil), queueUploadWWan,element_s]]];
  314. [stringFooter insertAttributedString:attachmentString atIndex:0];
  315. titleFooterLabel.attributedText = stringFooter;
  316. [view addSubview:titleFooterLabel];
  317. return view;
  318. }
  319. return nil;
  320. }
  321. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  322. {
  323. //NSString *titleSection;
  324. //if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]])
  325. // titleSection = [_sectionDataSource.sections objectAtIndex:section];
  326. //if ([titleSection rangeOfString:@"upload"].location != NSNotFound && [titleSection rangeOfString:@"wwan"].location != NSNotFound && titleSection != nil) return 18.0f;
  327. //else return 0.0f;
  328. return 18.0f;
  329. }
  330. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  331. {
  332. return [sectionDataSource.sections indexOfObject:title];
  333. }
  334. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  335. {
  336. NSString *fileID = [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  337. tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:fileID];
  338. if (metadata == nil || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata]) {
  339. return [CCCellMainTransfer new];
  340. }
  341. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  342. if (serverUrl == nil) {
  343. return [CCCellMainTransfer new];
  344. }
  345. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, serverUrl]];
  346. if (directory == nil) {
  347. return [CCCellMainTransfer new];
  348. }
  349. tableMetadata *metadataFolder = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", directory.fileID]];
  350. // Download thumbnail
  351. if (metadata.thumbnailExists && !metadataFolder.e2eEncrypted && ![CCUtility fileProviderStorageIconExists:metadata.fileID fileNameView:metadata.fileNameView]) {
  352. [self downloadThumbnail:metadata serverUrl:serverUrl indexPath:indexPath];
  353. }
  354. UITableViewCell *cell = [[NCMainCommon sharedInstance] cellForRowAtIndexPath:indexPath tableView:tableView metadata:metadata metadataFolder:metadataFolder serverUrl:serverUrl autoUploadFileName:@"" autoUploadDirectory:@""];
  355. // TRANSFER
  356. if ([cell isKindOfClass:[CCCellMainTransfer class]]) {
  357. // gesture Transfer
  358. [((CCCellMainTransfer *)cell).transferButton.stopButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  359. UILongPressGestureRecognizer *stopLongGesture = [UILongPressGestureRecognizer new];
  360. [stopLongGesture addTarget:self action:@selector(cancelAllTask:)];
  361. [((CCCellMainTransfer *)cell).transferButton.stopButton addGestureRecognizer:stopLongGesture];
  362. }
  363. return cell;
  364. }
  365. @end