CCTransfers.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  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. - (void)viewDidAppear:(BOOL)animated
  69. {
  70. [super viewDidAppear:animated];
  71. // Color
  72. [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
  73. [appDelegate aspectTabBar:self.tabBarController.tabBar hidden:NO];
  74. [self reloadDatasource:nil action:k_action_NULL];
  75. }
  76. - (void)changeTheming
  77. {
  78. if (self.isViewLoaded && self.view.window)
  79. [appDelegate changeTheming:self];
  80. }
  81. #pragma --------------------------------------------------------------------------------------------
  82. #pragma mark ==== DZNEmptyDataSetSource ====
  83. #pragma --------------------------------------------------------------------------------------------
  84. - (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView
  85. {
  86. return 0.0f;
  87. }
  88. - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
  89. {
  90. return [UIColor whiteColor];
  91. }
  92. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
  93. {
  94. return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"loadNoRecord"] multiplier:2 color:[NCBrandColor sharedInstance].graySoft];
  95. }
  96. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
  97. {
  98. NSString *text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_no_transfer_", nil)];
  99. NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:[UIColor lightGrayColor]};
  100. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  101. }
  102. - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
  103. {
  104. NSString *text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_no_transfer_sub_", nil)];
  105. NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
  106. paragraph.lineBreakMode = NSLineBreakByWordWrapping;
  107. paragraph.alignment = NSTextAlignmentCenter;
  108. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph};
  109. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  110. }
  111. #pragma --------------------------------------------------------------------------------------------
  112. #pragma mark ==== Download Thumbnail ====
  113. #pragma --------------------------------------------------------------------------------------------
  114. - (void)downloadThumbnail:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl indexPath:(NSIndexPath *)indexPath
  115. {
  116. CGFloat width = [[NCUtility sharedInstance] getScreenWidthForPreview];
  117. CGFloat height = [[NCUtility sharedInstance] getScreenHeightForPreview];
  118. OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:appDelegate.activeUser withUserID:appDelegate.activeUserID withPassword:appDelegate.activePassword withUrl:appDelegate.activeUrl];
  119. [ocNetworking downloadPreviewWithMetadata:metadata serverUrl:serverUrl withWidth:width andHeight:height completion:^(NSString *message, NSInteger errorCode) {
  120. if (errorCode == 0 && [[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]] && [[NCMainCommon sharedInstance] isValidIndexPath:indexPath tableView:self.tableView]) {
  121. [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  122. }
  123. }];
  124. }
  125. #pragma --------------------------------------------------------------------------------------------
  126. #pragma mark - ===== Progress & Task Button =====
  127. #pragma --------------------------------------------------------------------------------------------
  128. - (void)triggerProgressTask:(NSNotification *)notification
  129. {
  130. [[NCMainCommon sharedInstance] triggerProgressTask:notification sectionDataSourceFileIDIndexPath:sectionDataSource.fileIDIndexPath tableView:self.tableView];
  131. }
  132. - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
  133. {
  134. UITouch * touch = [[event allTouches] anyObject];
  135. CGPoint location = [touch locationInView:self.tableView];
  136. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  137. if (indexPath) {
  138. NSString *fileID = [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  139. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  140. if (metadata)
  141. [[NCMainCommon sharedInstance] cancelTransferMetadata:metadata reloadDatasource:true];
  142. }
  143. }
  144. - (void)cancelAllTask:(id)sender
  145. {
  146. CGPoint location = [sender locationInView:self.tableView];
  147. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  148. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  149. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_all_task_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  150. [[NCMainCommon sharedInstance] cancelAllTransfer];
  151. }]];
  152. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]];
  153. alertController.popoverPresentationController.sourceView = self.tableView;
  154. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  155. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  156. [alertController.view layoutIfNeeded];
  157. [self presentViewController:alertController animated:YES completion:nil];
  158. }
  159. #pragma --------------------------------------------------------------------------------------------
  160. #pragma mark - ==== Datasource ====
  161. #pragma --------------------------------------------------------------------------------------------
  162. - (void)reloadDatasource:(NSString *)fileID action:(NSInteger)action
  163. {
  164. // test
  165. if (appDelegate.activeAccount.length == 0 || !self.view.window)
  166. return;
  167. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  168. NSArray *recordsTableMetadata = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND ((session CONTAINS 'upload') OR (session CONTAINS 'download'))", appDelegate.activeAccount] sorted:@"sessionTaskIdentifier" ascending:NO];
  169. CCSectionDataSourceMetadata *sectionDataSourceTemp = [CCSectionDataSourceMetadata new];
  170. sectionDataSourceTemp = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:appDelegate.listProgressMetadata groupByField:@"session" filterFileID:appDelegate.filterFileID filterTypeFileImage:NO filterTypeFileVideo:NO activeAccount:appDelegate.activeAccount];
  171. dispatch_async(dispatch_get_main_queue(), ^{
  172. sectionDataSource = sectionDataSourceTemp;
  173. [self.tableView reloadData];
  174. });
  175. });
  176. }
  177. #pragma --------------------------------------------------------------------------------------------
  178. #pragma mark - ==== Table ====
  179. #pragma --------------------------------------------------------------------------------------------
  180. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  181. {
  182. return 60;
  183. }
  184. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  185. {
  186. return [[sectionDataSource.sectionArrayRow allKeys] count];
  187. }
  188. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  189. {
  190. return [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:section]] count];
  191. }
  192. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  193. {
  194. return 13.0f;
  195. }
  196. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  197. {
  198. UIVisualEffectView *visualEffectView;
  199. NSString *titleSection, *numberTitle;
  200. NSInteger typeOfSession = 0;
  201. 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];
  202. NSInteger queueDownloadWWan = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND session == %@", appDelegate.activeAccount, k_download_session_wwan] sorted:nil ascending:NO] count];
  203. 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];
  204. NSInteger queueUploadWWan = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND session == %@", appDelegate.activeAccount, k_upload_session_wwan] sorted:nil ascending:NO] count];
  205. if ([[sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [sectionDataSource.sections objectAtIndex:section];
  206. if ([[sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]]) titleSection = [CCUtility getTitleSectionDate:[sectionDataSource.sections objectAtIndex:section]];
  207. NSArray *metadatas = [sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:section]];
  208. NSUInteger rowsCount = [metadatas count];
  209. visualEffectView = [[UIVisualEffectView alloc] init];
  210. visualEffectView.backgroundColor = [UIColor clearColor];
  211. // title section
  212. if ([titleSection isEqualToString:@"_none_"]) {
  213. titleSection = @"";
  214. } else if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"]) {
  215. typeOfSession = download;
  216. titleSection = NSLocalizedString(@"_title_section_download_",nil);
  217. } else if ([titleSection containsString:@"download"] && [titleSection containsString:@"wwan"]) {
  218. typeOfSession = downloadwwan;
  219. titleSection = [NSLocalizedString(@"_title_section_download_",nil) stringByAppendingString:@" Wi-Fi"];
  220. } else if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"]) {
  221. typeOfSession = upload;
  222. titleSection = NSLocalizedString(@"_title_section_upload_",nil);
  223. } else if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"]) {
  224. typeOfSession = uploadwwan;
  225. titleSection = [NSLocalizedString(@"_title_section_upload_",nil) stringByAppendingString:@" Wi-Fi"];
  226. } else {
  227. titleSection = NSLocalizedString(titleSection,nil);
  228. }
  229. // title label on left
  230. UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(8, 3, 0, 13)];
  231. titleLabel.textColor = [UIColor blackColor];
  232. titleLabel.font = [UIFont systemFontOfSize:9];
  233. titleLabel.textAlignment = NSTextAlignmentLeft;
  234. titleLabel.text = titleSection;
  235. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  236. [visualEffectView.contentView addSubview:titleLabel];
  237. // element (s) on right
  238. UILabel *elementLabel=[[UILabel alloc]initWithFrame:CGRectMake(-8, 3, 0, 13)];
  239. elementLabel.textColor = [UIColor blackColor];
  240. elementLabel.font = [UIFont systemFontOfSize:9];
  241. elementLabel.textAlignment = NSTextAlignmentRight;
  242. elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  243. if ((typeOfSession == download && queueDownload > rowsCount) || (typeOfSession == downloadwwan && queueDownloadWWan > rowsCount) ||
  244. (typeOfSession == upload && queueUpload > rowsCount) || (typeOfSession == uploadwwan && queueUploadWWan > rowsCount)) {
  245. numberTitle = [NSString stringWithFormat:@"%lu+", (unsigned long)rowsCount];
  246. } else {
  247. numberTitle = [NSString stringWithFormat:@"%lu", (unsigned long)rowsCount];
  248. }
  249. if (rowsCount > 1)
  250. elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_elements_",nil)];
  251. else
  252. elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_element_",nil)];
  253. // view
  254. [visualEffectView.contentView addSubview:elementLabel];
  255. return visualEffectView;
  256. }
  257. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  258. {
  259. NSString *titleSection;
  260. NSString *element_s;
  261. if ([[sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [sectionDataSource.sections objectAtIndex:section];
  262. // Prepare view for title in footer
  263. UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
  264. UILabel *titleFooterLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)];
  265. titleFooterLabel.textColor = [UIColor blackColor];
  266. titleFooterLabel.font = [UIFont systemFontOfSize:12];
  267. titleFooterLabel.textAlignment = NSTextAlignmentCenter;
  268. // Footer Download
  269. if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
  270. 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];
  271. // element or elements ?
  272. if (queueDownload > 1) element_s = NSLocalizedString(@"_elements_",nil);
  273. else element_s = NSLocalizedString(@"_element_",nil);
  274. // Num record to upload
  275. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_download_", nil), queueDownload, element_s]];
  276. titleFooterLabel.attributedText = stringFooter;
  277. [view addSubview:titleFooterLabel];
  278. return view;
  279. }
  280. // Footer Download WWAN
  281. if ([titleSection containsString:@"download"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
  282. NSInteger queueDownloadWWan = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND session == %@", appDelegate.activeAccount, k_download_session_wwan] sorted:nil ascending:NO] count];
  283. // element or elements ?
  284. if (queueDownloadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
  285. else element_s = NSLocalizedString(@"_element_",nil);
  286. // Add the symbol WiFi and Num record
  287. NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
  288. attachment.image = [UIImage imageNamed:@"WiFiSmall"];
  289. NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
  290. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[@" " stringByAppendingString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_download_wwan_", nil), queueDownloadWWan, element_s]]];
  291. [stringFooter insertAttributedString:attachmentString atIndex:0];
  292. titleFooterLabel.attributedText = stringFooter;
  293. [view addSubview:titleFooterLabel];
  294. return view;
  295. }
  296. // Footer Upload
  297. if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
  298. 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];
  299. // element or elements ?
  300. if (queueUpload > 1) element_s = NSLocalizedString(@"_elements_",nil);
  301. else element_s = NSLocalizedString(@"_element_",nil);
  302. // Num record to upload
  303. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_", nil), queueUpload, element_s]];
  304. titleFooterLabel.attributedText = stringFooter;
  305. [view addSubview:titleFooterLabel];
  306. return view;
  307. }
  308. // Footer Upload WWAN
  309. if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
  310. NSInteger queueUploadWWan = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND session == %@", appDelegate.activeAccount, k_upload_session_wwan] sorted:nil ascending:NO] count];
  311. // element or elements ?
  312. if (queueUploadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
  313. else element_s = NSLocalizedString(@"_element_",nil);
  314. // Add the symbol WiFi and Num record
  315. NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
  316. attachment.image = [UIImage imageNamed:@"WiFiSmall"];
  317. NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
  318. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[@" " stringByAppendingString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_wwan_", nil), queueUploadWWan,element_s]]];
  319. [stringFooter insertAttributedString:attachmentString atIndex:0];
  320. titleFooterLabel.attributedText = stringFooter;
  321. [view addSubview:titleFooterLabel];
  322. return view;
  323. }
  324. return nil;
  325. }
  326. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  327. {
  328. //NSString *titleSection;
  329. //if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]])
  330. // titleSection = [_sectionDataSource.sections objectAtIndex:section];
  331. //if ([titleSection rangeOfString:@"upload"].location != NSNotFound && [titleSection rangeOfString:@"wwan"].location != NSNotFound && titleSection != nil) return 18.0f;
  332. //else return 0.0f;
  333. return 18.0f;
  334. }
  335. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  336. {
  337. return [sectionDataSource.sections indexOfObject:title];
  338. }
  339. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  340. {
  341. NSString *fileID = [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  342. tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:fileID];
  343. if (metadata == nil || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata]) {
  344. return [CCCellMainTransfer new];
  345. }
  346. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  347. if (serverUrl == nil) {
  348. return [CCCellMainTransfer new];
  349. }
  350. tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, serverUrl]];
  351. if (directory == nil) {
  352. return [CCCellMainTransfer new];
  353. }
  354. tableMetadata *metadataFolder = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", directory.fileID]];
  355. // Download thumbnail
  356. if (metadata.thumbnailExists && !metadataFolder.e2eEncrypted && ![CCUtility fileProviderStorageIconExists:metadata.fileID fileNameView:metadata.fileNameView]) {
  357. [self downloadThumbnail:metadata serverUrl:serverUrl indexPath:indexPath];
  358. }
  359. UITableViewCell *cell = [[NCMainCommon sharedInstance] cellForRowAtIndexPath:indexPath tableView:tableView metadata:metadata metadataFolder:metadataFolder serverUrl:serverUrl autoUploadFileName:@"" autoUploadDirectory:@""];
  360. // TRANSFER
  361. if ([cell isKindOfClass:[CCCellMainTransfer class]]) {
  362. // gesture Transfer
  363. [((CCCellMainTransfer *)cell).transferButton.stopButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  364. UILongPressGestureRecognizer *stopLongGesture = [UILongPressGestureRecognizer new];
  365. [stopLongGesture addTarget:self action:@selector(cancelAllTask:)];
  366. [((CCCellMainTransfer *)cell).transferButton.stopButton addGestureRecognizer:stopLongGesture];
  367. }
  368. return cell;
  369. }
  370. @end