Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Threema/Threema/Utilities/MWWrapper/   (VLC Media Plyer ©)  Datei vom 26.9.2026 mit Größe 6 kB image not shown  

Quelle  MediaBrowserFile.m  Sprache: unbekannt

 
Spracherkennung für: .m vermutete Sprache: Lisp {Lisp[54] Masm[54] ABAP[40]} [Methode: maximale Elemente, drei Dimensionen]

#import "MediaBrowserFile.h"
#import "Threema-Swift.h"
#import <ThreemaFramework/ThreemaUtilityObjC.h>
#import <ThreemaFramework/BundleUtil.h>

@interface MediaBrowserFile ()

@property FileMessageEntity *fileMessageEntity;

@end

@implementation MediaBrowserFile

@synthesize underlyingImage = _underlyingImage; // synth property from protocol

+ (instancetype)fileWithFileMessageEntity:(FileMessageEntity *)fileMessageEntity thumbnail:(BOOL)forThumbnail {
    MediaBrowserFile *file = [[self alloc] initWithFileMessage:fileMessageEntity thumbnail:forThumbnail];
    return file;
}

- (instancetype)initWithFileMessage:(FileMessageEntity *)fileMessageEntity thumbnail:(BOOL)forThumbnail
{
    self = [super init];
    if (self) {
        _fileMessageEntity = fileMessageEntity;

        BOOL isRenderingFileMessage = false;
        if (_fileMessageEntity.data != nil) {
            if (_fileMessageEntity.data.data != nil) {
                if ([_fileMessageEntity renderFileImageMessage] == true) {
                    isRenderingFileMessage = true;
                }
            }
        }
        
        if (isRenderingFileMessage == true) {
            _isUtiPreview = false;
            if (forThumbnail) {
                if (_fileMessageEntity.thumbnail != nil) {
                    if (_fileMessageEntity.thumbnail.data != nil) {
                        _underlyingImage = [[UIImage alloc] initWithData:_fileMessageEntity.thumbnail.data];
                    }
                }
            } else {
                _underlyingImage = [[UIImage alloc] initWithData:_fileMessageEntity.data.data];
            }
        }
        
        if (isRenderingFileMessage == false || _underlyingImage == nil) {
            UIImage *thumbnail = [fileMessageEntity previewThumbnail];
            _isUtiPreview = !fileMessageEntity.thumbnail;
            if (fileMessageEntity.thumbnail == nil) {
                UIImage *colorizedThumbnail = [thumbnail imageWithTintColor:UIColor.whiteColor];
                _underlyingImage = colorizedThumbnail;
            } else {
                if ([UTIConverter isGifMimeType:fileMessageEntity.mimeType]) {
                    thumbnail = [ThreemaUtilityObjC makeThumbWithOverlayFor:thumbnail];
                }
                
                _underlyingImage = thumbnail;
            }
        }
    }
    return self;
}

- (BOOL)isVideo {
    if ([_fileMessageEntity renderFileVideoMessage] == true) {
        return true;
    }
    return false;
}

- (UIImage *)padImage:(UIImage *)image toSize:(CGSize)size {
    UIGraphicsBeginImageContext(size);
    
    CGFloat x = (size.width - image.size.width)/2.0;
    CGFloat y = (size.height - image.size.height)/2.0;
    [image drawInRect:CGRectMake(x, y, image.size.width, image.size.height) blendMode:kCGBlendModeNormal alpha:0.8];
    
    UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return resultImage;
}

- (id)sourceReference {
    return _fileMessageEntity;
}

#pragma mark - MWPhoto Protocol Methods

-(BOOL)showControls {
    return !([_fileMessageEntity renderFileImageMessage]);
}

