package defpackage;

import android.R;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.KeyEvent;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import androidx.appcompat.view.menu.g;
import androidx.appcompat.widget.ActionBarContainer;
import androidx.appcompat.widget.ActionBarContextView;
import androidx.appcompat.widget.ActionBarOverlayLayout;
import androidx.appcompat.widget.Toolbar;
import defpackage.go7;
import defpackage.k7;
import defpackage.r7;
import defpackage.xn;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.WeakHashMap;

/* JADX INFO: loaded from: classes.dex */
@m38
public class hqa extends k7 implements ActionBarOverlayLayout.d {
    public static final AccelerateInterpolator y = new AccelerateInterpolator();
    public static final DecelerateInterpolator z = new DecelerateInterpolator();
    public Context a;
    public Context b;
    public ActionBarOverlayLayout c;
    public ActionBarContainer d;
    public yx1 e;
    public ActionBarContextView f;
    public final View g;
    public boolean h;
    public d i;
    public d j;
    public r7.a k;
    public boolean l;
    public final ArrayList m;
    public int n;
    public boolean o;
    public boolean p;
    public boolean q;
    public boolean r;
    public vka s;
    public boolean t;
    public boolean u;
    public final wka v;
    public final wka w;
    public final yka x;

    public class a extends xka {
        public a() {
        }

        @Override // defpackage.xka, defpackage.wka
        public final void onAnimationEnd() {
            View view;
            hqa hqaVar = hqa.this;
            if (hqaVar.o && (view = hqaVar.g) != null) {
                view.setTranslationY(0.0f);
                hqaVar.d.setTranslationY(0.0f);
            }
            hqaVar.d.setVisibility(8);
            hqaVar.d.setTransitioning(false);
            hqaVar.s = null;
            r7.a aVar = hqaVar.k;
            if (aVar != null) {
                ((xn.f) aVar).b(hqaVar.j);
                hqaVar.j = null;
                hqaVar.k = null;
            }
            ActionBarOverlayLayout actionBarOverlayLayout = hqaVar.c;
            if (actionBarOverlayLayout != null) {
                sia.x(actionBarOverlayLayout);
            }
        }
    }

    public class b extends xka {
        public b() {
        }

        @Override // defpackage.xka, defpackage.wka
        public final void onAnimationEnd() {
            hqa hqaVar = hqa.this;
            hqaVar.s = null;
            hqaVar.d.requestLayout();
        }
    }

    public class c implements yka {
        public c() {
        }

        @Override // defpackage.yka
        public final void a() {
            ((View) hqa.this.d.getParent()).invalidate();
        }
    }

    @m38
    public class d extends r7 implements g.a {
        public final Context c;
        public final g d;
        public r7.a e;
        public WeakReference f;

        public d(Context context, r7.a aVar) {
            this.c = context;
            this.e = aVar;
            g defaultShowAsAction = new g(context).setDefaultShowAsAction(1);
            this.d = defaultShowAsAction;
            defaultShowAsAction.setCallback(this);
        }

        @Override // defpackage.r7
        public final void a() {
            hqa hqaVar = hqa.this;
            if (hqaVar.i != this) {
                return;
            }
            if (hqaVar.p) {
                hqaVar.j = this;
                hqaVar.k = this.e;
            } else {
                ((xn.f) this.e).b(this);
            }
            this.e = null;
            hqaVar.e(false);
            ActionBarContextView actionBarContextView = hqaVar.f;
            if (actionBarContextView.m == null) {
                actionBarContextView.g();
            }
            hqaVar.c.setHideOnContentScrollEnabled(hqaVar.u);
            hqaVar.i = null;
        }

        @Override // defpackage.r7
        public final View b() {
            WeakReference weakReference = this.f;
            if (weakReference != null) {
                return (View) weakReference.get();
            }
            return null;
        }

        @Override // defpackage.r7
        public final g c() {
            return this.d;
        }

        @Override // defpackage.r7
        public final MenuInflater d() {
            return new fe9(this.c);
        }

        @Override // defpackage.r7
        public final CharSequence e() {
            return hqa.this.f.getSubtitle();
        }

        @Override // defpackage.r7
        public final CharSequence f() {
            return hqa.this.f.getTitle();
        }

        @Override // defpackage.r7
        public final void g() {
            if (hqa.this.i != this) {
                return;
            }
            g gVar = this.d;
            gVar.stopDispatchingItemsChanged();
            try {
                this.e.c(this, gVar);
            } finally {
                gVar.startDispatchingItemsChanged();
            }
        }

