CCTransfers.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. //
  2. // CCTransfers.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 12/04/17.
  6. // Copyright (c) 2017 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 "CCCellMainTransfer.h"
  29. #import "NCBridgeSwift.h"
  30. #define download 1
  31. #define downloadwwan 2
  32. #define upload 3
  33. #define uploadwwan 4
  34. @interface CCTransfers ()
  35. {
  36. AppDelegate *appDelegate;
  37. // Datasource
  38. CCSectionDataSourceMetadata *_sectionDataSource;
  39. }
  40. @end
  41. @implementation CCTransfers
  42. #pragma --------------------------------------------------------------------------------------------
  43. #pragma mark ===== Init =====
  44. #pragma --------------------------------------------------------------------------------------------
  45. - (id)initWithCoder:(NSCoder *)aDecoder
  46. {
  47. if (self = [super initWithCoder:aDecoder]) {
  48. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  49. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
  50. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  51. }
  52. return self;
  53. }
  54. - (void)viewDidLoad {
  55. [super viewDidLoad];
  56. // Custom Cell
  57. [_tableView registerNib:[UINib nibWithNibName:@"CCCellMainTransfer" bundle:nil] forCellReuseIdentifier:@"Cell"];
  58. _tableView.delegate = self;
  59. _tableView.dataSource = self;
  60. _tableView.emptyDataSetDelegate = self;
  61. _tableView.emptyDataSetSource = self;
  62. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  63. _tableView.backgroundColor = [NCBrandColor sharedInstance].backgroundView;
  64. self.title = NSLocalizedString(@"_transfers_", nil);
  65. [self reloadDatasource];
  66. }
  67. // Apparirà
  68. - (void)viewWillAppear:(BOOL)animated
  69. {
  70. [super viewWillAppear:animated];
  71. // Color
  72. [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
  73. [appDelegate aspectTabBar:self.tabBarController.tabBar hidden:NO];
  74. [self reloadDatasource];
  75. }
  76. - (void)changeTheming
  77. {
  78. if (self.isViewLoaded && self.view.window)
  79. [appDelegate changeTheming:self];
  80. }
  81. #pragma --------------------------------------------------------------------------------------------
  82. #pragma mark ==== DZNEmptyDataSetSource ====
  83. #pragma --------------------------------------------------------------------------------------------
  84. - (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView
  85. {
  86. return 0.0f;
  87. }
  88. - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
  89. {
  90. return [UIColor whiteColor];
  91. }
  92. - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
  93. {
  94. return [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"loadNoRecord"] multiplier:2 color:[NCBrandColor sharedInstance].graySoft];
  95. }
  96. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
  97. {
  98. NSString *text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_no_transfer_", nil)];
  99. NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:[UIColor lightGrayColor]};
  100. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  101. }
  102. - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
  103. {
  104. NSString *text = [NSString stringWithFormat:@"%@", NSLocalizedString(@"_no_transfer_sub_", nil)];
  105. NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
  106. paragraph.lineBreakMode = NSLineBreakByWordWrapping;
  107. paragraph.alignment = NSTextAlignmentCenter;
  108. NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph};
  109. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  110. }
  111. #pragma --------------------------------------------------------------------------------------------
  112. #pragma mark - ===== Progress & Task Button =====
  113. #pragma --------------------------------------------------------------------------------------------
  114. - (void)triggerProgressTask:(NSNotification *)notification
  115. {
  116. NSDictionary *dict = notification.userInfo;
  117. NSString *fileID = [dict valueForKey:@"fileID"];
  118. // NSString *serverUrl = [dict valueForKey:@"serverUrl"];
  119. long status = [[dict valueForKey:@"status"] longValue];
  120. NSString *statusString = @"";
  121. float progress = [[dict valueForKey:@"progress"] floatValue];
  122. long long totalBytes = [[dict valueForKey:@"totalBytes"] longLongValue];
  123. long long totalBytesExpected = [[dict valueForKey:@"totalBytesExpected"] longLongValue];
  124. // Check
  125. if (!fileID || [fileID isEqualToString: @""])
  126. return;
  127. [appDelegate.listProgressMetadata setObject:[NSNumber numberWithFloat:progress] forKey:fileID];
  128. NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:fileID];
  129. if (indexPath && indexPath.row == 0) {
  130. CCCellMainTransfer *cell = (CCCellMainTransfer *)[self.tableView cellForRowAtIndexPath:indexPath];
  131. if (status == k_metadataStatusInDownload) {
  132. statusString = @"↓";
  133. } else if (status == k_metadataStatusInUpload) {
  134. statusString = @"↑";
  135. }
  136. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ - %@%@", [CCUtility transformedSize:totalBytesExpected], statusString, [CCUtility transformedSize:totalBytes]];
  137. if ([cell isKindOfClass:[CCCellMainTransfer class]]) {
  138. cell.transferButton.progress = progress;
  139. }
  140. } else {
  141. [self reloadDatasource];
  142. }
  143. }
  144. - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
  145. {
  146. UITouch * touch = [[event allTouches] anyObject];
  147. CGPoint location = [touch locationInView:_tableView];
  148. NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:location];
  149. if (indexPath) {
  150. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  151. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  152. if (metadata)
  153. [appDelegate.activeMain cancelTaskButton:metadata reloadTable:YES];
  154. }
  155. }
  156. - (void)cancelAllTask
  157. {
  158. if (appDelegate.activeMain == nil)
  159. return;
  160. BOOL lastAndRefresh = NO;
  161. for (NSString *key in _sectionDataSource.allRecordsDataSource.allKeys) {
  162. if ([key isEqualToString:[_sectionDataSource.allRecordsDataSource.allKeys lastObject]])
  163. lastAndRefresh = YES;
  164. tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:key];
  165. if ([metadata.session containsString:@"upload"] && ((metadata.sessionTaskIdentifier == k_taskIdentifierDone) || (metadata.sessionTaskIdentifier >= 0)))
  166. continue;
  167. [appDelegate.activeMain cancelTaskButton:metadata reloadTable:lastAndRefresh];
  168. }
  169. }
  170. #pragma --------------------------------------------------------------------------------------------
  171. #pragma mark - ==== download Thumbnail ====
  172. #pragma --------------------------------------------------------------------------------------------
  173. #pragma --------------------------------------------------------------------------------------------
  174. #pragma mark - ==== Datasource ====
  175. #pragma --------------------------------------------------------------------------------------------
  176. - (void)reloadDatasource
  177. {
  178. // test
  179. if (appDelegate.activeAccount.length == 0)
  180. return;
  181. NSArray *recordsTableMetadata = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account = %@ AND ((session CONTAINS 'upload') OR (session CONTAINS 'download'))", appDelegate.activeAccount] sorted:@"sessionTaskIdentifier" ascending:YES];
  182. _sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:recordsTableMetadata listProgressMetadata:appDelegate.listProgressMetadata groupByField:@"session" fileIDHide:nil activeAccount:appDelegate.activeAccount];
  183. [_tableView reloadData];
  184. }
  185. #pragma --------------------------------------------------------------------------------------------
  186. #pragma mark - ==== Table ====
  187. #pragma --------------------------------------------------------------------------------------------
  188. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  189. {
  190. return 50;
  191. }
  192. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  193. {
  194. return [[_sectionDataSource.sectionArrayRow allKeys] count];
  195. }
  196. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  197. {
  198. return [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]] count];
  199. }
  200. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  201. {
  202. return 13.0f;
  203. }
  204. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  205. {
  206. UIVisualEffectView *visualEffectView;
  207. NSString *titleSection, *numberTitle;
  208. NSInteger typeOfSession = 0;
  209. NSInteger queueDownload = 0; // [[CCNetworking sharedNetworking] getNumDownloadInProgressWWan:NO];
  210. NSInteger queueDownloadWWan = 0; // [[CCNetworking sharedNetworking] getNumDownloadInProgressWWan:YES];
  211. NSInteger queueUpload = 0; // [[CCNetworking sharedNetworking] getNumUploadInProgressWWan:NO];
  212. NSInteger queueUploadWWan = 0; // [[CCNetworking sharedNetworking] getNumUploadInProgressWWan:YES];
  213. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
  214. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]]) titleSection = [CCUtility getTitleSectionDate:[_sectionDataSource.sections objectAtIndex:section]];
  215. NSArray *metadatas = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]];
  216. NSUInteger rowsCount = [metadatas count];
  217. visualEffectView = [[UIVisualEffectView alloc] init];
  218. visualEffectView.backgroundColor = [UIColor clearColor];
  219. // title section
  220. if ([titleSection isEqualToString:@"_none_"]) {
  221. titleSection = @"";
  222. } else if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"]) {
  223. typeOfSession = download;
  224. titleSection = NSLocalizedString(@"_title_section_download_",nil);
  225. } else if ([titleSection containsString:@"download"] && [titleSection containsString:@"wwan"]) {
  226. typeOfSession = downloadwwan;
  227. titleSection = [NSLocalizedString(@"_title_section_download_",nil) stringByAppendingString:@" Wi-Fi"];
  228. } else if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"]) {
  229. typeOfSession = upload;
  230. titleSection = NSLocalizedString(@"_title_section_upload_",nil);
  231. } else if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"]) {
  232. typeOfSession = uploadwwan;
  233. titleSection = [NSLocalizedString(@"_title_section_upload_",nil) stringByAppendingString:@" Wi-Fi"];
  234. } else {
  235. titleSection = NSLocalizedString(titleSection,nil);
  236. }
  237. // title label on left
  238. UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(8, 3, 0, 13)];
  239. titleLabel.textColor = [UIColor blackColor];
  240. titleLabel.font = [UIFont systemFontOfSize:9];
  241. titleLabel.textAlignment = NSTextAlignmentLeft;
  242. titleLabel.text = titleSection;
  243. titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  244. [visualEffectView.contentView addSubview:titleLabel];
  245. // element (s) on right
  246. UILabel *elementLabel=[[UILabel alloc]initWithFrame:CGRectMake(-8, 3, 0, 13)];
  247. elementLabel.textColor = [UIColor blackColor];
  248. elementLabel.font = [UIFont systemFontOfSize:9];
  249. elementLabel.textAlignment = NSTextAlignmentRight;
  250. elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  251. if ((typeOfSession == download && queueDownload > rowsCount) || (typeOfSession == downloadwwan && queueDownloadWWan > rowsCount) ||
  252. (typeOfSession == upload && queueUpload > rowsCount) || (typeOfSession == uploadwwan && queueUploadWWan > rowsCount)) {
  253. numberTitle = [NSString stringWithFormat:@"%lu+", (unsigned long)rowsCount];
  254. } else {
  255. numberTitle = [NSString stringWithFormat:@"%lu", (unsigned long)rowsCount];
  256. }
  257. if (rowsCount > 1)
  258. elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_elements_",nil)];
  259. else
  260. elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_element_",nil)];
  261. // view
  262. [visualEffectView.contentView addSubview:elementLabel];
  263. return visualEffectView;
  264. }
  265. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
  266. {
  267. NSString *titleSection;
  268. NSString *element_s;
  269. if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
  270. // Prepare view for title in footer
  271. UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
  272. UILabel *titleFooterLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)];
  273. titleFooterLabel.textColor = [UIColor blackColor];
  274. titleFooterLabel.font = [UIFont systemFontOfSize:12];
  275. titleFooterLabel.textAlignment = NSTextAlignmentCenter;
  276. // Footer Download
  277. if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
  278. NSInteger queueDownload = 0; // [[CCNetworking sharedNetworking] getNumDownloadInProgressWWan:NO];
  279. // element or elements ?
  280. if (queueDownload > 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), queueDownload, 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. NSInteger queueDownloadWWan = 0; //[[CCNetworking sharedNetworking] getNumDownloadInProgressWWan:YES];
  291. // element or elements ?
  292. if (queueDownloadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
  293. else element_s = NSLocalizedString(@"_element_",nil);
  294. // Add the symbol WiFi and Num record
  295. NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
  296. attachment.image = [UIImage imageNamed:@"WiFiSmall"];
  297. NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
  298. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[@" " stringByAppendingString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_download_wwan_", nil), queueDownloadWWan, element_s]]];
  299. [stringFooter insertAttributedString:attachmentString atIndex:0];
  300. titleFooterLabel.attributedText = stringFooter;
  301. [view addSubview:titleFooterLabel];
  302. return view;
  303. }
  304. // Footer Upload
  305. if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
  306. NSInteger queueUpload = 0; // [[CCNetworking sharedNetworking] getNumUploadInProgressWWan:NO];
  307. // element or elements ?
  308. if (queueUpload > 1) element_s = NSLocalizedString(@"_elements_",nil);
  309. else element_s = NSLocalizedString(@"_element_",nil);
  310. // Num record to upload
  311. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_", nil), queueUpload, element_s]];
  312. titleFooterLabel.attributedText = stringFooter;
  313. [view addSubview:titleFooterLabel];
  314. return view;
  315. }
  316. // Footer Upload WWAN
  317. if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
  318. NSInteger queueUploadWWan = 0; // [[CCNetworking sharedNetworking] getNumUploadInProgressWWan:YES];
  319. // element or elements ?
  320. if (queueUploadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
  321. else element_s = NSLocalizedString(@"_element_",nil);
  322. // Add the symbol WiFi and Num record
  323. NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
  324. attachment.image = [UIImage imageNamed:@"WiFiSmall"];
  325. NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
  326. NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[@" " stringByAppendingString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_wwan_", nil), queueUploadWWan,element_s]]];
  327. [stringFooter insertAttributedString:attachmentString atIndex:0];
  328. titleFooterLabel.attributedText = stringFooter;
  329. [view addSubview:titleFooterLabel];
  330. return view;
  331. }
  332. return nil;
  333. }
  334. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
  335. {
  336. //NSString *titleSection;
  337. //if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]])
  338. // titleSection = [_sectionDataSource.sections objectAtIndex:section];
  339. //if ([titleSection rangeOfString:@"upload"].location != NSNotFound && [titleSection rangeOfString:@"wwan"].location != NSNotFound && titleSection != nil) return 18.0f;
  340. //else return 0.0f;
  341. return 18.0f;
  342. }
  343. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
  344. {
  345. return [_sectionDataSource.sections indexOfObject:title];
  346. }
  347. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  348. {
  349. NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
  350. tableMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
  351. // Create File System
  352. if (metadata.directory) {
  353. [CCUtility getDirectoryProviderStorageFileID:metadata.fileID];
  354. } else {
  355. [CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileName:metadata.fileNameView];
  356. }
  357. CCCellMainTransfer *cell = (CCCellMainTransfer *)[tableView dequeueReusableCellWithIdentifier:@"CellMainTransfer" forIndexPath:indexPath];
  358. cell.separatorInset = UIEdgeInsetsMake(0.f, 60.f, 0.f, 0.f);
  359. cell.accessoryType = UITableViewCellAccessoryNone;
  360. cell.file.image = nil;
  361. cell.status.image = nil;
  362. cell.backgroundColor = [NCBrandColor sharedInstance].transferBackground;
  363. cell.labelTitle.textColor = [UIColor blackColor];
  364. cell.labelTitle.text = metadata.fileNameView;
  365. cell.transferButton.tintColor = [NCBrandColor sharedInstance].icon;
  366. // Write status on Label Info
  367. NSString *statusString = @"";
  368. switch (metadata.status) {
  369. case 2:
  370. statusString = NSLocalizedString(@"_status_wait_download_",nil);
  371. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ %@", [CCUtility transformedSize:metadata.size], statusString];
  372. break;
  373. case 3:
  374. statusString = NSLocalizedString(@"_status_in_download_",nil);
  375. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ %@", [CCUtility transformedSize:metadata.size], statusString];
  376. break;
  377. case 4:
  378. statusString = NSLocalizedString(@"_status_downloading_",nil);
  379. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", [CCUtility transformedSize:metadata.size]];
  380. break;
  381. case 6:
  382. statusString = NSLocalizedString(@"_status_wait_upload_",nil);
  383. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", statusString];
  384. break;
  385. case 7:
  386. statusString = NSLocalizedString(@"_status_in_upload_",nil);
  387. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", statusString];
  388. break;
  389. case 8:
  390. statusString = NSLocalizedString(@"_status_uploading_",nil);
  391. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@ %@", [CCUtility transformedSize:metadata.size], statusString];
  392. break;
  393. default:
  394. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", [CCUtility transformedSize:metadata.size]];
  395. break;
  396. }
  397. BOOL iconFileExists = [[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]];
  398. if (iconFileExists) {
  399. cell.file.image = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]];
  400. } else {
  401. if (metadata.iconName.length > 0) {
  402. cell.file.image = [UIImage imageNamed:metadata.iconName];
  403. } else {
  404. cell.file.image = [UIImage imageNamed:@"file"];
  405. }
  406. }
  407. // Session Upload Extension
  408. if ([metadata.session isEqualToString:k_upload_session_extension] && (metadata.status == k_metadataStatusInUpload || metadata.status == k_metadataStatusUploading)) {
  409. cell.labelTitle.enabled = NO;
  410. cell.labelInfoFile.enabled = NO;
  411. cell.userInteractionEnabled = NO;
  412. cell.transferButton.hidden = YES;
  413. } else {
  414. cell.labelTitle.enabled = YES;
  415. cell.labelInfoFile.enabled = YES;
  416. cell.userInteractionEnabled = YES;
  417. }
  418. // downloadFile
  419. if (metadata.status == k_metadataStatusWaitDownload || metadata.status == k_metadataStatusInDownload || metadata.status == k_metadataStatusDownloading || metadata.status == k_metadataStatusDownloadError) {
  420. //
  421. }
  422. // downloadFile Error
  423. if (metadata.status == k_metadataStatusDownloadError) {
  424. cell.status.image = [UIImage imageNamed:@"statuserror"];
  425. if ([metadata.sessionError length] == 0) {
  426. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_downloaded_",nil)];
  427. } else {
  428. cell.labelInfoFile.text = metadata.sessionError;
  429. }
  430. }
  431. // uploadFile
  432. if (metadata.status == k_metadataStatusWaitUpload || metadata.status == k_metadataStatusInUpload || metadata.status == k_metadataStatusUploading || metadata.status == k_metadataStatusUploadError) {
  433. if (!iconFileExists) {
  434. cell.file.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"uploadCloud"] multiplier:2 color:[NCBrandColor sharedInstance].brandElement];
  435. }
  436. cell.labelTitle.enabled = NO;
  437. }
  438. // uploadFileError
  439. if (metadata.status == k_metadataStatusUploadError) {
  440. cell.labelTitle.enabled = NO;
  441. cell.status.image = [UIImage imageNamed:@"statuserror"];
  442. if (!iconFileExists) {
  443. cell.file.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"uploadCloud"] multiplier:2 color:[NCBrandColor sharedInstance].brandElement];
  444. }
  445. if ([metadata.sessionError length] == 0) {
  446. cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_uploaded_",nil)];
  447. } else {
  448. cell.labelInfoFile.text = metadata.sessionError;
  449. }
  450. }
  451. // Progress
  452. float progress = [[appDelegate.listProgressMetadata objectForKey:metadata.fileID] floatValue];
  453. cell.transferButton.progress = progress;
  454. // gesture Transfer
  455. [cell.transferButton.stopButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
  456. UILongPressGestureRecognizer *stopLongGesture = [UILongPressGestureRecognizer new];
  457. [stopLongGesture addTarget:self action:@selector(cancelAllTask:)];
  458. [cell.transferButton.stopButton addGestureRecognizer:stopLongGesture];
  459. return cell;
  460. }
  461. @end