mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
[ASMultiplexImageNode] Copy recent changes made to ASNetworkImageNode for progress image handling
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
#import "ASPhotosFrameworkImageRequest.h"
|
#import "ASPhotosFrameworkImageRequest.h"
|
||||||
#import "ASEqualityHelpers.h"
|
#import "ASEqualityHelpers.h"
|
||||||
#import "ASInternalHelpers.h"
|
#import "ASInternalHelpers.h"
|
||||||
|
#import "ASDisplayNodeExtras.h"
|
||||||
|
|
||||||
#if !AS_IOS8_SDK_OR_LATER
|
#if !AS_IOS8_SDK_OR_LATER
|
||||||
#error ASMultiplexImageNode can be used on iOS 7, but must be linked against the iOS 8 SDK.
|
#error ASMultiplexImageNode can be used on iOS 7, but must be linked against the iOS 8 SDK.
|
||||||
@@ -293,9 +294,8 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
|
|||||||
- (void)visibilityDidChange:(BOOL)isVisible
|
- (void)visibilityDidChange:(BOOL)isVisible
|
||||||
{
|
{
|
||||||
[super visibilityDidChange:isVisible];
|
[super visibilityDidChange:isVisible];
|
||||||
|
|
||||||
if (_downloaderImplementsSetPriority) {
|
|
||||||
ASDN::MutexLocker l(_downloadIdentifierLock);
|
ASDN::MutexLocker l(_downloadIdentifierLock);
|
||||||
|
if (_downloaderImplementsSetPriority) {
|
||||||
if (_downloadIdentifier != nil) {
|
if (_downloadIdentifier != nil) {
|
||||||
if (isVisible) {
|
if (isVisible) {
|
||||||
[_downloader setPriority:ASImageDownloaderPriorityVisible withDownloadIdentifier:_downloadIdentifier];
|
[_downloader setPriority:ASImageDownloaderPriorityVisible withDownloadIdentifier:_downloadIdentifier];
|
||||||
@@ -305,32 +305,7 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_downloaderImplementsSetProgress) {
|
[self _updateProgressImageBlockOnDownloaderIfNeeded];
|
||||||
ASDN::MutexLocker l(_downloadIdentifierLock);
|
|
||||||
|
|
||||||
if (_downloadIdentifier != nil) {
|
|
||||||
__weak __typeof__(self) weakSelf = self;
|
|
||||||
ASImageDownloaderProgressImage progress = nil;
|
|
||||||
if (isVisible) {
|
|
||||||
progress = ^(UIImage * _Nonnull progressImage, id _Nullable downloadIdentifier) {
|
|
||||||
__typeof__(self) strongSelf = weakSelf;
|
|
||||||
if (strongSelf == nil) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ASDN::MutexLocker l(strongSelf->_downloadIdentifierLock);
|
|
||||||
//Getting a result back for a different download identifier, download must not have been successfully canceled
|
|
||||||
if (ASObjectIsEqual(strongSelf->_downloadIdentifier, downloadIdentifier) == NO && downloadIdentifier != nil) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
strongSelf.image = progressImage;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[_downloader setProgressImageBlock:progress callbackQueue:dispatch_get_main_queue() withDownloadIdentifier:_downloadIdentifier];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Core
|
#pragma mark - Core
|
||||||
@@ -478,6 +453,33 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
|
|||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
|
|
||||||
|
- (void)_updateProgressImageBlockOnDownloaderIfNeeded
|
||||||
|
{
|
||||||
|
if (!_downloaderImplementsSetProgress || _downloadIdentifier == nil) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ASImageDownloaderProgressImage progress = nil;
|
||||||
|
if (ASInterfaceStateIncludesVisible(self.interfaceState)) {
|
||||||
|
__weak __typeof__(self) weakSelf = self;
|
||||||
|
progress = ^(UIImage * _Nonnull progressImage, id _Nullable downloadIdentifier) {
|
||||||
|
__typeof__(self) strongSelf = weakSelf;
|
||||||
|
if (strongSelf == nil) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ASDN::MutexLocker l(strongSelf->_downloadIdentifierLock);
|
||||||
|
//Getting a result back for a different download identifier, download must not have been successfully canceled
|
||||||
|
if (ASObjectIsEqual(strongSelf->_downloadIdentifier, downloadIdentifier) == NO && downloadIdentifier != nil) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
strongSelf.image = progressImage;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
[_downloader setProgressImageBlock:progress callbackQueue:dispatch_get_main_queue() withDownloadIdentifier:_downloadIdentifier];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)_clearImage
|
- (void)_clearImage
|
||||||
{
|
{
|
||||||
// Destruction of bigger images on the main thread can be expensive
|
// Destruction of bigger images on the main thread can be expensive
|
||||||
@@ -823,6 +825,7 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
|
|||||||
}]];
|
}]];
|
||||||
#pragma clang diagnostic pop
|
#pragma clang diagnostic pop
|
||||||
}
|
}
|
||||||
|
[self _updateProgressImageBlockOnDownloaderIfNeeded];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -212,6 +212,7 @@ static const CGSize kMinReleaseImageOnBackgroundSize = {20.0, 20.0};
|
|||||||
- (void)visibilityDidChange:(BOOL)isVisible
|
- (void)visibilityDidChange:(BOOL)isVisible
|
||||||
{
|
{
|
||||||
[super visibilityDidChange:isVisible];
|
[super visibilityDidChange:isVisible];
|
||||||
|
|
||||||
ASDN::MutexLocker l(_lock);
|
ASDN::MutexLocker l(_lock);
|
||||||
if (_downloaderImplementsSetPriority) {
|
if (_downloaderImplementsSetPriority) {
|
||||||
if (_downloadIdentifier != nil) {
|
if (_downloadIdentifier != nil) {
|
||||||
@@ -388,7 +389,7 @@ static const CGSize kMinReleaseImageOnBackgroundSize = {20.0, 20.0};
|
|||||||
ASDN::MutexLocker l(strongSelf->_lock);
|
ASDN::MutexLocker l(strongSelf->_lock);
|
||||||
|
|
||||||
//Getting a result back for a different download identifier, download must not have been successfully canceled
|
//Getting a result back for a different download identifier, download must not have been successfully canceled
|
||||||
if (downloadIdentifier != nil && !ASObjectIsEqual(strongSelf->_downloadIdentifier, downloadIdentifier)) {
|
if (ASObjectIsEqual(strongSelf->_downloadIdentifier, downloadIdentifier) == NO && downloadIdentifier != nil) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user