        @Override // defpackage.r7
        public final boolean h() {
            return hqa.this.f.u;
        }

        @Override // defpackage.r7
        public final void i(View view) {
            hqa.this.f.setCustomView(view);
            this.f = new WeakReference(view);
        }

        @Override // defpackage.r7
        public final void j(int i) {
            k(hqa.this.a.getResources().getString(i));
        }

        @Override // defpackage.r7
        public final void k(CharSequence charSequence) {
            hqa.this.f.setSubtitle(charSequence);
        }

        @Override // defpackage.r7
        public final void l(int i) {
            m(hqa.this.a.getResources().getString(i));
        }

        @Override // defpackage.r7
        public final void m(CharSequence charSequence) {
            hqa.this.f.setTitle(charSequence);
        }

        @Override // defpackage.r7
        public final void n(boolean z) {
            this.b = z;
            hqa.this.f.setTitleOptional(z);
        }

        @Override // androidx.appcompat.view.menu.g.a
        public final boolean onMenuItemSelected(g gVar, MenuItem menuItem) {
            r7.a aVar = this.e;
            if (aVar != null) {
                return ((xn.f) aVar).a.a(this, menuItem);
            }
            return false;
        }

        @Override // androidx.appcompat.view.menu.g.a
        public final void onMenuModeChange(g gVar) {
            if (this.e == null) {
                return;
            }
            g();
            hqa.this.f.i();
        }
    }

    @m38
    public class e extends k7.f {
    }

    public hqa(Activity activity, boolean z2) {
        new ArrayList();
        this.m = new ArrayList();
        this.n = 0;
        this.o = true;
        this.r = true;
        this.v = new a();
        this.w = new b();
        this.x = new c();
        View decorView = activity.getWindow().getDecorView();
        h(decorView);
        if (z2) {
            return;
        }
        this.g = decorView.findViewById(R.id.content);
    }

    @Override // androidx.appcompat.widget.ActionBarOverlayLayout.d
    public final void a() {
        if (this.p) {
            this.p = false;
            l(true);
        }
    }

    @Override // androidx.appcompat.widget.ActionBarOverlayLayout.d
    public final void b(boolean z2) {
        this.o = z2;
    }

    @Override // androidx.appcompat.widget.ActionBarOverlayLayout.d
    public final void c() {
        if (this.p) {
            return;
        }
        this.p = true;
        l(true);
    }

    @Override // androidx.appcompat.widget.ActionBarOverlayLayout.d
    public final void d() {
        vka vkaVar = this.s;
        if (vkaVar != null) {
            vkaVar.a();
            this.s = null;
        }
    }

    public final void e(boolean z2) {
        uka ukaVarJ;
        uka ukaVarH;
        if (z2) {
            if (!this.q) {
                this.q = true;
                ActionBarOverlayLayout actionBarOverlayLayout = this.c;
                if (actionBarOverlayLayout != null) {
                    actionBarOverlayLayout.setShowingForActionMode(true);
                }
                l(false);
            }
        } else if (this.q) {
            this.q = false;
            ActionBarOverlayLayout actionBarOverlayLayout2 = this.c;
            if (actionBarOverlayLayout2 != null) {
                actionBarOverlayLayout2.setShowingForActionMode(false);
            }
            l(false);
        }
        ActionBarContainer actionBarContainer = this.d;
        WeakHashMap weakHashMap = sia.a;
        if (!actionBarContainer.isLaidOut()) {
            if (z2) {
                this.e.o(4);
                this.f.setVisibility(0);
                return;
            } else {
                this.e.o(0);
                this.f.setVisibility(8);
                return;
            }
        }
        if (z2) {
            ukaVarH = this.e.j(4, 100L);
            ukaVarJ = this.f.h(0, 200L);
        } else {
            ukaVarJ = this.e.j(0, 200L);
            ukaVarH = this.f.h(8, 100L);
        }
        vka vkaVar = new vka();
        ArrayList arrayList = vkaVar.a;
        arrayList.add(ukaVarH);
        View view = (View) ukaVarH.a.get();
        long duration = view != null ? view.animate().getDuration() : 0L;
        View view2 = (View) ukaVarJ.a.get();
        if (view2 != null) {
            view2.animate().setStartDelay(duration);
        }
        arrayList.add(ukaVarJ);
        vkaVar.b();
    }

