CCTransfers.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. //
  2. // CCTransfers.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 12/04/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 "CCTransfers.h"
  24. #import "AppDelegate.h"
  25. #import "CCMain.h"
  26. #import "CCSection.h"
  27. #import "CCCellMainTransfer.h"
  28. #import "NCBridgeSwift.h"
  29. #define download 1
  30. #define upload 2
  31. #define uploadwwan 3
  32. @interface CCTransfers ()
  33. {
  34. AppDelegate *appDelegate;
  35. // Datasource
  36. CCSectionDataSourceMetadata *sectionDataSource;
  37. tableMetadata *metadataForRecognizer;
  38. }
  39. @end
  40. @implementation CCTransfers
  41. #pragma --------------------------------------------------------------------------------------------
  42. #pragma mark ===== Init =====
  43. #pragma --------------------------------------------------------------------------------------------
  44. - (id)initWithCoder:(NSCoder *)aDecoder
  45. {
  46. if (self = [super initWithCoder:aDecoder]) {
  47. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  48. appDelegate.activeTransfers = self;
  49. }
  50. return self;
  51. }
  52. - (void)viewDidLoad {
  53. [super viewDidLoad];
  54. self.title = NSLocalizedString(@"_transfers_", nil);
  55. // Custom Cell
  56. [self.tableView registerNib:[UINib nibWithNibName:@"CCCellMain" bundle:nil] forCellReuseIdentifier:@"CellMain"];
  57. [self.tableView registerNib:[UINib nibWithNibName:@"CCCellMainTransfer" bundle:nil] forCellReuseIdentifier:@"CellMainTransfer"];
  58. self.tableView.delegate = self;
  59. self.tableView.dataSource = self;
  60. self.tableView.emptyDataSetDelegate = self;
  61. self.tableView.emptyDataSetSource = self;
  62. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  63. self.tableView.backgroundColor = NCBrandColor.sharedInstance.backgroundView;
  64. // long press recognizer TableView
  65. UILongPressGestureRecognizer* longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onLongPressTableView:)];
  66. [self.tableView addGestureRecognizer:longPressRecognizer];
  67. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:k_notificationCenter_progressTask object:nil];
  68. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadDatasource) name:k_notificationCenter_reloadDataSource object:nil];
  69. [self changeTheming];
  70. }
  71. - (void)viewDidAppear:(BOOL)animated
  72. {
  73. [super viewDidAppear:animated];
  74. [self reloadDatasource];
  75. }
  76. - (void)changeTheming
  77. {
  78. [appDelegate changeTheming:self tableView:self.tableView collectionView:nil form:false];
  79. }
  80. #pragma --------------------------------------------------------------------------------------------
  81. #pragma mark ==== DZNEmptyDataSetSource ====
  82. #pragma --------------------------------------------------------------------------------------------
  83. - (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView
  84. {
  85. return 0.0f;
  86. }
  87. - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
  88. {
  89. return NCBrandColor.sharedInstance.backgroundView;
  90. }
  91. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
  92. {
  93. return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"load"] width:300 height:300 color:NCBrandColor.sharedInstance.graySoft];
  94. }
  95. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
  96. {
  97. NSString *text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_no_transfer_", nil)];
  98. NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:[UIColor lightGrayColor]};
  99. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  100. }
  101. - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
  102. {
  103. NSString *text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_no_transfer_sub_", nil)];
  104. NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
  105. paragraph.lineBreakMode = NSLineBreakByWordWrapping;
  106. paragraph.alignment = NSTextAlignmentCenter;
  107. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph};
  108. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  109. }
  110. #pragma --------------------------------------------------------------------------------------------
  111. #pragma mark ===== Long Press Recognized Table View =====
  112. #pragma --------------------------------------------------------------------------------------------
  113. - (void)onLongPressTableView:(UILongPressGestureRecognizer*)recognizer
  114. {
  115. if (recognizer.state == UIGestureRecognizerStateBegan) {
  116. CGPoint touchPoint = [recognizer locationInView:self.tableView];
  117. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touchPoint];
  118. metadataForRecognizer = [[NCMainCommon sharedInstance] getMetadataFromSectionDataSourceIndexPath:indexPath sectionDataSource:sectionDataSource];
  119. [self becomeFirstResponder];
  120. UIMenuController *menuController = [UIMenuController sharedMenuController];
  121. UIMenuItem *startTaskItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"_start_", nil) action:@selector(startTask:)];
  122. [menuController setMenuItems:[NSArray arrayWithObjects:startTaskItem, nil]];
  123. [menuController setTargetRect:CGRectMake(touchPoint.x, touchPoint.y, 0.0f, 0.0f) inView:self.tableView];
  124. [menuController setMenuVisible:YES animated:YES];
  125. }
  126. }
  127. - (BOOL)canBecomeFirstResponder
  128. {
  129. return YES;
  130. }
  131. - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
  132. {
  133. if (@selector(startTask:) != action) return NO;
  134. if (metadataForRecognizer == nil) return NO;
  135. // Detect E2EE
  136. NSString *saveserverUrl = @"";
  137. NSArray *metadatasForE2EE = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"status != %d", k_metadataStatusNormal] sorted:@"serverUrl" ascending:NO];
  138. for (tableMetadata *metadata in metadatasForE2EE) {
  139. if (![saveserverUrl isEqualToString:metadata.serverUrl]) {
  140. saveserverUrl = metadata.serverUrl;
  141. if ([[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@ AND e2eEncrypted == 1", metadata.account, metadata.serverUrl]] != nil) {
  142. return NO;
  143. }
  144. }
  145. }
  146. /*
  147. if (!([metadataForRecognizer.session isEqualToString:k_upload_session_extension]) &&(metadataForRecognizer.status == k_metadataStatusWaitUpload || metadataForRecognizer.status == k_metadataStatusUploading)) {
  148. return YES;
  149. }
  150. */
  151. return NO;
  152. }
  153. #pragma --------------------------------------------------------------------------------------------
  154. #pragma mark - ===== Progress & Task Button =====
  155. #pragma --------------------------------------------------------------------------------------------
  156. - (void)triggerProgressTask:(NSNotification *)notification
  157. {
  158. if (sectionDataSource.ocIdIndexPath != nil) {
  159. [[NCMainCommon sharedInstance] triggerProgressTask:notification sectionDataSourceocIdIndexPath:sectionDataSource.ocIdIndexPath tableView:self.tableView viewController:self serverUrlViewController:nil];
  160. }
  161. }
  162. - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
  163. {
  164. UITouch * touch = [[event allTouches] anyObject];
  165. CGPoint location = [touch locationInView:self.tableView];
  166. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  167. if (indexPath) {
  168. NSString *ocId = [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  169. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId = %@", ocId]];
  170. if (metadata)
  171. [[NCMainCommon sharedInstance] cancelTransferMetadata:metadata reloadDatasource:true uploadStatusForcedStart:false];
  172. }
  173. }
  174. - (void)cancelAllTask:(id)sender
  175. {
  176. CGPoint location = [sender locationInView:self.tableView];
  177. NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
  178. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  179. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_all_task_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  180. [[NCMainCommon sharedInstance] cancelAllTransfer];
  181. }]];
  182. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { }]];
  183. alertController.popoverPresentationController.sourceView = self.tableView;
  184. alertController.popoverPresentationController.sourceRect = [self.tableView rectForRowAtIndexPath:indexPath];
  185. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  186. [alertController.view layoutIfNeeded];
  187. [self presentViewController:alertController animated:YES completion:nil];
  188. }
  189. - (void)startTask:(id)sender
  190. {
  191. if (metadataForRecognizer.status == k_metadataStatusUploading) {
  192. [[NCMainCommon sharedInstance] cancelTransferMetadata:metadataForRecognizer reloadDatasource:false uploadStatusForcedStart:true];
  193. } else {
  194. metadataForRecognizer.status = k_metadataStatusInUpload;
  195. metadataForRecognizer.session = NCCommunicationCommon.shared.sessionIdentifierBackground;
  196. [[NCNetworking shared] uploadWithMetadata:[[NCManageDatabase sharedInstance] addMetadata:metadataForRecognizer]];
  197. }
  198. }
  199. #pragma --------------------------------------------------------------------------------------------
  200. #pragma mark - ==== Datasource ====
  201. #pragma --------------------------------------------------------------------------------------------
  202. - (void)reloadDatasource
  203. {
  204. // test
  205. if (appDelegate.activeAccount.length == 0 || self.view.window == nil)
  206. return;
  207. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  208. NSArray *recordsTableMetadata = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"(session CONTAINS 'upload') OR (session CONTAINS 'download')"] sorted:nil ascending:NO];
  209. CCSectionDataSourceMetadata *sectionDataSourceTemp = [CCSectionDataSourceMetadata new];
  210. sectionDataSourceTemp = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:appDelegate.listProgressMetadata groupByField:@"session" filterTypeFileImage:NO filterTypeFileVideo:NO sorted:@"fileName" ascending:NO activeAccount:appDelegate.activeAccount];
  211. dispatch_async(dispatch_get_main_queue(), ^{
  212. sectionDataSource = sectionDataSourceTemp;
  213. [self.tableView reloadData];
  214. });
  215. });
  216. }
  217. #pragma --------------------------------------------------------------------------------------------
  218. #pragma mark - ==== Table ====
  219. #pragma --------------------------------------------------------------------------------------------
  220. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  221. {
  222. return 60;
  223. }
  224. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  225. {
  226. return [[sectionDataSource.sectionArrayRow allKeys] count];
  227. }
  228. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  229. {
  230. return [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:section]] count];
  231. }
  232. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  233. {
  234. return 13.0f;
  235. }
  236. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  237. {
  238. UIVisualEffectView *visualEffectView;
  239. NSString *titleSection, *numberTitle;
  240. NSInteger typeOfSession = 0;
  241. NSString *sessionDownload = [[NCCommunicationCommon shared] sessionIdentifierDownload];
  242. NSInteger queueDownload = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"session == %@", sessionDownload] sorted:nil ascending:NO] count];
  243. NSInteger queueUpload = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"session == %@", NCCommunicationCommon.shared.sessionIdentifierBackground] sorted:nil ascending:NO] count];
  244. NSInteger queueUploadWWan = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"session == %@", NCCommunicationCommon.shared.sessionIdentifierBackgroundWWan] sorted:nil ascending:NO] count];
  245. if ([[sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [sectionDataSource.sections objectAtIndex:section];
  246. if ([[sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]]) titleSection = [CCUtility getTitleSectionDate:[sectionDataSource.sections objectAtIndex:section]];
  247. NSArray *metadatas = [sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:section]];
  248. NSUInteger rowsCount = [metadatas count];
  249. visualEffectView = [[UIVisualEffectView alloc] init];
  250. visualEffectView.backgroundColor = [UIColor clearColor];
  251. // title section
  252. if ([titleSection isEqualToString:@"_none_"]) {
  253. titleSection = @"";
  254. } else if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"]) {
  255. typeOfSession = download;
  256. titleSection = NSLocalizedString(@"_title_section_download_",nil);
  257. } else if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"]) {
  258. typeOfSession = upload;
  259. titleSection = NSLocalizedString(@"_title_section_upload_",nil);
  260. } else if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"]) {
  261. typeOfSession = uploadwwan;
  262. titleSection = [NSLocalizedString(@"_title_section_upload_",nil) stringByAppendingString:@" Wi-Fi"];
  263. } else {
  264. titleSection = NSLocalizedString(titleSection,nil);
  265. }
  266. // title label on left
  267. UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(8, 3, 0, 13)];
  268. titleLabel.textColor = [UIColor blackColor];
  269. titleLabel.font = [UIFont systemFontOfSize:9];
  270. titleLabel.textAlignment = NSTextAlignmentLeft;
  271. titleLabel.text = titleSection;
  272. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  273. [visualEffectView.contentView addSubview:titleLabel];
  274. // element (s) on right
  275. UILabel *elementLabel=[[UILabel alloc]initWithFrame:CGRectMake(-8, 3, 0, 13)];
  276. elementLabel.textColor = [UIColor blackColor];
  277. elementLabel.font = [UIFont systemFontOfSize:9];
  278. elementLabel.textAlignment = NSTextAlignmentRight;
  279. elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  280. if ((typeOfSession == download && queueDownload > rowsCount) || (typeOfSession == upload && queueUpload > rowsCount) || (typeOfSession == uploadwwan && queueUploadWWan > rowsCount)) {
  281. numberTitle = [NSString stringWithFormat:@"%lu+", (unsigned long)rowsCount];
  282. } else {
  283. numberTitle = [NSString stringWithFormat:@"%lu", (unsigned long)rowsCount];
  284. }
  285. if (rowsCount > 1)
  286. elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_elements_",nil)];
  287. else
  288. elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_element_",nil)];
  289. // view
  290. [visualEffectView.contentView addSubview:elementLabel];
  291. return visualEffectView;
  292. }
  293. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  294. {
  295. NSString *titleSection;
  296. NSString *element_s;
  297. if ([[sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [sectionDataSource.sections objectAtIndex:section];
  298. // Prepare view for title in footer
  299. UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
  300. UILabel *titleFooterLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)];
  301. titleFooterLabel.textColor = [UIColor blackColor];
  302. titleFooterLabel.font = [UIFont systemFontOfSize:12];
  303. titleFooterLabel.textAlignment = NSTextAlignmentCenter;
  304. // Footer Download
  305. if ([titleSection containsString:@"download"] && titleSection != nil) {
  306. NSString *session = [[NCCommunicationCommon shared] sessionIdentifierDownload];
  307. NSInteger queueDownload = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"session == %@", session] sorted:nil ascending:NO] count];
  308. // element or elements ?
  309. if (queueDownload > 1) element_s = NSLocalizedString(@"_elements_",nil);
  310. else element_s = NSLocalizedString(@"_element_",nil);
  311. // Num record to upload
  312. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_download_", nil), queueDownload, element_s]];
  313. titleFooterLabel.attributedText = stringFooter;
  314. [view addSubview:titleFooterLabel];
  315. return view;
  316. }
  317. // Footer Upload
  318. if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
  319. NSInteger queueUpload = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"session == %@", NCCommunicationCommon.shared.sessionIdentifierBackground] sorted:nil ascending:NO] count];
  320. // element or elements ?
  321. if (queueUpload > 1) element_s = NSLocalizedString(@"_elements_",nil);
  322. else element_s = NSLocalizedString(@"_element_",nil);
  323. // Num record to upload
  324. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_", nil), queueUpload, element_s]];
  325. titleFooterLabel.attributedText = stringFooter;
  326. [view addSubview:titleFooterLabel];
  327. return view;
  328. }
  329. // Footer Upload WWAN
  330. if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
  331. NSInteger queueUploadWWan = [[[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"session == %@", NCCommunicationCommon.shared.sessionIdentifierBackgroundWWan] sorted:nil ascending:NO] count];
  332. // element or elements ?
  333. if (queueUploadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
  334. else element_s = NSLocalizedString(@"_element_",nil);
  335. // Add the symbol WiFi and Num record
  336. NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
  337. attachment.image = [UIImage imageNamed:@"WiFiSmall"];
  338. NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
  339. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[@" " stringByAppendingString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_wwan_", nil), queueUploadWWan,element_s]]];
  340. [stringFooter insertAttributedString:attachmentString atIndex:0];
  341. titleFooterLabel.attributedText = stringFooter;
  342. [view addSubview:titleFooterLabel];
  343. return view;
  344. }
  345. return nil;
  346. }
  347. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  348. {
  349. //NSString *titleSection;
  350. //if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]])
  351. // titleSection = [_sectionDataSource.sections objectAtIndex:section];
  352. //if ([titleSection rangeOfString:@"upload"].location != NSNotFound && [titleSection rangeOfString:@"wwan"].location != NSNotFound && titleSection != nil) return 18.0f;
  353. //else return 0.0f;
  354. return 18.0f;
  355. }
  356. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  357. {
  358. return [sectionDataSource.sections indexOfObject:title];
  359. }
  360. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  361. {
  362. NSString *ocId = [[sectionDataSource.sectionArrayRow objectForKey:[sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  363. tableMetadata *metadata = [sectionDataSource.allRecordsDataSource objectForKey:ocId];
  364. if (metadata == nil || [[NCManageDatabase sharedInstance] isTableInvalidated:metadata]) {
  365. return [CCCellMainTransfer new];
  366. }
  367. UITableViewCell *cell = [[NCMainCommon sharedInstance] cellForRowAtIndexPath:indexPath tableView:tableView metadata:metadata metadataFolder:nil serverUrl:metadata.serverUrl autoUploadFileName:@"" autoUploadDirectory:@"" tableShare:nil];
  368. // TRANSFER
  369. if ([cell isKindOfClass:[CCCellMainTransfer class]]) {
  370. // gesture Transfer
  371. [((CCCellMainTransfer *)cell).transferButton.stopButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  372. UILongPressGestureRecognizer *stopLongGesture = [UILongPressGestureRecognizer new];
  373. [stopLongGesture addTarget:self action:@selector(cancelAllTask:)];
  374. [((CCCellMainTransfer *)cell).transferButton.stopButton addGestureRecognizer:stopLongGesture];
  375. }
  376. return cell;
  377. }
  378. - (BOOL)indexPathIsValid:(NSIndexPath *)indexPath
  379. {
  380. if (!indexPath)
  381. return NO;
  382. NSInteger section = indexPath.section;
  383. NSInteger row = indexPath.row;
  384. NSInteger lastSectionIndex = [self numberOfSectionsInTableView:self.tableView] - 1;
  385. if (section > lastSectionIndex || lastSectionIndex < 0)
  386. return NO;
  387. NSInteger rowCount = [self.tableView numberOfRowsInSection:indexPath.section] - 1;
  388. if (rowCount < 0)
  389. return NO;
  390. return row <= rowCount;
  391. }
  392. @end