package pl.droidsonroids.gif;

import android.os.SystemClock;
import java.util.concurrent.TimeUnit;

/* JADX INFO: loaded from: classes3.dex */
public final class p extends q {
    @Override // pl.droidsonroids.gif.q
    public final void a() {
        c cVar = this.f32051a;
        long jP = cVar.f32029g.p(cVar.f32028f);
        if (jP >= 0) {
            this.f32051a.f32025c = SystemClock.uptimeMillis() + jP;
            if (this.f32051a.isVisible() && this.f32051a.f32024b) {
                c cVar2 = this.f32051a;
                if (!cVar2.f32034l) {
                    cVar2.f32023a.remove(this);
                    c cVar3 = this.f32051a;
                    cVar3.S = cVar3.f32023a.schedule(this, jP, TimeUnit.MILLISECONDS);
                }
            }
            if (!this.f32051a.f32030h.isEmpty() && this.f32051a.f32029g.c() == this.f32051a.f32029g.j() - 1) {
                c cVar4 = this.f32051a;
                e.i iVar = cVar4.f32035m;
                GifInfoHandle gifInfoHandle = cVar4.f32029g;
                int iD = gifInfoHandle.d();
                if (iD != 0 && iD >= gifInfoHandle.h()) {
                    iD--;
                }
                iVar.sendEmptyMessageAtTime(iD, this.f32051a.f32025c);
            }
        } else {
            c cVar5 = this.f32051a;
            cVar5.f32025c = Long.MIN_VALUE;
            cVar5.f32024b = false;
        }
        if (!this.f32051a.isVisible() || this.f32051a.f32035m.hasMessages(-1)) {
            return;
        }
        this.f32051a.f32035m.sendEmptyMessageAtTime(-1, 0L);
    }
}
