CCTransfers.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. //
  2. // CCTransfers.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 12/04/17.
  6. // Copyright (c) 2014 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCTransfers.h"
  24. #import "AppDelegate.h"
  25. #import "CCMain.h"
  26. #import "CCDetail.h"
  27. #import "CCSection.h"
  28. #import "CCMetadata.h"
  29. #import "CCTransfersCell.h"
  30. #ifdef CUSTOM_BUILD
  31. #import "CustomSwift.h"
  32. #else
  33. #import "Nextcloud-Swift.h"
  34. #endif
  35. #define download 1
  36. #define downloadwwan 2
  37. #define upload 3
  38. #define uploadwwan 4
  39. @interface CCTransfers ()
  40. {
  41. // Datasource
  42. CCSectionDataSourceMetadata *_sectionDataSource;
  43. }
  44. @end
  45. @implementation CCTransfers
  46. #pragma --------------------------------------------------------------------------------------------
  47. #pragma mark ===== Init =====
  48. #pragma --------------------------------------------------------------------------------------------
  49. - (id)initWithCoder:(NSCoder *)aDecoder
  50. {
  51. if (self = [super initWithCoder:aDecoder]) {
  52. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
  53. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  54. app.activeTransfers = self;
  55. }
  56. return self;
  57. }
  58. - (void)viewDidLoad {
  59. [super viewDidLoad];
  60. // Custom Cell
  61. [_tableView registerNib:[UINib nibWithNibName:@"CCTransfersCell" bundle:nil] forCellReuseIdentifier:@"Cell"];
  62. _tableView.delegate = self;
  63. _tableView.dataSource = self;
  64. _tableView.emptyDataSetDelegate = self;
  65. _tableView.emptyDataSetSource = self;
  66. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  67. _tableView.backgroundColor = [NCBrandColor sharedInstance].tableBackground;
  68. self.title = NSLocalizedString(@"_transfers_", nil);
  69. [self reloadDatasource];
  70. }
  71. // Apparirà
  72. - (void)viewWillAppear:(BOOL)animated
  73. {
  74. [super viewWillAppear:animated];
  75. // Color
  76. [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  77. [app aspectTabBar:self.tabBarController.tabBar hidden:NO];
  78. }
  79. // E' arrivato
  80. - (void)viewDidAppear:(BOOL)animated
  81. {
  82. [super viewDidAppear:animated];
  83. [self reloadDatasource];
  84. }
  85. - (void)changeTheming
  86. {
  87. if (self.isViewLoaded && self.view.window)
  88. [app changeTheming:self];
  89. }
  90. #pragma --------------------------------------------------------------------------------------------
  91. #pragma mark ==== DZNEmptyDataSetSource ====
  92. #pragma --------------------------------------------------------------------------------------------
  93. - (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView
  94. {
  95. return 0.0f;
  96. }
  97. - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
  98. {
  99. return [UIColor whiteColor];
  100. }
  101. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
  102. {
  103. return [UIImage imageNamed:image_transfersNoRecord];
  104. }
  105. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
  106. {
  107. NSString *text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_no_transfer_", nil)];
  108. NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:[UIColor lightGrayColor]};
  109. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  110. }
  111. - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
  112. {
  113. NSString *text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_no_transfer_sub_", nil)];
  114. NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
  115. paragraph.lineBreakMode = NSLineBreakByWordWrapping;
  116. paragraph.alignment = NSTextAlignmentCenter;
  117. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph};
  118. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  119. }
  120. #pragma --------------------------------------------------------------------------------------------
  121. #pragma mark - ===== Progress & Task Button =====
  122. #pragma --------------------------------------------------------------------------------------------
  123. - (void)triggerProgressTask:(NSNotification *)notification
  124. {
  125. NSDictionary *dict = notification.userInfo;
  126. NSString *fileID = [dict valueForKey:@"fileID"];
  127. BOOL cryptated = [[dict valueForKey:@"cryptated"] boolValue];
  128. float progress = [[dict valueForKey:@"progress"] floatValue];
  129. // Check
  130. if (!fileID)
  131. return;
  132. [app.listProgressMetadata setObject:[NSNumber numberWithFloat:progress] forKey:fileID];
  133. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:fileID];
  134. if (indexPath && indexPath.row == 0) {
  135. CCTransfersCell *cell = (CCTransfersCell *)[_tableView cellForRowAtIndexPath:indexPath];
  136. if (cryptated) cell.progressView.progressTintColor = [NCBrandColor sharedInstance].cryptocloud;
  137. else cell.progressView.progressTintColor = [UIColor blackColor];
  138. cell.progressView.hidden = NO;
  139. [cell.progressView setProgress:progress];
  140. } else {
  141. [self reloadDatasource];
  142. }
  143. }
  144. - (void)reloadTaskButton:(id)sender withEvent:(UIEvent *)event
  145. {
  146. if (app.activeMain == nil)
  147. return;
  148. UITouch * touch = [[event allTouches] anyObject];
  149. CGPoint location = [touch locationInView:_tableView];
  150. NSIndexPath * indexPath = [_tableView indexPathForRowAtPoint:location];
  151. if (indexPath) {
  152. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  153. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  154. if (metadata)
  155. [app.activeMain reloadTaskButton:metadata];
  156. }
  157. }
  158. - (void)reloadAllTask
  159. {
  160. if (app.activeMain == nil)
  161. return;
  162. for (NSString *key in _sectionDataSource.allRecordsDataSource.allKeys) {
  163. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:key];
  164. if ([metadata.session containsString:@"download"] && (metadata.sessionTaskIdentifierPlist != k_taskIdentifierDone))
  165. continue;
  166. if ([metadata.session containsString:@"upload"] && (metadata.sessionTaskIdentifier != k_taskIdentifierStop))
  167. continue;
  168. [app.activeMain reloadTaskButton:metadata];
  169. }
  170. }
  171. - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
  172. {
  173. if (app.activeMain == nil)
  174. return;
  175. UITouch * touch = [[event allTouches] anyObject];
  176. CGPoint location = [touch locationInView:_tableView];
  177. NSIndexPath * indexPath = [_tableView indexPathForRowAtPoint:location];
  178. if (indexPath) {
  179. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  180. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  181. if (metadata)
  182. [app.activeMain cancelTaskButton:metadata reloadTable:YES];
  183. }
  184. }
  185. - (void)cancelAllTask
  186. {
  187. if (app.activeMain == nil)
  188. return;
  189. BOOL lastAndRefresh = NO;
  190. for (NSString *key in _sectionDataSource.allRecordsDataSource.allKeys) {
  191. if ([key isEqualToString:[_sectionDataSource.allRecordsDataSource.allKeys lastObject]])
  192. lastAndRefresh = YES;
  193. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:key];
  194. if ([metadata.session containsString:@"upload"] && metadata.cryptated && ((metadata.sessionTaskIdentifier == k_taskIdentifierDone && metadata.sessionTaskIdentifierPlist >= 0) || (metadata.sessionTaskIdentifier >= 0 && metadata.sessionTaskIdentifierPlist == k_taskIdentifierDone)))
  195. continue;
  196. [app.activeMain cancelTaskButton:metadata reloadTable:lastAndRefresh];
  197. }
  198. }
  199. - (void)stopTaskButton:(id)sender withEvent:(UIEvent *)event
  200. {
  201. if (app.activeMain == nil)
  202. return;
  203. UITouch * touch = [[event allTouches] anyObject];
  204. CGPoint location = [touch locationInView:_tableView];
  205. NSIndexPath * indexPath = [_tableView indexPathForRowAtPoint:location];
  206. if (indexPath) {
  207. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  208. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  209. if (metadata)
  210. [app.activeMain stopTaskButton:metadata];
  211. }
  212. }
  213. - (void)stopAllTask
  214. {
  215. if (app.activeMain == nil)
  216. return;
  217. for (NSString *key in _sectionDataSource.allRecordsDataSource.allKeys) {
  218. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:key];
  219. if ([metadata.session containsString:@"download"]) {
  220. [app.activeMain cancelTaskButton:metadata reloadTable:YES];
  221. continue;
  222. }
  223. if ([metadata.session containsString:@"upload"] && metadata.cryptated && ((metadata.sessionTaskIdentifier == k_taskIdentifierDone && metadata.sessionTaskIdentifierPlist >= 0) || (metadata.sessionTaskIdentifier >= 0 && metadata.sessionTaskIdentifierPlist == k_taskIdentifierDone)))
  224. continue;
  225. [app.activeMain stopTaskButton:metadata];
  226. }
  227. }
  228. #pragma --------------------------------------------------------------------------------------------
  229. #pragma mark - ==== Datasource ====
  230. #pragma --------------------------------------------------------------------------------------------
  231. - (void)reloadDatasource
  232. {
  233. // test
  234. if (app.activeAccount.length == 0)
  235. return;
  236. NSArray *recordsTableMetadata = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND ((session CONTAINS 'upload') OR (session CONTAINS 'download' AND (sessionSelector != 'loadPlist')))", app.activeAccount] fieldOrder:@"sessionTaskIdentifier" ascending:YES];
  237. _sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:app.listProgressMetadata groupByField:@"session" replaceDateToExifDate:NO activeAccount:app.activeAccount];
  238. [_tableView reloadData];
  239. }
  240. #pragma --------------------------------------------------------------------------------------------
  241. #pragma mark - ==== Table ====
  242. #pragma --------------------------------------------------------------------------------------------
  243. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  244. {
  245. return 50;
  246. }
  247. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  248. {
  249. return [[_sectionDataSource.sectionArrayRow allKeys] count];
  250. }
  251. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  252. {
  253. return [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]] count];
  254. }
  255. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  256. {
  257. return 13.0f;
  258. }
  259. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  260. {
  261. UIVisualEffectView *visualEffectView;
  262. NSString *titleSection, *numberTitle;
  263. NSInteger typeOfSession = 0;
  264. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
  265. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]]) titleSection = [CCUtility getTitleSectionDate:[_sectionDataSource.sections objectAtIndex:section]];
  266. NSArray *metadatas = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]];
  267. NSUInteger rowsCount = [metadatas count];
  268. visualEffectView = [[UIVisualEffectView alloc] init];
  269. visualEffectView.backgroundColor = [UIColor clearColor];
  270. // title section
  271. if ([titleSection isEqualToString:@"_none_"]) {
  272. titleSection = @"";
  273. } else if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"]) {
  274. typeOfSession = download;
  275. titleSection = NSLocalizedString(@"_title_section_download_",nil);
  276. } else if ([titleSection containsString:@"download"] && [titleSection containsString:@"wwan"]) {
  277. typeOfSession = downloadwwan;
  278. titleSection = [NSLocalizedString(@"_title_section_download_",nil) stringByAppendingString:@" Wi-Fi"];
  279. } else if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"]) {
  280. typeOfSession = upload;
  281. titleSection = NSLocalizedString(@"_title_section_upload_",nil);
  282. } else if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"]) {
  283. typeOfSession = uploadwwan;
  284. titleSection = [NSLocalizedString(@"_title_section_upload_",nil) stringByAppendingString:@" Wi-Fi"];
  285. } else {
  286. titleSection = NSLocalizedString(titleSection,nil);
  287. }
  288. // title label on left
  289. UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(8, 3, 0, 13)];
  290. titleLabel.textColor = [UIColor blackColor];
  291. titleLabel.font = [UIFont systemFontOfSize:9];
  292. titleLabel.textAlignment = NSTextAlignmentLeft;
  293. titleLabel.text = titleSection;
  294. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  295. [visualEffectView addSubview:titleLabel];
  296. // element (s) on right
  297. UILabel *elementLabel=[[UILabel alloc]initWithFrame:CGRectMake(-8, 3, 0, 13)];
  298. elementLabel.textColor = [UIColor blackColor];
  299. elementLabel.font = [UIFont systemFontOfSize:9];
  300. elementLabel.textAlignment = NSTextAlignmentRight;
  301. elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  302. if ((typeOfSession == download && app.queueNunDownload > rowsCount) || (typeOfSession == downloadwwan && app.queueNumDownloadWWan > rowsCount) ||
  303. (typeOfSession == upload && app.queueNumUpload > rowsCount) || (typeOfSession == uploadwwan && app.queueNumUploadWWan > rowsCount)) {
  304. numberTitle = [NSString stringWithFormat:@"%lu+", (unsigned long)rowsCount];
  305. } else {
  306. numberTitle = [NSString stringWithFormat:@"%lu", (unsigned long)rowsCount];
  307. }
  308. if (rowsCount > 1)
  309. elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_elements_",nil)];
  310. else
  311. elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_element_",nil)];
  312. // view
  313. [visualEffectView addSubview:elementLabel];
  314. return visualEffectView;
  315. }
  316. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  317. {
  318. NSString *titleSection;
  319. NSString *element_s;
  320. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
  321. // Prepare view for title in footer
  322. UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
  323. UILabel *titleFooterLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)];
  324. titleFooterLabel.textColor = [UIColor blackColor];
  325. titleFooterLabel.font = [UIFont systemFontOfSize:12];
  326. titleFooterLabel.textAlignment = NSTextAlignmentCenter;
  327. // Footer Download
  328. if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
  329. // element or elements ?
  330. if (app.queueNunDownload > 1) element_s = NSLocalizedString(@"_elements_",nil);
  331. else element_s = NSLocalizedString(@"_element_",nil);
  332. // Num record to upload
  333. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_download_", nil), app.queueNunDownload, element_s]];
  334. titleFooterLabel.attributedText = stringFooter;
  335. [view addSubview:titleFooterLabel];
  336. return view;
  337. }
  338. // Footer Download WWAN
  339. if ([titleSection containsString:@"download"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
  340. // element or elements ?
  341. if (app.queueNumDownloadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
  342. else element_s = NSLocalizedString(@"_element_",nil);
  343. // Add the symbol WiFi and Num record
  344. NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
  345. attachment.image = [UIImage imageNamed:image_WiFiSmall];
  346. NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
  347. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_download_wwan_", nil), app.queueNumDownloadWWan, element_s]];
  348. [stringFooter insertAttributedString:attachmentString atIndex:0];
  349. titleFooterLabel.attributedText = stringFooter;
  350. [view addSubview:titleFooterLabel];
  351. return view;
  352. }
  353. // Footer Upload
  354. if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
  355. // element or elements ?
  356. if (app.queueNumUpload > 1) element_s = NSLocalizedString(@"_elements_",nil);
  357. else element_s = NSLocalizedString(@"_element_",nil);
  358. // Num record to upload
  359. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_", nil), app.queueNumUpload, element_s]];
  360. titleFooterLabel.attributedText = stringFooter;
  361. [view addSubview:titleFooterLabel];
  362. return view;
  363. }
  364. // Footer Upload WWAN
  365. if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
  366. // element or elements ?
  367. if (app.queueNumUploadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
  368. else element_s = NSLocalizedString(@"_element_",nil);
  369. // Add the symbol WiFi and Num record
  370. NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
  371. attachment.image = [UIImage imageNamed:image_WiFiSmall];
  372. NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
  373. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_wwan_", nil), app.queueNumUploadWWan,element_s]];
  374. [stringFooter insertAttributedString:attachmentString atIndex:0];
  375. titleFooterLabel.attributedText = stringFooter;
  376. [view addSubview:titleFooterLabel];
  377. return view;
  378. }
  379. return nil;
  380. }
  381. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  382. {
  383. //NSString *titleSection;
  384. //if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]])
  385. // titleSection = [_sectionDataSource.sections objectAtIndex:section];
  386. //if ([titleSection rangeOfString:@"upload"].location != NSNotFound && [titleSection rangeOfString:@"wwan"].location != NSNotFound && titleSection != nil) return 18.0f;
  387. //else return 0.0f;
  388. return 18.0f;
  389. }
  390. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  391. {
  392. return [_sectionDataSource.sections indexOfObject:title];
  393. }
  394. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  395. {
  396. NSString *dataFile;
  397. NSString *lunghezzaFile;
  398. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  399. CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  400. CCTransfersCell *cell = (CCTransfersCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
  401. cell.backgroundColor = [UIColor clearColor];
  402. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  403. // ----------------------------------------------------------------------------------------------------------
  404. // DEFAULT
  405. // ----------------------------------------------------------------------------------------------------------
  406. cell.fileImageView.image = nil;
  407. cell.statusImageView.image = nil;
  408. cell.labelTitle.enabled = YES;
  409. cell.labelTitle.text = @"";
  410. cell.labelInfoFile.enabled = YES;
  411. cell.labelInfoFile.text = @"";
  412. cell.progressView.progress = 0.0;
  413. cell.progressView.hidden = YES;
  414. cell.cancelTaskButton.hidden = YES;
  415. cell.reloadTaskButton.hidden = YES;
  416. cell.stopTaskButton.hidden = YES;
  417. // colori e font
  418. if (metadata.cryptated) {
  419. cell.labelTitle.textColor = [NCBrandColor sharedInstance].cryptocloud;
  420. cell.labelInfoFile.textColor = [UIColor blackColor];
  421. } else {
  422. cell.labelTitle.textColor = [UIColor blackColor];
  423. cell.labelInfoFile.textColor = [UIColor blackColor];
  424. }
  425. // ----------------------------------------------------------------------------------------------------------
  426. // File Name & Folder
  427. // ----------------------------------------------------------------------------------------------------------
  428. // nome del file
  429. cell.labelTitle.text = metadata.fileNamePrint;
  430. // è una directory
  431. if (metadata.directory) {
  432. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  433. cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
  434. lunghezzaFile = @" ";
  435. } else {
  436. // è un file
  437. dataFile = [CCUtility dateDiff:metadata.date];
  438. lunghezzaFile = [CCUtility transformedSize:metadata.size];
  439. // Plist ancora da scaricare
  440. if (metadata.cryptated && [metadata.title length] == 0) {
  441. dataFile = @" ";
  442. lunghezzaFile = @" ";
  443. }
  444. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  445. [dateFormatter setDateStyle:NSDateFormatterShortStyle];
  446. [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
  447. cell.accessoryType = UITableViewCellAccessoryNone;
  448. }
  449. // ----------------------------------------------------------------------------------------------------------
  450. // File Image View
  451. // ----------------------------------------------------------------------------------------------------------
  452. // assegnamo l'immagine anteprima se esiste, altrimenti metti quella standars
  453. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]]) {
  454. cell.fileImageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
  455. } else {
  456. cell.fileImageView.image = [UIImage imageNamed:metadata.iconName];
  457. }
  458. // ----------------------------------------------------------------------------------------------------------
  459. // Image Status cyptated & Lock Passcode
  460. // ----------------------------------------------------------------------------------------------------------
  461. // File Cyptated
  462. if (metadata.cryptated && metadata.directory == NO && [metadata.type isEqualToString: k_metadataType_template] == NO) {
  463. cell.statusImageView.image = [UIImage imageNamed:image_lock];
  464. }
  465. // ----------------------------------------------------------------------------------------------------------
  466. // downloadFile
  467. // ----------------------------------------------------------------------------------------------------------
  468. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"download"].location != NSNotFound) {
  469. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusdownloadcrypto];
  470. else cell.statusImageView.image = [UIImage imageNamed:image_statusdownload];
  471. // Fai comparire il RELOAD e lo STOP solo se non è un Task Plist
  472. if (metadata.sessionTaskIdentifierPlist == k_taskIdentifierDone) {
  473. if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptaskcrypto] forState:UIControlStateNormal];
  474. else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptask] forState:UIControlStateNormal];
  475. cell.cancelTaskButton.hidden = NO;
  476. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
  477. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
  478. cell.reloadTaskButton.hidden = NO;
  479. }
  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 = [NCBrandColor sharedInstance].cryptocloud;
  484. else cell.progressView.progressTintColor = [UIColor blackColor];
  485. cell.progressView.progress = progress;
  486. cell.progressView.hidden = NO;
  487. }
  488. // ----------------------------------------------------------------------------------------------------------
  489. // downloadFile Error
  490. // ----------------------------------------------------------------------------------------------------------
  491. if (metadata.sessionTaskIdentifier == k_taskIdentifierError || metadata.sessionTaskIdentifierPlist == k_taskIdentifierError) {
  492. cell.statusImageView.image = [UIImage imageNamed:image_statuserror];
  493. if ([metadata.sessionError length] == 0)
  494. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_downloaded_",nil)];
  495. else
  496. cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
  497. }
  498. }
  499. // ----------------------------------------------------------------------------------------------------------
  500. // uploadFile
  501. // ----------------------------------------------------------------------------------------------------------
  502. if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"upload"].location != NSNotFound) {
  503. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusuploadcrypto];
  504. else cell.statusImageView.image = [UIImage imageNamed:image_statusupload];
  505. if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_removetaskcrypto] forState:UIControlStateNormal];
  506. else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_removetask] forState:UIControlStateNormal];
  507. cell.cancelTaskButton.hidden = NO;
  508. if (metadata.sessionTaskIdentifier == k_taskIdentifierStop) {
  509. if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
  510. else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
  511. if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusstopcrypto];
  512. else cell.statusImageView.image = [UIImage imageNamed:image_statusstop];
  513. cell.reloadTaskButton.hidden = NO;
  514. cell.stopTaskButton.hidden = YES;
  515. } else {
  516. if (metadata.cryptated)[cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptaskcrypto] forState:UIControlStateNormal];
  517. else [cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptask] forState:UIControlStateNormal];
  518. cell.stopTaskButton.hidden = NO;
  519. cell.reloadTaskButton.hidden = YES;
  520. }
  521. // se non c'è una preview in bianconero metti l'immagine di default
  522. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]] == NO)
  523. cell.fileImageView.image = [UIImage imageNamed:image_uploaddisable];
  524. cell.labelTitle.enabled = NO;
  525. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
  526. float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  527. if (progress > 0) {
  528. if (metadata.cryptated) cell.progressView.progressTintColor = [NCBrandColor sharedInstance].cryptocloud;
  529. else cell.progressView.progressTintColor = [UIColor blackColor];
  530. cell.progressView.progress = progress;
  531. cell.progressView.hidden = NO;
  532. }
  533. // ----------------------------------------------------------------------------------------------------------
  534. // uploadFileError
  535. // ----------------------------------------------------------------------------------------------------------
  536. if (metadata.sessionTaskIdentifier == k_taskIdentifierError || metadata.sessionTaskIdentifierPlist == k_taskIdentifierError) {
  537. cell.labelTitle.enabled = NO;
  538. cell.statusImageView.image = [UIImage imageNamed:image_statuserror];
  539. if ([metadata.sessionError length] == 0)
  540. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_uploaded_",nil)];
  541. else
  542. cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
  543. }
  544. }
  545. [cell.reloadTaskButton addTarget:self action:@selector(reloadTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  546. [cell.cancelTaskButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  547. [cell.stopTaskButton addTarget:self action:@selector(stopTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  548. return cell;
  549. }
  550. @end