CCTransfers.m 32 KB

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