99#import " FileDownloadView.h"
1010#import " ASProgressPopUpView.h"
1111#import " Coding_FileManager.h"
12+ #import " UIImageView+AFNetworking.h"
13+ #import < YLGIFImage/YLImageView.h>
1214
1315@interface FileDownloadView ()
14- @property (strong , nonatomic ) UIImageView *iconView;
16+ @property (strong , nonatomic ) YLImageView *iconView;
1517@property (strong , nonatomic ) UILabel *nameLabel, *infoLabel, *sizeLabel;
1618@property (strong , nonatomic ) ASProgressPopUpView *progressView;
1719@property (strong , nonatomic ) UIButton *stateButton;
@@ -25,12 +27,78 @@ - (instancetype)initWithFrame:(CGRect)frame{
2527 if (self) {
2628 // Initialization code
2729 // CGFloat frameHeight = CGRectGetHeight(frame);
28- CGFloat frameWidth = CGRectGetWidth (frame);
30+ }
31+ return self;
32+ }
33+
34+ - (void )setFile : (ProjectFile *)file {
35+ _file = file;
36+ if (!_file) {
37+ return ;
38+ }
39+ [self loadLayoutWithCurFile ];
40+
41+ if (_file.preview && _file.preview .length > 0 ) {
2942
30- CGFloat curBottomY = 80 ;
43+ [_iconView setImageWithURLRequest: [[NSURLRequest alloc ] initWithURL: [NSURL URLWithString: _file.owner_preview]] placeholderImage: nil success: nil failure: ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
44+ if (error) {
45+ [error showError: error];
46+ }
47+ }];
48+ }else {
49+ _iconView.image = [UIImage imageNamed: [_file fileIconName ]];
50+ }
51+ _nameLabel.text = _file.name ;
52+ _sizeLabel.text = [NSString sizeDisplayWithByte: _file.size.floatValue];
53+
54+ [self changeToState: _file.downloadState];
55+
56+ [_progressView showPopUpViewAnimated: NO ];
57+
58+ Coding_DownloadTask *cDownloadTask = [_file cDownloadTask ];
59+ if (cDownloadTask) {
60+ self.progress = cDownloadTask.progress ;
61+ }
62+ }
63+
64+ - (void )loadLayoutWithCurFile {
65+ if (!_file) {
66+ return ;
67+ }
68+
69+ CGFloat frameWidth = CGRectGetWidth (self.bounds );
70+ if (_file.preview && _file.preview .length > 0 ) {
71+ CGFloat curBottomY = CGRectGetHeight (self.bounds ) - 80 ;
3172
3273 if (!_iconView) {
33- _iconView = [[UIImageView alloc ] initWithFrame: CGRectMake ((frameWidth - 90 )/2 , curBottomY, 90 , 90 )];
74+ _iconView = [[YLImageView alloc ] initWithFrame: self .bounds];
75+ _iconView.backgroundColor = [UIColor blackColor ];
76+ _iconView.contentMode = UIViewContentModeScaleAspectFit;
77+ [self addSubview: _iconView];
78+ }
79+
80+ if (!_progressView) {
81+ _progressView = [[ASProgressPopUpView alloc ] initWithFrame: CGRectMake (kPaddingLeftWidth , curBottomY, kScreen_Width - 2 *kPaddingLeftWidth , 2.0 )];
82+
83+ _progressView.popUpViewCornerRadius = 12.0 ;
84+ _progressView.font = [UIFont fontWithName: @" Futura-CondensedExtraBold" size: 12 ];
85+ [_progressView setTrackTintColor: [UIColor colorWithHexString: @" 0xe6e6e6" ]];
86+ _progressView.popUpViewAnimatedColors = @[[UIColor colorWithHexString: @" 0x3bbd79" ]];
87+ _progressView.hidden = YES ;
88+ [_progressView hidePopUpViewAnimated: NO ];
89+ [self addSubview: self .progressView];
90+ }
91+ curBottomY += 20 ;
92+ if (!_stateButton) {
93+ _stateButton = [[UIButton alloc ] initWithFrame: CGRectMake ((frameWidth - 260 )/2 , curBottomY, 260 , 45 )];
94+ _stateButton = [UIButton buttonWithStyle: StrapPrimaryStyle andTitle: @" 下载文件" andFrame: CGRectMake ((frameWidth - 260 )/2 , curBottomY, 260 , 45 ) target: self action: @selector (clickedByUser )];
95+ [self addSubview: _stateButton];
96+ }
97+ }else {
98+ CGFloat curBottomY = 80 ;
99+ if (!_iconView) {
100+ _iconView = [[YLImageView alloc ] initWithFrame: CGRectMake ((frameWidth - 90 )/2 , curBottomY, 90 , 90 )];
101+ _iconView.contentMode = UIViewContentModeScaleAspectFill;
34102 _iconView.layer .masksToBounds = YES ;
35103 _iconView.layer .cornerRadius = 2.0 ;
36104 _iconView.layer .borderWidth = 0.5 ;
@@ -73,32 +141,10 @@ - (instancetype)initWithFrame:(CGRect)frame{
73141 [self addSubview: _stateButton];
74142 }
75143 }
76- return self;
77144}
78145
79- - (void )setFile : (ProjectFile *)file {
80- _file = file;
81- if (!_file) {
82- return ;
83- }
84-
85- if (_file.preview && _file.preview .length > 0 ) {
86- [_iconView sd_setImageWithURL: [NSURL URLWithString: _file.preview]];
87- }else {
88- _iconView.image = [UIImage imageNamed: [_file fileIconName ]];
89- }
90- _nameLabel.text = _file.name ;
91- _sizeLabel.text = [NSString sizeDisplayWithByte: _file.size.floatValue];
92-
93- [self changeToState: _file.downloadState];
94-
95- [_progressView showPopUpViewAnimated: NO ];
96-
97- Coding_DownloadTask *cDownloadTask = [_file cDownloadTask ];
98- if (cDownloadTask) {
99- self.progress = cDownloadTask.progress ;
100- }
101- }
146+
147+
102148
103149- (void )setProgress : (NSProgress *)progress {
104150 _progress = progress;
0 commit comments