CCTransfers.m 25 KB

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