//
|
// FileStatusCell.m
|
// terminalMgr
|
//
|
// Created by WindShan on 2017/3/16.
|
// Copyright © 2017年 WindShan. All rights reserved.
|
//
|
|
#import "FileStatusCell.h"
|
#import "GloriaLabel.h"
|
#import "UIImageView+WebCache.h"
|
#import "commenProgressView.h"
|
|
@interface FileStatusCell()
|
{
|
|
}
|
|
@property (nonatomic, strong) UIImageView * bkImage;
|
@property (nonatomic, strong) UIImageView * file_name_tag;
|
@property (nonatomic, strong) UIImageView * file_name_line;
|
@property (nonatomic, strong) UIImageView * file_cmd_line;
|
@property (nonatomic, strong) UIImageView * file_cmd_line2;
|
@property (nonatomic, strong) GloriaLabel * fileName;
|
@property (nonatomic, strong) QKYDelayButton * startBtn;
|
@property (nonatomic, strong) UIButton * stopBtn;
|
@property (nonatomic, strong) UIButton * deleteBtn;
|
@property (nonatomic, strong) commenProgressView * rateProgressView;
|
@end
|
|
@implementation FileStatusCell
|
|
/*
|
// Only override drawRect: if you perform custom drawing.
|
// An empty implementation adversely affects performance during animation.
|
- (void)drawRect:(CGRect)rect {
|
// Drawing code
|
}
|
*/
|
- (UIProgressView *) rateProgressView
|
{
|
if(!_rateProgressView)
|
{
|
CGFloat bkImageW = 356;
|
if(IsiPhone4 || IsiPhone5)
|
{
|
bkImageW = 300;
|
}
|
|
_rateProgressView = [commenProgressView initCommenProgressView];
|
_rateProgressView.frame = CGRectMake(5, 60,[UIScreen mainScreen].bounds.size.width - 10 , 20);
|
|
|
_rateProgressView.progressBackGroundColor = RgbColor(182, 231, 203);
|
_rateProgressView.progressTintColor = RgbColor(34, 231, 203);
|
|
_rateProgressView.progressCornerRadius = 0;
|
_rateProgressView.backgroundColor = [UIColor redColor];
|
_rateProgressView.layer.masksToBounds = YES;
|
_rateProgressView.layer.cornerRadius = 1;
|
[self.contentView addSubview:_rateProgressView];
|
}
|
|
return _rateProgressView;
|
}
|
|
-(void)detailAction
|
{
|
if ( _delegate && [_delegate respondsToSelector:@selector(didCellDetailSection:)])
|
{
|
[_delegate didCellDetailSection:self.model];
|
}
|
}
|
|
-(UIButton*)deleteBtn
|
{
|
if(!_deleteBtn)
|
{
|
_deleteBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
|
_deleteBtn.frame = CGRectMake(0, SCREEN_HEIGHT-100, 118, 30);
|
[_deleteBtn setImage:[UIImage imageNamed:@"file_download_del"] forState:UIControlStateNormal];
|
[_deleteBtn setTitle:@"删 除" forState:UIControlStateNormal];
|
[_deleteBtn setTitleColor:kUIColorFromRGB(0x5a5a5a) forState:UIControlStateNormal];
|
//_deleteBtn.backgroundColor = [UIColor redColor]; //上左下右
|
|
_deleteBtn.titleLabel.font = [UIFont systemFontOfSize: 12.0];
|
[_deleteBtn addTarget:self action:@selector(deleteAction) forControlEvents:UIControlEventTouchUpInside];
|
|
[_deleteBtn setTintColor:RgbColor(253,137,8)];
|
|
[self.contentView addSubview:_deleteBtn];
|
}
|
|
return _deleteBtn;
|
}
|
|
-(void)deleteAction
|
{
|
self.model.handleCmd = @"3";
|
self.rateProgressView.progressValue = 0;
|
[self.rateProgressView setNeedsLayout];
|
[[MCDownloadManager defaultInstance] removeWithURL:self.model.path];
|
}
|
|
-(UIButton*)stopBtn
|
{
|
if(!_stopBtn)
|
{
|
_stopBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
|
_stopBtn.frame = CGRectMake(0, SCREEN_HEIGHT-100, 118, 30);
|
[_stopBtn setImage:[UIImage imageNamed:@"file_download_stop"] forState:UIControlStateNormal];
|
[_stopBtn setTitle:@"暂 停" forState:UIControlStateNormal];
|
[_stopBtn setTitleColor:kUIColorFromRGB(0x5a5a5a) forState:UIControlStateNormal];
|
//_stopBtn.backgroundColor = [UIColor redColor]; //上左下右
|
|
_stopBtn.titleLabel.font = [UIFont systemFontOfSize: 12.0];
|
[_stopBtn addTarget:self action:@selector(stopAction) forControlEvents:UIControlEventTouchUpInside];
|
|
[_stopBtn setTintColor:RgbColor(253,137,8)];
|
|
[self.contentView addSubview:_stopBtn];
|
}
|
|
return _stopBtn;
|
}
|
|
-(void)stopAction
|
{
|
MCDownloadReceipt *receipt = [[MCDownloadManager defaultInstance] downloadReceiptForURL:self.model.path];
|
|
if (receipt.state == MCDownloadStateDownloading)
|
{
|
[self.startBtn setTitle:@"继续下载" forState:UIControlStateNormal];
|
[[MCDownloadManager defaultInstance] suspendWithDownloadReceipt:receipt];
|
}
|
else if (receipt.state == MCDownloadStateCompleted)
|
{
|
[self.startBtn setTitle:@"重新下载" forState:UIControlStateNormal];
|
}
|
else
|
{
|
[self.startBtn setTitle:@"开始下载" forState:UIControlStateNormal];
|
[self download];
|
}
|
|
}
|
|
-(UIButton*)startBtn
|
{
|
if(!_startBtn)
|
{
|
_startBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
|
_startBtn.frame = CGRectMake(0, SCREEN_HEIGHT-100, 118, 30);
|
[_startBtn setImage:[UIImage imageNamed:@"file_download_start"] forState:UIControlStateNormal];
|
[_startBtn setTitle:@"下 载" forState:UIControlStateNormal];
|
[_startBtn setTitleColor:kUIColorFromRGB(0x5a5a5a) forState:UIControlStateNormal];
|
//_startBtn.backgroundColor = [UIColor redColor]; //上左下右
|
|
|
_startBtn.titleLabel.font = [UIFont systemFontOfSize: 12.0];
|
[_startBtn addTarget:self action:@selector(startAction) forControlEvents:UIControlEventTouchUpInside];
|
|
[_startBtn setTintColor:RgbColor(253,137,8)];
|
|
[self.contentView addSubview:_startBtn];
|
}
|
|
return _startBtn;
|
}
|
|
-(void)startAction
|
{
|
MCDownloadReceipt *receipt = [[MCDownloadManager defaultInstance] downloadReceiptForURL:self.model.path];
|
|
if (receipt.state == MCDownloadStateDownloading)
|
{
|
[self.startBtn setTitle:@"正在下载" forState:UIControlStateNormal];
|
[[MCDownloadManager defaultInstance] suspendWithDownloadReceipt:receipt];
|
}
|
else if (receipt.state == MCDownloadStateCompleted)
|
{
|
self.rateProgressView.progressValue = 0;
|
[self.rateProgressView setNeedsLayout];
|
[[MCDownloadManager defaultInstance] removeWithURL:self.model.path];
|
[self download];
|
}
|
else
|
{
|
[self.startBtn setTitle:@"开始下载" forState:UIControlStateNormal];
|
[self download];
|
}
|
}
|
|
- (GloriaLabel *) fileName
|
{
|
if(!_fileName)
|
{
|
_fileName = [[GloriaLabel alloc] initWithFrame:CGRectMake(8+10+45, 5,SCREEN_WIDTH/2, 30)];
|
_fileName.font = [UIFont systemFontOfSize:12];
|
_fileName.textAlignment = UITextAlignmentLeft;
|
_fileName.textColor = kUIColorFromRGB(0x6e6e6e);
|
[self.contentView addSubview:_fileName];
|
}
|
|
return _fileName;
|
}
|
|
- (UIImageView *)file_name_tag
|
{
|
if (!_file_name_tag)
|
{
|
_file_name_tag = [[UIImageView alloc] initWithFrame:CGRectMake(8, 5, SCREEN_WIDTH-16, 70)];
|
[self.contentView addSubview:_file_name_tag];
|
}
|
|
return _file_name_tag;
|
}
|
|
- (UIImageView *)bkImage
|
{
|
if (!_bkImage)
|
{
|
|
CGFloat bkImageW = 708;
|
if(IsiPhone4 || IsiPhone5)
|
{
|
bkImageW = 620;
|
}
|
|
_bkImage = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-bkImageW)/2-10, 0, bkImageW-20, 80)];
|
[self.contentView addSubview:_bkImage];
|
}
|
|
return _bkImage;
|
}
|
|
|
|
- (UIImageView *)file_name_line
|
{
|
if (!_file_name_line)
|
{
|
_file_name_line = [[UIImageView alloc] initWithFrame:CGRectMake(8, 5, SCREEN_WIDTH-16, 70)];
|
_file_name_line.image = [UIImage imageNamed:@"file_name_line"];
|
[self.contentView addSubview:_file_name_line];
|
}
|
|
return _file_name_line;
|
}
|
|
- (UIImageView *)file_cmd_line
|
{
|
if (!_file_cmd_line)
|
{
|
_file_cmd_line = [[UIImageView alloc] initWithFrame:CGRectMake(8, 5, SCREEN_WIDTH-16, 70)];
|
_file_cmd_line.image = [UIImage imageNamed:@"file_cmd_line"];
|
[self.contentView addSubview:_file_cmd_line];
|
}
|
|
return _file_cmd_line;
|
}
|
|
- (UIImageView *)file_cmd_line2
|
{
|
if (!_file_cmd_line2)
|
{
|
_file_cmd_line2 = [[UIImageView alloc] initWithFrame:CGRectMake(8, 5, SCREEN_WIDTH-16, 70)];
|
_file_cmd_line2.image = [UIImage imageNamed:@"file_cmd_line"];
|
[self.contentView addSubview:_file_cmd_line2];
|
}
|
|
return _file_cmd_line2;
|
}
|
|
|
//@property (nonatomic, strong) UIImageView * bkImage;
|
//@property (nonatomic, strong) UIImageView * iconImage;
|
//@property (nonatomic, strong) UIImageView * nameCircleImage;
|
//@property (nonatomic, strong) UIImageView * statusCircleImage;
|
//@property (nonatomic, strong) GloriaLabel * deviceName;
|
//@property (nonatomic, strong) GloriaLabel * FileStatus;
|
|
- (void)layoutSubviews
|
{
|
[super layoutSubviews];
|
|
CGFloat bkImageW = 356;
|
CGFloat btnW = 118;
|
CGFloat leftOffX = 10;
|
CGFloat lineOffX = 0;
|
if(IsiPhone4 || IsiPhone5)
|
{
|
bkImageW = 300;
|
btnW = 110;
|
leftOffX = 0;
|
lineOffX = 10;
|
}
|
|
self.bkImage.frame = CGRectMake((SCREEN_WIDTH-bkImageW)/2, 10, bkImageW, 98);
|
self.file_name_tag.frame = CGRectMake((SCREEN_WIDTH-bkImageW)/2+10, 21, 8, 8);
|
self.file_name_line.frame = CGRectMake((SCREEN_WIDTH-bkImageW+20)/2, 40, bkImageW-20, 1);
|
|
self.rateProgressView.frame = CGRectMake((SCREEN_WIDTH-bkImageW+20)/2, 50, bkImageW-20, 16);
|
//_rateProgressView.transform = CGAffineTransformMakeScale(1.0f,3.0f);
|
|
self.fileName.frame = CGRectMake((SCREEN_WIDTH-bkImageW)/2+10+20, 10, SCREEN_WIDTH/2, 30);
|
self.startBtn.frame = CGRectMake((SCREEN_WIDTH-bkImageW)/2+2, 75, btnW, 30);
|
self.startBtn.titleEdgeInsets = UIEdgeInsetsMake(0, leftOffX+16+5, 0, 20);
|
//UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)
|
self.startBtn.imageEdgeInsets = UIEdgeInsetsMake(0, leftOffX, 0, 20);
|
|
self.file_cmd_line.frame = CGRectMake((SCREEN_WIDTH-bkImageW)/2+2+btnW-lineOffX, 80, 1, 20);
|
|
self.stopBtn.frame = CGRectMake((SCREEN_WIDTH-bkImageW)/2+2+btnW-lineOffX, 75, btnW, 30);
|
self.stopBtn.titleEdgeInsets = UIEdgeInsetsMake(0, leftOffX+16+5, 0, 20);
|
//UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)
|
self.stopBtn.imageEdgeInsets = UIEdgeInsetsMake(0, leftOffX, 0, 20);
|
|
|
self.file_cmd_line2.frame = CGRectMake((SCREEN_WIDTH-bkImageW)/2+2+btnW*2-lineOffX, 80, 1, 20);
|
|
self.deleteBtn.frame = CGRectMake((SCREEN_WIDTH-bkImageW)/2+2+btnW*2-lineOffX, 75, btnW, 30);
|
self.deleteBtn.titleEdgeInsets = UIEdgeInsetsMake(0, leftOffX+16+5, 0, 20);
|
//UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)
|
self.deleteBtn.imageEdgeInsets = UIEdgeInsetsMake(0, leftOffX, 0, 20);
|
}
|
|
/** 设置数据*/
|
- (void)setItemView:(FileStatus*)model
|
{
|
self.model = model;
|
self.contentView.backgroundColor = [UIColor clearColor];
|
|
self.bkImage.image = [UIImage imageNamed:@"file_download_item_bk"];
|
self.file_name_tag.image = [UIImage imageNamed:@"file_name_tag"];
|
|
[self.fileName setText:[NSString stringWithFormat:@"文件名:%@",model.name]];
|
|
MCDownloadReceipt *receipt = [[MCDownloadManager defaultInstance] downloadReceiptForURL:model.path];
|
|
self.rateProgressView.progressValue = 0;
|
self.rateProgressView.progressValue = receipt.progress.fractionCompleted;
|
|
if (receipt.state == MCDownloadStateDownloading)
|
{
|
[self.startBtn setTitle:@"继续下载" forState:UIControlStateNormal];
|
}
|
else if (receipt.state == MCDownloadStateCompleted)
|
{
|
[self.startBtn setTitle:@"重新下载" forState:UIControlStateNormal];
|
}
|
else
|
{
|
[self.startBtn setTitle:@"开始下载" forState:UIControlStateNormal];
|
}
|
|
receipt.progressBlock = ^(NSProgress * _Nonnull downloadProgress,MCDownloadReceipt *receipt)
|
{
|
if ([receipt.url isEqualToString:model.path])
|
{
|
self.rateProgressView.progressValue = downloadProgress.fractionCompleted ;
|
[self.rateProgressView setNeedsLayout];
|
}
|
};
|
|
receipt.successBlock = ^(NSURLRequest * _Nullablerequest, NSHTTPURLResponse * _Nullableresponse, NSURL * _NonnullfilePath) {
|
[self.startBtn setTitle:@"重新下载" forState:UIControlStateNormal];
|
};
|
|
receipt.failureBlock = ^(NSURLRequest * _Nullable request, NSHTTPURLResponse * _Nullable response, NSError * _Nonnull error) {
|
[self.startBtn setTitle:@"开始下载" forState:UIControlStateNormal];
|
};
|
}
|
|
- (void)download
|
{
|
[[MCDownloadManager defaultInstance] downloadFileWithURL:self.model.path
|
progress:^(NSProgress * _Nonnull downloadProgress, MCDownloadReceipt *receipt)
|
{
|
if ([receipt.url isEqualToString:self.model.path])
|
{
|
self.rateProgressView.progressValue = downloadProgress.fractionCompleted ;
|
[self.rateProgressView setNeedsLayout];
|
}
|
}
|
destination:nil
|
success:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, NSURL * _Nonnull filePath)
|
{
|
// 下载成功处理
|
if ( _delegate && [_delegate respondsToSelector:@selector(didCellDetailSection:)])
|
{
|
self.model.filePath = [[MCDownloadManager defaultInstance] getURLPath:self.model.path];
|
|
[_delegate didCellDetailSection:self.model];
|
}
|
[self.startBtn setTitle:@"重新下载" forState:UIControlStateNormal];
|
}
|
failure:^(NSURLRequest * _Nonnull request, NSHTTPURLResponse * _Nullable response, NSError * _Nonnull error)
|
{
|
[self.startBtn setTitle:@"开始下载" forState:UIControlStateNormal];
|
}];
|
|
}
|
|
|
@end
|