package com.bumptech.glide.request.target;

import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/* JADX INFO: loaded from: classes.dex */
public abstract class h extends m implements r5.b {

    @Nullable
    private Animatable animatable;

    private void maybeUpdateAnimatable(@Nullable Object obj) {
        if (!(obj instanceof Animatable)) {
            this.animatable = null;
            return;
        }
        Animatable animatable = (Animatable) obj;
        this.animatable = animatable;
        animatable.start();
    }

    private void setResourceInternal(@Nullable Object obj) {
        setResource(obj);
        maybeUpdateAnimatable(obj);
    }

    @Override // n5.i
    public final void b() {
        Animatable animatable = this.animatable;
        if (animatable != null) {
            animatable.stop();
        }
    }

    @Override // n5.i
    public final void d() {
        Animatable animatable = this.animatable;
        if (animatable != null) {
            animatable.start();
        }
    }

    @Override // r5.b
    @Nullable
    public Drawable getCurrentDrawable() {
        return ((ImageView) this.f5897b).getDrawable();
    }

    @Override // com.bumptech.glide.request.target.m, com.bumptech.glide.request.target.a, com.bumptech.glide.request.target.j
    public void onLoadCleared(@Nullable Drawable drawable) {
        super.onLoadCleared(drawable);
        Animatable animatable = this.animatable;
        if (animatable != null) {
            animatable.stop();
        }
        setResourceInternal(null);
        ((ImageView) this.f5897b).setImageDrawable(drawable);
    }

    @Override // com.bumptech.glide.request.target.a, com.bumptech.glide.request.target.j
    public void onLoadFailed(@Nullable Drawable drawable) {
        super.onLoadFailed(drawable);
        setResourceInternal(null);
        ((ImageView) this.f5897b).setImageDrawable(drawable);
    }

    @Override // com.bumptech.glide.request.target.m, com.bumptech.glide.request.target.a, com.bumptech.glide.request.target.j
    public void onLoadStarted(@Nullable Drawable drawable) {
        super.onLoadStarted(drawable);
        setResourceInternal(null);
        ((ImageView) this.f5897b).setImageDrawable(drawable);
    }

    @Override // com.bumptech.glide.request.target.m, com.bumptech.glide.request.target.a, com.bumptech.glide.request.target.j
    public void onResourceReady(@NonNull Object obj, @Nullable r5.c cVar) {
        setResourceInternal(obj);
    }

    public abstract void setResource(@Nullable Object obj);
}
