CCTransfers.m 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. //
  2. // CCTransfers.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 12/04/17.
  6. // Copyright (c) 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCTransfers.h"
  24. #import "AppDelegate.h"
  25. #import "CCMain.h"
  26. #import "CCDetail.h"
  27. #import "CCSection.h"
  28. #import "CCTransfersCell.h"
  29. #import "NCBridgeSwift.h"
  30. #define download 1
  31. #define downloadwwan 2
  32. #define upload 3
  33. #define uploadwwan 4
  34. @interface CCTransfers ()
  35. {
  36. AppDelegate *appDelegate;
  37. // Datasource
  38. CCSectionDataSourceMetadata *_sectionDataSource;
  39. }
  40. @end
  41. @implementation CCTransfers
  42. #pragma --------------------------------------------------------------------------------------------
  43. #pragma mark ===== Init =====
  44. #pragma --------------------------------------------------------------------------------------------
  45. - (id)initWithCoder:(NSCoder *)aDecoder
  46. {
  47. if (self = [super initWithCoder:aDecoder]) {
  48. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  49. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
  50. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  51. appDelegate.activeTransfers = self;
  52. }
  53. return self;
  54. }
  55. - (void)viewDidLoad {
  56. [super viewDidLoad];
  57. // Custom Cell
  58. [_tableView registerNib:[UINib nibWithNibName:@"CCTransfersCell" bundle:nil] forCellReuseIdentifier:@"Cell"];
  59. _tableView.delegate = self;
  60. _tableView.dataSource = self;
  61. _tableView.emptyDataSetDelegate = self;
  62. _tableView.emptyDataSetSource = self;
  63. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  64. _tableView.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
  65. self.title = NSLocalizedString(@"_transfers_", nil);
  66. [self reloadDatasource];
  67. }
  68. // Apparirà
  69. - (void)viewWillAppear:(BOOL)animated
  70. {
  71. [super viewWillAppear:animated];
  72. // Color
  73. [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
  74. [appDelegate aspectTabBar:self.tabBarController.tabBar hidden:NO];
  75. [self reloadDatasource];
  76. }
  77. - (void)changeTheming
  78. {
  79. if (self.isViewLoaded && self.view.window)
  80. [appDelegate changeTheming:self];
  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 [UIColor whiteColor];
  92. }
  93. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
  94. {
  95. return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"loadNoRecord"] 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 - ===== Progress & Task Button =====
  114. #pragma --------------------------------------------------------------------------------------------
  115. - (void)triggerProgressTask:(NSNotification *)notification
  116. {
  117. NSDictionary *dict = notification.userInfo;
  118. NSString *fileID = [dict valueForKey:@"fileID"];
  119. float progress = [[dict valueForKey:@"progress"] floatValue];
  120. // Check
  121. if (!fileID)
  122. return;
  123. [appDelegate.listProgressMetadata setObject:[NSNumber numberWithFloat:progress] forKey:fileID];
  124. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:fileID];
  125. if (indexPath && indexPath.row == 0) {
  126. CCTransfersCell *cell = (CCTransfersCell *)[_tableView cellForRowAtIndexPath:indexPath];
  127. cell.progressView.progressTintColor = [UIColor blackColor];
  128. cell.progressView.hidden = NO;
  129. [cell.progressView setProgress:progress];
  130. } else {
  131. [self reloadDatasource];
  132. }
  133. }
  134. - (void)reloadTaskButton:(id)sender withEvent:(UIEvent *)event
  135. {
  136. if (appDelegate.activeMain == nil)
  137. return;
  138. UITouch * touch = [[event allTouches] anyObject];
  139. CGPoint location = [touch locationInView:_tableView];
  140. NSIndexPath * indexPath = [_tableView indexPathForRowAtPoint:location];
  141. if (indexPath) {
  142. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  143. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  144. if (metadata)
  145. [appDelegate.activeMain reloadTaskButton:metadata];
  146. }
  147. }
  148. - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
  149. {
  150. if (appDelegate.activeMain == nil)
  151. return;
  152. UITouch * touch = [[event allTouches] anyObject];
  153. CGPoint location = [touch locationInView:_tableView];
  154. NSIndexPath * indexPath = [_tableView indexPathForRowAtPoint:location];
  155. if (indexPath) {
  156. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  157. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  158. if (metadata)
  159. [appDelegate.activeMain cancelTaskButton:metadata reloadTable:YES];
  160. }
  161. }
  162. - (void)cancelAllTask
  163. {
  164. if (appDelegate.activeMain == nil)
  165. return;
  166. BOOL lastAndRefresh = NO;
  167. for (NSString *key in _sectionDataSource.allRecordsDataSource.allKeys) {
  168. if ([key isEqualToString:[_sectionDataSource.allRecordsDataSource.allKeys lastObject]])
  169. lastAndRefresh = YES;
  170. tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:key];
  171. if ([metadata.session containsString:@"upload"] && ((metadata.sessionTaskIdentifier == k_taskIdentifierDone) || (metadata.sessionTaskIdentifier >= 0)))
  172. continue;
  173. [appDelegate.activeMain cancelTaskButton:metadata reloadTable:lastAndRefresh];
  174. }
  175. }
  176. - (void)stopTaskButton:(id)sender withEvent:(UIEvent *)event
  177. {
  178. if (appDelegate.activeMain == nil)
  179. return;
  180. UITouch * touch = [[event allTouches] anyObject];
  181. CGPoint location = [touch locationInView:_tableView];
  182. NSIndexPath * indexPath = [_tableView indexPathForRowAtPoint:location];
  183. if (indexPath) {
  184. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  185. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  186. if (metadata)
  187. [appDelegate.activeMain stopTaskButton:metadata];
  188. }
  189. }
  190. - (void)stopAllTask
  191. {
  192. if (appDelegate.activeMain == nil)
  193. return;
  194. for (NSString *key in _sectionDataSource.allRecordsDataSource.allKeys) {
  195. tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:key];
  196. if ([metadata.session containsString:@"download"]) {
  197. [appDelegate.activeMain cancelTaskButton:metadata reloadTable:YES];
  198. continue;
  199. }
  200. if ([metadata.session containsString:@"upload"] && ((metadata.sessionTaskIdentifier == k_taskIdentifierDone) || (metadata.sessionTaskIdentifier >= 0)))
  201. continue;
  202. [appDelegate.activeMain stopTaskButton:metadata];
  203. }
  204. }
  205. #pragma --------------------------------------------------------------------------------------------
  206. #pragma mark - ==== download Thumbnail ====
  207. #pragma --------------------------------------------------------------------------------------------
  208. - (void)downloadThumbnailSuccessFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  209. {
  210. // Check Active Account
  211. if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
  212. return;
  213. if (errorCode == 0) {
  214. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadataNet.fileID];
  215. if (indexPath && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, metadataNet.fileID]]) {
  216. [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  217. }
  218. }
  219. }
  220. #pragma --------------------------------------------------------------------------------------------
  221. #pragma mark - ==== Datasource ====
  222. #pragma --------------------------------------------------------------------------------------------
  223. - (void)reloadDatasource
  224. {
  225. // test
  226. if (appDelegate.activeAccount.length == 0)
  227. return;
  228. NSArray *recordsTableMetadata = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND ((session CONTAINS 'upload') OR (session CONTAINS 'download'))", appDelegate.activeAccount] sorted:@"sessionTaskIdentifier" ascending:YES];
  229. _sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:appDelegate.listProgressMetadata groupByField:@"session" activeAccount:appDelegate.activeAccount];
  230. [_tableView reloadData];
  231. }
  232. #pragma --------------------------------------------------------------------------------------------
  233. #pragma mark - ==== Table ====
  234. #pragma --------------------------------------------------------------------------------------------
  235. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  236. {
  237. return 50;
  238. }
  239. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  240. {
  241. return [[_sectionDataSource.sectionArrayRow allKeys] count];
  242. }
  243. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  244. {
  245. return [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]] count];
  246. }
  247. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  248. {
  249. return 13.0f;
  250. }
  251. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  252. {
  253. UIVisualEffectView *visualEffectView;
  254. NSString *titleSection, *numberTitle;
  255. NSInteger typeOfSession = 0;
  256. NSInteger queueDownload = [[CCNetworking sharedNetworking] getNumDownloadInProgressWWan:NO];
  257. NSInteger queueDownloadWWan = [[CCNetworking sharedNetworking] getNumDownloadInProgressWWan:YES];
  258. NSInteger queueUpload = [[CCNetworking sharedNetworking] getNumUploadInProgressWWan:NO];
  259. NSInteger queueUploadWWan = [[CCNetworking sharedNetworking] getNumUploadInProgressWWan:YES];
  260. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
  261. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]]) titleSection = [CCUtility getTitleSectionDate:[_sectionDataSource.sections objectAtIndex:section]];
  262. NSArray *metadatas = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]];
  263. NSUInteger rowsCount = [metadatas count];
  264. visualEffectView = [[UIVisualEffectView alloc] init];
  265. visualEffectView.backgroundColor = [UIColor clearColor];
  266. // title section
  267. if ([titleSection isEqualToString:@"_none_"]) {
  268. titleSection = @"";
  269. } else if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"]) {
  270. typeOfSession = download;
  271. titleSection = NSLocalizedString(@"_title_section_download_",nil);
  272. } else if ([titleSection containsString:@"download"] && [titleSection containsString:@"wwan"]) {
  273. typeOfSession = downloadwwan;
  274. titleSection = [NSLocalizedString(@"_title_section_download_",nil) stringByAppendingString:@" Wi-Fi"];
  275. } else if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"]) {
  276. typeOfSession = upload;
  277. titleSection = NSLocalizedString(@"_title_section_upload_",nil);
  278. } else if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"]) {
  279. typeOfSession = uploadwwan;
  280. titleSection = [NSLocalizedString(@"_title_section_upload_",nil) stringByAppendingString:@" Wi-Fi"];
  281. } else {
  282. titleSection = NSLocalizedString(titleSection,nil);
  283. }
  284. // title label on left
  285. UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(8, 3, 0, 13)];
  286. titleLabel.textColor = [UIColor blackColor];
  287. titleLabel.font = [UIFont systemFontOfSize:9];
  288. titleLabel.textAlignment = NSTextAlignmentLeft;
  289. titleLabel.text = titleSection;
  290. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  291. [visualEffectView.contentView addSubview:titleLabel];
  292. // element (s) on right
  293. UILabel *elementLabel=[[UILabel alloc]initWithFrame:CGRectMake(-8, 3, 0, 13)];
  294. elementLabel.textColor = [UIColor blackColor];
  295. elementLabel.font = [UIFont systemFontOfSize:9];
  296. elementLabel.textAlignment = NSTextAlignmentRight;
  297. elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  298. if ((typeOfSession == download && queueDownload > rowsCount) || (typeOfSession == downloadwwan && queueDownloadWWan > rowsCount) ||
  299. (typeOfSession == upload && queueUpload > rowsCount) || (typeOfSession == uploadwwan && queueUploadWWan > rowsCount)) {
  300. numberTitle = [NSString stringWithFormat:@"%lu+", (unsigned long)rowsCount];
  301. } else {
  302. numberTitle = [NSString stringWithFormat:@"%lu", (unsigned long)rowsCount];
  303. }
  304. if (rowsCount > 1)
  305. elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_elements_",nil)];
  306. else
  307. elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_element_",nil)];
  308. // view
  309. [visualEffectView.contentView addSubview:elementLabel];
  310. return visualEffectView;
  311. }
  312. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  313. {
  314. NSString *titleSection;
  315. NSString *element_s;
  316. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
  317. // Prepare view for title in footer
  318. UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
  319. UILabel *titleFooterLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)];
  320. titleFooterLabel.textColor = [UIColor blackColor];
  321. titleFooterLabel.font = [UIFont systemFontOfSize:12];
  322. titleFooterLabel.textAlignment = NSTextAlignmentCenter;
  323. // Footer Download
  324. if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
  325. NSInteger queueDownload = [[CCNetworking sharedNetworking] getNumDownloadInProgressWWan:NO];
  326. // element or elements ?
  327. if (queueDownload > 1) element_s = NSLocalizedString(@"_elements_",nil);
  328. else element_s = NSLocalizedString(@"_element_",nil);
  329. // Num record to upload
  330. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_download_", nil), queueDownload, element_s]];
  331. titleFooterLabel.attributedText = stringFooter;
  332. [view addSubview:titleFooterLabel];
  333. return view;
  334. }
  335. // Footer Download WWAN
  336. if ([titleSection containsString:@"download"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
  337. NSInteger queueDownloadWWan = [[CCNetworking sharedNetworking] getNumDownloadInProgressWWan:YES];
  338. // element or elements ?
  339. if (queueDownloadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
  340. else element_s = NSLocalizedString(@"_element_",nil);
  341. // Add the symbol WiFi and Num record
  342. NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
  343. attachment.image = [UIImage imageNamed:@"WiFiSmall"];
  344. NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
  345. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[@" " stringByAppendingString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_download_wwan_", nil), queueDownloadWWan, element_s]]];
  346. [stringFooter insertAttributedString:attachmentString atIndex:0];
  347. titleFooterLabel.attributedText = stringFooter;
  348. [view addSubview:titleFooterLabel];
  349. return view;
  350. }
  351. // Footer Upload
  352. if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
  353. NSInteger queueUpload = [[CCNetworking sharedNetworking] getNumUploadInProgressWWan:NO];
  354. // element or elements ?
  355. if (queueUpload > 1) element_s = NSLocalizedString(@"_elements_",nil);
  356. else element_s = NSLocalizedString(@"_element_",nil);
  357. // Num record to upload
  358. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_", nil), queueUpload, element_s]];
  359. titleFooterLabel.attributedText = stringFooter;
  360. [view addSubview:titleFooterLabel];
  361. return view;
  362. }
  363. // Footer Upload WWAN
  364. if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
  365. NSInteger queueUploadWWan = [[CCNetworking sharedNetworking] getNumUploadInProgressWWan:YES];
  366. // element or elements ?
  367. if (queueUploadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
  368. else element_s = NSLocalizedString(@"_element_",nil);
  369. // Add the symbol WiFi and Num record
  370. NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
  371. attachment.image = [UIImage imageNamed:@"WiFiSmall"];
  372. NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
  373. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[@" " stringByAppendingString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_wwan_", nil), queueUploadWWan,element_s]]];
  374. [stringFooter insertAttributedString:attachmentString atIndex:0];
  375. titleFooterLabel.attributedText = stringFooter;
  376. [view addSubview:titleFooterLabel];
  377. return view;
  378. }
  379. return nil;
  380. }
  381. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  382. {
  383. //NSString *titleSection;
  384. //if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]])
  385. // titleSection = [_sectionDataSource.sections objectAtIndex:section];
  386. //if ([titleSection rangeOfString:@"upload"].location != NSNotFound && [titleSection rangeOfString:@"wwan"].location != NSNotFound && titleSection != nil) return 18.0f;
  387. //else return 0.0f;
  388. return 18.0f;
  389. }
  390. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  391. {
  392. return [_sectionDataSource.sections indexOfObject:title];
  393. }
  394. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  395. {
  396. NSString *dataFile;
  397. NSString *lunghezzaFile;
  398. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  399. tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  400. CCTransfersCell *cell = (CCTransfersCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
  401. cell.backgroundColor = [UIColor clearColor];
  402. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  403. // ----------------------------------------------------------------------------------------------------------
  404. // DEFAULT
  405. // ----------------------------------------------------------------------------------------------------------
  406. cell.file.image = nil;
  407. cell.status.image = nil;
  408. cell.labelTitle.enabled = YES;
  409. cell.labelTitle.text = @"";
  410. cell.labelInfoFile.enabled = YES;
  411. cell.labelInfoFile.text = @"";
  412. cell.progressView.progress = 0.0;
  413. cell.progressView.hidden = YES;
  414. cell.cancelTaskButton.hidden = YES;
  415. cell.reloadTaskButton.hidden = YES;
  416. cell.stopTaskButton.hidden = YES;
  417. cell.labelTitle.textColor = [UIColor blackColor];
  418. cell.labelInfoFile.textColor = [UIColor blackColor];
  419. // ----------------------------------------------------------------------------------------------------------
  420. // File Name & Folder
  421. // ----------------------------------------------------------------------------------------------------------
  422. // nome del file
  423. cell.labelTitle.text = metadata.fileNameView;
  424. // è una directory
  425. if (metadata.directory) {
  426. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  427. cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
  428. lunghezzaFile = @" ";
  429. } else {
  430. // è un file
  431. dataFile = [CCUtility dateDiff:metadata.date];
  432. lunghezzaFile = [CCUtility transformedSize:metadata.size];
  433. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  434. [dateFormatter setDateStyle:NSDateFormatterShortStyle];
  435. [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
  436. cell.accessoryType = UITableViewCellAccessoryNone;
  437. }
  438. // ----------------------------------------------------------------------------------------------------------
  439. // File Image View
  440. // ----------------------------------------------------------------------------------------------------------
  441. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  442. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, metadata.fileID]]) {
  443. cell.file.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, metadata.fileID]];
  444. } else {
  445. cell.file.image = [UIImage imageNamed:metadata.iconName];
  446. if (metadata.thumbnailExists)
  447. [[CCActions sharedInstance] downloadTumbnail:metadata delegate:self];
  448. }
  449. // ----------------------------------------------------------------------------------------------------------
  450. // downloadFile
  451. // ----------------------------------------------------------------------------------------------------------
  452. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"download"].location != NSNotFound) {
  453. cell.status.image = [UIImage imageNamed:@"statusdownload"];
  454. // Fai comparire il RELOAD e lo STOP solo se non è un Task Plist
  455. [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:@"stoptask"] forState:UIControlStateNormal];
  456. cell.cancelTaskButton.hidden = NO;
  457. [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:@"reloadtask"] forState:UIControlStateNormal];
  458. cell.reloadTaskButton.hidden = NO;
  459. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  460. float progress = [[appDelegate.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  461. if (progress > 0) {
  462. cell.progressView.progressTintColor = [UIColor blackColor];
  463. cell.progressView.progress = progress;
  464. cell.progressView.hidden = NO;
  465. }
  466. // ----------------------------------------------------------------------------------------------------------
  467. // downloadFile Error
  468. // ----------------------------------------------------------------------------------------------------------
  469. if (metadata.status == k_metadataStatusDownloadError) {
  470. cell.status.image = [UIImage imageNamed:@"statuserror"];
  471. if ([metadata.sessionError length] == 0) {
  472. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_downloaded_",nil)];
  473. } else {
  474. cell.labelInfoFile.text = metadata.sessionError;
  475. }
  476. }
  477. }
  478. // ----------------------------------------------------------------------------------------------------------
  479. // uploadFile
  480. // ----------------------------------------------------------------------------------------------------------
  481. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"upload"].location != NSNotFound) {
  482. cell.status.image = [UIImage imageNamed:@"statusupload"];
  483. [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:@"removetask"] forState:UIControlStateNormal];
  484. cell.cancelTaskButton.hidden = NO;
  485. if (metadata.sessionTaskIdentifier == k_taskIdentifierStop) {
  486. [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:@"reloadtask"] forState:UIControlStateNormal];
  487. cell.status.image = [UIImage imageNamed:@"statusstop"];
  488. cell.reloadTaskButton.hidden = NO;
  489. cell.stopTaskButton.hidden = YES;
  490. } else {
  491. [cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:@"stoptask"] forState:UIControlStateNormal];
  492. cell.stopTaskButton.hidden = NO;
  493. cell.reloadTaskButton.hidden = YES;
  494. }
  495. // se non c'è una preview in bianconero metti l'immagine di default
  496. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, metadata.fileID]] == NO)
  497. cell.file.image = [UIImage imageNamed:@"uploadCloud"];
  498. cell.labelTitle.enabled = NO;
  499. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  500. float progress = [[appDelegate.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  501. if (progress > 0) {
  502. cell.progressView.progressTintColor = [UIColor blackColor];
  503. cell.progressView.progress = progress;
  504. cell.progressView.hidden = NO;
  505. }
  506. // ----------------------------------------------------------------------------------------------------------
  507. // uploadFileError
  508. // ----------------------------------------------------------------------------------------------------------
  509. if (metadata.status == k_metadataStatusUploadError) {
  510. cell.labelTitle.enabled = NO;
  511. cell.status.image = [UIImage imageNamed:@"statuserror"];
  512. if ([metadata.sessionError length] == 0) {
  513. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_uploaded_",nil)];
  514. } else {
  515. cell.labelInfoFile.text = metadata.sessionError;
  516. }
  517. }
  518. }
  519. [cell.reloadTaskButton addTarget:self action:@selector(reloadTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  520. [cell.cancelTaskButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  521. [cell.stopTaskButton addTarget:self action:@selector(stopTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  522. return cell;
  523. }
  524. @end