CCControlCenterTransfer.m 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. //
  2. // CCControlCenterPageContent.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 01/03/17.
  6. // Copyright © 2017 TWS. All rights reserved.
  7. //
  8. #import "CCControlCenterTransfer.h"
  9. #import "AppDelegate.h"
  10. #import "CCMain.h"
  11. #import "CCDetail.h"
  12. #import "CCSection.h"
  13. #import "CCMetadata.h"
  14. #import "CCControlCenterTransferCell.h"
  15. #define download 1
  16. #define downloadwwan 2
  17. #define upload 3
  18. #define uploadwwan 4
  19. @interface CCControlCenterTransfer ()
  20. {
  21. // Datasource
  22. CCSectionDataSourceMetadata *_sectionDataSource;
  23. }
  24. @end
  25. @implementation CCControlCenterTransfer
  26. #pragma --------------------------------------------------------------------------------------------
  27. #pragma mark ===== Init =====
  28. #pragma --------------------------------------------------------------------------------------------
  29. - (id)initWithCoder:(NSCoder *)aDecoder
  30. {
  31. if (self = [super initWithCoder:aDecoder]) {
  32. app.controlCenterTransfer = self;
  33. }
  34. return self;
  35. }
  36. - (void)viewDidLoad {
  37. [super viewDidLoad];
  38. // Custom Cell
  39. [_tableView registerNib:[UINib nibWithNibName:@"CCControlCenterTransferCell" bundle:nil] forCellReuseIdentifier:@"ControlCenterTransferCell"];
  40. _tableView.delegate = self;
  41. _tableView.dataSource = self;
  42. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  43. _tableView.backgroundColor = [UIColor clearColor];
  44. [self reloadDatasource];
  45. }
  46. // Apparirà
  47. - (void)viewWillAppear:(BOOL)animated
  48. {
  49. [super viewWillAppear:animated];
  50. [self reloadDatasource];
  51. }
  52. // E' arrivato
  53. - (void)viewDidAppear:(BOOL)animated
  54. {
  55. [super viewDidAppear:animated];
  56. // update Badge
  57. [app updateApplicationIconBadgeNumber];
  58. }
  59. - (void)didReceiveMemoryWarning {
  60. [super didReceiveMemoryWarning];
  61. }
  62. #pragma --------------------------------------------------------------------------------------------
  63. #pragma mark - ===== Progress & Task Button =====
  64. #pragma --------------------------------------------------------------------------------------------
  65. - (void)progressTask:(NSString *)fileID serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated progress:(float)progress;
  66. {
  67. // Chech
  68. if (!fileID)
  69. return;
  70. [app.listProgressMetadata setObject:[NSNumber numberWithFloat:progress] forKey:fileID];
  71. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:fileID];
  72. if (indexPath && indexPath.row == 0) {
  73. CCControlCenterTransferCell *cell = (CCControlCenterTransferCell *)[_tableView cellForRowAtIndexPath:indexPath];
  74. if (cryptated) cell.progressView.progressTintColor = COLOR_CRYPTOCLOUD;
  75. else cell.progressView.progressTintColor = COLOR_TEXT_ANTHRACITE;
  76. cell.progressView.hidden = NO;
  77. [cell.progressView setProgress:progress];
  78. } else {
  79. [self reloadDatasource];
  80. }
  81. }
  82. - (void)reloadTaskButton:(id)sender withEvent:(UIEvent *)event
  83. {
  84. if (app.activeMain == nil)
  85. return;
  86. UITouch * touch = [[event allTouches] anyObject];
  87. CGPoint location = [touch locationInView:_tableView];
  88. NSIndexPath * indexPath = [_tableView indexPathForRowAtPoint:location];
  89. if (indexPath) {
  90. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  91. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  92. if (metadata)
  93. [app.activeMain reloadTaskButton:metadata];
  94. }
  95. }
  96. - (void)reloadAllTask
  97. {
  98. if (app.activeMain == nil)
  99. return;
  100. for (NSString *key in _sectionDataSource.allRecordsDataSource.allKeys) {
  101. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:key];
  102. if ([metadata.session containsString:@"download"] && (metadata.sessionTaskIdentifierPlist != k_taskIdentifierDone))
  103. continue;
  104. if ([metadata.session containsString:@"upload"] && (metadata.sessionTaskIdentifier != k_taskIdentifierStop))
  105. continue;
  106. [app.activeMain reloadTaskButton:metadata];
  107. }
  108. }
  109. - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
  110. {
  111. if (app.activeMain == nil)
  112. return;
  113. UITouch * touch = [[event allTouches] anyObject];
  114. CGPoint location = [touch locationInView:_tableView];
  115. NSIndexPath * indexPath = [_tableView indexPathForRowAtPoint:location];
  116. if (indexPath) {
  117. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  118. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  119. if (metadata)
  120. [app.activeMain cancelTaskButton:metadata reloadTable:YES];
  121. }
  122. }
  123. - (void)cancelAllTask
  124. {
  125. if (app.activeMain == nil)
  126. return;
  127. BOOL lastAndRefresh = NO;
  128. for (NSString *key in _sectionDataSource.allRecordsDataSource.allKeys) {
  129. if ([key isEqualToString:[_sectionDataSource.allRecordsDataSource.allKeys lastObject]])
  130. lastAndRefresh = YES;
  131. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:key];
  132. if ([metadata.session containsString:@"upload"] && metadata.cryptated && ((metadata.sessionTaskIdentifier == k_taskIdentifierDone && metadata.sessionTaskIdentifierPlist >= 0) || (metadata.sessionTaskIdentifier >= 0 && metadata.sessionTaskIdentifierPlist == k_taskIdentifierDone)))
  133. continue;
  134. [app.activeMain cancelTaskButton:metadata reloadTable:lastAndRefresh];
  135. }
  136. }
  137. - (void)stopTaskButton:(id)sender withEvent:(UIEvent *)event
  138. {
  139. if (app.activeMain == nil)
  140. return;
  141. UITouch * touch = [[event allTouches] anyObject];
  142. CGPoint location = [touch locationInView:_tableView];
  143. NSIndexPath * indexPath = [_tableView indexPathForRowAtPoint:location];
  144. if (indexPath) {
  145. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  146. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  147. if (metadata)
  148. [app.activeMain stopTaskButton:metadata];
  149. }
  150. }
  151. - (void)stopAllTask
  152. {
  153. if (app.activeMain == nil)
  154. return;
  155. for (NSString *key in _sectionDataSource.allRecordsDataSource.allKeys) {
  156. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:key];
  157. if ([metadata.session containsString:@"download"]) {
  158. [app.activeMain cancelTaskButton:metadata reloadTable:YES];
  159. continue;
  160. }
  161. if ([metadata.session containsString:@"upload"] && metadata.cryptated && ((metadata.sessionTaskIdentifier == k_taskIdentifierDone && metadata.sessionTaskIdentifierPlist >= 0) || (metadata.sessionTaskIdentifier >= 0 && metadata.sessionTaskIdentifierPlist == k_taskIdentifierDone)))
  162. continue;
  163. [app.activeMain stopTaskButton:metadata];
  164. }
  165. }
  166. #pragma --------------------------------------------------------------------------------------------
  167. #pragma mark - ==== Datasource ====
  168. #pragma --------------------------------------------------------------------------------------------
  169. - (void)reloadDatasource
  170. {
  171. // test
  172. if (app.activeAccount.length == 0)
  173. return;
  174. if (app.controlCenter.isOpen) {
  175. NSArray *recordsTableMetadata = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND ((session CONTAINS 'upload') OR (session CONTAINS 'download' AND (sessionSelector != 'loadPlist')))", app.activeAccount] fieldOrder:@"sessionTaskIdentifier" ascending:YES];
  176. _sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:app.listProgressMetadata groupByField:@"session" replaceDateToExifDate:NO activeAccount:app.activeAccount];
  177. if ([_sectionDataSource.allRecordsDataSource count] == 0) {
  178. app.controlCenter.noRecord.text = NSLocalizedString(@"_no_transfer_",nil);
  179. app.controlCenter.noRecord.hidden = NO;
  180. } else {
  181. app.controlCenter.noRecord.hidden = YES;
  182. }
  183. }
  184. [_tableView reloadData];
  185. [app updateApplicationIconBadgeNumber];
  186. }
  187. #pragma --------------------------------------------------------------------------------------------
  188. #pragma mark - ==== Table ====
  189. #pragma --------------------------------------------------------------------------------------------
  190. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  191. {
  192. return 50;
  193. }
  194. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  195. {
  196. return [[_sectionDataSource.sectionArrayRow allKeys] count];
  197. }
  198. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  199. {
  200. return [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]] count];
  201. }
  202. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  203. {
  204. return 13.0f;
  205. }
  206. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  207. {
  208. UIVisualEffectView *visualEffectView;
  209. NSString *titleSection, *numberTitle;
  210. NSInteger typeOfSession = 0;
  211. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
  212. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]]) titleSection = [CCUtility getTitleSectionDate:[_sectionDataSource.sections objectAtIndex:section]];
  213. NSArray *metadatas = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]];
  214. NSUInteger rowsCount = [metadatas count];
  215. visualEffectView = [[UIVisualEffectView alloc] init];
  216. visualEffectView.backgroundColor = [UIColor clearColor];
  217. // title section
  218. if ([titleSection isEqualToString:@"_none_"]) {
  219. titleSection = @"";
  220. } else if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"]) {
  221. typeOfSession = download;
  222. titleSection = NSLocalizedString(@"_title_section_download_",nil);
  223. } else if ([titleSection containsString:@"download"] && [titleSection containsString:@"wwan"]) {
  224. typeOfSession = downloadwwan;
  225. titleSection = [NSLocalizedString(@"_title_section_download_",nil) stringByAppendingString:@" Wi-Fi"];
  226. } else if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"]) {
  227. typeOfSession = upload;
  228. titleSection = NSLocalizedString(@"_title_section_upload_",nil);
  229. } else if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"]) {
  230. typeOfSession = uploadwwan;
  231. titleSection = [NSLocalizedString(@"_title_section_upload_",nil) stringByAppendingString:@" Wi-Fi"];
  232. } else {
  233. titleSection = NSLocalizedString(titleSection,nil);
  234. }
  235. // title label on left
  236. UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(8, 3, 0, 13)];
  237. titleLabel.textColor = COLOR_TEXT_ANTHRACITE;
  238. titleLabel.font = [UIFont systemFontOfSize:9];
  239. titleLabel.textAlignment = NSTextAlignmentLeft;
  240. titleLabel.text = titleSection;
  241. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  242. [visualEffectView addSubview:titleLabel];
  243. // element (s) on right
  244. UILabel *elementLabel=[[UILabel alloc]initWithFrame:CGRectMake(-8, 3, 0, 13)];
  245. elementLabel.textColor = COLOR_TEXT_ANTHRACITE;
  246. elementLabel.font = [UIFont systemFontOfSize:9];
  247. elementLabel.textAlignment = NSTextAlignmentRight;
  248. elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  249. if ((typeOfSession == download && app.queueNunDownload > rowsCount) || (typeOfSession == downloadwwan && app.queueNumDownloadWWan > rowsCount) ||
  250. (typeOfSession == upload && app.queueNumUpload > rowsCount) || (typeOfSession == uploadwwan && app.queueNumUploadWWan > rowsCount)) {
  251. numberTitle = [NSString stringWithFormat:@"%lu+", (unsigned long)rowsCount];
  252. } else {
  253. numberTitle = [NSString stringWithFormat:@"%lu", (unsigned long)rowsCount];
  254. }
  255. if (rowsCount > 1)
  256. elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_elements_",nil)];
  257. else
  258. elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_element_",nil)];
  259. // view
  260. [visualEffectView addSubview:elementLabel];
  261. return visualEffectView;
  262. }
  263. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  264. {
  265. NSString *titleSection;
  266. NSString *element_s;
  267. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
  268. // Prepare view for title in footer
  269. UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
  270. UILabel *titleFooterLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)];
  271. titleFooterLabel.textColor = COLOR_TEXT_ANTHRACITE;
  272. titleFooterLabel.font = [UIFont systemFontOfSize:12];
  273. titleFooterLabel.textAlignment = NSTextAlignmentCenter;
  274. // Footer Download
  275. if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
  276. // element or elements ?
  277. if (app.queueNunDownload > 1) element_s = NSLocalizedString(@"_elements_",nil);
  278. else element_s = NSLocalizedString(@"_element_",nil);
  279. // Num record to upload
  280. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_download_", nil), app.queueNunDownload, element_s]];
  281. titleFooterLabel.attributedText = stringFooter;
  282. [view addSubview:titleFooterLabel];
  283. return view;
  284. }
  285. // Footer Download WWAN
  286. if ([titleSection containsString:@"download"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
  287. // element or elements ?
  288. if (app.queueNumDownloadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
  289. else element_s = NSLocalizedString(@"_element_",nil);
  290. // Add the symbol WiFi and Num record
  291. NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
  292. attachment.image = [UIImage imageNamed:image_WiFiSmall];
  293. NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
  294. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_download_wwan_", nil), app.queueNumDownloadWWan, element_s]];
  295. [stringFooter insertAttributedString:attachmentString atIndex:0];
  296. titleFooterLabel.attributedText = stringFooter;
  297. [view addSubview:titleFooterLabel];
  298. return view;
  299. }
  300. // Footer Upload
  301. if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
  302. // element or elements ?
  303. if (app.queueNumUpload > 1) element_s = NSLocalizedString(@"_elements_",nil);
  304. else element_s = NSLocalizedString(@"_element_",nil);
  305. // Num record to upload
  306. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_", nil), app.queueNumUpload, element_s]];
  307. titleFooterLabel.attributedText = stringFooter;
  308. [view addSubview:titleFooterLabel];
  309. return view;
  310. }
  311. // Footer Upload WWAN
  312. if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
  313. // element or elements ?
  314. if (app.queueNumUploadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
  315. else element_s = NSLocalizedString(@"_element_",nil);
  316. // Add the symbol WiFi and Num record
  317. NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
  318. attachment.image = [UIImage imageNamed:image_WiFiSmall];
  319. NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
  320. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_wwan_", nil), app.queueNumUploadWWan,element_s]];
  321. [stringFooter insertAttributedString:attachmentString atIndex:0];
  322. titleFooterLabel.attributedText = stringFooter;
  323. [view addSubview:titleFooterLabel];
  324. return view;
  325. }
  326. return nil;
  327. }
  328. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  329. {
  330. //NSString *titleSection;
  331. //if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]])
  332. // titleSection = [_sectionDataSource.sections objectAtIndex:section];
  333. //if ([titleSection rangeOfString:@"upload"].location != NSNotFound && [titleSection rangeOfString:@"wwan"].location != NSNotFound && titleSection != nil) return 18.0f;
  334. //else return 0.0f;
  335. return 18.0f;
  336. }
  337. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  338. {
  339. return [_sectionDataSource.sections indexOfObject:title];
  340. }
  341. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  342. {
  343. NSString *dataFile;
  344. NSString *lunghezzaFile;
  345. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  346. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  347. CCControlCenterTransferCell *cell = (CCControlCenterTransferCell *)[tableView dequeueReusableCellWithIdentifier:@"ControlCenterTransferCell" forIndexPath:indexPath];
  348. cell.backgroundColor = [UIColor clearColor];
  349. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  350. // ----------------------------------------------------------------------------------------------------------
  351. // DEFAULT
  352. // ----------------------------------------------------------------------------------------------------------
  353. cell.fileImageView.image = nil;
  354. cell.statusImageView.image = nil;
  355. cell.labelTitle.enabled = YES;
  356. cell.labelTitle.text = @"";
  357. cell.labelInfoFile.enabled = YES;
  358. cell.labelInfoFile.text = @"";
  359. cell.progressView.progress = 0.0;
  360. cell.progressView.hidden = YES;
  361. cell.cancelTaskButton.hidden = YES;
  362. cell.reloadTaskButton.hidden = YES;
  363. cell.stopTaskButton.hidden = YES;
  364. // colori e font
  365. if (metadata.cryptated) {
  366. cell.labelTitle.textColor = COLOR_CRYPTOCLOUD;
  367. cell.labelInfoFile.textColor = [UIColor blackColor];
  368. } else {
  369. cell.labelTitle.textColor = COLOR_TEXT_ANTHRACITE;
  370. cell.labelInfoFile.textColor = [UIColor blackColor];
  371. }
  372. // ----------------------------------------------------------------------------------------------------------
  373. // File Name & Folder
  374. // ----------------------------------------------------------------------------------------------------------
  375. // nome del file
  376. cell.labelTitle.text = metadata.fileNamePrint;
  377. // è una directory
  378. if (metadata.directory) {
  379. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  380. cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
  381. lunghezzaFile = @" ";
  382. } else {
  383. // è un file
  384. dataFile = [CCUtility dateDiff:metadata.date];
  385. lunghezzaFile = [CCUtility transformedSize:metadata.size];
  386. // Plist ancora da scaricare
  387. if (metadata.cryptated && [metadata.title length] == 0) {
  388. dataFile = @" ";
  389. lunghezzaFile = @" ";
  390. }
  391. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  392. [dateFormatter setDateStyle:NSDateFormatterShortStyle];
  393. [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
  394. cell.accessoryType = UITableViewCellAccessoryNone;
  395. }
  396. // ----------------------------------------------------------------------------------------------------------
  397. // File Image View
  398. // ----------------------------------------------------------------------------------------------------------
  399. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  400. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]]) {
  401. cell.fileImageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
  402. } else {
  403. cell.fileImageView.image = [UIImage imageNamed:metadata.iconName];
  404. }
  405. // ----------------------------------------------------------------------------------------------------------
  406. // Image Status cyptated & Lock Passcode
  407. // ----------------------------------------------------------------------------------------------------------
  408. // File Cyptated
  409. if (metadata.cryptated && metadata.directory == NO && [metadata.type isEqualToString: k_metadataType_template] == NO) {
  410. cell.statusImageView.image = [UIImage imageNamed:image_lock];
  411. }
  412. // ----------------------------------------------------------------------------------------------------------
  413. // downloadFile
  414. // ----------------------------------------------------------------------------------------------------------
  415. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"download"].location != NSNotFound) {
  416. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusdownloadcrypto];
  417. else cell.statusImageView.image = [UIImage imageNamed:image_statusdownload];
  418. // Fai comparire il RELOAD e lo STOP solo se non è un Task Plist
  419. if (metadata.sessionTaskIdentifierPlist == k_taskIdentifierDone) {
  420. if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptaskcrypto] forState:UIControlStateNormal];
  421. else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptask] forState:UIControlStateNormal];
  422. cell.cancelTaskButton.hidden = NO;
  423. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
  424. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
  425. cell.reloadTaskButton.hidden = NO;
  426. }
  427. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  428. float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  429. if (progress > 0) {
  430. if (metadata.cryptated) cell.progressView.progressTintColor = COLOR_CRYPTOCLOUD;
  431. else cell.progressView.progressTintColor = COLOR_TEXT_ANTHRACITE;
  432. cell.progressView.progress = progress;
  433. cell.progressView.hidden = NO;
  434. }
  435. // ----------------------------------------------------------------------------------------------------------
  436. // downloadFile Error
  437. // ----------------------------------------------------------------------------------------------------------
  438. if (metadata.sessionTaskIdentifier == k_taskIdentifierError || metadata.sessionTaskIdentifierPlist == k_taskIdentifierError) {
  439. cell.statusImageView.image = [UIImage imageNamed:image_statuserror];
  440. if ([metadata.sessionError length] == 0)
  441. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_downloaded_",nil)];
  442. else
  443. cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
  444. }
  445. }
  446. // ----------------------------------------------------------------------------------------------------------
  447. // uploadFile
  448. // ----------------------------------------------------------------------------------------------------------
  449. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"upload"].location != NSNotFound) {
  450. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusuploadcrypto];
  451. else cell.statusImageView.image = [UIImage imageNamed:image_statusupload];
  452. if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_removetaskcrypto] forState:UIControlStateNormal];
  453. else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_removetask] forState:UIControlStateNormal];
  454. cell.cancelTaskButton.hidden = NO;
  455. if (metadata.sessionTaskIdentifier == k_taskIdentifierStop) {
  456. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
  457. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
  458. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusstopcrypto];
  459. else cell.statusImageView.image = [UIImage imageNamed:image_statusstop];
  460. cell.reloadTaskButton.hidden = NO;
  461. cell.stopTaskButton.hidden = YES;
  462. } else {
  463. if (metadata.cryptated)[cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptaskcrypto] forState:UIControlStateNormal];
  464. else [cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptask] forState:UIControlStateNormal];
  465. cell.stopTaskButton.hidden = NO;
  466. cell.reloadTaskButton.hidden = YES;
  467. }
  468. // se non c'è una preview in bianconero metti l'immagine di default
  469. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]] == NO)
  470. cell.fileImageView.image = [UIImage imageNamed:image_uploaddisable];
  471. cell.labelTitle.enabled = NO;
  472. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  473. float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  474. if (progress > 0) {
  475. if (metadata.cryptated) cell.progressView.progressTintColor = COLOR_CRYPTOCLOUD;
  476. else cell.progressView.progressTintColor = COLOR_TEXT_ANTHRACITE;
  477. cell.progressView.progress = progress;
  478. cell.progressView.hidden = NO;
  479. }
  480. // ----------------------------------------------------------------------------------------------------------
  481. // uploadFileError
  482. // ----------------------------------------------------------------------------------------------------------
  483. if (metadata.sessionTaskIdentifier == k_taskIdentifierError || metadata.sessionTaskIdentifierPlist == k_taskIdentifierError) {
  484. cell.labelTitle.enabled = NO;
  485. cell.statusImageView.image = [UIImage imageNamed:image_statuserror];
  486. if ([metadata.sessionError length] == 0)
  487. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_uploaded_",nil)];
  488. else
  489. cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
  490. }
  491. }
  492. [cell.reloadTaskButton addTarget:self action:@selector(reloadTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  493. [cell.cancelTaskButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  494. [cell.stopTaskButton addTarget:self action:@selector(stopTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  495. return cell;
  496. }
  497. @end