123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965 |
- #import "CCControlCenter.h"
- #import "AppDelegate.h"
- #import "CCMain.h"
- #import "CCDetail.h"
- #define BORDER_TOUCH_UPDOWN 50.0f
- #define TOOLBAR_TRANSFER_H 0.0f
- #define TOOLBAR_ADD_BORDER 20.0f
- #define SIZE_FONT_NORECORD 18.0f
- #define ANIMATION_GESTURE 0.50f
- #define download 1
- #define downloadwwan 2
- #define upload 3
- #define uploadwwan 4
- @interface CCControlCenter ()
- {
- UIVisualEffectView *_mainView;
- UITableView *_tableView;
- UILabel *_noRecord;
-
- UIImageView *_imageDrag;
- UIView *_endLine;
-
- CGFloat start, stop;
-
- UIPanGestureRecognizer *panNavigationBar, *panImageDrag;
- UITapGestureRecognizer *_singleFingerTap;
-
-
- CCSectionDataSource *_sectionDataSource;
- }
- @end
- @implementation CCControlCenter
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Init =====
- #pragma --------------------------------------------------------------------------------------------
- - (id)initWithCoder:(NSCoder *)aDecoder
- {
- if (self = [super initWithCoder:aDecoder]) {
-
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
- _mainView = [[UIVisualEffectView alloc] initWithEffect:effect];
- [_mainView setFrame:CGRectMake(0, 0, self.navigationBar.frame.size.width, 0)];
- _mainView.hidden = YES;
-
-
-
-
- _tableView = [[UITableView alloc] init];
- [_tableView setFrame:CGRectMake(0, 0, self.navigationBar.frame.size.width, 0)];
- _tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
- [_tableView registerNib:[UINib nibWithNibName:@"CCControlCenterCell" bundle:nil] forCellReuseIdentifier:@"CCControlCenterCell"];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.backgroundColor = [UIColor clearColor];
- [_mainView addSubview:_tableView];
-
- _noRecord =[[UILabel alloc]init];
- _noRecord.backgroundColor=[UIColor clearColor];
- _noRecord.textColor = COLOR_BRAND;
- _noRecord.font = [UIFont systemFontOfSize:SIZE_FONT_NORECORD];
- _noRecord.textAlignment = NSTextAlignmentCenter;
- _noRecord.text = NSLocalizedString(@"_no_transfer_",nil);
- [_mainView addSubview:_noRecord];
-
-
-
- _imageDrag = [[UIImageView alloc] init];
- [_imageDrag setFrame:CGRectMake(0, 0, self.navigationBar.frame.size.width, 0)];
- _imageDrag.image = [UIImage imageNamed:image_drag];
- _imageDrag.contentMode = UIViewContentModeCenter;
- _imageDrag.userInteractionEnabled = YES;
- [_mainView addSubview:_imageDrag];
-
- _endLine = [[UIView alloc] init];
- [_endLine setFrame:CGRectMake(0, 0, self.navigationBar.frame.size.width, 0)];
- _endLine.backgroundColor = COLOR_BRAND;
- [_mainView addSubview:_endLine];
-
- [self.navigationBar.superview insertSubview:_mainView belowSubview:self.navigationBar];
-
-
- [self.interactivePopGestureRecognizer addTarget:self action:@selector(handlePopGesture:)];
-
- panImageDrag = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
- panImageDrag.maximumNumberOfTouches = panImageDrag.minimumNumberOfTouches = 1;
-
- [_imageDrag addGestureRecognizer:panImageDrag];
-
- panNavigationBar = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGesture:)];
- panNavigationBar.maximumNumberOfTouches = panNavigationBar.minimumNumberOfTouches = 1;
-
- [self.navigationBar addGestureRecognizer:panNavigationBar];
-
- [self reloadDatasource];
- }
- - (void)handlePanGesture:(UIPanGestureRecognizer *)gesture;
- {
- CGPoint currentPoint = [gesture locationInView:self.view];
- CGFloat navigationBarH = self.navigationBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height;
- CGFloat navigationBarW = self.navigationBar.frame.size.width;
- CGFloat heightScreen = [UIScreen mainScreen].bounds.size.height - self.tabBarController.tabBar.frame.size.height;
- CGFloat heightTableView = [UIScreen mainScreen].bounds.size.height - self.tabBarController.tabBar.frame.size.height - navigationBarH - BORDER_TOUCH_UPDOWN - TOOLBAR_TRANSFER_H - TOOLBAR_ADD_BORDER;
- float centerMaxH = [self getMaxH] / 2;
- float step = [self getMaxH] / 10;
- float tableViewY = navigationBarH;
-
-
- _mainView.hidden = NO;
-
-
- if (gesture.state == UIGestureRecognizerStateBegan) {
-
- start = currentPoint.y;
- }
-
-
- if (gesture.state == UIGestureRecognizerStateCancelled) {
-
- currentPoint.y = 0;
- tableViewY = 0;
- panNavigationBar.enabled = YES;
- }
-
- if (gesture.state == UIGestureRecognizerStateEnded) {
-
- stop = currentPoint.y;
-
-
- if (start < stop) {
-
- if (stop < (start + step + navigationBarH) && start <= navigationBarH) {
- currentPoint.y = 0;
- tableViewY = 0;
- panNavigationBar.enabled = YES;
- } else {
- currentPoint.y = [self getMaxH];
- tableViewY = navigationBarH;
- panNavigationBar.enabled = NO;
- }
- }
-
-
- if (start >= stop && start >= navigationBarH) {
-
- if (stop > (start - step)) {
- currentPoint.y = [self getMaxH];
- tableViewY = navigationBarH;
- panNavigationBar.enabled = NO;
- } else {
- currentPoint.y = 0;
- tableViewY = 0;
- panNavigationBar.enabled = YES;
- }
- }
- }
-
-
- if (gesture.state == UIGestureRecognizerStateChanged) {
-
- if (currentPoint.y <= navigationBarH) {
- currentPoint.y = 0;
- tableViewY = 0;
- }
- else if (currentPoint.y >= [self getMaxH]) {
- currentPoint.y = [self getMaxH];
- tableViewY = navigationBarH;
- }
- else {
- if (currentPoint.y - navigationBarH < navigationBarH) tableViewY = currentPoint.y - navigationBarH;
- else tableViewY = navigationBarH;
- }
- }
-
- [UIView animateWithDuration:ANIMATION_GESTURE delay:0.0 options:UIViewAnimationOptionTransitionCrossDissolve
- animations:^ {
-
- _mainView.frame = CGRectMake(0, 0, navigationBarW, currentPoint.y);
-
- _tableView.frame = CGRectMake(0, currentPoint.y - heightScreen + navigationBarH, navigationBarW, heightTableView);
- _noRecord.frame = CGRectMake(0, currentPoint.y - centerMaxH - TOOLBAR_TRANSFER_H, navigationBarW, SIZE_FONT_NORECORD+10);
-
- _imageDrag.frame = CGRectMake(0, currentPoint.y - BORDER_TOUCH_UPDOWN, navigationBarW, BORDER_TOUCH_UPDOWN);
- _endLine.frame = CGRectMake(0, currentPoint.y - BORDER_TOUCH_UPDOWN, navigationBarW, 1);
-
- } completion:^ (BOOL completed) {
-
- if (_mainView.frame.size.height == [self getMaxH]) {
- [self setIsOpen:YES];
- } else {
- [self setIsOpen:NO];
- }
-
-
- if (_mainView.frame.size.height == 0)
- _mainView.hidden = YES;
- }
- ];
- }
- - (void)handlePopGesture:(UIGestureRecognizer *)gesture
- {
- if (gesture.state == UIGestureRecognizerStateBegan) {
- _isPopGesture = YES;
- }
-
- if (gesture.state == UIGestureRecognizerStateEnded) {
- _isPopGesture = NO;
- }
- }
- - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
- {
- if (_isOpen) {
-
- [self setControlCenterHidden:YES];
-
- [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
-
- [self openControlCenterToSize:size];
-
- [self setControlCenterHidden: self.navigationBarHidden];
- }];
-
-
- }
-
- [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
- }
- - (void)setControlCenterHidden:(BOOL)hidden
- {
- _mainView.hidden = hidden;
- }
- - (float)getMaxH
- {
-
-
- return [UIScreen mainScreen].bounds.size.height - self.tabBarController.tabBar.frame.size.height;
- }
- - (void)openControlCenterToSize:(CGSize)size
- {
- CGFloat navigationBarH = self.navigationBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height;
-
- _mainView.frame = CGRectMake(0, 0, size.width, [self getMaxH]);
- _tableView.frame = CGRectMake(0, navigationBarH, _mainView.frame.size.width, _mainView.frame.size.height - navigationBarH - BORDER_TOUCH_UPDOWN - TOOLBAR_TRANSFER_H - TOOLBAR_ADD_BORDER);
- _noRecord.frame = CGRectMake(0, _mainView.frame.size.height / 2 - TOOLBAR_TRANSFER_H, _mainView.frame.size.width, SIZE_FONT_NORECORD+10);
-
- _imageDrag.frame = CGRectMake(0, _mainView.frame.size.height - BORDER_TOUCH_UPDOWN, _mainView.frame.size.width, BORDER_TOUCH_UPDOWN);
- _endLine.frame = CGRectMake(0, _mainView.frame.size.height - BORDER_TOUCH_UPDOWN, _mainView.frame.size.width, 1);
-
- panNavigationBar.enabled = NO;
- [self setIsOpen:YES];
- }
- - (void)setIsOpen:(BOOL)setOpen
- {
- if (setOpen) {
-
- if (!_isOpen) {
-
- _isOpen = YES;
- [self reloadDatasource];
- }
-
- } else {
-
- _isOpen = NO;
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark - ===== Single Finger Tap =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)enableSingleFingerTap:(SEL)selector target:(id)target
- {
- _singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:target action:selector];
- [self.navigationBar addGestureRecognizer:_singleFingerTap];
- }
- - (void)disableSingleFingerTap
- {
- [self.navigationBar removeGestureRecognizer:_singleFingerTap];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark - ===== Progress & Task Button =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)progressTask:(NSString *)fileID serverUrl:(NSString *)serverUrl cryptated:(BOOL)cryptated progress:(float)progress;
- {
-
- if (!fileID)
- return;
-
- [app.listProgressMetadata setObject:[NSNumber numberWithFloat:progress] forKey:fileID];
- NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:fileID];
-
- if (indexPath && indexPath.row == 0) {
-
- CCControlCenterCell *cell = (CCControlCenterCell *)[_tableView cellForRowAtIndexPath:indexPath];
-
- if (cryptated) cell.progressView.progressTintColor = COLOR_ENCRYPTED;
- else cell.progressView.progressTintColor = COLOR_CLEAR;
-
- cell.progressView.hidden = NO;
- [cell.progressView setProgress:progress];
-
- } else {
-
- [self reloadDatasource];
- }
- }
- - (void)reloadTaskButton:(id)sender withEvent:(UIEvent *)event
- {
- if (app.activeMain == nil)
- return;
-
- UITouch * touch = [[event allTouches] anyObject];
- CGPoint location = [touch locationInView:_tableView];
- NSIndexPath * indexPath = [_tableView indexPathForRowAtPoint:location];
-
- if (indexPath) {
-
- NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
- CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
-
- if (metadata)
- [app.activeMain reloadTaskButton:metadata];
- }
- }
- - (void)reloadAllTask
- {
- if (app.activeMain == nil)
- return;
-
- for (NSString *key in _sectionDataSource.allRecordsDataSource.allKeys) {
-
- CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:key];
-
- if ([metadata.session containsString:@"download"] && (metadata.sessionTaskIdentifierPlist != taskIdentifierDone))
- continue;
-
- if ([metadata.session containsString:@"upload"] && (metadata.sessionTaskIdentifier != taskIdentifierStop))
- continue;
-
- [app.activeMain reloadTaskButton:metadata];
- }
- }
- - (void)cancelTaskButton:(id)sender withEvent:(UIEvent *)event
- {
- if (app.activeMain == nil)
- return;
-
- UITouch * touch = [[event allTouches] anyObject];
- CGPoint location = [touch locationInView:_tableView];
- NSIndexPath * indexPath = [_tableView indexPathForRowAtPoint:location];
-
- if (indexPath) {
-
- NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
- CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
-
- if (metadata)
- [app.activeMain cancelTaskButton:metadata reloadTable:YES];
- }
- }
- - (void)cancelAllTask
- {
- if (app.activeMain == nil)
- return;
-
- BOOL lastAndRefresh = NO;
-
- for (NSString *key in _sectionDataSource.allRecordsDataSource.allKeys) {
-
- if ([key isEqualToString:[_sectionDataSource.allRecordsDataSource.allKeys lastObject]])
- lastAndRefresh = YES;
- CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:key];
-
- if ([metadata.session containsString:@"upload"] && metadata.cryptated && ((metadata.sessionTaskIdentifier == taskIdentifierDone && metadata.sessionTaskIdentifierPlist >= 0) || (metadata.sessionTaskIdentifier >= 0 && metadata.sessionTaskIdentifierPlist == taskIdentifierDone)))
- continue;
-
- [app.activeMain cancelTaskButton:metadata reloadTable:lastAndRefresh];
- }
- }
- - (void)stopTaskButton:(id)sender withEvent:(UIEvent *)event
- {
- if (app.activeMain == nil)
- return;
-
- UITouch * touch = [[event allTouches] anyObject];
- CGPoint location = [touch locationInView:_tableView];
- NSIndexPath * indexPath = [_tableView indexPathForRowAtPoint:location];
-
- if (indexPath) {
-
- NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
- CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
-
- if (metadata)
- [app.activeMain stopTaskButton:metadata];
- }
- }
- - (void)stopAllTask
- {
- if (app.activeMain == nil)
- return;
-
- for (NSString *key in _sectionDataSource.allRecordsDataSource.allKeys) {
-
- CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:key];
-
- if ([metadata.session containsString:@"download"]) {
- [app.activeMain cancelTaskButton:metadata reloadTable:YES];
- continue;
- }
-
- if ([metadata.session containsString:@"upload"] && metadata.cryptated && ((metadata.sessionTaskIdentifier == taskIdentifierDone && metadata.sessionTaskIdentifierPlist >= 0) || (metadata.sessionTaskIdentifier >= 0 && metadata.sessionTaskIdentifierPlist == taskIdentifierDone)))
- continue;
-
- [app.activeMain stopTaskButton:metadata];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark - ==== Datasource ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)reloadDatasource
- {
- if (app.activeAccount == nil || app.activeUrl == nil)
- return;
-
- if (_isOpen) {
-
- NSArray *recordsTableMetadata = [CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND ((session CONTAINS 'upload') OR (session CONTAINS 'download' AND (sessionSelector != 'loadPlist')))", app.activeAccount] fieldOrder:@"sessionTaskIdentifier" ascending:YES];
-
- _sectionDataSource = [CCSection creataDataSourseSectionTableMetadata:recordsTableMetadata listProgressMetadata:app.listProgressMetadata groupByField:@"session" replaceDateToExifDate:NO activeAccount:app.activeAccount];
-
- if ([_sectionDataSource.allRecordsDataSource count] == 0) _noRecord.hidden = NO;
- else _noRecord.hidden = YES;
- }
-
- [_tableView reloadData];
-
- [app updateApplicationIconBadgeNumber];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark - ==== Table ====
- #pragma --------------------------------------------------------------------------------------------
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- return 50;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return [[_sectionDataSource.sectionArrayRow allKeys] count];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]] count];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- return 13.0f;
- }
- -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- {
- UIVisualEffectView *visualEffectView;
-
- NSString *titleSection, *numberTitle;
- NSInteger typeOfSession = 0;
-
- if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
- if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSDate class]]) titleSection = [CCUtility getTitleSectionDate:[_sectionDataSource.sections objectAtIndex:section]];
-
- NSArray *metadatas = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]];
- NSUInteger rowsCount = [metadatas count];
-
- visualEffectView = [[UIVisualEffectView alloc] init];
- visualEffectView.backgroundColor = [UIColor clearColor];
-
-
- if ([titleSection isEqualToString:@"_none_"]) {
- titleSection = @"";
- } else if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"]) {
- typeOfSession = download;
- titleSection = NSLocalizedString(@"_title_section_download_",nil);
- } else if ([titleSection containsString:@"download"] && [titleSection containsString:@"wwan"]) {
- typeOfSession = downloadwwan;
- titleSection = [NSLocalizedString(@"_title_section_download_",nil) stringByAppendingString:@" Wi-Fi"];
- } else if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"]) {
- typeOfSession = upload;
- titleSection = NSLocalizedString(@"_title_section_upload_",nil);
- } else if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"]) {
- typeOfSession = uploadwwan;
- titleSection = [NSLocalizedString(@"_title_section_upload_",nil) stringByAppendingString:@" Wi-Fi"];
- } else {
- titleSection = NSLocalizedString(titleSection,nil);
- }
-
-
- UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(8, 3, 0, 13)];
- titleLabel.textColor = COLOR_GRAY;
- titleLabel.font = [UIFont systemFontOfSize:9];
- titleLabel.textAlignment = NSTextAlignmentLeft;
- titleLabel.text = titleSection;
- titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
- [visualEffectView addSubview:titleLabel];
-
-
- UILabel *elementLabel=[[UILabel alloc]initWithFrame:CGRectMake(-8, 3, 0, 13)];
- elementLabel.textColor = COLOR_GRAY;
- elementLabel.font = [UIFont systemFontOfSize:9];
- elementLabel.textAlignment = NSTextAlignmentRight;
- elementLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
- if ((typeOfSession == download && app.queueNunDownload > rowsCount) || (typeOfSession == downloadwwan && app.queueNumDownloadWWan > rowsCount) ||
- (typeOfSession == upload && app.queueNumUpload > rowsCount) || (typeOfSession == uploadwwan && app.queueNumUploadWWan > rowsCount)) {
- numberTitle = [NSString stringWithFormat:@"%lu+", (unsigned long)rowsCount];
- } else {
- numberTitle = [NSString stringWithFormat:@"%lu", (unsigned long)rowsCount];
- }
-
- if (rowsCount > 1)
- elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_elements_",nil)];
- else
- elementLabel.text = [NSString stringWithFormat:@"%@ %@", numberTitle, NSLocalizedString(@"_element_",nil)];
-
-
- [visualEffectView addSubview:elementLabel];
-
- return visualEffectView;
- }
- - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
- {
- NSString *titleSection;
- NSString *element_s;
-
- if ([[_sectionDataSource.sections objectAtIndex:section] isKindOfClass:[NSString class]]) titleSection = [_sectionDataSource.sections objectAtIndex:section];
-
-
- UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
-
- UILabel *titleFooterLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)];
- titleFooterLabel.textColor = COLOR_GRAY;
- titleFooterLabel.font = [UIFont systemFontOfSize:12];
- titleFooterLabel.textAlignment = NSTextAlignmentCenter;
-
- if ([titleSection containsString:@"download"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
-
-
- if (app.queueNunDownload > 1) element_s = NSLocalizedString(@"_elements_",nil);
- else element_s = NSLocalizedString(@"_element_",nil);
-
-
- NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_download_", nil), app.queueNunDownload, element_s]];
- titleFooterLabel.attributedText = stringFooter;
-
- [view addSubview:titleFooterLabel];
- return view;
- }
-
-
- if ([titleSection containsString:@"download"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
-
-
- if (app.queueNumDownloadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
- else element_s = NSLocalizedString(@"_element_",nil);
-
-
- NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
- attachment.image = [UIImage imageNamed:image_WiFiSmall];
- NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
- NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_download_wwan_", nil), app.queueNumDownloadWWan, element_s]];
- [stringFooter insertAttributedString:attachmentString atIndex:0];
- titleFooterLabel.attributedText = stringFooter;
-
- [view addSubview:titleFooterLabel];
- return view;
- }
-
- if ([titleSection containsString:@"upload"] && ![titleSection containsString:@"wwan"] && titleSection != nil) {
-
-
- if (app.queueNumUpload > 1) element_s = NSLocalizedString(@"_elements_",nil);
- else element_s = NSLocalizedString(@"_element_",nil);
-
-
- NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_", nil), app.queueNumUpload, element_s]];
- titleFooterLabel.attributedText = stringFooter;
-
- [view addSubview:titleFooterLabel];
- return view;
- }
-
- if ([titleSection containsString:@"upload"] && [titleSection containsString:@"wwan"] && titleSection != nil) {
-
-
- if (app.queueNumUploadWWan > 1) element_s = NSLocalizedString(@"_elements_",nil);
- else element_s = NSLocalizedString(@"_element_",nil);
-
-
- NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
- attachment.image = [UIImage imageNamed:image_WiFiSmall];
- NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
- NSMutableAttributedString *stringFooter= [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"_tite_footer_upload_wwan_", nil), app.queueNumUploadWWan,element_s]];
- [stringFooter insertAttributedString:attachmentString atIndex:0];
- titleFooterLabel.attributedText = stringFooter;
-
- [view addSubview:titleFooterLabel];
- return view;
- }
-
- return nil;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- {
-
-
-
-
-
-
-
-
- return 18.0f;
- }
- - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
- {
- return [_sectionDataSource.sections indexOfObject:title];
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSString *dataFile;
- NSString *lunghezzaFile;
-
- NSString *fileID = [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
- CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
-
- CCControlCenterCell *cell = (CCControlCenterCell *)[tableView dequeueReusableCellWithIdentifier:@"CCControlCenterCell" forIndexPath:indexPath];
- cell.backgroundColor = [UIColor clearColor];
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
-
-
-
-
-
- cell.fileImageView.image = nil;
- cell.statusImageView.image = nil;
-
- cell.labelTitle.enabled = YES;
- cell.labelTitle.text = @"";
- cell.labelInfoFile.enabled = YES;
- cell.labelInfoFile.text = @"";
-
- cell.progressView.progress = 0.0;
- cell.progressView.hidden = YES;
-
- cell.cancelTaskButton.hidden = YES;
- cell.reloadTaskButton.hidden = YES;
- cell.stopTaskButton.hidden = YES;
-
-
- if (metadata.cryptated) {
- cell.labelTitle.textColor = COLOR_ENCRYPTED;
-
- cell.labelInfoFile.textColor = [UIColor blackColor];
-
- } else {
- cell.labelTitle.textColor = COLOR_CLEAR;
-
- cell.labelInfoFile.textColor = [UIColor blackColor];
-
- }
-
-
-
-
-
-
- cell.labelTitle.text = metadata.fileNamePrint;
-
-
- if (metadata.directory) {
-
- cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
- cell.labelInfoFile.text = [CCUtility dateDiff:metadata.date];
-
- lunghezzaFile = @" ";
-
- } else {
-
-
-
- dataFile = [CCUtility dateDiff:metadata.date];
- lunghezzaFile = [CCUtility transformedSize:metadata.size];
-
-
- if (metadata.cryptated && [metadata.title length] == 0) {
-
- dataFile = @" ";
- lunghezzaFile = @" ";
- }
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateStyle:NSDateFormatterShortStyle];
- [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
-
- cell.accessoryType = UITableViewCellAccessoryNone;
- }
-
-
-
-
-
-
- if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]]) {
-
- cell.fileImageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
-
- } else {
-
- cell.fileImageView.image = [UIImage imageNamed:metadata.iconName];
- }
-
-
-
-
-
-
- if (metadata.cryptated && metadata.directory == NO && [metadata.type isEqualToString:metadataType_model] == NO) {
-
- cell.statusImageView.image = [UIImage imageNamed:image_lock];
- }
-
-
-
-
-
- if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"download"].location != NSNotFound) {
-
- if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusdownloadcrypto];
- else cell.statusImageView.image = [UIImage imageNamed:image_statusdownload];
-
-
- if (metadata.sessionTaskIdentifierPlist == taskIdentifierDone) {
-
- if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptaskcrypto] forState:UIControlStateNormal];
- else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptask] forState:UIControlStateNormal];
-
- cell.cancelTaskButton.hidden = NO;
-
- if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
- else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
-
- cell.reloadTaskButton.hidden = NO;
- }
-
- cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
-
- float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
- if (progress > 0) {
-
- if (metadata.cryptated) cell.progressView.progressTintColor = COLOR_ENCRYPTED;
- else cell.progressView.progressTintColor = COLOR_CLEAR;
-
- cell.progressView.progress = progress;
- cell.progressView.hidden = NO;
- }
-
-
-
-
-
- if (metadata.sessionTaskIdentifier == taskIdentifierError || metadata.sessionTaskIdentifierPlist == taskIdentifierError) {
-
- cell.statusImageView.image = [UIImage imageNamed:image_statuserror];
-
- if ([metadata.sessionError length] == 0)
- cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_downloaded_",nil)];
- else
- cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
- }
- }
-
-
-
-
-
- if ([metadata.session length] > 0 && [metadata.session rangeOfString:@"upload"].location != NSNotFound) {
-
- if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusuploadcrypto];
- else cell.statusImageView.image = [UIImage imageNamed:image_statusupload];
-
- if (metadata.cryptated)[cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_removetaskcrypto] forState:UIControlStateNormal];
- else [cell.cancelTaskButton setBackgroundImage:[UIImage imageNamed:image_removetask] forState:UIControlStateNormal];
- cell.cancelTaskButton.hidden = NO;
-
- if (metadata.sessionTaskIdentifier == taskIdentifierStop) {
-
- if (metadata.cryptated)[cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtaskcrypto] forState:UIControlStateNormal];
- else [cell.reloadTaskButton setBackgroundImage:[UIImage imageNamed:image_reloadtask] forState:UIControlStateNormal];
-
- if (metadata.cryptated) cell.statusImageView.image = [UIImage imageNamed:image_statusstopcrypto];
- else cell.statusImageView.image = [UIImage imageNamed:image_statusstop];
-
- cell.reloadTaskButton.hidden = NO;
- cell.stopTaskButton.hidden = YES;
-
- } else {
-
- if (metadata.cryptated)[cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptaskcrypto] forState:UIControlStateNormal];
- else [cell.stopTaskButton setBackgroundImage:[UIImage imageNamed:image_stoptask] forState:UIControlStateNormal];
-
- cell.stopTaskButton.hidden = NO;
- cell.reloadTaskButton.hidden = YES;
- }
-
-
- if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]] == NO)
- cell.fileImageView.image = [UIImage imageNamed:image_uploaddisable];
-
- cell.labelTitle.enabled = NO;
- cell.labelInfoFile.text = [NSString stringWithFormat:@"%@", lunghezzaFile];
-
- float progress = [[app.listProgressMetadata objectForKey:metadata.fileID] floatValue];
- if (progress > 0) {
-
- if (metadata.cryptated) cell.progressView.progressTintColor = COLOR_ENCRYPTED;
- else cell.progressView.progressTintColor = COLOR_CLEAR;
-
- cell.progressView.progress = progress;
- cell.progressView.hidden = NO;
- }
-
-
-
-
-
- if (metadata.sessionTaskIdentifier == taskIdentifierError || metadata.sessionTaskIdentifierPlist == taskIdentifierError) {
-
- cell.labelTitle.enabled = NO;
- cell.statusImageView.image = [UIImage imageNamed:image_statuserror];
-
- if ([metadata.sessionError length] == 0)
- cell.labelInfoFile.text = [NSString stringWithFormat:@"%@, %@", NSLocalizedString(@"_error_",nil), NSLocalizedString(@"_file_not_uploaded_",nil)];
- else
- cell.labelInfoFile.text = [CCError manageErrorKCF:[metadata.sessionError integerValue] withNumberError:NO];
- }
- }
-
- [cell.reloadTaskButton addTarget:self action:@selector(reloadTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
- [cell.cancelTaskButton addTarget:self action:@selector(cancelTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
- [cell.stopTaskButton addTarget:self action:@selector(stopTaskButton:withEvent:) forControlEvents:UIControlEventTouchUpInside];
-
- return cell;
- }
- @end
|