    public final void f(boolean z2) {
        if (z2 == this.l) {
            return;
        }
        this.l = z2;
        ArrayList arrayList = this.m;
        int size = arrayList.size();
        for (int i = 0; i < size; i++) {
            ((k7.d) arrayList.get(i)).a();
        }
    }

    public final Context g() {
        if (this.b == null) {
            TypedValue typedValue = new TypedValue();
            this.a.getTheme().resolveAttribute(com.strmr.ps.R.attr.actionBarWidgetTheme, typedValue, true);
            int i = typedValue.resourceId;
            if (i != 0) {
                this.b = new ContextThemeWrapper(this.a, i);
            } else {
                this.b = this.a;
            }
        }
        return this.b;
    }

    public final void h(View view) {
        yx1 wrapper;
        ActionBarOverlayLayout actionBarOverlayLayout = (ActionBarOverlayLayout) view.findViewById(com.strmr.ps.R.id.decor_content_parent);
        this.c = actionBarOverlayLayout;
        if (actionBarOverlayLayout != null) {
            actionBarOverlayLayout.setActionBarVisibilityCallback(this);
        }
        KeyEvent.Callback callbackFindViewById = view.findViewById(com.strmr.ps.R.id.action_bar);
        if (callbackFindViewById instanceof yx1) {
            wrapper = (yx1) callbackFindViewById;
        } else {
            if (!(callbackFindViewById instanceof Toolbar)) {
                throw new IllegalStateException("Can't make a decor toolbar out of ".concat(callbackFindViewById != null ? callbackFindViewById.getClass().getSimpleName() : "null"));
            }
            wrapper = ((Toolbar) callbackFindViewById).getWrapper();
        }
        this.e = wrapper;
        this.f = (ActionBarContextView) view.findViewById(com.strmr.ps.R.id.action_context_bar);
        ActionBarContainer actionBarContainer = (ActionBarContainer) view.findViewById(com.strmr.ps.R.id.action_bar_container);
        this.d = actionBarContainer;
        yx1 yx1Var = this.e;
        if (yx1Var == null || this.f == null || actionBarContainer == null) {
            throw new IllegalStateException(getClass().getSimpleName().concat(" can only be used with a compatible window decor layout"));
        }
        this.a = yx1Var.getContext();
        if ((this.e.p() & 4) != 0) {
            this.h = true;
        }
        Context context = this.a;
        int i = context.getApplicationInfo().targetSdkVersion;
        this.e.getClass();
        j(context.getResources().getBoolean(com.strmr.ps.R.bool.abc_action_bar_embed_tabs));
        TypedArray typedArrayObtainStyledAttributes = this.a.obtainStyledAttributes(null, go7.m.a, com.strmr.ps.R.attr.actionBarStyle, 0);
        if (typedArrayObtainStyledAttributes.getBoolean(14, false)) {
            ActionBarOverlayLayout actionBarOverlayLayout2 = this.c;
            if (!actionBarOverlayLayout2.j) {
                throw new IllegalStateException("Action bar must be in overlay mode (Window.FEATURE_OVERLAY_ACTION_BAR) to enable hide on content scroll");
            }
            this.u = true;
            actionBarOverlayLayout2.setHideOnContentScrollEnabled(true);
        }
        int dimensionPixelSize = typedArrayObtainStyledAttributes.getDimensionPixelSize(12, 0);
        if (dimensionPixelSize != 0) {
            sia.ad(this.d, dimensionPixelSize);
        }
        typedArrayObtainStyledAttributes.recycle();
    }

    public final void i(boolean z2) {
        if (this.h) {
            return;
        }
        int i = z2 ? 4 : 0;
        int iP = this.e.p();
        this.h = true;
        this.e.i((i & 4) | (iP & (-5)));
    }

    public final void j(boolean z2) {
        if (z2) {
            this.d.setTabContainer(null);
            this.e.m();
        } else {
            this.e.m();
            this.d.setTabContainer(null);
        }
        this.e.getClass();
        this.e.k(false);
        this.c.setHasNonEmbeddedTabs(false);
    }

    public final void k(CharSequence charSequence) {
        this.e.setWindowTitle(charSequence);
    }

