mirror of
https://github.com/zhigang1992/PINRemoteImage.git
synced 2026-04-26 05:15:25 +08:00
Follow up to #175, addressing comments
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// PINAlternateRepresentationDelegate.h
|
||||
// PINAlternateRepresentationProvider.h
|
||||
// Pods
|
||||
//
|
||||
// Created by Garrett Moon on 3/17/16.
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#import "PINRemoteImageManager.h"
|
||||
|
||||
@protocol PINRemoteImageManagerAlternateRepresentationDelegate <NSObject>
|
||||
@protocol PINRemoteImageManagerAlternateRepresentationProvider <NSObject>
|
||||
@required
|
||||
|
||||
/**
|
||||
@@ -20,6 +20,6 @@
|
||||
|
||||
@end
|
||||
|
||||
@interface PINAlternateRepresentationDelegate : NSObject <PINRemoteImageManagerAlternateRepresentationDelegate>
|
||||
@interface PINAlternateRepresentationProvider : NSObject <PINRemoteImageManagerAlternateRepresentationProvider>
|
||||
|
||||
@end
|
||||
@@ -1,19 +1,19 @@
|
||||
//
|
||||
// PINAlternateRepresentationDelegate.m
|
||||
// PINAlternateRepresentationProvider.m
|
||||
// Pods
|
||||
//
|
||||
// Created by Garrett Moon on 3/17/16.
|
||||
//
|
||||
//
|
||||
|
||||
#import "PINAlternateRepresentationDelegate.h"
|
||||
#import "PINAlternateRepresentationProvider.h"
|
||||
|
||||
#import "NSData+ImageDetectors.h"
|
||||
#if USE_FLANIMATED_IMAGE
|
||||
#import <FLAnimatedImage/FLAnimatedImage.h>
|
||||
#endif
|
||||
|
||||
@implementation PINAlternateRepresentationDelegate
|
||||
@implementation PINAlternateRepresentationProvider
|
||||
|
||||
- (id)alternateRepresentationWithData:(NSData *)data options:(PINRemoteImageManagerDownloadOptions)options
|
||||
{
|
||||
@@ -14,7 +14,7 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#endif
|
||||
|
||||
@protocol PINRemoteImageManagerAlternateRepresentationDelegate;
|
||||
@protocol PINRemoteImageManagerAlternateRepresentationProvider;
|
||||
|
||||
#import "PINRemoteImageManagerResult.h"
|
||||
|
||||
@@ -136,12 +136,12 @@ typedef void(^PINRemoteImageManagerProgressDownload)(int64_t completedBytes, int
|
||||
- (nonnull instancetype)initWithSessionConfiguration:(nullable NSURLSessionConfiguration *)configuration;
|
||||
|
||||
/**
|
||||
Create and return a PINRemoteImageManager with the specified configuration and alternative representation delegate. If configuration is nil, [NSURLSessionConfiguration defaultConfiguration] is used. Specify a custom configuration if you need to configure timeout values, cookie policies, additional HTTP headers, etc. If alternativeRepresentationDelegate is nil, the default is used (and supports FLAnimatedImage).
|
||||
Create and return a PINRemoteImageManager with the specified configuration and alternative representation delegate. If configuration is nil, [NSURLSessionConfiguration defaultConfiguration] is used. Specify a custom configuration if you need to configure timeout values, cookie policies, additional HTTP headers, etc. If alternativeRepresentationProvider is nil, the default is used (and supports FLAnimatedImage).
|
||||
@param configuration The configuration used to create the PINRemoteImageManager.
|
||||
@param alternativeRepDelegate a delegate which conforms to the PINRemoteImageManagerAlternateRepresentationDelegate protocol. Provide a delegate if you want to have non image results. @see PINAlternativeRepresentationDelaget for an example.
|
||||
@param alternativeRepDelegate a delegate which conforms to the PINRemoteImageManagerAlternateRepresentationProvider protocol. Provide a delegate if you want to have non image results. @see PINAlternativeRepresentationDelaget for an example.
|
||||
@return A PINRemoteImageManager with the specified configuration.
|
||||
*/
|
||||
- (nonnull instancetype)initWithSessionConfiguration:(nullable NSURLSessionConfiguration *)configuration alternativeRepresentationDelegate:(nullable id <PINRemoteImageManagerAlternateRepresentationDelegate>)alternateRepDelegate;
|
||||
- (nonnull instancetype)initWithSessionConfiguration:(nullable NSURLSessionConfiguration *)configuration alternativeRepresentationProvider:(nullable id <PINRemoteImageManagerAlternateRepresentationProvider>)alternateRepDelegate NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
/**
|
||||
Get the shared instance of PINRemoteImageManager
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
#import <PINCache/PINCache.h>
|
||||
|
||||
#import "PINAlternateRepresentationDelegate.h"
|
||||
#import "PINAlternateRepresentationProvider.h"
|
||||
#import "PINRemoteImage.h"
|
||||
#import "PINRemoteLock.h"
|
||||
#import "PINProgressiveImage.h"
|
||||
@@ -95,12 +95,14 @@ typedef void (^PINRemoteImageManagerDataCompletion)(NSData *data, NSError *error
|
||||
|
||||
@interface PINRemoteImageManager () <PINURLSessionManagerDelegate>
|
||||
{
|
||||
dispatch_queue_t _callbackQueue;
|
||||
PINRemoteLock *_lock;
|
||||
NSOperationQueue *_concurrentOperationQueue;
|
||||
NSOperationQueue *_urlSessionTaskQueue;
|
||||
PINAlternateRepresentationDelegate *_defaultAlternateRepresentationDelegate;
|
||||
__weak PINAlternateRepresentationDelegate *_alternateRepDelegate;
|
||||
dispatch_queue_t _callbackQueue;
|
||||
PINRemoteLock *_lock;
|
||||
NSOperationQueue *_concurrentOperationQueue;
|
||||
NSOperationQueue *_urlSessionTaskQueue;
|
||||
|
||||
// Necesarry to have a strong reference to _defaultAlternateRepresentationProvider because _alternateRepProvider is __weak
|
||||
PINAlternateRepresentationProvider *_defaultAlternateRepresentationProvider;
|
||||
__weak PINAlternateRepresentationProvider *_alternateRepProvider;
|
||||
}
|
||||
|
||||
@property (nonatomic, strong) PINCache *cache;
|
||||
@@ -169,10 +171,10 @@ static dispatch_once_t sharedDispatchToken;
|
||||
|
||||
- (instancetype)initWithSessionConfiguration:(NSURLSessionConfiguration *)configuration
|
||||
{
|
||||
return [self initWithSessionConfiguration:configuration alternativeRepresentationDelegate:nil];
|
||||
return [self initWithSessionConfiguration:configuration alternativeRepresentationProvider:nil];
|
||||
}
|
||||
|
||||
- (instancetype)initWithSessionConfiguration:(NSURLSessionConfiguration *)configuration alternativeRepresentationDelegate:(id <PINRemoteImageManagerAlternateRepresentationDelegate>)alternateRepDelegate
|
||||
- (instancetype)initWithSessionConfiguration:(NSURLSessionConfiguration *)configuration alternativeRepresentationProvider:(id <PINRemoteImageManagerAlternateRepresentationProvider>)alternateRepProvider
|
||||
{
|
||||
if (self = [super init]) {
|
||||
self.cache = [self defaultImageCache];
|
||||
@@ -206,11 +208,11 @@ static dispatch_once_t sharedDispatchToken;
|
||||
self.canceledTasks = [[NSMutableSet alloc] init];
|
||||
self.taskQOS = [[NSMutableArray alloc] initWithCapacity:5];
|
||||
|
||||
if (alternateRepDelegate == nil) {
|
||||
_defaultAlternateRepresentationDelegate = [[PINAlternateRepresentationDelegate alloc] init];
|
||||
alternateRepDelegate = _defaultAlternateRepresentationDelegate;
|
||||
if (alternateRepProvider == nil) {
|
||||
_defaultAlternateRepresentationProvider = [[PINAlternateRepresentationProvider alloc] init];
|
||||
alternateRepProvider = _defaultAlternateRepresentationProvider;
|
||||
}
|
||||
_alternateRepDelegate = alternateRepDelegate;
|
||||
_alternateRepProvider = alternateRepProvider;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -1319,10 +1321,10 @@ static dispatch_once_t sharedDispatchToken;
|
||||
}
|
||||
|
||||
if (alternateRepresentationsAllowed) {
|
||||
alternateRepresentation = [_alternateRepDelegate alternateRepresentationWithData:data options:options];
|
||||
alternateRepresentation = [_alternateRepProvider alternateRepresentationWithData:data options:options];
|
||||
}
|
||||
|
||||
if (alternateRepresentation == NO) {
|
||||
if (alternateRepresentation == nil) {
|
||||
//we need the image
|
||||
[container.lock lockWithBlock:^{
|
||||
image = container.image;
|
||||
|
||||
Reference in New Issue
Block a user