package s9;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ValueAnimator;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.LinearInterpolator;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.ActionMenuView;
import androidx.core.view.x1;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.internal.q;
import com.google.android.material.internal.w0;
import com.google.android.material.search.SearchBar;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;

/* JADX INFO: loaded from: classes2.dex */
public final class f {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final LinkedHashSet f32687b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public boolean f32688c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public boolean f32689d;

    @Nullable
    private Animator defaultCenterViewAnimator;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public boolean f32690e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public Animator f32691f;

    @Nullable
    private Animator secondaryViewAnimator;

    public f() {
        new LinkedHashSet();
        this.f32686a = new LinkedHashSet();
        this.f32687b = new LinkedHashSet();
        this.f32690e = true;
        this.f32691f = null;
    }

    public static void a(f fVar, SearchBar searchBar, View view, AppBarLayout appBarLayout, boolean z10) {
        fVar.getClass();
        AnimatorSet animatorSet = new AnimatorSet();
        List<View> children = w0.getChildren(searchBar);
        if (searchBar.getCenterView() != null) {
            children.remove(searchBar.getCenterView());
        }
        ValueAnimator valueAnimatorOfFloat = ValueAnimator.ofFloat(1.0f, 0.0f);
        valueAnimatorOfFloat.addUpdateListener(new q(new c7.g(8), children));
        valueAnimatorOfFloat.addUpdateListener(new o9.a(view, 1));
        valueAnimatorOfFloat.setDuration(75L);
        valueAnimatorOfFloat.setInterpolator(y8.a.f36864a);
        animatorSet.playSequentially(valueAnimatorOfFloat, fVar.getExpandAnimator(searchBar, view, appBarLayout));
        animatorSet.addListener(new d(fVar, 0));
        Iterator it = fVar.f32686a.iterator();
        while (it.hasNext()) {
            animatorSet.addListener((AnimatorListenerAdapter) it.next());
        }
        if (z10) {
            animatorSet.setDuration(0L);
        }
        animatorSet.start();
        fVar.f32691f = animatorSet;
    }

    private Animator getDefaultCenterViewAnimator(@Nullable View view) {
        ValueAnimator valueAnimatorOfFloat = ValueAnimator.ofFloat(0.0f, 1.0f);
        valueAnimatorOfFloat.addUpdateListener(q.a(view));
        LinearInterpolator linearInterpolator = y8.a.f36864a;
        valueAnimatorOfFloat.setInterpolator(linearInterpolator);
        valueAnimatorOfFloat.setDuration(this.f32690e ? 250L : 0L);
        valueAnimatorOfFloat.setStartDelay(this.f32690e ? 500L : 0L);
        ValueAnimator valueAnimatorOfFloat2 = ValueAnimator.ofFloat(1.0f, 0.0f);
        valueAnimatorOfFloat2.addUpdateListener(q.a(view));
        valueAnimatorOfFloat2.setInterpolator(linearInterpolator);
        valueAnimatorOfFloat2.setDuration(250L);
        valueAnimatorOfFloat2.setStartDelay(750L);
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playSequentially(valueAnimatorOfFloat, valueAnimatorOfFloat2);
        return animatorSet;
    }

