CCControlCenterTransfer.m 28 KB

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