CCControlCenterTransfer.m 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  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 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 = [CCSection creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:app.listProgressMetadata groupByField:@"session" replaceDateToExifDate:NO activeAccount:app.activeAccount];
  177. //if ([_sectionDataSource.allRecordsDataSource count] == 0) _noRecord.hidden = NO;
  178. //else _noRecord.hidden = YES;
  179. }
  180. [_tableView reloadData];
  181. [app updateApplicationIconBadgeNumber];
  182. }
  183. #pragma --------------------------------------------------------------------------------------------
  184. #pragma mark - ==== Table ====
  185. #pragma --------------------------------------------------------------------------------------------
  186. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  187. {
  188. return 50;
  189. }
  190. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  191. {
  192. return [[_sectionDataSource.sectionArrayRow allKeys] count];
  193. }
  194. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  195. {
  196. return [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]] count];
  197. }
  198. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  199. {
  200. return 13.0f;
  201. }
  202. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  203. {
  204. UIVisualEffectView *visualEffectView;
  205. NSString *titleSection, *numberTitle;
  206. NSInteger typeOfSession = 0;
  207. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
  208. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]]) titleSection = [CCUtility getTitleSectionDate:[_sectionDataSource.sections objectAtIndex:section]];
  209. NSArray *metadatas = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]];
  210. NSUInteger rowsCount = [metadatas count];
  211. visualEffectView = [[UIVisualEffectView alloc] init];
  212. visualEffectView.backgroundColor = [UIColor clearColor];
  213. // title section
  214. if ([titleSection isEqualToString:@"_none_"]) {
  215. titleSection = @"";
  216. } else if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"]) {
  217. typeOfSession = download;
  218. titleSection = NSLocalizedString(@"_title_section_download_",nil);
  219. } else if ([titleSection containsString:@"download"] && [titleSection containsString:@"wwan"]) {
  220. typeOfSession = downloadwwan;
  221. titleSection = [NSLocalizedString(@"_title_section_download_",nil) stringByAppendingString:@" Wi-Fi"];
  222. } else if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"]) {
  223. typeOfSession = upload;
  224. titleSection = NSLocalizedString(@"_title_section_upload_",nil);
  225. } else if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"]) {
  226. typeOfSession = uploadwwan;
  227. titleSection = [NSLocalizedString(@"_title_section_upload_",nil) stringByAppendingString:@" Wi-Fi"];
  228. } else {
  229. titleSection = NSLocalizedString(titleSection,nil);
  230. }
  231. // title label on left
  232. UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(8, 3, 0, 13)];
  233. titleLabel.textColor = COLOR_TEXT_ANTHRACITE;
  234. titleLabel.font = [UIFont systemFontOfSize:9];
  235. titleLabel.textAlignment = NSTextAlignmentLeft;
  236. titleLabel.text = titleSection;
  237. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  238. [visualEffectView addSubview:titleLabel];
  239. // element (s) on right
  240. UILabel *elementLabel=[[UILabel alloc]initWithFrame:CGRectMake(-8, 3, 0, 13)];
  241. elementLabel.textColor = COLOR_TEXT_ANTHRACITE;
  242. elementLabel.font = [UIFont systemFontOfSize:9];
  243. elementLabel.textAlignment = NSTextAlignmentRight;
  244. elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  245. if ((typeOfSession == download && app.queueNunDownload > rowsCount) || (typeOfSession == downloadwwan && app.queueNumDownloadWWan > rowsCount) ||
  246. (typeOfSession == upload && app.queueNumUpload > rowsCount) || (typeOfSession == uploadwwan && app.queueNumUploadWWan > rowsCount)) {
  247. numberTitle = [NSString stringWithFormat:@"%lu+", (unsigned long)rowsCount];
  248. } else {
  249. numberTitle = [NSString stringWithFormat:@"%lu", (unsigned long)rowsCount];
  250. }
  251. if (rowsCount > 1)
  252. elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_elements_",nil)];
  253. else
  254. elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_element_",nil)];
  255. // view
  256. [visualEffectView addSubview:elementLabel];
  257. return visualEffectView;
  258. }
  259. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  260. {
  261. NSString *titleSection;
  262. NSString *element_s;
  263. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
  264. // Prepare view for title in footer
  265. UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
  266. UILabel *titleFooterLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)];
  267. titleFooterLabel.textColor = COLOR_TEXT_ANTHRACITE;
  268. titleFooterLabel.font = [UIFont systemFontOfSize:12];
  269. titleFooterLabel.textAlignment = NSTextAlignmentCenter;
  270. // Footer Download
  271. if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
  272. // element or elements ?
  273. if (app.queueNunDownload > 1) element_s = NSLocalizedString(@"_elements_",nil);
  274. else element_s = NSLocalizedString(@"_element_",nil);
  275. // Num record to upload
  276. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_download_", nil), app.queueNunDownload, element_s]];
  277. titleFooterLabel.attributedText = stringFooter;
  278. [view addSubview:titleFooterLabel];
  279. return view;
  280. }
  281. // Footer Download WWAN
  282. if ([titleSection containsString:@"download"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
  283. // element or elements ?
  284. if (app.queueNumDownloadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
  285. else element_s = NSLocalizedString(@"_element_",nil);
  286. // Add the symbol WiFi and Num record
  287. NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
  288. attachment.image = [UIImage imageNamed:image_WiFiSmall];
  289. NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
  290. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_download_wwan_", nil), app.queueNumDownloadWWan, element_s]];
  291. [stringFooter insertAttributedString:attachmentString atIndex:0];
  292. titleFooterLabel.attributedText = stringFooter;
  293. [view addSubview:titleFooterLabel];
  294. return view;
  295. }
  296. // Footer Upload
  297. if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
  298. // element or elements ?
  299. if (app.queueNumUpload > 1) element_s = NSLocalizedString(@"_elements_",nil);
  300. else element_s = NSLocalizedString(@"_element_",nil);
  301. // Num record to upload
  302. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_", nil), app.queueNumUpload, element_s]];
  303. titleFooterLabel.attributedText = stringFooter;
  304. [view addSubview:titleFooterLabel];
  305. return view;
  306. }
  307. // Footer Upload WWAN
  308. if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
  309. // element or elements ?
  310. if (app.queueNumUploadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
  311. else element_s = NSLocalizedString(@"_element_",nil);
  312. // Add the symbol WiFi and Num record
  313. NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
  314. attachment.image = [UIImage imageNamed:image_WiFiSmall];
  315. NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
  316. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_wwan_", nil), app.queueNumUploadWWan,element_s]];
  317. [stringFooter insertAttributedString:attachmentString atIndex:0];
  318. titleFooterLabel.attributedText = stringFooter;
  319. [view addSubview:titleFooterLabel];
  320. return view;
  321. }
  322. return nil;
  323. }
  324. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  325. {
  326. //NSString *titleSection;
  327. //if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]])
  328. // titleSection = [_sectionDataSource.sections objectAtIndex:section];
  329. //if ([titleSection rangeOfString:@"upload"].location != NSNotFound && [titleSection rangeOfString:@"wwan"].location != NSNotFound && titleSection != nil) return 18.0f;
  330. //else return 0.0f;
  331. return 18.0f;
  332. }
  333. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  334. {
  335. return [_sectionDataSource.sections indexOfObject:title];
  336. }
  337. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  338. {
  339. NSString *dataFile;
  340. NSString *lunghezzaFile;
  341. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  342. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  343. CCControlCenterTransferCell *cell = (CCControlCenterTransferCell *)[tableView dequeueReusableCellWithIdentifier:@"ControlCenterTransferCell" forIndexPath:indexPath];
  344. cell.backgroundColor = [UIColor clearColor];
  345. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  346. // ----------------------------------------------------------------------------------------------------------
  347. // DEFAULT
  348. // ----------------------------------------------------------------------------------------------------------
  349. cell.fileImageView.image = nil;
  350. cell.statusImageView.image = nil;
  351. cell.labelTitle.enabled = YES;
  352. cell.labelTitle.text = @"";
  353. cell.labelInfoFile.enabled = YES;
  354. cell.labelInfoFile.text = @"";
  355. cell.progressView.progress = 0.0;
  356. cell.progressView.hidden = YES;
  357. cell.cancelTaskButton.hidden = YES;
  358. cell.reloadTaskButton.hidden = YES;
  359. cell.stopTaskButton.hidden = YES;
  360. // colori e font
  361. if (metadata.cryptated) {
  362. cell.labelTitle.textColor = COLOR_CRYPTOCLOUD;
  363. cell.labelInfoFile.textColor = [UIColor blackColor];
  364. } else {
  365. cell.labelTitle.textColor = COLOR_TEXT_ANTHRACITE;
  366. cell.labelInfoFile.textColor = [UIColor blackColor];
  367. }
  368. // ----------------------------------------------------------------------------------------------------------
  369. // File Name & Folder
  370. // ----------------------------------------------------------------------------------------------------------
  371. // nome del file
  372. cell.labelTitle.text = metadata.fileNamePrint;
  373. // è una directory
  374. if (metadata.directory) {
  375. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  376. cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
  377. lunghezzaFile = @" ";
  378. } else {
  379. // è un file
  380. dataFile = [CCUtility dateDiff:metadata.date];
  381. lunghezzaFile = [CCUtility transformedSize:metadata.size];
  382. // Plist ancora da scaricare
  383. if (metadata.cryptated && [metadata.title length] == 0) {
  384. dataFile = @" ";
  385. lunghezzaFile = @" ";
  386. }
  387. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  388. [dateFormatter setDateStyle:NSDateFormatterShortStyle];
  389. [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
  390. cell.accessoryType = UITableViewCellAccessoryNone;
  391. }
  392. // ----------------------------------------------------------------------------------------------------------
  393. // File Image View
  394. // ----------------------------------------------------------------------------------------------------------
  395. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  396. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]]) {
  397. cell.fileImageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
  398. } else {
  399. cell.fileImageView.image = [UIImage imageNamed:metadata.iconName];
  400. }
  401. // ----------------------------------------------------------------------------------------------------------
  402. // Image Status cyptated & Lock Passcode
  403. // ----------------------------------------------------------------------------------------------------------
  404. // File Cyptated
  405. if (metadata.cryptated && metadata.directory == NO && [metadata.type isEqualToString: k_metadataType_template] == NO) {
  406. cell.statusImageView.image = [UIImage imageNamed:image_lock];
  407. }
  408. // ----------------------------------------------------------------------------------------------------------
  409. // downloadFile
  410. // ----------------------------------------------------------------------------------------------------------
  411. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"download"].location != NSNotFound) {
  412. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusdownloadcrypto];
  413. else cell.statusImageView.image = [UIImage imageNamed:image_statusdownload];
  414. // Fai comparire il RELOAD e lo STOP solo se non è un Task Plist
  415. if (metadata.sessionTaskIdentifierPlist == k_taskIdentifierDone) {
  416. if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptaskcrypto] forState:UIControlStateNormal];
  417. else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptask] forState:UIControlStateNormal];
  418. cell.cancelTaskButton.hidden = NO;
  419. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
  420. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
  421. cell.reloadTaskButton.hidden = NO;
  422. }
  423. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  424. float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  425. if (progress > 0) {
  426. if (metadata.cryptated) cell.progressView.progressTintColor = COLOR_CRYPTOCLOUD;
  427. else cell.progressView.progressTintColor = COLOR_TEXT_ANTHRACITE;
  428. cell.progressView.progress = progress;
  429. cell.progressView.hidden = NO;
  430. }
  431. // ----------------------------------------------------------------------------------------------------------
  432. // downloadFile Error
  433. // ----------------------------------------------------------------------------------------------------------
  434. if (metadata.sessionTaskIdentifier == k_taskIdentifierError || metadata.sessionTaskIdentifierPlist == k_taskIdentifierError) {
  435. cell.statusImageView.image = [UIImage imageNamed:image_statuserror];
  436. if ([metadata.sessionError length] == 0)
  437. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_downloaded_",nil)];
  438. else
  439. cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
  440. }
  441. }
  442. // ----------------------------------------------------------------------------------------------------------
  443. // uploadFile
  444. // ----------------------------------------------------------------------------------------------------------
  445. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"upload"].location != NSNotFound) {
  446. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusuploadcrypto];
  447. else cell.statusImageView.image = [UIImage imageNamed:image_statusupload];
  448. if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_removetaskcrypto] forState:UIControlStateNormal];
  449. else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_removetask] forState:UIControlStateNormal];
  450. cell.cancelTaskButton.hidden = NO;
  451. if (metadata.sessionTaskIdentifier == k_taskIdentifierStop) {
  452. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
  453. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
  454. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusstopcrypto];
  455. else cell.statusImageView.image = [UIImage imageNamed:image_statusstop];
  456. cell.reloadTaskButton.hidden = NO;
  457. cell.stopTaskButton.hidden = YES;
  458. } else {
  459. if (metadata.cryptated)[cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptaskcrypto] forState:UIControlStateNormal];
  460. else [cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptask] forState:UIControlStateNormal];
  461. cell.stopTaskButton.hidden = NO;
  462. cell.reloadTaskButton.hidden = YES;
  463. }
  464. // se non c'è una preview in bianconero metti l'immagine di default
  465. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]] == NO)
  466. cell.fileImageView.image = [UIImage imageNamed:image_uploaddisable];
  467. cell.labelTitle.enabled = NO;
  468. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  469. float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  470. if (progress > 0) {
  471. if (metadata.cryptated) cell.progressView.progressTintColor = COLOR_CRYPTOCLOUD;
  472. else cell.progressView.progressTintColor = COLOR_TEXT_ANTHRACITE;
  473. cell.progressView.progress = progress;
  474. cell.progressView.hidden = NO;
  475. }
  476. // ----------------------------------------------------------------------------------------------------------
  477. // uploadFileError
  478. // ----------------------------------------------------------------------------------------------------------
  479. if (metadata.sessionTaskIdentifier == k_taskIdentifierError || metadata.sessionTaskIdentifierPlist == k_taskIdentifierError) {
  480. cell.labelTitle.enabled = NO;
  481. cell.statusImageView.image = [UIImage imageNamed:image_statuserror];
  482. if ([metadata.sessionError length] == 0)
  483. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_uploaded_",nil)];
  484. else
  485. cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
  486. }
  487. }
  488. [cell.reloadTaskButton addTarget:self action:@selector(reloadTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  489. [cell.cancelTaskButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  490. [cell.stopTaskButton addTarget:self action:@selector(stopTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  491. return cell;
  492. }
  493. @end