Skip to content

Commit d1bcede

Browse files
committed
Update to use the branch dependency of SDWebImage, update the Example to show UIImageView with link title
1 parent 30d966c commit d1bcede

5 files changed

Lines changed: 37 additions & 20 deletions

File tree

Example/Podfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use_frameworks!
33
target 'SDWebImageLinkPlugin_Example' do
44
platform :ios, '13.0'
55
pod 'SDWebImageLinkPlugin', :path => '../'
6-
pod 'SDWebImage', :path => '/Users/lizhuoli/Documents/GitHub/sdwebImage'
6+
pod 'SDWebImage', :git => 'https://github.com/dreampiggy/SDWebImage.git', :branch => 'feature_extended_metadata_disk_cache'
77

88
target 'SDWebImageLinkPlugin_Tests' do
99
inherit! :search_paths
@@ -14,5 +14,5 @@ end
1414
target 'SDWebImageLinkPlugin_Example macOS' do
1515
platform :osx, '10.15'
1616
pod 'SDWebImageLinkPlugin', :path => '../'
17-
pod 'SDWebImage', :path => '/Users/lizhuoli/Documents/GitHub/sdwebImage'
17+
pod 'SDWebImage', :git => 'https://github.com/dreampiggy/SDWebImage.git', :branch => 'feature_extended_metadata_disk_cache'
1818
end

Example/Podfile.lock

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ PODS:
88

99
DEPENDENCIES:
1010
- Expecta
11-
- SDWebImage (from `/Users/lizhuoli/Documents/GitHub/sdwebImage`)
11+
- SDWebImage (from `https://github.com/dreampiggy/SDWebImage.git`, branch `feature_extended_metadata_disk_cache`)
1212
- SDWebImageLinkPlugin (from `../`)
1313

1414
SPEC REPOS:
@@ -17,15 +17,21 @@ SPEC REPOS:
1717

1818
EXTERNAL SOURCES:
1919
SDWebImage:
20-
:path: "/Users/lizhuoli/Documents/GitHub/sdwebImage"
20+
:branch: feature_extended_metadata_disk_cache
21+
:git: https://github.com/dreampiggy/SDWebImage.git
2122
SDWebImageLinkPlugin:
2223
:path: "../"
2324

25+
CHECKOUT OPTIONS:
26+
SDWebImage:
27+
:commit: 46b0c4bae83103209431b2ec1eddae718a55d6df
28+
:git: https://github.com/dreampiggy/SDWebImage.git
29+
2430
SPEC CHECKSUMS:
2531
Expecta: 3b6bd90a64b9a1dcb0b70aa0e10a7f8f631667d5
2632
SDWebImage: 6ac2eb96571bff96ecde31a987172c5934a0eb7d
2733
SDWebImageLinkPlugin: f77eb1f3ef322a2cb331ecf62cf78444529de597
2834

29-
PODFILE CHECKSUM: b080bcae01315fea0c82763be9711485ae91d032
35+
PODFILE CHECKSUM: 41395b7a314d9ee9da20f929cbea78bfaced4aef
3036

3137
COCOAPODS: 1.8.4

Example/SDWebImageLinkPlugin/SDViewController.m

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ - (void)layoutSubviews {
3737

3838
@interface ImageTableViewCell : UITableViewCell
3939

40-
@property (nonatomic, strong) UILabel *customTextLabel;
40+
@property (nonatomic, strong) UILabel *hostLabel;
41+
@property (nonatomic, strong) UILabel *titleLabel;
4142
@property (nonatomic, strong) UIImageView *customImageView;
4243

4344
@end
@@ -51,17 +52,22 @@ - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSStr
5152
_customImageView.clipsToBounds = YES;
5253
_customImageView.layer.cornerRadius = 10;
5354
[self.contentView addSubview:_customImageView];
54-
_customTextLabel = [[UILabel alloc] init];
55-
[self.contentView addSubview:_customTextLabel];
55+
_hostLabel = [[UILabel alloc] init];
56+
_hostLabel.font = [UIFont systemFontOfSize:12];
57+
[self.contentView addSubview:_hostLabel];
58+
_titleLabel = [[UILabel alloc] init];
59+
_titleLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightBold];
60+
[self.contentView addSubview:_titleLabel];
5661
}
5762
return self;
5863
}
5964