    private Animator getExpandAnimator(SearchBar searchBar, View view, @Nullable AppBarLayout appBarLayout) {
        com.google.android.material.internal.j expandCollapseAnimationHelper = getExpandCollapseAnimationHelper(searchBar, view, appBarLayout);
        expandCollapseAnimationHelper.f22773e = 300L;
        e eVar = new e(this, searchBar, 0);
        ArrayList arrayList = expandCollapseAnimationHelper.f22771c;
        arrayList.add(eVar);
        AnimatorSet animatorSetA = expandCollapseAnimationHelper.a(true);
        animatorSetA.addListener(new com.google.android.material.internal.i(expandCollapseAnimationHelper, 0));
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            animatorSetA.addListener((AnimatorListenerAdapter) it.next());
        }
        return animatorSetA;
    }

    private com.google.android.material.internal.j getExpandCollapseAnimationHelper(SearchBar searchBar, View view, @Nullable AppBarLayout appBarLayout) {
        com.google.android.material.internal.j jVar = new com.google.android.material.internal.j(searchBar, view);
        com.google.android.material.shape.k kVarCreateWithElevationOverlay = com.google.android.material.shape.k.createWithElevationOverlay(view.getContext(), 0.0f, null);
        float cornerSize = searchBar.getCornerSize();
        com.google.android.material.shape.q qVarH = kVarCreateWithElevationOverlay.f23095b.f23068a.h();
        qVarH.c(cornerSize);
        kVarCreateWithElevationOverlay.setShapeAppearanceModel(qVarH.a());
        kVarCreateWithElevationOverlay.w(searchBar.getElevation());
        com.google.android.material.internal.j additionalUpdateListener = jVar.setAdditionalUpdateListener(new x1(kVarCreateWithElevationOverlay, view, 4));
        additionalUpdateListener.f22774f = appBarLayout != null ? appBarLayout.getTop() : 0;
        boolean z10 = view.getLayoutDirection() == 1;
        ArrayList arrayList = new ArrayList();
        if (view instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) view;
            for (int i10 = 0; i10 < viewGroup.getChildCount(); i10++) {
                View childAt = viewGroup.getChildAt(i10);
                if ((!z10 && (childAt instanceof ActionMenuView)) || (z10 && !(childAt instanceof ActionMenuView))) {
                    arrayList.add(childAt);
                }
            }
        }
        additionalUpdateListener.f22772d.addAll(arrayList);
        return additionalUpdateListener;
    }

    private Animator getSecondaryActionMenuItemAnimator(@Nullable View view) {
        ValueAnimator valueAnimatorOfFloat = ValueAnimator.ofFloat(0.0f, 1.0f);
        valueAnimatorOfFloat.addUpdateListener(q.a(view));
        valueAnimatorOfFloat.setInterpolator(y8.a.f36864a);
        valueAnimatorOfFloat.setDuration(250L);
        return valueAnimatorOfFloat;
    }

    private Animator getSecondaryViewAnimator(TextView textView, @Nullable View view) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.setStartDelay(250L);
        ValueAnimator valueAnimatorOfFloat = ValueAnimator.ofFloat(0.0f, 1.0f);
        valueAnimatorOfFloat.addUpdateListener(q.a(textView));
        valueAnimatorOfFloat.setInterpolator(y8.a.f36864a);
        valueAnimatorOfFloat.setDuration(250L);
        animatorSet.play(valueAnimatorOfFloat);
        if (view != null) {
            animatorSet.play(getSecondaryActionMenuItemAnimator(view));
        }
        return animatorSet;
    }

    public final void b(SearchBar searchBar) {
        Animator animator = this.secondaryViewAnimator;
        if (animator != null) {
            animator.end();
        }
        Animator animator2 = this.defaultCenterViewAnimator;
        if (animator2 != null) {
            animator2.end();
        }
        View centerView = searchBar.getCenterView();
        if (centerView != null) {
            centerView.setAlpha(0.0f);
        }
    }

    public void startCollapseAnimation(SearchBar searchBar, View view, @Nullable AppBarLayout appBarLayout, boolean z10) {
        Animator animator;
        if (this.f32688c && (animator = this.f32691f) != null) {
            animator.cancel();
        }
        this.f32689d = true;
        AnimatorSet animatorSet = new AnimatorSet();
        com.google.android.material.internal.j expandCollapseAnimationHelper = getExpandCollapseAnimationHelper(searchBar, view, appBarLayout);
        expandCollapseAnimationHelper.f22773e = 250L;
        e eVar = new e(this, searchBar, 1);
        ArrayList arrayList = expandCollapseAnimationHelper.f22771c;
        arrayList.add(eVar);
        AnimatorSet animatorSetA = expandCollapseAnimationHelper.a(false);
        animatorSetA.addListener(new com.google.android.material.internal.i(expandCollapseAnimationHelper, 1));
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            animatorSetA.addListener((AnimatorListenerAdapter) it.next());
        }
        List<View> children = w0.getChildren(searchBar);
        if (searchBar.getCenterView() != null) {
            children.remove(searchBar.getCenterView());
        }
        ValueAnimator valueAnimatorOfFloat = ValueAnimator.ofFloat(0.0f, 1.0f);
        valueAnimatorOfFloat.addUpdateListener(new q(new c7.g(8), children));
        valueAnimatorOfFloat.setDuration(100L);
        valueAnimatorOfFloat.setInterpolator(y8.a.f36864a);
        animatorSet.playSequentially(animatorSetA, valueAnimatorOfFloat);
        animatorSet.addListener(new d(this, 1));
        Iterator it2 = this.f32687b.iterator();
        while (it2.hasNext()) {
            animatorSet.addListener((AnimatorListenerAdapter) it2.next());
        }
        if (z10) {
            animatorSet.setDuration(0L);
        }
        animatorSet.start();
        this.f32691f = animatorSet;
    }

    public void startExpandAnimation(SearchBar searchBar, View view, @Nullable AppBarLayout appBarLayout, boolean z10) {
        Animator animator;
        if (this.f32689d && (animator = this.f32691f) != null) {
            animator.cancel();
        }
        this.f32688c = true;
        view.setVisibility(4);
        view.post(new c(this, searchBar, view, appBarLayout, z10, 0));
    }
}
