package h0;

import android.animation.AnimatorSet;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import com.martsnew.tv.R;
import d5.AbstractC0844a;
import e0.C0853a;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

/* JADX INFO: renamed from: h0.m, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1013m {

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final ArrayList f13215c;

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

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

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

    public C1013m(ViewGroup viewGroup) {
        P6.g.e(viewGroup, "container");
        this.f13213a = viewGroup;
        this.f13214b = new ArrayList();
        this.f13215c = new ArrayList();
    }

    public static final C1013m i(ViewGroup viewGroup, P p3) {
        P6.g.e(viewGroup, "container");
        P6.g.e(p3, "fragmentManager");
        P6.g.d(p3.J(), "fragmentManager.specialEffectsControllerFactory");
        Object tag = viewGroup.getTag(R.id.special_effects_controller_view_tag);
        if (tag instanceof C1013m) {
            return (C1013m) tag;
        }
        C1013m c1013m = new C1013m(viewGroup);
        viewGroup.setTag(R.id.special_effects_controller_view_tag, c1013m);
        return c1013m;
    }

    public static boolean j(ArrayList arrayList) {
        boolean z8;
        int size = arrayList.size();
        int i = 0;
        loop0: while (true) {
            z8 = true;
            while (i < size) {
                Object obj = arrayList.get(i);
                i++;
                b0 b0Var = (b0) obj;
                if (!b0Var.f13188k.isEmpty()) {
                    ArrayList arrayList2 = b0Var.f13188k;
                    if (arrayList2 == null || !arrayList2.isEmpty()) {
                        int size2 = arrayList2.size();
                        int i5 = 0;
                        while (i5 < size2) {
                            Object obj2 = arrayList2.get(i5);
                            i5++;
                            a0 a0Var = (a0) obj2;
                            a0Var.getClass();
                            if (!(a0Var instanceof C1009i)) {
                                break;
                            }
                        }
                    }
                }
                z8 = false;
            }
            break loop0;
        }
        if (z8) {
            ArrayList arrayList3 = new ArrayList();
            int size3 = arrayList.size();
            int i8 = 0;
            while (i8 < size3) {
                Object obj3 = arrayList.get(i8);
                i8++;
                B6.q.d0(((b0) obj3).f13188k, arrayList3);
            }
            if (!arrayList3.isEmpty()) {
                return true;
            }
        }
        return false;
    }

    public final void a(b0 b0Var) {
        P6.g.e(b0Var, "operation");
        if (b0Var.i) {
            AbstractC0844a.d(b0Var.f13179a, b0Var.f13181c.b0(), this.f13213a);
            b0Var.i = false;
        }
    }

    public final void b(ArrayList arrayList, boolean z8) {
        Object obj;
        Object next;
        if (P.L(2)) {
            Log.v("FragmentManager", "Collecting Effects");
        }
        Iterator it = arrayList.iterator();
        while (true) {
            obj = null;
            if (!it.hasNext()) {
                next = null;
                break;
            }
            next = it.next();
            b0 b0Var = (b0) next;
            View view = b0Var.f13181c.X;
            P6.g.d(view, "operation.fragment.mView");
            if (view.getAlpha() != 0.0f || view.getVisibility() != 0) {
                int visibility = view.getVisibility();
                if (visibility != 0) {
                    if (visibility != 4 && visibility != 8) {
                        throw new IllegalArgumentException(AbstractC0844a.j("Unknown visibility ", visibility));
                    }
                } else if (b0Var.f13179a != 2) {
                    break;
                }
            }
        }
        b0 b0Var2 = (b0) next;
        ListIterator listIterator = arrayList.listIterator(arrayList.size());
        while (true) {
            if (!listIterator.hasPrevious()) {
                break;
            }
            Object objPrevious = listIterator.previous();
            b0 b0Var3 = (b0) objPrevious;
            View view2 = b0Var3.f13181c.X;
            P6.g.d(view2, "operation.fragment.mView");
            if (view2.getAlpha() != 0.0f || view2.getVisibility() != 0) {
                int visibility2 = view2.getVisibility();
                if (visibility2 == 0) {
                    continue;
                } else if (visibility2 != 4 && visibility2 != 8) {
                    throw new IllegalArgumentException(AbstractC0844a.j("Unknown visibility ", visibility2));
                }
            }
            if (b0Var3.f13179a == 2) {
                obj = objPrevious;
                break;
            }
        }
        b0 b0Var4 = (b0) obj;
        if (P.L(2)) {
            Log.v("FragmentManager", "Executing operations from " + b0Var2 + " to " + b0Var4);
        }
        ArrayList arrayList2 = new ArrayList();
        ArrayList arrayList3 = new ArrayList();
        ComponentCallbacksC1023x componentCallbacksC1023x = ((b0) B6.k.n0(arrayList)).f13181c;
        int size = arrayList.size();
        int i = 0;
        while (i < size) {
            Object obj2 = arrayList.get(i);
            i++;
            C1021v c1021v = ((b0) obj2).f13181c.f13280a0;
            C1021v c1021v2 = componentCallbacksC1023x.f13280a0;
            c1021v.f13247b = c1021v2.f13247b;
            c1021v.f13248c = c1021v2.f13248c;
            c1021v.f13249d = c1021v2.f13249d;
            c1021v.f13250e = c1021v2.f13250e;
        }
        int size2 = arrayList.size();
        int i5 = 0;
        while (true) {
            boolean z9 = true;
            if (i5 >= size2) {
                break;
            }
            Object obj3 = arrayList.get(i5);
            i5++;
            b0 b0Var5 = (b0) obj3;
            arrayList2.add(new C1007g(b0Var5, z8));
            if (!z8 ? b0Var5 != b0Var4 : b0Var5 != b0Var2) {
                z9 = false;
            }
            C1012l c1012l = new C1012l(b0Var5);
            int i8 = b0Var5.f13179a;
            ComponentCallbacksC1023x componentCallbacksC1023x2 = b0Var5.f13181c;
            if (i8 == 2) {
                if (z8) {
                    C1021v c1021v3 = componentCallbacksC1023x2.f13280a0;
                } else {
                    componentCallbacksC1023x2.getClass();
                }
            } else if (z8) {
                C1021v c1021v4 = componentCallbacksC1023x2.f13280a0;
            } else {
                componentCallbacksC1023x2.getClass();
            }
            if (b0Var5.f13179a == 2) {
                if (z8) {
                    C1021v c1021v5 = componentCallbacksC1023x2.f13280a0;
                } else {
                    C1021v c1021v6 = componentCallbacksC1023x2.f13280a0;
                }
            }
            if (z9) {
                if (z8) {
                    C1021v c1021v7 = componentCallbacksC1023x2.f13280a0;
                } else {
                    componentCallbacksC1023x2.getClass();
                }
            }
            arrayList3.add(c1012l);
            b0Var5.f13182d.add(new RunnableC1004d(this, b0Var5, 0));
        }
        ArrayList arrayList4 = new ArrayList();
        int size3 = arrayList3.size();
        int i9 = 0;
        while (i9 < size3) {
            Object obj4 = arrayList3.get(i9);
            i9++;
            if (!((C1012l) obj4).t()) {
                arrayList4.add(obj4);
            }
        }
        ArrayList arrayList5 = new ArrayList();
        int size4 = arrayList4.size();
        int i10 = 0;
        while (i10 < size4) {
            Object obj5 = arrayList4.get(i10);
            i10++;
            ((C1012l) obj5).getClass();
        }
        int size5 = arrayList5.size();
        int i11 = 0;
        while (i11 < size5) {
            Object obj6 = arrayList5.get(i11);
            i11++;
            ((C1012l) obj6).getClass();
        }
        ArrayList arrayList6 = new ArrayList();
        ArrayList arrayList7 = new ArrayList();
        int size6 = arrayList2.size();
        int i12 = 0;
        while (i12 < size6) {
            Object obj7 = arrayList2.get(i12);
            i12++;
            B6.q.d0(((b0) ((C1007g) obj7).f5146q).f13188k, arrayList7);
        }
        boolean zIsEmpty = arrayList7.isEmpty();
        int size7 = arrayList2.size();
        boolean z10 = false;
        int i13 = 0;
        while (i13 < size7) {
            Object obj8 = arrayList2.get(i13);
            i13++;
            C1007g c1007g = (C1007g) obj8;
            Context context = this.f13213a.getContext();
            b0 b0Var6 = (b0) c1007g.f5146q;
            P6.g.d(context, "context");
            C0853a c0853aF = c1007g.F(context);
            if (c0853aF != null) {
                if (((AnimatorSet) c0853aF.f12398s) == null) {
                    arrayList6.add(c1007g);
                } else {
                    ComponentCallbacksC1023x componentCallbacksC1023x3 = b0Var6.f13181c;
                    if (b0Var6.f13188k.isEmpty()) {
                        if (b0Var6.f13179a == 3) {
                            b0Var6.i = false;
                        }
                        b0Var6.f13187j.add(new C1009i(c1007g));
                        z10 = true;
                    } else if (P.L(2)) {
                        Log.v("FragmentManager", "Ignoring Animator set on " + componentCallbacksC1023x3 + " as this Fragment was involved in a Transition.");
                    }
                }
            }
        }
        int size8 = arrayList6.size();
        int i14 = 0;
        while (i14 < size8) {
            Object obj9 = arrayList6.get(i14);
            i14++;
            C1007g c1007g2 = (C1007g) obj9;
            b0 b0Var7 = (b0) c1007g2.f5146q;
            ComponentCallbacksC1023x componentCallbacksC1023x4 = b0Var7.f13181c;
            if (zIsEmpty) {
                if (!z10) {
                    b0Var7.f13187j.add(new C1006f(c1007g2));
                } else if (P.L(2)) {
                    Log.v("FragmentManager", "Ignoring Animation set on " + componentCallbacksC1023x4 + " as Animations cannot run alongside Animators.");
                }
            } else if (P.L(2)) {
                Log.v("FragmentManager", "Ignoring Animation set on " + componentCallbacksC1023x4 + " as Animations cannot run alongside Transitions.");
            }
        }
    }

    public final void c(ArrayList arrayList) {
        P6.g.e(arrayList, "operations");
        ArrayList arrayList2 = new ArrayList();
        int size = arrayList.size();
        int i = 0;
        while (i < size) {
            Object obj = arrayList.get(i);
            i++;
            B6.q.d0(((b0) obj).f13188k, arrayList2);
        }
        List listX0 = B6.k.x0(B6.k.A0(arrayList2));
        int size2 = listX0.size();
        for (int i5 = 0; i5 < size2; i5++) {
            ((a0) listX0.get(i5)).b(this.f13213a);
        }
        int size3 = arrayList.size();
        for (int i8 = 0; i8 < size3; i8++) {
            a((b0) arrayList.get(i8));
        }
        List listX02 = B6.k.x0(arrayList);
        int size4 = listX02.size();
        for (int i9 = 0; i9 < size4; i9++) {
            b0 b0Var = (b0) listX02.get(i9);
            if (b0Var.f13188k.isEmpty()) {
                b0Var.b();
            }
        }
    }

    public final void d(int i, int i5, W w4) {
        synchronized (this.f13214b) {
            try {
                ComponentCallbacksC1023x componentCallbacksC1023x = w4.f13125c;
                P6.g.d(componentCallbacksC1023x, "fragmentStateManager.fragment");
                b0 b0VarF = f(componentCallbacksC1023x);
                if (b0VarF == null) {
                    ComponentCallbacksC1023x componentCallbacksC1023x2 = w4.f13125c;
                    b0VarF = (componentCallbacksC1023x2.f13259C || componentCallbacksC1023x2.f13258B) ? g(componentCallbacksC1023x2) : null;
                }
                if (b0VarF != null) {
                    b0VarF.d(i, i5);
                    return;
                }
                b0 b0Var = new b0(i, i5, w4);
                this.f13214b.add(b0Var);
                b0Var.f13182d.add(new RunnableC1004d(this, b0Var, 1));
                b0Var.f13182d.add(new RunnableC1004d(this, b0Var, 2));
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void e() {
        boolean z8;
        if (this.f13218f) {
            return;
        }
        if (!this.f13213a.isAttachedToWindow()) {
            h();
            this.f13217e = false;
            return;
        }
        synchronized (this.f13214b) {
            try {
                ArrayList arrayListY0 = B6.k.y0(this.f13215c);
                this.f13215c.clear();
                int size = arrayListY0.size();
                int i = 0;
                while (true) {
                    z8 = true;
                    if (i >= size) {
                        break;
                    }
                    Object obj = arrayListY0.get(i);
                    i++;
                    b0 b0Var = (b0) obj;
                    if (this.f13214b.isEmpty() || !b0Var.f13181c.f13259C) {
                        z8 = false;
                    }
                    b0Var.f13185g = z8;
                }
                int size2 = arrayListY0.size();
                int i5 = 0;
                while (i5 < size2) {
                    Object obj2 = arrayListY0.get(i5);
                    i5++;
                    b0 b0Var2 = (b0) obj2;
                    if (this.f13216d) {
                        if (P.L(2)) {
                            Log.v("FragmentManager", "SpecialEffectsController: Completing non-seekable operation " + b0Var2);
                        }
                        b0Var2.b();
                    } else {
                        if (P.L(2)) {
                            Log.v("FragmentManager", "SpecialEffectsController: Cancelling operation " + b0Var2);
                        }
                        b0Var2.a(this.f13213a);
                    }
                    this.f13216d = false;
                    if (!b0Var2.f13184f) {
                        this.f13215c.add(b0Var2);
                    }
                }
                if (!this.f13214b.isEmpty()) {
                    l();
                    ArrayList arrayListY02 = B6.k.y0(this.f13214b);
                    if (arrayListY02.isEmpty()) {
                        return;
                    }
                    this.f13214b.clear();
                    this.f13215c.addAll(arrayListY02);
                    if (P.L(2)) {
                        Log.v("FragmentManager", "SpecialEffectsController: Executing pending operations");
                    }
                    b(arrayListY02, this.f13217e);
                    boolean zJ = j(arrayListY02);
                    int size3 = arrayListY02.size();
                    int i8 = 0;
                    boolean z9 = true;
                    while (i8 < size3) {
                        Object obj3 = arrayListY02.get(i8);
                        i8++;
                        if (!((b0) obj3).f13181c.f13259C) {
                            z9 = false;
                        }
                    }
                    if (!z9 || zJ) {
                        z8 = false;
                    }
                    this.f13216d = z8;
                    if (P.L(2)) {
                        Log.v("FragmentManager", "SpecialEffectsController: Operation seekable = " + zJ + " \ntransition = " + z9);
                    }
                    if (!z9) {
                        k(arrayListY02);
                        c(arrayListY02);
                    } else if (zJ) {
                        k(arrayListY02);
                        int size4 = arrayListY02.size();
                        for (int i9 = 0; i9 < size4; i9++) {
                            a((b0) arrayListY02.get(i9));
                        }
                    }
                    this.f13217e = false;
                    if (P.L(2)) {
                        Log.v("FragmentManager", "SpecialEffectsController: Finished executing pending operations");
                    }
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final b0 f(ComponentCallbacksC1023x componentCallbacksC1023x) {
        Object obj;
        ArrayList arrayList = this.f13214b;
        int size = arrayList.size();
        int i = 0;
        while (true) {
            if (i >= size) {
                obj = null;
                break;
            }
            obj = arrayList.get(i);
            i++;
            b0 b0Var = (b0) obj;
            if (P6.g.a(b0Var.f13181c, componentCallbacksC1023x) && !b0Var.f13183e) {
                break;
            }
        }
        return (b0) obj;
    }

    public final b0 g(ComponentCallbacksC1023x componentCallbacksC1023x) {
        Object obj;
        ArrayList arrayList = this.f13215c;
        int size = arrayList.size();
        int i = 0;
        while (true) {
            if (i >= size) {
                obj = null;
                break;
            }
            obj = arrayList.get(i);
            i++;
            b0 b0Var = (b0) obj;
            if (P6.g.a(b0Var.f13181c, componentCallbacksC1023x) && !b0Var.f13183e) {
                break;
            }
        }
        return (b0) obj;
    }

    public final void h() {
        String str;
        String str2;
        if (P.L(2)) {
            Log.v("FragmentManager", "SpecialEffectsController: Forcing all operations to complete");
        }
        boolean zIsAttachedToWindow = this.f13213a.isAttachedToWindow();
        synchronized (this.f13214b) {
            try {
                l();
                k(this.f13214b);
                ArrayList arrayListY0 = B6.k.y0(this.f13215c);
                int size = arrayListY0.size();
                int i = 0;
                int i5 = 0;
                while (i5 < size) {
                    Object obj = arrayListY0.get(i5);
                    i5++;
                    ((b0) obj).f13185g = false;
                }
                int size2 = arrayListY0.size();
                int i8 = 0;
                while (i8 < size2) {
                    Object obj2 = arrayListY0.get(i8);
                    i8++;
                    b0 b0Var = (b0) obj2;
                    if (P.L(2)) {
                        if (zIsAttachedToWindow) {
                            str2 = "";
                        } else {
                            str2 = "Container " + this.f13213a + " is not attached to window. ";
                        }
                        Log.v("FragmentManager", "SpecialEffectsController: " + str2 + "Cancelling running operation " + b0Var);
                    }
                    b0Var.a(this.f13213a);
                }
                ArrayList arrayListY02 = B6.k.y0(this.f13214b);
                int size3 = arrayListY02.size();
                int i9 = 0;
                while (i9 < size3) {
                    Object obj3 = arrayListY02.get(i9);
                    i9++;
                    ((b0) obj3).f13185g = false;
                }
                int size4 = arrayListY02.size();
                while (i < size4) {
                    Object obj4 = arrayListY02.get(i);
                    i++;
                    b0 b0Var2 = (b0) obj4;
                    if (P.L(2)) {
                        if (zIsAttachedToWindow) {
                            str = "";
                        } else {
                            str = "Container " + this.f13213a + " is not attached to window. ";
                        }
                        Log.v("FragmentManager", "SpecialEffectsController: " + str + "Cancelling pending operation " + b0Var2);
                    }
                    b0Var2.a(this.f13213a);
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void k(ArrayList arrayList) {
        int size = arrayList.size();
        for (int i = 0; i < size; i++) {
            b0 b0Var = (b0) arrayList.get(i);
            if (!b0Var.f13186h) {
                b0Var.f13186h = true;
                int i5 = b0Var.f13180b;
                W w4 = b0Var.f13189l;
                if (i5 == 2) {
                    ComponentCallbacksC1023x componentCallbacksC1023x = w4.f13125c;
                    P6.g.d(componentCallbacksC1023x, "fragmentStateManager.fragment");
                    View viewFindFocus = componentCallbacksC1023x.X.findFocus();
                    if (viewFindFocus != null) {
                        componentCallbacksC1023x.k().f13255k = viewFindFocus;
                        if (P.L(2)) {
                            Log.v("FragmentManager", "requestFocus: Saved focused view " + viewFindFocus + " for Fragment " + componentCallbacksC1023x);
                        }
                    }
                    View viewB0 = b0Var.f13181c.b0();
                    if (viewB0.getParent() == null) {
                        if (P.L(2)) {
                            Log.v("FragmentManager", "Adding fragment " + componentCallbacksC1023x + " view " + viewB0 + " to container in onStart");
                        }
                        w4.b();
                        viewB0.setAlpha(0.0f);
                    }
                    if (viewB0.getAlpha() == 0.0f && viewB0.getVisibility() == 0) {
                        if (P.L(2)) {
                            Log.v("FragmentManager", "Making view " + viewB0 + " INVISIBLE in onStart");
                        }
                        viewB0.setVisibility(4);
                    }
                    C1021v c1021v = componentCallbacksC1023x.f13280a0;
                    viewB0.setAlpha(c1021v == null ? 1.0f : c1021v.f13254j);
                    if (P.L(2)) {
                        StringBuilder sb = new StringBuilder("Setting view alpha to ");
                        C1021v c1021v2 = componentCallbacksC1023x.f13280a0;
                        sb.append(c1021v2 != null ? c1021v2.f13254j : 1.0f);
                        sb.append(" in onStart");
                        Log.v("FragmentManager", sb.toString());
                    }
                } else if (i5 == 3) {
                    ComponentCallbacksC1023x componentCallbacksC1023x2 = w4.f13125c;
                    P6.g.d(componentCallbacksC1023x2, "fragmentStateManager.fragment");
                    View viewB02 = componentCallbacksC1023x2.b0();
                    if (P.L(2)) {
                        Log.v("FragmentManager", "Clearing focus " + viewB02.findFocus() + " on view " + viewB02 + " for Fragment " + componentCallbacksC1023x2);
                    }
                    viewB02.clearFocus();
                }
            }
        }
        ArrayList arrayList2 = new ArrayList();
        int size2 = arrayList.size();
        int i8 = 0;
        while (i8 < size2) {
            Object obj = arrayList.get(i8);
            i8++;
            B6.q.d0(((b0) obj).f13188k, arrayList2);
        }
        List listX0 = B6.k.x0(B6.k.A0(arrayList2));
        int size3 = listX0.size();
        for (int i9 = 0; i9 < size3; i9++) {
            a0 a0Var = (a0) listX0.get(i9);
            a0Var.getClass();
            ViewGroup viewGroup = this.f13213a;
            P6.g.e(viewGroup, "container");
            if (!a0Var.f13164a) {
                a0Var.d(viewGroup);
            }
            a0Var.f13164a = true;
        }
    }

    public final void l() {
        ArrayList arrayList = this.f13214b;
        int size = arrayList.size();
        int i = 0;
        while (i < size) {
            Object obj = arrayList.get(i);
            i++;
            b0 b0Var = (b0) obj;
            int i5 = 2;
            if (b0Var.f13180b == 2) {
                int visibility = b0Var.f13181c.b0().getVisibility();
                if (visibility != 0) {
                    i5 = 4;
                    if (visibility != 4) {
                        if (visibility != 8) {
                            throw new IllegalArgumentException(AbstractC0844a.j("Unknown visibility ", visibility));
                        }
                        i5 = 3;
                    }
                }
                b0Var.d(i5, 1);
            }
        }
    }
}