6065
- (void)layoutSubviews {
6166
[super layoutSubviews];
62-
self.customImageView.frame = CGRectInset(self.bounds, 20, 20);
63-
[self.customTextLabel sizeToFit];
64-
self.customTextLabel.frame = CGRectMake(20, self.bounds.size.height - 20, self.bounds.size.width - 40, self.customTextLabel.frame.size.height);
67+
self.customImageView.frame = CGRectInset(self.bounds, 20, 40);
68+
self.hostLabel.frame = CGRectMake(30, self.bounds.size.height - 20, self.bounds.size.width - 2 * 30, 20);
69+
self.titleLabel.frame = CGRectMake(30, self.bounds.size.height - 40, self.bounds.size.width - 2 * 30, 20);
70+
6571
}
6672

6773
@end
@@ -147,8 +153,15 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
147153
if (![cell isKindOfClass:ImageTableViewCell.class]) {
148154
cell = [[ImageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
149155
}
150-
((ImageTableViewCell *)cell).customTextLabel.text = url.host;
151-
[((ImageTableViewCell *)cell).customImageView sd_setImageWithURL:url];
156+
((ImageTableViewCell *)cell).hostLabel.text = url.host;
157+
[((ImageTableViewCell *)cell).customImageView sd_setImageWithURL:url completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
158+
if (image) {
159+
id extendedObject = image.sd_extendedObject;
160+
if ([extendedObject isKindOfClass:LPLinkMetadata.class]) {
161+
((ImageTableViewCell *)cell).titleLabel.text = ((LPLinkMetadata *)extendedObject).title;
162+
}
163+
}
164+
}];
152165
}
153166

154167
return cell;

SDWebImageLinkPlugin/Classes/LPLinkView+WebCache.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ - (void)sd_setImageWithURL:(nullable NSURL *)url
6565
if (metadata) {
6666
// Already exist
6767
} else if (image) {
68-
NSData *extendedData = image.sd_extendedData;
68+
id extendedObject = image.sd_extendedObject;
6969
// Re-generate the metadata from local information
70-
if (extendedData) {
71-
metadata = [NSKeyedUnarchiver unarchivedObjectOfClass:LPLinkMetadata.class fromData:extendedData error:nil];
70+
if ([extendedObject isKindOfClass:LPLinkMetadata.class]) {
71+
metadata = extendedObject;
7272
} else {
7373
metadata = [[LPLinkMetadata alloc] init];
7474
metadata.originalURL = url;

SDWebImageLinkPlugin/Classes/SDImageLinkLoader.m

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ - (void)fetchImageDataWithProvider:(NSItemProvider *)imageProvider operation:(SD
158158
// The original metadata contains image data and is large, we pick the metadata info only to avoid double cache of image
159159
LPLinkMetadata *metadata = [self.class strippedMetadata:url.sd_linkMetadata];
160160
// Save the metadata to extended data
161-
NSData *extendedData = [NSKeyedArchiver archivedDataWithRootObject:metadata requiringSecureCoding:YES error:nil];
162-
image.sd_extendedData = extendedData;
161+
image.sd_extendedObject = metadata;
163162
}
164163
if (completedBlock) {
165164
dispatch_main_async_safe(^{
@@ -202,8 +201,7 @@ - (void)fetchImageWithProvider:(NSItemProvider *)imageProvider operation:(SDImag
202201
// The original metadata contains image data and is large, we pick the metadata info only to avoid double cache of image
203202
LPLinkMetadata *metadata = [self.class strippedMetadata:url.sd_linkMetadata];
204203
// Save the metadata to extended data
205-
NSData *extendedData = [NSKeyedArchiver archivedDataWithRootObject:metadata requiringSecureCoding:YES error:nil];
206-
image.sd_extendedData = extendedData;
204+
image.sd_extendedObject = metadata;
207205
}
208206
if (completedBlock) {
209207
dispatch_main_async_safe(^{

0 commit comments

Comments
 (0)