    public final void l(boolean z2) {
        boolean z3 = this.p;
        boolean z4 = this.q;
        yka ykaVar = this.x;
        View view = this.g;
        if (!z4 && z3) {
            if (this.r) {
                this.r = false;
                vka vkaVar = this.s;
                if (vkaVar != null) {
                    vkaVar.a();
                }
                int i = this.n;
                wka wkaVar = this.v;
                if (i != 0 || (!this.t && !z2)) {
                    ((a) wkaVar).onAnimationEnd();
                    return;
                }
                this.d.setAlpha(1.0f);
                this.d.setTransitioning(true);
                vka vkaVar2 = new vka();
                float f = -this.d.getHeight();
                if (z2) {
                    this.d.getLocationInWindow(new int[]{0, 0});
                    f -= r12[1];
                }
                uka ukaVarA = sia.a(this.d);
                ukaVarA.e(f);
                View view2 = (View) ukaVarA.a.get();
                if (view2 != null) {
                    view2.animate().setUpdateListener(ykaVar != null ? new jn(ykaVar, view2, 2) : null);
                }
                boolean z5 = vkaVar2.e;
                ArrayList arrayList = vkaVar2.a;
                if (!z5) {
                    arrayList.add(ukaVarA);
                }
                if (this.o && view != null) {
                    uka ukaVarA2 = sia.a(view);
                    ukaVarA2.e(f);
                    if (!vkaVar2.e) {
                        arrayList.add(ukaVarA2);
                    }
                }
                boolean z6 = vkaVar2.e;
                if (!z6) {
                    vkaVar2.c = y;
                }
                if (!z6) {
                    vkaVar2.b = 250L;
                }
                xka xkaVar = (xka) wkaVar;
                if (!z6) {
                    vkaVar2.d = xkaVar;
                }
                this.s = vkaVar2;
                vkaVar2.b();
                return;
            }
            return;
        }
        if (this.r) {
            return;
        }
        this.r = true;
        vka vkaVar3 = this.s;
        if (vkaVar3 != null) {
            vkaVar3.a();
        }
        this.d.setVisibility(0);
        int i2 = this.n;
        wka wkaVar2 = this.w;
        if (i2 == 0 && (this.t || z2)) {
            this.d.setTranslationY(0.0f);
            float f2 = -this.d.getHeight();
            if (z2) {
                this.d.getLocationInWindow(new int[]{0, 0});
                f2 -= r12[1];
            }
            this.d.setTranslationY(f2);
            vka vkaVar4 = new vka();
            uka ukaVarA3 = sia.a(this.d);
            ukaVarA3.e(0.0f);
            View view3 = (View) ukaVarA3.a.get();
            if (view3 != null) {
                view3.animate().setUpdateListener(ykaVar != null ? new jn(ykaVar, view3, 2) : null);
            }
            boolean z7 = vkaVar4.e;
            ArrayList arrayList2 = vkaVar4.a;
            if (!z7) {
                arrayList2.add(ukaVarA3);
            }
            if (this.o && view != null) {
                view.setTranslationY(f2);
                uka ukaVarA4 = sia.a(view);
                ukaVarA4.e(0.0f);
                if (!vkaVar4.e) {
                    arrayList2.add(ukaVarA4);
                }
            }
            boolean z8 = vkaVar4.e;
            if (!z8) {
                vkaVar4.c = z;
            }
            if (!z8) {
                vkaVar4.b = 250L;
            }
            xka xkaVar2 = (xka) wkaVar2;
            if (!z8) {
                vkaVar4.d = xkaVar2;
            }
            this.s = vkaVar4;
            vkaVar4.b();
        } else {
            this.d.setAlpha(1.0f);
            this.d.setTranslationY(0.0f);
            if (this.o && view != null) {
                view.setTranslationY(0.0f);
            }
            ((b) wkaVar2).onAnimationEnd();
        }
        ActionBarOverlayLayout actionBarOverlayLayout = this.c;
        if (actionBarOverlayLayout != null) {
            sia.x(actionBarOverlayLayout);
        }
    }

    @Override // androidx.appcompat.widget.ActionBarOverlayLayout.d
    public final void onWindowVisibilityChanged(int i) {
        this.n = i;
    }

    public hqa(Dialog dialog) {
        new ArrayList();
        this.m = new ArrayList();
        this.n = 0;
        this.o = true;
        this.r = true;
        this.v = new a();
        this.w = new b();
        this.x = new c();
        h(dialog.getWindow().getDecorView());
    }
}
