package androidx.core.view;

import android.animation.ValueAnimator;
import android.view.View;
import android.view.WindowInsets;
import java.util.Objects;

/* JADX INFO: loaded from: classes.dex */
public final class g2 implements View.OnApplyWindowInsetsListener {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final d2 f1754a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public f3 f1755b;

    public g2(View view, d2 d2Var) {
        this.f1754a = d2Var;
        f3 rootWindowInsets = s1.getRootWindowInsets(view);
        this.f1755b = rootWindowInsets != null ? new r2(rootWindowInsets).f1814a.b() : null;
    }

    @Override // android.view.View.OnApplyWindowInsetsListener
    public final WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
        if (!view.isLaidOut()) {
            this.f1755b = f3.toWindowInsetsCompat(windowInsets, view);
            return h2.i(view, windowInsets);
        }
        f3 windowInsetsCompat = f3.toWindowInsetsCompat(windowInsets, view);
        if (this.f1755b == null) {
            this.f1755b = s1.getRootWindowInsets(view);
        }
        if (this.f1755b == null) {
            this.f1755b = windowInsetsCompat;
            return h2.i(view, windowInsets);
        }
        d2 callback = h2.getCallback(view);
        if (callback != null && Objects.equals(callback.f1725a, windowInsets)) {
            return h2.i(view, windowInsets);
        }
        f3 f3Var = this.f1755b;
        int i10 = 0;
        for (int i11 = 1; i11 <= 256; i11 <<= 1) {
            if (!windowInsetsCompat.f1747a.f(i11).equals(f3Var.f1747a.f(i11))) {
                i10 |= i11;
            }
        }
        if (i10 == 0) {
            return h2.i(view, windowInsets);
        }
        f3 f3Var2 = this.f1755b;
        l2 l2Var = new l2(i10, (i10 & 8) != 0 ? windowInsetsCompat.f1747a.f(8).f28505d > f3Var2.f1747a.f(8).f28505d ? h2.f1761d : h2.f1762e : h2.f1763f, 160L);
        l2Var.f1784a.d(0.0f);
        ValueAnimator duration = ValueAnimator.ofFloat(0.0f, 1.0f).setDuration(l2Var.f1784a.a());
        j0.d dVarF = windowInsetsCompat.f1747a.f(i10);
        j0.d dVarF2 = f3Var2.f1747a.f(i10);
        int iMin = Math.min(dVarF.f28502a, dVarF2.f28502a);
        int i12 = dVarF.f28503b;
        int i13 = dVarF2.f28503b;
        int iMin2 = Math.min(i12, i13);
        int i14 = dVarF.f28504c;
        int i15 = dVarF2.f28504c;
        int iMin3 = Math.min(i14, i15);
        int i16 = dVarF.f28505d;
        int i17 = i10;
        int i18 = dVarF2.f28505d;
        fe.h hVar = new fe.h(j0.d.b(iMin, iMin2, iMin3, Math.min(i16, i18)), j0.d.b(Math.max(dVarF.f28502a, dVarF2.f28502a), Math.max(i12, i13), Math.max(i14, i15), Math.max(i16, i18)), 1);
        h2.f(view, l2Var, windowInsets, false);
        duration.addUpdateListener(new e2(l2Var, windowInsetsCompat, f3Var2, i17, view));
        duration.addListener(new y1(this, l2Var, view, 1));
        o0.a(view, new f2(this, view, l2Var, hVar, duration, 0));
        this.f1755b = windowInsetsCompat;
        return h2.i(view, windowInsets);
    }
}
