package com.google.android.material.behavior;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.TimeInterpolator;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewPropertyAnimator;
import androidx.coordinatorlayout.widget.CoordinatorLayout;

/* JADX INFO: loaded from: classes.dex */
public class HideBottomViewOnScrollBehavior<V extends View> extends CoordinatorLayout.c<V> {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private int f3575a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private int f3576b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private int f3577c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private ViewPropertyAnimator f3578d;

    class a extends AnimatorListenerAdapter {
        a() {
        }

        @Override // android.animation.AnimatorListenerAdapter, android.animation.Animator.AnimatorListener
        public void onAnimationEnd(Animator animator) {
            HideBottomViewOnScrollBehavior.this.f3578d = null;
        }
    }

    public HideBottomViewOnScrollBehavior() {
        this.f3575a = 0;
        this.f3576b = 2;
        this.f3577c = 0;
    }

    private void F(V v2, int i3, long j3, TimeInterpolator timeInterpolator) {
        this.f3578d = v2.animate().translationY(i3).setInterpolator(timeInterpolator).setDuration(j3).setListener(new a());
    }

    @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
    public boolean A(CoordinatorLayout coordinatorLayout, V v2, View view, View view2, int i3, int i4) {
        return i3 == 2;
    }

    public boolean G() {
        return this.f3576b == 1;
    }

    public boolean H() {
        return this.f3576b == 2;
    }

    public void I(V v2, int i3) {
        this.f3577c = i3;
        if (this.f3576b == 1) {
            v2.setTranslationY(this.f3575a + i3);
        }
    }

    public void J(V v2) {
        K(v2, true);
    }

    public void K(V v2, boolean z2) {
        if (G()) {
            return;
        }
        ViewPropertyAnimator viewPropertyAnimator = this.f3578d;
        if (viewPropertyAnimator != null) {
            viewPropertyAnimator.cancel();
            v2.clearAnimation();
        }
        this.f3576b = 1;
        int i3 = this.f3575a + this.f3577c;
        if (z2) {
            F(v2, i3, 175L, m0.a.f5555c);
        } else {
            v2.setTranslationY(i3);
        }
    }

    public void L(V v2) {
        M(v2, true);
    }

    public void M(V v2, boolean z2) {
        if (H()) {
            return;
        }
        ViewPropertyAnimator viewPropertyAnimator = this.f3578d;
        if (viewPropertyAnimator != null) {
            viewPropertyAnimator.cancel();
            v2.clearAnimation();
        }
        this.f3576b = 2;
        if (z2) {
            F(v2, 0, 225L, m0.a.f5556d);
        } else {
            v2.setTranslationY(0);
        }
    }

    @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
    public boolean l(CoordinatorLayout coordinatorLayout, V v2, int i3) {
        this.f3575a = v2.getMeasuredHeight() + ((ViewGroup.MarginLayoutParams) v2.getLayoutParams()).bottomMargin;
        return super.l(coordinatorLayout, v2, i3);
    }

    @Override // androidx.coordinatorlayout.widget.CoordinatorLayout.c
    public void t(CoordinatorLayout coordinatorLayout, V v2, View view, int i3, int i4, int i5, int i6, int i7, int[] iArr) {
        if (i4 > 0) {
            J(v2);
        } else if (i4 < 0) {
            L(v2);
        }
    }

    public HideBottomViewOnScrollBehavior(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.f3575a = 0;
        this.f3576b = 2;
        this.f3577c = 0;
    }
}
