CCTransfers.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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:@"transfersNoRecord"] color:[NCBrandColor sharedInstance].brandElement];
  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)reloadAllTask
  149. {
  150. if (appDelegate.activeMain == nil)
  151. return;
  152. for (NSString *key in _sectionDataSource.allRecordsDataSource.allKeys) {
  153. tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:key];
  154. if ([metadata.session containsString:@"upload"] && (metadata.sessionTaskIdentifier != k_taskIdentifierStop))
  155. continue;
  156. [appDelegate.activeMain reloadTaskButton:metadata];
  157. }
  158. }
  159. - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
  160. {
  161. if (appDelegate.activeMain == nil)
  162. return;
  163. UITouch * touch = [[event allTouches] anyObject];
  164. CGPoint location = [touch locationInView:_tableView];
  165. NSIndexPath * indexPath = [_tableView indexPathForRowAtPoint:location];
  166. if (indexPath) {
  167. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  168. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  169. if (metadata)
  170. [appDelegate.activeMain cancelTaskButton:metadata reloadTable:YES];
  171. }
  172. }
  173. - (void)cancelAllTask
  174. {
  175. if (appDelegate.activeMain == nil)
  176. return;
  177. BOOL lastAndRefresh = NO;
  178. for (NSString *key in _sectionDataSource.allRecordsDataSource.allKeys) {
  179. if ([key isEqualToString:[_sectionDataSource.allRecordsDataSource.allKeys lastObject]])
  180. lastAndRefresh = YES;
  181. tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:key];
  182. if ([metadata.session containsString:@"upload"] && ((metadata.sessionTaskIdentifier == k_taskIdentifierDone) || (metadata.sessionTaskIdentifier >= 0)))
  183. continue;
  184. [appDelegate.activeMain cancelTaskButton:metadata reloadTable:lastAndRefresh];
  185. }
  186. }
  187. - (void)stopTaskButton:(id)sender withEvent:(UIEvent *)event
  188. {
  189. if (appDelegate.activeMain == nil)
  190. return;
  191. UITouch * touch = [[event allTouches] anyObject];
  192. CGPoint location = [touch locationInView:_tableView];
  193. NSIndexPath * indexPath = [_tableView indexPathForRowAtPoint:location];
  194. if (indexPath) {
  195. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  196. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  197. if (metadata)
  198. [appDelegate.activeMain stopTaskButton:metadata];
  199. }
  200. }
  201. - (void)stopAllTask
  202. {
  203. if (appDelegate.activeMain == nil)
  204. return;
  205. for (NSString *key in _sectionDataSource.allRecordsDataSource.allKeys) {
  206. tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:key];
  207. if ([metadata.session containsString:@"download"]) {
  208. [appDelegate.activeMain cancelTaskButton:metadata reloadTable:YES];
  209. continue;
  210. }
  211. if ([metadata.session containsString:@"upload"] && ((metadata.sessionTaskIdentifier == k_taskIdentifierDone) || (metadata.sessionTaskIdentifier >= 0)))
  212. continue;
  213. [appDelegate.activeMain stopTaskButton:metadata];
  214. }
  215. }
  216. #pragma --------------------------------------------------------------------------------------------
  217. #pragma mark - ==== download Thumbnail ====
  218. #pragma --------------------------------------------------------------------------------------------
  219. - (void)downloadThumbnailSuccess:(CCMetadataNet *)metadataNet
  220. {
  221. // Check Active Account
  222. if (![metadataNet.account isEqualToString:appDelegate.activeAccount])
  223. return;
  224. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadataNet.fileID];
  225. if (indexPath && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, metadataNet.fileID]]) {
  226. [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
  227. }
  228. }
  229. #pragma --------------------------------------------------------------------------------------------
  230. #pragma mark - ==== Datasource ====
  231. #pragma --------------------------------------------------------------------------------------------
  232. - (void)reloadDatasource
  233. {
  234. // test
  235. if (appDelegate.activeAccount.length == 0)
  236. return;
  237. NSArray *recordsTableMetadata = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND ((session CONTAINS 'upload') OR (session CONTAINS 'download'))", appDelegate.activeAccount] sorted:@"sessionTaskIdentifier" ascending:YES];
  238. _sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:appDelegate.listProgressMetadata e2eEncryptions:nil groupByField:@"session" activeAccount:appDelegate.activeAccount];
  239. [_tableView reloadData];
  240. }
  241. #pragma --------------------------------------------------------------------------------------------
  242. #pragma mark - ==== Table ====
  243. #pragma --------------------------------------------------------------------------------------------
  244. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  245. {
  246. return 50;
  247. }
  248. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  249. {
  250. return [[_sectionDataSource.sectionArrayRow allKeys] count];
  251. }
  252. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  253. {
  254. return [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]] count];
  255. }
  256. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  257. {
  258. return 13.0f;
  259. }
  260. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  261. {
  262. UIVisualEffectView *visualEffectView;
  263. NSString *titleSection, *numberTitle;
  264. NSInteger typeOfSession = 0;
  265. NSInteger queueDownload = [[[NCManageDatabase sharedInstance] getTableMetadataDownload] count] + [[NCManageDatabase sharedInstance] countQueueDownloadWithSession:k_download_session];
  266. NSInteger queueDownloadWWan = [[[NCManageDatabase sharedInstance] getTableMetadataDownloadWWan] count] + [[NCManageDatabase sharedInstance] countQueueDownloadWithSession:k_download_session_wwan];
  267. NSInteger queueUpload = [[[NCManageDatabase sharedInstance] getTableMetadataUpload] count] + [[NCManageDatabase sharedInstance] countQueueUploadWithSession:k_upload_session];
  268. NSInteger queueUploadWWan = [[[NCManageDatabase sharedInstance] getTableMetadataUploadWWan] count] + [[NCManageDatabase sharedInstance] countQueueUploadWithSession:k_upload_session_wwan];
  269. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
  270. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]]) titleSection = [CCUtility getTitleSectionDate:[_sectionDataSource.sections objectAtIndex:section]];
  271. NSArray *metadatas = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]];
  272. NSUInteger rowsCount = [metadatas count];
  273. visualEffectView = [[UIVisualEffectView alloc] init];
  274. visualEffectView.backgroundColor = [UIColor clearColor];
  275. // title section
  276. if ([titleSection isEqualToString:@"_none_"]) {
  277. titleSection = @"";
  278. } else if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"]) {
  279. typeOfSession = download;
  280. titleSection = NSLocalizedString(@"_title_section_download_",nil);
  281. } else if ([titleSection containsString:@"download"] && [titleSection containsString:@"wwan"]) {
  282. typeOfSession = downloadwwan;
  283. titleSection = [NSLocalizedString(@"_title_section_download_",nil) stringByAppendingString:@" Wi-Fi"];
  284. } else if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"]) {
  285. typeOfSession = upload;
  286. titleSection = NSLocalizedString(@"_title_section_upload_",nil);
  287. } else if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"]) {
  288. typeOfSession = uploadwwan;
  289. titleSection = [NSLocalizedString(@"_title_section_upload_",nil) stringByAppendingString:@" Wi-Fi"];
  290. } else {
  291. titleSection = NSLocalizedString(titleSection,nil);
  292. }
  293. // title label on left
  294. UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(8, 3, 0, 13)];
  295. titleLabel.textColor = [UIColor blackColor];
  296. titleLabel.font = [UIFont systemFontOfSize:9];
  297. titleLabel.textAlignment = NSTextAlignmentLeft;
  298. titleLabel.text = titleSection;
  299. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  300. [visualEffectView.contentView addSubview:titleLabel];
  301. // element (s) on right
  302. UILabel *elementLabel=[[UILabel alloc]initWithFrame:CGRectMake(-8, 3, 0, 13)];
  303. elementLabel.textColor = [UIColor blackColor];
  304. elementLabel.font = [UIFont systemFontOfSize:9];
  305. elementLabel.textAlignment = NSTextAlignmentRight;
  306. elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  307. if ((typeOfSession == download && queueDownload > rowsCount) || (typeOfSession == downloadwwan && queueDownloadWWan > rowsCount) ||
  308. (typeOfSession == upload && queueUpload > rowsCount) || (typeOfSession == uploadwwan && queueUploadWWan > rowsCount)) {
  309. numberTitle = [NSString stringWithFormat:@"%lu+", (unsigned long)rowsCount];
  310. } else {
  311. numberTitle = [NSString stringWithFormat:@"%lu", (unsigned long)rowsCount];
  312. }
  313. if (rowsCount > 1)
  314. elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_elements_",nil)];
  315. else
  316. elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_element_",nil)];
  317. // view
  318. [visualEffectView.contentView addSubview:elementLabel];
  319. return visualEffectView;
  320. }
  321. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  322. {
  323. NSString *titleSection;
  324. NSString *element_s;
  325. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
  326. // Prepare view for title in footer
  327. UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
  328. UILabel *titleFooterLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)];
  329. titleFooterLabel.textColor = [UIColor blackColor];
  330. titleFooterLabel.font = [UIFont systemFontOfSize:12];
  331. titleFooterLabel.textAlignment = NSTextAlignmentCenter;
  332. // Footer Download
  333. if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
  334. NSInteger queueDownload = [[[NCManageDatabase sharedInstance] getTableMetadataDownload] count] + [[NCManageDatabase sharedInstance] countQueueDownloadWithSession:k_download_session];
  335. // element or elements ?
  336. if (queueDownload > 1) element_s = NSLocalizedString(@"_elements_",nil);
  337. else element_s = NSLocalizedString(@"_element_",nil);
  338. // Num record to upload
  339. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_download_", nil), queueDownload, element_s]];
  340. titleFooterLabel.attributedText = stringFooter;
  341. [view addSubview:titleFooterLabel];
  342. return view;
  343. }
  344. // Footer Download WWAN
  345. if ([titleSection containsString:@"download"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
  346. NSInteger queueDownloadWWan = [[[NCManageDatabase sharedInstance] getTableMetadataDownloadWWan] count] + [[NCManageDatabase sharedInstance] countQueueDownloadWithSession:k_download_session_wwan];
  347. // element or elements ?
  348. if (queueDownloadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
  349. else element_s = NSLocalizedString(@"_element_",nil);
  350. // Add the symbol WiFi and Num record
  351. NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
  352. attachment.image = [UIImage imageNamed:@"WiFiSmall"];
  353. NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
  354. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[@" " stringByAppendingString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_download_wwan_", nil), queueDownloadWWan, element_s]]];
  355. [stringFooter insertAttributedString:attachmentString atIndex:0];
  356. titleFooterLabel.attributedText = stringFooter;
  357. [view addSubview:titleFooterLabel];
  358. return view;
  359. }
  360. // Footer Upload
  361. if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
  362. NSInteger queueUpload = [[[NCManageDatabase sharedInstance] getTableMetadataUpload] count] + [[NCManageDatabase sharedInstance] countQueueUploadWithSession:k_upload_session];
  363. // element or elements ?
  364. if (queueUpload > 1) element_s = NSLocalizedString(@"_elements_",nil);
  365. else element_s = NSLocalizedString(@"_element_",nil);
  366. // Num record to upload
  367. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_", nil), queueUpload, element_s]];
  368. titleFooterLabel.attributedText = stringFooter;
  369. [view addSubview:titleFooterLabel];
  370. return view;
  371. }
  372. // Footer Upload WWAN
  373. if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
  374. NSInteger queueUploadWWan = [[[NCManageDatabase sharedInstance] getTableMetadataUploadWWan] count] + [[NCManageDatabase sharedInstance] countQueueUploadWithSession:k_upload_session_wwan];
  375. // element or elements ?
  376. if (queueUploadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
  377. else element_s = NSLocalizedString(@"_element_",nil);
  378. // Add the symbol WiFi and Num record
  379. NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
  380. attachment.image = [UIImage imageNamed:@"WiFiSmall"];
  381. NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
  382. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[@" " stringByAppendingString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_wwan_", nil), queueUploadWWan,element_s]]];
  383. [stringFooter insertAttributedString:attachmentString atIndex:0];
  384. titleFooterLabel.attributedText = stringFooter;
  385. [view addSubview:titleFooterLabel];
  386. return view;
  387. }
  388. return nil;
  389. }
  390. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  391. {
  392. //NSString *titleSection;
  393. //if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]])
  394. // titleSection = [_sectionDataSource.sections objectAtIndex:section];
  395. //if ([titleSection rangeOfString:@"upload"].location != NSNotFound && [titleSection rangeOfString:@"wwan"].location != NSNotFound && titleSection != nil) return 18.0f;
  396. //else return 0.0f;
  397. return 18.0f;
  398. }
  399. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  400. {
  401. return [_sectionDataSource.sections indexOfObject:title];
  402. }
  403. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  404. {
  405. NSString *dataFile;
  406. NSString *lunghezzaFile;
  407. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  408. tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  409. CCTransfersCell *cell = (CCTransfersCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
  410. cell.backgroundColor = [UIColor clearColor];
  411. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  412. // ----------------------------------------------------------------------------------------------------------
  413. // DEFAULT
  414. // ----------------------------------------------------------------------------------------------------------
  415. cell.file.image = nil;
  416. cell.status.image = nil;
  417. cell.labelTitle.enabled = YES;
  418. cell.labelTitle.text = @"";
  419. cell.labelInfoFile.enabled = YES;
  420. cell.labelInfoFile.text = @"";
  421. cell.progressView.progress = 0.0;
  422. cell.progressView.hidden = YES;
  423. cell.cancelTaskButton.hidden = YES;
  424. cell.reloadTaskButton.hidden = YES;
  425. cell.stopTaskButton.hidden = YES;
  426. cell.labelTitle.textColor = [UIColor blackColor];
  427. cell.labelInfoFile.textColor = [UIColor blackColor];
  428. // ----------------------------------------------------------------------------------------------------------
  429. // File Name & Folder
  430. // ----------------------------------------------------------------------------------------------------------
  431. // nome del file
  432. cell.labelTitle.text = metadata.fileNameView;
  433. // è una directory
  434. if (metadata.directory) {
  435. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  436. cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
  437. lunghezzaFile = @" ";
  438. } else {
  439. // è un file
  440. dataFile = [CCUtility dateDiff:metadata.date];
  441. lunghezzaFile = [CCUtility transformedSize:metadata.size];
  442. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  443. [dateFormatter setDateStyle:NSDateFormatterShortStyle];
  444. [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
  445. cell.accessoryType = UITableViewCellAccessoryNone;
  446. }
  447. // ----------------------------------------------------------------------------------------------------------
  448. // File Image View
  449. // ----------------------------------------------------------------------------------------------------------
  450. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  451. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, metadata.fileID]]) {
  452. cell.file.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, metadata.fileID]];
  453. } else {
  454. cell.file.image = [UIImage imageNamed:metadata.iconName];
  455. if (metadata.thumbnailExists)
  456. [[CCActions sharedInstance] downloadTumbnail:metadata delegate:self];
  457. }
  458. // ----------------------------------------------------------------------------------------------------------
  459. // downloadFile
  460. // ----------------------------------------------------------------------------------------------------------
  461. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"download"].location != NSNotFound) {
  462. cell.status.image = [UIImage imageNamed:@"statusdownload"];
  463. // Fai comparire il RELOAD e lo STOP solo se non è un Task Plist
  464. [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:@"stoptask"] forState:UIControlStateNormal];
  465. cell.cancelTaskButton.hidden = NO;
  466. [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:@"reloadtask"] forState:UIControlStateNormal];
  467. cell.reloadTaskButton.hidden = NO;
  468. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  469. float progress = [[appDelegate.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  470. if (progress > 0) {
  471. cell.progressView.progressTintColor = [UIColor blackColor];
  472. cell.progressView.progress = progress;
  473. cell.progressView.hidden = NO;
  474. }
  475. // ----------------------------------------------------------------------------------------------------------
  476. // downloadFile Error
  477. // ----------------------------------------------------------------------------------------------------------
  478. if (metadata.sessionTaskIdentifier == k_taskIdentifierError) {
  479. cell.status.image = [UIImage imageNamed:@"statuserror"];
  480. if ([metadata.sessionError length] == 0) {
  481. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_downloaded_",nil)];
  482. } else {
  483. cell.labelInfoFile.text = metadata.sessionError;
  484. }
  485. }
  486. }
  487. // ----------------------------------------------------------------------------------------------------------
  488. // uploadFile
  489. // ----------------------------------------------------------------------------------------------------------
  490. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"upload"].location != NSNotFound) {
  491. cell.status.image = [UIImage imageNamed:@"statusupload"];
  492. [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:@"removetask"] forState:UIControlStateNormal];
  493. cell.cancelTaskButton.hidden = NO;
  494. if (metadata.sessionTaskIdentifier == k_taskIdentifierStop) {
  495. [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:@"reloadtask"] forState:UIControlStateNormal];
  496. cell.status.image = [UIImage imageNamed:@"statusstop"];
  497. cell.reloadTaskButton.hidden = NO;
  498. cell.stopTaskButton.hidden = YES;
  499. } else {
  500. [cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:@"stoptask"] forState:UIControlStateNormal];
  501. cell.stopTaskButton.hidden = NO;
  502. cell.reloadTaskButton.hidden = YES;
  503. }
  504. // se non c'è una preview in bianconero metti l'immagine di default
  505. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", appDelegate.directoryUser, metadata.fileID]] == NO)
  506. cell.file.image = [UIImage imageNamed:@"uploaddisable"];
  507. cell.labelTitle.enabled = NO;
  508. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  509. float progress = [[appDelegate.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  510. if (progress > 0) {
  511. cell.progressView.progressTintColor = [UIColor blackColor];
  512. cell.progressView.progress = progress;
  513. cell.progressView.hidden = NO;
  514. }
  515. // ----------------------------------------------------------------------------------------------------------
  516. // uploadFileError
  517. // ----------------------------------------------------------------------------------------------------------
  518. if (metadata.sessionTaskIdentifier == k_taskIdentifierError) {
  519. cell.labelTitle.enabled = NO;
  520. cell.status.image = [UIImage imageNamed:@"statuserror"];
  521. if ([metadata.sessionError length] == 0) {
  522. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_uploaded_",nil)];
  523. } else {
  524. cell.labelInfoFile.text = metadata.sessionError;
  525. }
  526. }
  527. }
  528. [cell.reloadTaskButton addTarget:self action:@selector(reloadTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  529. [cell.cancelTaskButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  530. [cell.stopTaskButton addTarget:self action:@selector(stopTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  531. return cell;
  532. }
  533. @end