CCTransfers.m 34 KB

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