CCControlCenterPageContent.m 28 KB

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