Search in sources :

Example 1 with LoadingStickerDrawable

use of org.telegram.ui.Components.LoadingStickerDrawable in project Telegram-FOSS by Telegram-FOSS-Team.

the class ImageReceiver method setImageBitmapByKey.

protected boolean setImageBitmapByKey(Drawable drawable, String key, int type, boolean memCache, int guid) {
    if (drawable == null || key == null || currentGuid != guid) {
        return false;
    }
    if (type == TYPE_IMAGE) {
        if (!key.equals(currentImageKey)) {
            return false;
        }
        if (!(drawable instanceof AnimatedFileDrawable)) {
            ImageLoader.getInstance().incrementUseCount(currentImageKey);
        } else {
            AnimatedFileDrawable animatedFileDrawable = (AnimatedFileDrawable) drawable;
            animatedFileDrawable.setStartEndTime(startTime, endTime);
            if (animatedFileDrawable.isWebmSticker) {
                ImageLoader.getInstance().incrementUseCount(currentImageKey);
            }
        }
        currentImageDrawable = drawable;
        if (drawable instanceof ExtendedBitmapDrawable) {
            imageOrientation = ((ExtendedBitmapDrawable) drawable).getOrientation();
        }
        updateDrawableRadius(drawable);
        if (isVisible && (!memCache && !forcePreview || forceCrossfade) && crossfadeDuration != 0) {
            boolean allowCorssfade = true;
            if (currentMediaDrawable instanceof AnimatedFileDrawable && ((AnimatedFileDrawable) currentMediaDrawable).hasBitmap()) {
                allowCorssfade = false;
            } else if (currentImageDrawable instanceof RLottieDrawable) {
                allowCorssfade = staticThumbDrawable instanceof LoadingStickerDrawable || staticThumbDrawable instanceof SvgHelper.SvgDrawable || staticThumbDrawable instanceof Emoji.EmojiDrawable;
            }
            if (allowCorssfade && (currentThumbDrawable != null || staticThumbDrawable != null || forceCrossfade)) {
                if (currentThumbDrawable != null && staticThumbDrawable != null) {
                    previousAlpha = currentAlpha;
                } else {
                    previousAlpha = 1f;
                }
                currentAlpha = 0.0f;
                lastUpdateAlphaTime = System.currentTimeMillis();
                crossfadeWithThumb = crossfadeImage != null || currentThumbDrawable != null || staticThumbDrawable != null;
            }
        } else {
            currentAlpha = 1.0f;
            previousAlpha = 1f;
        }
    } else if (type == TYPE_MEDIA) {
        if (!key.equals(currentMediaKey)) {
            return false;
        }
        if (!(drawable instanceof AnimatedFileDrawable)) {
            ImageLoader.getInstance().incrementUseCount(currentMediaKey);
        } else {
            AnimatedFileDrawable animatedFileDrawable = (AnimatedFileDrawable) drawable;
            animatedFileDrawable.setStartEndTime(startTime, endTime);
            if (animatedFileDrawable.isWebmSticker) {
                ImageLoader.getInstance().incrementUseCount(currentImageKey);
            }
        }
        currentMediaDrawable = drawable;
        updateDrawableRadius(drawable);
        if (currentImageDrawable == null) {
            boolean allowCorssfade = true;
            if (!memCache && !forcePreview || forceCrossfade) {
                if (currentThumbDrawable == null && staticThumbDrawable == null || currentAlpha == 1.0f || forceCrossfade) {
                    if (currentThumbDrawable != null && staticThumbDrawable != null) {
                        previousAlpha = currentAlpha;
                    } else {
                        previousAlpha = 1f;
                    }
                    currentAlpha = 0.0f;
                    lastUpdateAlphaTime = System.currentTimeMillis();
                    crossfadeWithThumb = crossfadeImage != null || currentThumbDrawable != null || staticThumbDrawable != null;
                }
            } else {
                currentAlpha = 1.0f;
                previousAlpha = 1f;
            }
        }
    } else if (type == TYPE_THUMB) {
        if (currentThumbDrawable != null) {
            return false;
        }
        if (!forcePreview) {
            AnimatedFileDrawable animation = getAnimation();
            if (animation != null && animation.hasBitmap()) {
                return false;
            }
            if (currentImageDrawable != null && !(currentImageDrawable instanceof AnimatedFileDrawable) || currentMediaDrawable != null && !(currentMediaDrawable instanceof AnimatedFileDrawable)) {
                return false;
            }
        }
        if (!key.equals(currentThumbKey)) {
            return false;
        }
        ImageLoader.getInstance().incrementUseCount(currentThumbKey);
        currentThumbDrawable = drawable;
        if (drawable instanceof ExtendedBitmapDrawable) {
            thumbOrientation = ((ExtendedBitmapDrawable) drawable).getOrientation();
        }
        updateDrawableRadius(drawable);
        if (!memCache && crossfadeAlpha != 2) {
            if (currentParentObject instanceof MessageObject && ((MessageObject) currentParentObject).isRoundVideo() && ((MessageObject) currentParentObject).isSending()) {
                currentAlpha = 1.0f;
                previousAlpha = 1f;
            } else {
                currentAlpha = 0.0f;
                previousAlpha = 1f;
                lastUpdateAlphaTime = System.currentTimeMillis();
                crossfadeWithThumb = staticThumbDrawable != null;
            }
        } else {
            currentAlpha = 1.0f;
            previousAlpha = 1f;
        }
    }
    if (delegate != null) {
        delegate.didSetImage(this, currentImageDrawable != null || currentThumbDrawable != null || staticThumbDrawable != null || currentMediaDrawable != null, currentImageDrawable == null && currentMediaDrawable == null, memCache);
    }
    if (drawable instanceof AnimatedFileDrawable) {
        AnimatedFileDrawable fileDrawable = (AnimatedFileDrawable) drawable;
        fileDrawable.setUseSharedQueue(useSharedAnimationQueue);
        if (attachedToWindow) {
            fileDrawable.addParent(parentView);
        }
        if (allowStartAnimation && currentOpenedLayerFlags == 0) {
            fileDrawable.start();
        }
        fileDrawable.setAllowDecodeSingleFrame(allowDecodeSingleFrame);
        animationReadySent = false;
        if (parentView != null) {
            parentView.invalidate();
        }
    } else if (drawable instanceof RLottieDrawable) {
        RLottieDrawable fileDrawable = (RLottieDrawable) drawable;
        fileDrawable.addParentView(parentView);
        if (allowStartLottieAnimation && (!fileDrawable.isHeavyDrawable() || currentOpenedLayerFlags == 0)) {
            fileDrawable.start();
        }
        fileDrawable.setAllowDecodeSingleFrame(true);
        fileDrawable.setAutoRepeat(autoRepeat);
        animationReadySent = false;
    }
    if (parentView != null) {
        if (invalidateAll) {
            parentView.invalidate();
        } else {
            parentView.invalidate((int) imageX, (int) imageY, (int) (imageX + imageW), (int) (imageY + imageH));
        }
    }
    return true;
}
Also used : LoadingStickerDrawable(org.telegram.ui.Components.LoadingStickerDrawable) AnimatedFileDrawable(org.telegram.ui.Components.AnimatedFileDrawable) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable)

Aggregations

AnimatedFileDrawable (org.telegram.ui.Components.AnimatedFileDrawable)1 LoadingStickerDrawable (org.telegram.ui.Components.LoadingStickerDrawable)1 RLottieDrawable (org.telegram.ui.Components.RLottieDrawable)1