CCControlCenterTransfer.m 29 KB

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