CCTransfers.m 31 KB

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