CCTransfers.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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. // Datasource
  37. CCSectionDataSourceMetadata *_sectionDataSource;
  38. }
  39. @end
  40. @implementation CCTransfers
  41. #pragma --------------------------------------------------------------------------------------------
  42. #pragma mark ===== Init =====
  43. #pragma --------------------------------------------------------------------------------------------
  44. - (id)initWithCoder:(NSCoder *)aDecoder
  45. {
  46. if (self = [super initWithCoder:aDecoder]) {
  47. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
  48. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  49. app.activeTransfers = self;
  50. }
  51. return self;
  52. }
  53. - (void)viewDidLoad {
  54. [super viewDidLoad];
  55. // Custom Cell
  56. [_tableView registerNib:[UINib nibWithNibName:@"CCTransfersCell" bundle:nil] forCellReuseIdentifier:@"Cell"];
  57. _tableView.delegate = self;
  58. _tableView.dataSource = self;
  59. _tableView.emptyDataSetDelegate = self;
  60. _tableView.emptyDataSetSource = self;
  61. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  62. _tableView.backgroundColor = [NCBrandColor sharedInstance].tableBackground;
  63. self.title = NSLocalizedString(@"_transfers_", nil);
  64. [self reloadDatasource];
  65. }
  66. // Apparirà
  67. - (void)viewWillAppear:(BOOL)animated
  68. {
  69. [super viewWillAppear:animated];
  70. // Color
  71. [app aspectNavigationControllerBar:self.navigationController.navigationBar online:[app.reachability isReachable] hidden:NO];
  72. [app aspectTabBar:self.tabBarController.tabBar hidden:NO];
  73. [self reloadDatasource];
  74. }
  75. - (void)changeTheming
  76. {
  77. if (self.isViewLoaded && self.view.window)
  78. [app changeTheming:self];
  79. }
  80. #pragma --------------------------------------------------------------------------------------------
  81. #pragma mark ==== DZNEmptyDataSetSource ====
  82. #pragma --------------------------------------------------------------------------------------------
  83. - (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView
  84. {
  85. return 0.0f;
  86. }
  87. - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
  88. {
  89. return [UIColor whiteColor];
  90. }
  91. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
  92. {
  93. return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"transfersNoRecord"] color:[NCBrandColor sharedInstance].brand];
  94. }
  95. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
  96. {
  97. NSString *text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_no_transfer_", nil)];
  98. NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:[UIColor lightGrayColor]};
  99. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  100. }
  101. - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
  102. {
  103. NSString *text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_no_transfer_sub_", nil)];
  104. NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
  105. paragraph.lineBreakMode = NSLineBreakByWordWrapping;
  106. paragraph.alignment = NSTextAlignmentCenter;
  107. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph};
  108. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  109. }
  110. #pragma --------------------------------------------------------------------------------------------
  111. #pragma mark - ===== Progress & Task Button =====
  112. #pragma --------------------------------------------------------------------------------------------
  113. - (void)triggerProgressTask:(NSNotification *)notification
  114. {
  115. NSDictionary *dict = notification.userInfo;
  116. NSString *fileID = [dict valueForKey:@"fileID"];
  117. float progress = [[dict valueForKey:@"progress"] floatValue];
  118. // Check
  119. if (!fileID)
  120. return;
  121. [app.listProgressMetadata setObject:[NSNumber numberWithFloat:progress] forKey:fileID];
  122. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:fileID];
  123. if (indexPath && indexPath.row == 0) {
  124. CCTransfersCell *cell = (CCTransfersCell *)[_tableView cellForRowAtIndexPath:indexPath];
  125. cell.progressView.progressTintColor = [UIColor blackColor];
  126. cell.progressView.hidden = NO;
  127. [cell.progressView setProgress:progress];
  128. } else {
  129. [self reloadDatasource];
  130. }
  131. }
  132. - (void)reloadTaskButton:(id)sender withEvent:(UIEvent *)event
  133. {
  134. if (app.activeMain == nil)
  135. return;
  136. UITouch * touch = [[event allTouches] anyObject];
  137. CGPoint location = [touch locationInView:_tableView];
  138. NSIndexPath * indexPath = [_tableView indexPathForRowAtPoint:location];
  139. if (indexPath) {
  140. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  141. tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  142. if (metadata)
  143. [app.activeMain reloadTaskButton:metadata];
  144. }
  145. }
  146. - (void)reloadAllTask
  147. {
  148. if (app.activeMain == nil)
  149. return;
  150. for (NSString *key in _sectionDataSource.allRecordsDataSource.allKeys) {
  151. tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:key];
  152. if ([metadata.session containsString:@"upload"] && (metadata.sessionTaskIdentifier != k_taskIdentifierStop))
  153. continue;
  154. [app.activeMain reloadTaskButton:metadata];
  155. }
  156. }
  157. - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
  158. {
  159. if (app.activeMain == nil)
  160. return;
  161. UITouch * touch = [[event allTouches] anyObject];
  162. CGPoint location = [touch locationInView:_tableView];
  163. NSIndexPath * indexPath = [_tableView indexPathForRowAtPoint:location];
  164. if (indexPath) {
  165. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  166. tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  167. if (metadata)
  168. [app.activeMain cancelTaskButton:metadata reloadTable:YES];
  169. }
  170. }
  171. - (void)cancelAllTask
  172. {
  173. if (app.activeMain == nil)
  174. return;
  175. BOOL lastAndRefresh = NO;
  176. for (NSString *key in _sectionDataSource.allRecordsDataSource.allKeys) {
  177. if ([key isEqualToString:[_sectionDataSource.allRecordsDataSource.allKeys lastObject]])
  178. lastAndRefresh = YES;
  179. tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:key];
  180. if ([metadata.session containsString:@"upload"] && ((metadata.sessionTaskIdentifier == k_taskIdentifierDone) || (metadata.sessionTaskIdentifier >= 0)))
  181. continue;
  182. [app.activeMain cancelTaskButton:metadata reloadTable:lastAndRefresh];
  183. }
  184. }
  185. - (void)stopTaskButton:(id)sender withEvent:(UIEvent *)event
  186. {
  187. if (app.activeMain == nil)
  188. return;
  189. UITouch * touch = [[event allTouches] anyObject];
  190. CGPoint location = [touch locationInView:_tableView];
  191. NSIndexPath * indexPath = [_tableView indexPathForRowAtPoint:location];
  192. if (indexPath) {
  193. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  194. tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  195. if (metadata)
  196. [app.activeMain stopTaskButton:metadata];
  197. }
  198. }
  199. - (void)stopAllTask
  200. {
  201. if (app.activeMain == nil)
  202. return;
  203. for (NSString *key in _sectionDataSource.allRecordsDataSource.allKeys) {
  204. tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:key];
  205. if ([metadata.session containsString:@"download"]) {
  206. [app.activeMain cancelTaskButton:metadata reloadTable:YES];
  207. continue;
  208. }
  209. if ([metadata.session containsString:@"upload"] && ((metadata.sessionTaskIdentifier == k_taskIdentifierDone) || (metadata.sessionTaskIdentifier >= 0)))
  210. continue;
  211. [app.activeMain stopTaskButton:metadata];
  212. }
  213. }
  214. #pragma --------------------------------------------------------------------------------------------
  215. #pragma mark - ==== download Thumbnail ====
  216. #pragma --------------------------------------------------------------------------------------------
  217. - (void)downloadThumbnailSuccess:(CCMetadataNet *)metadataNet
  218. {
  219. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadataNet.fileID];
  220. if (indexPath && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadataNet.fileID]]) {
  221. [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  222. }
  223. }
  224. #pragma --------------------------------------------------------------------------------------------
  225. #pragma mark - ==== Datasource ====
  226. #pragma --------------------------------------------------------------------------------------------
  227. - (void)reloadDatasource
  228. {
  229. // test
  230. if (app.activeAccount.length == 0)
  231. return;
  232. NSArray *recordsTableMetadata = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND ((session CONTAINS 'upload') OR (session CONTAINS 'download' AND (sessionSelector != 'loadPlist')))", app.activeAccount] sorted:@"sessionTaskIdentifier" ascending:YES];
  233. _sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:app.listProgressMetadata e2eEncryptions:nil groupByField:@"session" activeAccount:app.activeAccount];
  234. [_tableView reloadData];
  235. }
  236. #pragma --------------------------------------------------------------------------------------------
  237. #pragma mark - ==== Table ====
  238. #pragma --------------------------------------------------------------------------------------------
  239. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  240. {
  241. return 50;
  242. }
  243. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  244. {
  245. return [[_sectionDataSource.sectionArrayRow allKeys] count];
  246. }
  247. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  248. {
  249. return [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]] count];
  250. }
  251. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  252. {
  253. return 13.0f;
  254. }
  255. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  256. {
  257. UIVisualEffectView *visualEffectView;
  258. NSString *titleSection, *numberTitle;
  259. NSInteger typeOfSession = 0;
  260. NSInteger queueDownload = [[[NCManageDatabase sharedInstance] getTableMetadataDownload] count] + [[NCManageDatabase sharedInstance] countQueueDownloadWithSession:k_download_session];
  261. NSInteger queueDownloadWWan = [[[NCManageDatabase sharedInstance] getTableMetadataDownloadWWan] count] + [[NCManageDatabase sharedInstance] countQueueDownloadWithSession:k_download_session_wwan];
  262. NSInteger queueUpload = [[[NCManageDatabase sharedInstance] getTableMetadataUpload] count] + [[NCManageDatabase sharedInstance] countQueueUploadWithSession:k_upload_session];
  263. NSInteger queueUploadWWan = [[[NCManageDatabase sharedInstance] getTableMetadataUploadWWan] count] + [[NCManageDatabase sharedInstance] countQueueUploadWithSession:k_upload_session_wwan];
  264. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
  265. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]]) titleSection = [CCUtility getTitleSectionDate:[_sectionDataSource.sections objectAtIndex:section]];
  266. NSArray *metadatas = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]];
  267. NSUInteger rowsCount = [metadatas count];
  268. visualEffectView = [[UIVisualEffectView alloc] init];
  269. visualEffectView.backgroundColor = [UIColor clearColor];
  270. // title section
  271. if ([titleSection isEqualToString:@"_none_"]) {
  272. titleSection = @"";
  273. } else if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"]) {
  274. typeOfSession = download;
  275. titleSection = NSLocalizedString(@"_title_section_download_",nil);
  276. } else if ([titleSection containsString:@"download"] && [titleSection containsString:@"wwan"]) {
  277. typeOfSession = downloadwwan;
  278. titleSection = [NSLocalizedString(@"_title_section_download_",nil) stringByAppendingString:@" Wi-Fi"];
  279. } else if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"]) {
  280. typeOfSession = upload;
  281. titleSection = NSLocalizedString(@"_title_section_upload_",nil);
  282. } else if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"]) {
  283. typeOfSession = uploadwwan;
  284. titleSection = [NSLocalizedString(@"_title_section_upload_",nil) stringByAppendingString:@" Wi-Fi"];
  285. } else {
  286. titleSection = NSLocalizedString(titleSection,nil);
  287. }
  288. // title label on left
  289. UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(8, 3, 0, 13)];
  290. titleLabel.textColor = [UIColor blackColor];
  291. titleLabel.font = [UIFont systemFontOfSize:9];
  292. titleLabel.textAlignment = NSTextAlignmentLeft;
  293. titleLabel.text = titleSection;
  294. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  295. [visualEffectView.contentView addSubview:titleLabel];
  296. // element (s) on right
  297. UILabel *elementLabel=[[UILabel alloc]initWithFrame:CGRectMake(-8, 3, 0, 13)];
  298. elementLabel.textColor = [UIColor blackColor];
  299. elementLabel.font = [UIFont systemFontOfSize:9];
  300. elementLabel.textAlignment = NSTextAlignmentRight;
  301. elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  302. if ((typeOfSession == download && queueDownload > rowsCount) || (typeOfSession == downloadwwan && queueDownloadWWan > rowsCount) ||
  303. (typeOfSession == upload && queueUpload > rowsCount) || (typeOfSession == uploadwwan && queueUploadWWan > rowsCount)) {
  304. numberTitle = [NSString stringWithFormat:@"%lu+", (unsigned long)rowsCount];
  305. } else {
  306. numberTitle = [NSString stringWithFormat:@"%lu", (unsigned long)rowsCount];
  307. }
  308. if (rowsCount > 1)
  309. elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_elements_",nil)];
  310. else
  311. elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_element_",nil)];
  312. // view
  313. [visualEffectView.contentView addSubview:elementLabel];
  314. return visualEffectView;
  315. }
  316. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  317. {
  318. NSString *titleSection;
  319. NSString *element_s;
  320. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
  321. // Prepare view for title in footer
  322. UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
  323. UILabel *titleFooterLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)];
  324. titleFooterLabel.textColor = [UIColor blackColor];
  325. titleFooterLabel.font = [UIFont systemFontOfSize:12];
  326. titleFooterLabel.textAlignment = NSTextAlignmentCenter;
  327. // Footer Download
  328. if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
  329. NSInteger queueDownload = [[[NCManageDatabase sharedInstance] getTableMetadataDownload] count] + [[NCManageDatabase sharedInstance] countQueueDownloadWithSession:k_download_session];
  330. // element or elements ?
  331. if (queueDownload > 1) element_s = NSLocalizedString(@"_elements_",nil);
  332. else element_s = NSLocalizedString(@"_element_",nil);
  333. // Num record to upload
  334. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_download_", nil), queueDownload, element_s]];
  335. titleFooterLabel.attributedText = stringFooter;
  336. [view addSubview:titleFooterLabel];
  337. return view;
  338. }
  339. // Footer Download WWAN
  340. if ([titleSection containsString:@"download"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
  341. NSInteger queueDownloadWWan = [[[NCManageDatabase sharedInstance] getTableMetadataDownloadWWan] count] + [[NCManageDatabase sharedInstance] countQueueDownloadWithSession:k_download_session_wwan];
  342. // element or elements ?
  343. if (queueDownloadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
  344. else element_s = NSLocalizedString(@"_element_",nil);
  345. // Add the symbol WiFi and Num record
  346. NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
  347. attachment.image = [UIImage imageNamed:@"WiFiSmall"];
  348. NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
  349. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[@" " stringByAppendingString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_download_wwan_", nil), queueDownloadWWan, element_s]]];
  350. [stringFooter insertAttributedString:attachmentString atIndex:0];
  351. titleFooterLabel.attributedText = stringFooter;
  352. [view addSubview:titleFooterLabel];
  353. return view;
  354. }
  355. // Footer Upload
  356. if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
  357. NSInteger queueUpload = [[[NCManageDatabase sharedInstance] getTableMetadataUpload] count] + [[NCManageDatabase sharedInstance] countQueueUploadWithSession:k_upload_session];
  358. // element or elements ?
  359. if (queueUpload > 1) element_s = NSLocalizedString(@"_elements_",nil);
  360. else element_s = NSLocalizedString(@"_element_",nil);
  361. // Num record to upload
  362. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_", nil), queueUpload, element_s]];
  363. titleFooterLabel.attributedText = stringFooter;
  364. [view addSubview:titleFooterLabel];
  365. return view;
  366. }
  367. // Footer Upload WWAN
  368. if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
  369. NSInteger queueUploadWWan = [[[NCManageDatabase sharedInstance] getTableMetadataUploadWWan] count] + [[NCManageDatabase sharedInstance] countQueueUploadWithSession:k_upload_session_wwan];
  370. // element or elements ?
  371. if (queueUploadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
  372. else element_s = NSLocalizedString(@"_element_",nil);
  373. // Add the symbol WiFi and Num record
  374. NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
  375. attachment.image = [UIImage imageNamed:@"WiFiSmall"];
  376. NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
  377. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[@" " stringByAppendingString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_wwan_", nil), queueUploadWWan,element_s]]];
  378. [stringFooter insertAttributedString:attachmentString atIndex:0];
  379. titleFooterLabel.attributedText = stringFooter;
  380. [view addSubview:titleFooterLabel];
  381. return view;
  382. }
  383. return nil;
  384. }
  385. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  386. {
  387. //NSString *titleSection;
  388. //if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]])
  389. // titleSection = [_sectionDataSource.sections objectAtIndex:section];
  390. //if ([titleSection rangeOfString:@"upload"].location != NSNotFound && [titleSection rangeOfString:@"wwan"].location != NSNotFound && titleSection != nil) return 18.0f;
  391. //else return 0.0f;
  392. return 18.0f;
  393. }
  394. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  395. {
  396. return [_sectionDataSource.sections indexOfObject:title];
  397. }
  398. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  399. {
  400. NSString *dataFile;
  401. NSString *lunghezzaFile;
  402. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  403. tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  404. CCTransfersCell *cell = (CCTransfersCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
  405. cell.backgroundColor = [UIColor clearColor];
  406. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  407. // ----------------------------------------------------------------------------------------------------------
  408. // DEFAULT
  409. // ----------------------------------------------------------------------------------------------------------
  410. cell.file.image = nil;
  411. cell.status.image = nil;
  412. cell.labelTitle.enabled = YES;
  413. cell.labelTitle.text = @"";
  414. cell.labelInfoFile.enabled = YES;
  415. cell.labelInfoFile.text = @"";
  416. cell.progressView.progress = 0.0;
  417. cell.progressView.hidden = YES;
  418. cell.cancelTaskButton.hidden = YES;
  419. cell.reloadTaskButton.hidden = YES;
  420. cell.stopTaskButton.hidden = YES;
  421. cell.labelTitle.textColor = [UIColor blackColor];
  422. cell.labelInfoFile.textColor = [UIColor blackColor];
  423. // ----------------------------------------------------------------------------------------------------------
  424. // File Name & Folder
  425. // ----------------------------------------------------------------------------------------------------------
  426. // nome del file
  427. cell.labelTitle.text = metadata.fileName;
  428. // è una directory
  429. if (metadata.directory) {
  430. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  431. cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
  432. lunghezzaFile = @" ";
  433. } else {
  434. // è un file
  435. dataFile = [CCUtility dateDiff:metadata.date];
  436. lunghezzaFile = [CCUtility transformedSize:metadata.size];
  437. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  438. [dateFormatter setDateStyle:NSDateFormatterShortStyle];
  439. [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
  440. cell.accessoryType = UITableViewCellAccessoryNone;
  441. }
  442. // ----------------------------------------------------------------------------------------------------------
  443. // File Image View
  444. // ----------------------------------------------------------------------------------------------------------
  445. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  446. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]]) {
  447. cell.file.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
  448. } else {
  449. cell.file.image = [UIImage imageNamed:metadata.iconName];
  450. if (metadata.thumbnailExists)
  451. [[CCActions sharedInstance] downloadTumbnail:metadata delegate:self];
  452. }
  453. // ----------------------------------------------------------------------------------------------------------
  454. // downloadFile
  455. // ----------------------------------------------------------------------------------------------------------
  456. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"download"].location != NSNotFound) {
  457. cell.status.image = [UIImage imageNamed:@"statusdownload"];
  458. // Fai comparire il RELOAD e lo STOP solo se non è un Task Plist
  459. [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:@"stoptask"] forState:UIControlStateNormal];
  460. cell.cancelTaskButton.hidden = NO;
  461. [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:@"reloadtask"] forState:UIControlStateNormal];
  462. cell.reloadTaskButton.hidden = NO;
  463. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  464. float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  465. if (progress > 0) {
  466. cell.progressView.progressTintColor = [UIColor blackColor];
  467. cell.progressView.progress = progress;
  468. cell.progressView.hidden = NO;
  469. }
  470. // ----------------------------------------------------------------------------------------------------------
  471. // downloadFile Error
  472. // ----------------------------------------------------------------------------------------------------------
  473. if (metadata.sessionTaskIdentifier == k_taskIdentifierError) {
  474. cell.status.image = [UIImage imageNamed:@"statuserror"];
  475. if ([metadata.sessionError length] == 0)
  476. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_downloaded_",nil)];
  477. else
  478. cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
  479. }
  480. }
  481. // ----------------------------------------------------------------------------------------------------------
  482. // uploadFile
  483. // ----------------------------------------------------------------------------------------------------------
  484. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"upload"].location != NSNotFound) {
  485. cell.status.image = [UIImage imageNamed:@"statusupload"];
  486. [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:@"removetask"] forState:UIControlStateNormal];
  487. cell.cancelTaskButton.hidden = NO;
  488. if (metadata.sessionTaskIdentifier == k_taskIdentifierStop) {
  489. [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:@"reloadtask"] forState:UIControlStateNormal];
  490. cell.status.image = [UIImage imageNamed:@"statusstop"];
  491. cell.reloadTaskButton.hidden = NO;
  492. cell.stopTaskButton.hidden = YES;
  493. } else {
  494. [cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:@"stoptask"] forState:UIControlStateNormal];
  495. cell.stopTaskButton.hidden = NO;
  496. cell.reloadTaskButton.hidden = YES;
  497. }
  498. // se non c'è una preview in bianconero metti l'immagine di default
  499. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]] == NO)
  500. cell.file.image = [UIImage imageNamed:@"uploaddisable"];
  501. cell.labelTitle.enabled = NO;
  502. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  503. float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  504. if (progress > 0) {
  505. cell.progressView.progressTintColor = [UIColor blackColor];
  506. cell.progressView.progress = progress;
  507. cell.progressView.hidden = NO;
  508. }
  509. // ----------------------------------------------------------------------------------------------------------
  510. // uploadFileError
  511. // ----------------------------------------------------------------------------------------------------------
  512. if (metadata.sessionTaskIdentifier == k_taskIdentifierError) {
  513. cell.labelTitle.enabled = NO;
  514. cell.status.image = [UIImage imageNamed:@"statuserror"];
  515. if ([metadata.sessionError length] == 0)
  516. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_uploaded_",nil)];
  517. else
  518. cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
  519. }
  520. }
  521. [cell.reloadTaskButton addTarget:self action:@selector(reloadTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  522. [cell.cancelTaskButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  523. [cell.stopTaskButton addTarget:self action:@selector(stopTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  524. return cell;
  525. }
  526. @end