CCTransfers.m 25 KB

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