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