Skip to content

Commit 271643e

Browse files
committed
afnetwork 支持YLGIFImage
文件预览支持gif动画
1 parent e9eec3f commit 271643e

File tree

3 files changed

+85
-31
lines changed

3 files changed

+85
-31
lines changed

Coding_iOS/Vendor/AFNetworking/UIKit/UIImageView+AFNetworking.m

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// THE SOFTWARE.
2222

2323
#import "UIImageView+AFNetworking.h"
24+
#import <YLGIFImage/YLGIFImage.h>
2425

2526
#import <objc/runtime.h>
2627

@@ -92,7 +93,9 @@ + (void)setSharedImageCache:(id <AFImageCache>)imageCache {
9293
static id <AFURLResponseSerialization> _af_defaultImageResponseSerializer = nil;
9394
static dispatch_once_t onceToken;
9495
dispatch_once(&onceToken, ^{
95-
_af_defaultImageResponseSerializer = [AFImageResponseSerializer serializer];
96+
// easeeeeeeeee modify
97+
// _af_defaultImageResponseSerializer = [AFImageResponseSerializer serializer];
98+
_af_defaultImageResponseSerializer = [AFHTTPResponseSerializer serializer];
9699
});
97100

98101
#pragma clang diagnostic push
@@ -145,6 +148,10 @@ - (void)setImageWithURLRequest:(NSURLRequest *)urlRequest
145148
self.af_imageRequestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest];
146149
self.af_imageRequestOperation.responseSerializer = self.imageResponseSerializer;
147150
[self.af_imageRequestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
151+
//easeeeeeeeee add
152+
if (responseObject && ![responseObject isKindOfClass:[UIImage class]]) {
153+
responseObject = [YLGIFImage imageWithData:responseObject];
154+
}
148155
__strong __typeof(weakSelf)strongSelf = weakSelf;
149156
if ([[urlRequest URL] isEqual:[strongSelf.af_imageRequestOperation.request URL]]) {
150157
if (success) {

Coding_iOS/Views/Cell/FileListFileCell.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
#import "AFURLSessionManager.h"
1515
#import "Coding_FileManager.h"
1616
#import "ASProgressPopUpView.h"
17+
#import <YLGIFImage/YLImageView.h>
1718

1819

1920
@interface FileListFileCell ()<ASProgressPopUpViewDelegate>
20-
@property (strong, nonatomic) UIImageView *iconView;
21+
@property (strong, nonatomic) YLImageView *iconView;
2122
@property (strong, nonatomic) UILabel *nameLabel, *infoLabel, *sizeLabel;
2223
@property (strong, nonatomic) UIButton *stateButton;
2324

@@ -32,7 +33,7 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
3233
if (self) {
3334
// Initialization code
3435
if (!_iconView) {
35-
_iconView = [[UIImageView alloc] initWithFrame:CGRectMake(kPaddingLeftWidth, ([FileListFileCell cellHeight] - kFileListFileCell_IconWidth)/2, kFileListFileCell_IconWidth, kFileListFileCell_IconWidth)];
36+
_iconView = [[YLImageView alloc] initWithFrame:CGRectMake(kPaddingLeftWidth, ([FileListFileCell cellHeight] - kFileListFileCell_IconWidth)/2, kFileListFileCell_IconWidth, kFileListFileCell_IconWidth)];
3637
_iconView.layer.masksToBounds = YES;
3738
_iconView.layer.cornerRadius = 2.0;
3839
_iconView.layer.borderWidth = 0.5;

Coding_iOS/Views/FileDownloadView.m

Lines changed: 74 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
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

Comments
 (0)