CCControlCenterTransfer.m 29 KB

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