-(void)handleSingleTap:(CGPoint)touchPoint {
    if (_fileMessageEntity.data != nil) {
        if ([_fileMessageEntity renderFileImageMessage] == true) {
            [_delegate toggleControls];
        }
        else if ([_fileMessageEntity renderFileVideoMessage] == true) {
            [self play];
        }
        else {
            [_delegate showFile: _fileMessageEntity];
        }
    } else {
        BlobManagerObjCWrapper *manager = [[BlobManagerObjCWrapper alloc] init];
        [manager syncBlobsFor:_fileMessageEntity.objectID onCompletion:^(enum BlobManagerObjCResult result){
            NSAssert(result != BlobManagerObjCResultUploaded, @"We never upload a file in this case");
            [[NSNotificationCenter defaultCenter] postNotificationName:MWPHOTO_LOADING_DID_END_NOTIFICATION object:self];
        }];
    }
}

- (void)play {
    if (_delegate) {
        [_delegate playFileVideo: _fileMessageEntity];
    }
}

-(BOOL)canScaleImage {
    if ([_fileMessageEntity renderFileImageMessage] == true) {
        return true;
    }
    return NO;
}

-(NSURL *)urlForExportData:(NSString *)tmpFileName {
    if (_fileMessageEntity == nil || _fileMessageEntity.data == nil) {
        return nil;
    }
    NSURL *url = [_fileMessageEntity tempFileURLWithFallBackFileName:tmpFileName];
    [_fileMessageEntity exportDataTo:url];
    return url;
}

- (UIImage *)underlyingImage {
    return _underlyingImage;
}

- (void)loadUnderlyingImageAndNotify {
    // loaded already
        
    if (_fileMessageEntity.thumbnail != nil) {
        if (_fileMessageEntity.thumbnail != nil) {
            if (_fileMessageEntity.thumbnail.data != nil) {
                _underlyingImage = [[UIImage alloc] initWithData:_fileMessageEntity.thumbnail.data];
                [self postCompleteNotification];
                return;
            }
        }
    }
    
    if (_fileMessageEntity.data != nil) {
        UIImage *thumbnail = [_fileMessageEntity previewThumbnail];
        _isUtiPreview = !_fileMessageEntity.thumbnail;
        if (_fileMessageEntity.thumbnail == nil) {
            UIImage *colorizedThumbnail = [thumbnail imageWithTintColor:UIColor.whiteColor];
            _underlyingImage = colorizedThumbnail;
        } else {
            if ([UTIConverter isGifMimeType:_fileMessageEntity.mimeType]) {
                thumbnail = [ThreemaUtilityObjC makeThumbWithOverlayFor:thumbnail];
            }
            _underlyingImage = thumbnail;
        }
        [self postCompleteNotification];
        return;
    }
        
    // loading
    if (_fileMessageEntity.progress != nil) {
        return;
    }
    
    [self performLoadUnderlyingImageAndNotify];
}

- (void)performLoadUnderlyingImageAndNotify {
    BlobManagerObjCWrapper *manager = [[BlobManagerObjCWrapper alloc] init];
    [manager syncBlobsFor:_fileMessageEntity.objectID onCompletion:^(enum BlobManagerObjCResult result){
        NSAssert(result != BlobManagerObjCResultUploaded, @"We never upload a file in this case");
        [[NSNotificationCenter defaultCenter] postNotificationName:MWPHOTO_LOADING_DID_END_NOTIFICATION object:self];
    }];
}

- (void)postCompleteNotification {
    [[NSNotificationCenter defaultCenter] postNotificationName:MWPHOTO_LOADING_DID_END_NOTIFICATION object:self];
}

- (void)unloadUnderlyingImage {
    _underlyingImage = nil;
}

- (void)cancelAnyLoading {
    
}

- (void)getVideoURL:(void (^)(NSURL *))completion {
    completion([self urlForExportData:@"video"]);
}

/***** BEGIN THREEMA MODIFICATION: add function *********/
- (NSString *)accessibilityLabelForContent {
    NSString *date = [DateFormatter accessibilityDateTime:_fileMessageEntity.remoteSentDate];
    return [NSString stringWithFormat:@"%@. %@", [BundleUtil localizedStringForKey:@"file"], date];
}

- (BOOL)canHideToolBar {
    return [UTIConverter isImageMimeType:_fileMessageEntity.mimeType];
}
/***** END THREEMA MODIFICATION: add function *********/

@end

[Dauer der Verarbeitung: 0.30 Sekunden]