mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Add default PINRemoteImageDownloader
This commit is contained in:
@@ -6,51 +6,51 @@
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#import <CoreGraphics/CoreGraphics.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef void(^ASImageCacherCompletion)(UIImage * _Nullable imageFromCache);
|
||||
|
||||
@protocol ASImageCacheProtocol <NSObject>
|
||||
|
||||
@required
|
||||
/**
|
||||
@abstract Attempts to fetch an image with the given URL from the cache.
|
||||
@param URL The URL of the image to retrieve from the cache.
|
||||
@param callbackQueue The queue to call `completion` on. If this value is nil, @{ref completion} will be invoked on the
|
||||
main-queue.
|
||||
@param completion The block to be called when the cache has either hit or missed.
|
||||
@param imageFromCache The image that was retrieved from the cache, if the image could be retrieved; nil otherwise.
|
||||
@discussion If `URL` is nil, `completion` will be invoked immediately with a nil image. This method should not block
|
||||
the calling thread as it is likely to be called from the main thread.
|
||||
@deprecated This method is deprecated @see cachedImageWithURL:callbackQueue:completion: instead
|
||||
*/
|
||||
- (void)fetchCachedImageWithURL:(nullable NSURL *)URL
|
||||
callbackQueue:(nullable dispatch_queue_t)callbackQueue
|
||||
completion:(void (^)(CGImageRef _Nullable imageFromCache))completion;
|
||||
|
||||
/**
|
||||
@abstract Attempts to fetch an image with the given URL from the cache.
|
||||
@param URL The URL of the image to retrieve from the cache.
|
||||
@param callbackQueue The queue to call `completion` on. If this value is nil, @{ref completion} will be invoked on the
|
||||
main-queue.
|
||||
@param completion The block to be called when the cache has either hit or missed.
|
||||
@param imageFromCache The image that was retrieved from the cache, if the image could be retrieved; nil otherwise.
|
||||
@discussion If `URL` is nil, `completion` will be invoked immediately with a nil image. This method should not block
|
||||
the calling thread as it is likely to be called from the main thread.
|
||||
*/
|
||||
- (void)cachedImageWithURL:(nullable NSURL *)URL
|
||||
callbackQueue:(nullable dispatch_queue_t)callbackQueue
|
||||
completion:(ASImageCacherCompletion)completion;
|
||||
|
||||
@end
|
||||
|
||||
typedef void(^ASImageDownloaderCompletion)(UIImage * _Nullable image, NSError * _Nullable error, id _Nullable downloadIdentifier);
|
||||
typedef void(^ASImageDownloaderProgress)(CGFloat progress);
|
||||
typedef void(^ASImageDownloaderProgressImage)(UIImage *progressImage, id _Nullable downloadIdentifier);
|
||||
|
||||
typedef NS_ENUM(NSUInteger, ASImageDownloaderPriority) {
|
||||
ASImageDownloaderPriorityNormal = 0,
|
||||
ASImageDownloaderPriorityDisplay,
|
||||
};
|
||||
|
||||
@protocol ASImageDownloaderProtocol <NSObject>
|
||||
|
||||
@required
|
||||
/**
|
||||
@abstract Downloads an image with the given URL.
|
||||
@param URL The URL of the image to download.
|
||||
@param callbackQueue The queue to call `downloadProgressBlock` and `completion` on. If this value is nil, both blocks
|
||||
will be invoked on the main-queue.
|
||||
@param downloadProgressBlock The block to be invoked when the download of `URL` progresses.
|
||||
@param progress The progress of the download, in the range of (0.0, 1.0), inclusive.
|
||||
@param completion The block to be invoked when the download has completed, or has failed.
|
||||
@param image The image that was downloaded, if the image could be successfully downloaded; nil otherwise.
|
||||
@param error An error describing why the download of `URL` failed, if the download failed; nil otherwise.
|
||||
@discussion This method is likely to be called on the main thread, so any custom implementations should make sure to background any expensive download operations.
|
||||
@result An opaque identifier to be used in canceling the download, via `cancelImageDownloadForIdentifier:`. You must
|
||||
retain the identifier if you wish to use it later.
|
||||
*/
|
||||
- (nullable id)downloadImageWithURL:(NSURL *)URL
|
||||
callbackQueue:(nullable dispatch_queue_t)callbackQueue
|
||||
downloadProgressBlock:(void (^ _Nullable)(CGFloat progress))downloadProgressBlock
|
||||
completion:(void (^ _Nullable)(CGImageRef _Nullable image, NSError * _Nullable error))completion;
|
||||
|
||||
/**
|
||||
@abstract Cancels an image download.
|
||||
@@ -58,7 +58,58 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
`downloadImageWithURL:callbackQueue:downloadProgressBlock:completion:`.
|
||||
@discussion This method has no effect if `downloadIdentifier` is nil.
|
||||
*/
|
||||
- (void)cancelImageDownloadForIdentifier:(nullable id)downloadIdentifier;
|
||||
- (void)cancelImageDownloadForIdentifier:(id)downloadIdentifier;
|
||||
|
||||
@optional
|
||||
|
||||
//You must implement one of the two following methods
|
||||
|
||||
/**
|
||||
@deprecated This method is deprecated @see downloadImageWithURL:callbackQueue:downloadProgress:completion: instead
|
||||
*/
|
||||
- (nullable id)downloadImageWithURL:(NSURL *)URL
|
||||
callbackQueue:(nullable dispatch_queue_t)callbackQueue
|
||||
downloadProgressBlock:(void (^ _Nullable)(CGFloat progress))downloadProgressBlock
|
||||
completion:(void (^ _Nullable)(CGImageRef _Nullable image, NSError * _Nullable error))completion;
|
||||
|
||||
/**
|
||||
@abstract Downloads an image with the given URL.
|
||||
@param URL The URL of the image to download.
|
||||
@param callbackQueue The queue to call `downloadProgressBlock` and `completion` on.
|
||||
@param downloadProgress The block to be invoked when the download of `URL` progresses.
|
||||
@param progress The progress of the download, in the range of (0.0, 1.0), inclusive.
|
||||
@param completion The block to be invoked when the download has completed, or has failed.
|
||||
@param image The image that was downloaded, if the image could be successfully downloaded; nil otherwise.
|
||||
@param error An error describing why the download of `URL` failed, if the download failed; nil otherwise.
|
||||
@discussion This method is likely to be called on the main thread, so any custom implementations should make sure to background any expensive download operations.
|
||||
@result An opaque identifier to be used in canceling the download, via `cancelImageDownloadForIdentifier:`. You must
|
||||
retain the identifier if you wish to use it later.
|
||||
*/
|
||||
- (nullable id)downloadImageWithURL:(NSURL *)URL
|
||||
callbackQueue:(dispatch_queue_t)callbackQueue
|
||||
downloadProgress:(nullable ASImageDownloaderProgress)downloadProgress
|
||||
completion:(nullable ASImageDownloaderCompletion)completion;
|
||||
|
||||
|
||||
/**
|
||||
@abstract Sets block to be called when a progress image is available.
|
||||
@param progressBlock The block to be invoked when the download has a progressive render of an image available.
|
||||
@param callbackQueue The queue to call `progressBlock` on.
|
||||
@param downloadIdentifier The opaque download identifier object returned from
|
||||
`downloadImageWithURL:callbackQueue:downloadProgressBlock:completion:`.
|
||||
*/
|
||||
- (void)setProgressImageBlock:(nullable ASImageDownloaderProgressImage)progressBlock
|
||||
callbackQueue:(dispatch_queue_t)callbackQueue
|
||||
withDownloadIdentifier:(id)downloadIdentifier;
|
||||
|
||||
/**
|
||||
@abstract Called to indicate what priority an image should be downloaded at.
|
||||
@param priority The priority at which the image should be downloaded.
|
||||
@param downloadIdentifier The opaque download identifier object returned from
|
||||
`downloadImageWithURL:callbackQueue:downloadProgressBlock:completion:`.
|
||||
*/
|
||||
- (void)setPriority:(ASImageDownloaderPriority)priority
|
||||
withDownloadIdentifier:(id)downloadIdentifier;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user