package android.support.v4.app;

import android.support.v4.app.e;
import android.support.v4.app.k;
import android.util.Log;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;

/* JADX INFO: compiled from: BackStackRecord.java */
/* JADX INFO: loaded from: classes.dex */
final class c extends o implements k.l {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    final k f494a;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    int f497d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    int f498e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    int f499f;
    int g;
    int h;
    boolean i;
    String j;
    boolean k;
    int m;
    CharSequence n;
    int o;
    CharSequence p;
    ArrayList<String> q;
    ArrayList<String> r;
    ArrayList<Runnable> t;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    ArrayList<a> f495b = new ArrayList<>();
    int l = -1;
    boolean s = false;

    /* JADX INFO: compiled from: BackStackRecord.java */
    static final class a {

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

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        e f501b;

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

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        int f503d;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        int f504e;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        int f505f;

        a() {
        }

        a(int i, e eVar) {
            this.f500a = i;
            this.f501b = eVar;
        }
    }

    public c(k kVar) {
        this.f494a = kVar;
    }

    private static boolean l(a aVar) {
        e eVar = aVar.f501b;
        return (eVar == null || !eVar.l || eVar.J == null || eVar.C || eVar.B || !eVar.I()) ? false : true;
    }

    @Override // android.support.v4.app.k.l
    public boolean a(ArrayList<c> arrayList, ArrayList<Boolean> arrayList2) {
        if (k.F) {
            Log.v("FragmentManager", "Run: " + this);
        }
        arrayList.add(this);
        arrayList2.add(Boolean.FALSE);
        if (!this.i) {
            return true;
        }
        this.f494a.f(this);
        return true;
    }

    void b(a aVar) {
        this.f495b.add(aVar);
        aVar.f502c = this.f496c;
        aVar.f503d = this.f497d;
        aVar.f504e = this.f498e;
        aVar.f505f = this.f499f;
    }

    void c(int i) {
        if (this.i) {
            if (k.F) {
                Log.v("FragmentManager", "Bump nesting in " + this + " by " + i);
            }
            int size = this.f495b.size();
            for (int i2 = 0; i2 < size; i2++) {
                a aVar = this.f495b.get(i2);
                e eVar = aVar.f501b;
                if (eVar != null) {
                    eVar.r += i;
                    if (k.F) {
                        Log.v("FragmentManager", "Bump nesting of " + aVar.f501b + " to " + aVar.f501b.r);
                    }
                }
            }
        }
    }

    public void d(String str, FileDescriptor fileDescriptor, PrintWriter printWriter, String[] strArr) {
        e(str, printWriter, true);
    }

    public void e(String str, PrintWriter printWriter, boolean z) {
        String str2;
        if (z) {
            printWriter.print(str);
            printWriter.print("mName=");
            printWriter.print(this.j);
            printWriter.print(" mIndex=");
            printWriter.print(this.l);
            printWriter.print(" mCommitted=");
            printWriter.println(this.k);
            if (this.g != 0) {
                printWriter.print(str);
                printWriter.print("mTransition=#");
                printWriter.print(Integer.toHexString(this.g));
                printWriter.print(" mTransitionStyle=#");
                printWriter.println(Integer.toHexString(this.h));
            }
            if (this.f496c != 0 || this.f497d != 0) {
                printWriter.print(str);
                printWriter.print("mEnterAnim=#");
                printWriter.print(Integer.toHexString(this.f496c));
                printWriter.print(" mExitAnim=#");
                printWriter.println(Integer.toHexString(this.f497d));
            }
            if (this.f498e != 0 || this.f499f != 0) {
                printWriter.print(str);
                printWriter.print("mPopEnterAnim=#");
                printWriter.print(Integer.toHexString(this.f498e));
                printWriter.print(" mPopExitAnim=#");
                printWriter.println(Integer.toHexString(this.f499f));
            }
            if (this.m != 0 || this.n != null) {
                printWriter.print(str);
                printWriter.print("mBreadCrumbTitleRes=#");
                printWriter.print(Integer.toHexString(this.m));
                printWriter.print(" mBreadCrumbTitleText=");
                printWriter.println(this.n);
            }
            if (this.o != 0 || this.p != null) {
                printWriter.print(str);
                printWriter.print("mBreadCrumbShortTitleRes=#");
                printWriter.print(Integer.toHexString(this.o));
                printWriter.print(" mBreadCrumbShortTitleText=");
                printWriter.println(this.p);
            }
        }
        if (this.f495b.isEmpty()) {
            return;
        }
        printWriter.print(str);
        printWriter.println("Operations:");
        String str3 = str + "    ";
        int size = this.f495b.size();
        for (int i = 0; i < size; i++) {
            a aVar = this.f495b.get(i);
            switch (aVar.f500a) {
                case 0:
                    str2 = "NULL";
                    break;
                case 1:
                    str2 = "ADD";
                    break;
                case 2:
                    str2 = "REPLACE";
                    break;
                case 3:
                    str2 = "REMOVE";
                    break;
                case 4:
                    str2 = "HIDE";
                    break;
                case 5:
                    str2 = "SHOW";
                    break;
                case 6:
                    str2 = "DETACH";
                    break;
                case 7:
                    str2 = "ATTACH";
                    break;
                case 8:
                    str2 = "SET_PRIMARY_NAV";
                    break;
                case 9:
                    str2 = "UNSET_PRIMARY_NAV";
                    break;
                default:
                    str2 = "cmd=" + aVar.f500a;
                    break;
            }
            printWriter.print(str);
            printWriter.print("  Op #");
            printWriter.print(i);
            printWriter.print(": ");
            printWriter.print(str2);
            printWriter.print(" ");
            printWriter.println(aVar.f501b);
            if (z) {
                if (aVar.f502c != 0 || aVar.f503d != 0) {
                    printWriter.print(str);
                    printWriter.print("enterAnim=#");
                    printWriter.print(Integer.toHexString(aVar.f502c));
                    printWriter.print(" exitAnim=#");
                    printWriter.println(Integer.toHexString(aVar.f503d));
                }
                if (aVar.f504e != 0 || aVar.f505f != 0) {
                    printWriter.print(str);
                    printWriter.print("popEnterAnim=#");
                    printWriter.print(Integer.toHexString(aVar.f504e));
                    printWriter.print(" popExitAnim=#");
                    printWriter.println(Integer.toHexString(aVar.f505f));
                }
            }
        }
    }

    void f() {
        int size = this.f495b.size();
        for (int i = 0; i < size; i++) {
            a aVar = this.f495b.get(i);
            e eVar = aVar.f501b;
            if (eVar != null) {
                eVar.X0(this.g, this.h);
            }
            switch (aVar.f500a) {
                case 1:
                    eVar.W0(aVar.f502c);
                    this.f494a.g(eVar, false);
                    break;
                case 2:
                default:
                    throw new IllegalArgumentException("Unknown cmd: " + aVar.f500a);
                case 3:
                    eVar.W0(aVar.f503d);
                    this.f494a.J0(eVar);
                    break;
                case 4:
                    eVar.W0(aVar.f503d);
                    this.f494a.p0(eVar);
                    break;
                case 5:
                    eVar.W0(aVar.f502c);
                    this.f494a.Z0(eVar);
                    break;
                case 6:
                    eVar.W0(aVar.f503d);
                    this.f494a.p(eVar);
                    break;
                case 7:
                    eVar.W0(aVar.f502c);
                    this.f494a.j(eVar);
                    break;
                case 8:
                    this.f494a.W0(eVar);
                    break;
                case 9:
                    this.f494a.W0(null);
                    break;
            }
            if (!this.s && aVar.f500a != 1 && eVar != null) {
                this.f494a.z0(eVar);
            }
        }
        if (this.s) {
            return;
        }
        k kVar = this.f494a;
        kVar.A0(kVar.m, true);
    }

    void g(boolean z) {
        for (int size = this.f495b.size() - 1; size >= 0; size--) {
            a aVar = this.f495b.get(size);
            e eVar = aVar.f501b;
            if (eVar != null) {
                eVar.X0(k.O0(this.g), this.h);
            }
            switch (aVar.f500a) {
                case 1:
                    eVar.W0(aVar.f505f);
                    this.f494a.J0(eVar);
                    break;
                case 2:
                default:
                    throw new IllegalArgumentException("Unknown cmd: " + aVar.f500a);
                case 3:
                    eVar.W0(aVar.f504e);
                    this.f494a.g(eVar, false);
                    break;
                case 4:
                    eVar.W0(aVar.f504e);
                    this.f494a.Z0(eVar);
                    break;
                case 5:
                    eVar.W0(aVar.f505f);
                    this.f494a.p0(eVar);
                    break;
                case 6:
                    eVar.W0(aVar.f504e);
                    this.f494a.j(eVar);
                    break;
                case 7:
                    eVar.W0(aVar.f505f);
                    this.f494a.p(eVar);
                    break;
                case 8:
                    this.f494a.W0(null);
                    break;
                case 9:
                    this.f494a.W0(eVar);
                    break;
            }
            if (!this.s && aVar.f500a != 3 && eVar != null) {
                this.f494a.z0(eVar);
            }
        }
        if (this.s || !z) {
            return;
        }
        k kVar = this.f494a;
        kVar.A0(kVar.m, true);
    }

    /* JADX WARN: Removed duplicated region for block: B:34:0x00b2  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    android.support.v4.app.e h(java.util.ArrayList<android.support.v4.app.e> r17, android.support.v4.app.e r18) {
        /*
            r16 = this;
            r0 = r16
            r1 = r17
            r3 = r18
            r4 = 0
        L7:
            java.util.ArrayList<android.support.v4.app.c$a> r5 = r0.f495b
            int r5 = r5.size()
            if (r4 >= r5) goto Lba
            java.util.ArrayList<android.support.v4.app.c$a> r5 = r0.f495b
            java.lang.Object r5 = r5.get(r4)
            android.support.v4.app.c$a r5 = (android.support.v4.app.c.a) r5
            int r6 = r5.f500a
            r7 = 0
            r8 = 1
            if (r6 == r8) goto Lb2
            r9 = 2
            r10 = 3
            r11 = 9
            if (r6 == r9) goto L58
            if (r6 == r10) goto L41
            r9 = 6
            if (r6 == r9) goto L41
            r7 = 7
            if (r6 == r7) goto Lb2
            r7 = 8
            if (r6 == r7) goto L31
            goto Lb7
        L31:
            java.util.ArrayList<android.support.v4.app.c$a> r6 = r0.f495b
            android.support.v4.app.c$a r7 = new android.support.v4.app.c$a
            r7.<init>(r11, r3)
            r6.add(r4, r7)
            int r4 = r4 + 1
            android.support.v4.app.e r3 = r5.f501b
            goto Lb7
        L41:
            android.support.v4.app.e r6 = r5.f501b
            r1.remove(r6)
            android.support.v4.app.e r5 = r5.f501b
            if (r5 != r3) goto Lb7
            java.util.ArrayList<android.support.v4.app.c$a> r3 = r0.f495b
            android.support.v4.app.c$a r6 = new android.support.v4.app.c$a
            r6.<init>(r11, r5)
            r3.add(r4, r6)
            int r4 = r4 + 1
            r3 = r7
            goto Lb7
        L58:
            android.support.v4.app.e r6 = r5.f501b
            int r9 = r6.z
            int r12 = r17.size()
            int r12 = r12 - r8
            r13 = 0
        L62:
            if (r12 < 0) goto La2
            java.lang.Object r14 = r1.get(r12)
            android.support.v4.app.e r14 = (android.support.v4.app.e) r14
            int r15 = r14.z
            if (r15 != r9) goto L9f
            if (r14 != r6) goto L72
            r13 = r8
            goto L9f
        L72:
            if (r14 != r3) goto L81
            java.util.ArrayList<android.support.v4.app.c$a> r3 = r0.f495b
            android.support.v4.app.c$a r15 = new android.support.v4.app.c$a
            r15.<init>(r11, r14)
            r3.add(r4, r15)
            int r4 = r4 + 1
            r3 = r7
        L81:
            android.support.v4.app.c$a r15 = new android.support.v4.app.c$a
            r15.<init>(r10, r14)
            int r2 = r5.f502c
            r15.f502c = r2
            int r2 = r5.f504e
            r15.f504e = r2
            int r2 = r5.f503d
            r15.f503d = r2
            int r2 = r5.f505f
            r15.f505f = r2
            java.util.ArrayList<android.support.v4.app.c$a> r2 = r0.f495b
            r2.add(r4, r15)
            r1.remove(r14)
            int r4 = r4 + r8
        L9f:
            int r12 = r12 + (-1)
            goto L62
        La2:
            if (r13 == 0) goto Lac
            java.util.ArrayList<android.support.v4.app.c$a> r2 = r0.f495b
            r2.remove(r4)
            int r4 = r4 + (-1)
            goto Lb7
        Lac:
            r5.f500a = r8
            r1.add(r6)
            goto Lb7
        Lb2:
            android.support.v4.app.e r2 = r5.f501b
            r1.add(r2)
        Lb7:
            int r4 = r4 + r8
            goto L7
        Lba:
            return r3
        */
        throw new UnsupportedOperationException("Method not decompiled: android.support.v4.app.c.h(java.util.ArrayList, android.support.v4.app.e):android.support.v4.app.e");
    }

    public String i() {
        return this.j;
    }

    boolean j(int i) {
        int size = this.f495b.size();
        for (int i2 = 0; i2 < size; i2++) {
            e eVar = this.f495b.get(i2).f501b;
            int i3 = eVar != null ? eVar.z : 0;
            if (i3 != 0 && i3 == i) {
                return true;
            }
        }
        return false;
    }

    boolean k(ArrayList<c> arrayList, int i, int i2) {
        if (i2 == i) {
            return false;
        }
        int size = this.f495b.size();
        int i3 = -1;
        for (int i4 = 0; i4 < size; i4++) {
            e eVar = this.f495b.get(i4).f501b;
            int i5 = eVar != null ? eVar.z : 0;
            if (i5 != 0 && i5 != i3) {
                for (int i6 = i; i6 < i2; i6++) {
                    c cVar = arrayList.get(i6);
                    int size2 = cVar.f495b.size();
                    for (int i7 = 0; i7 < size2; i7++) {
                        e eVar2 = cVar.f495b.get(i7).f501b;
                        if ((eVar2 != null ? eVar2.z : 0) == i5) {
                            return true;
                        }
                    }
                }
                i3 = i5;
            }
        }
        return false;
    }

    boolean m() {
        for (int i = 0; i < this.f495b.size(); i++) {
            if (l(this.f495b.get(i))) {
                return true;
            }
        }
        return false;
    }

    public void n() {
        ArrayList<Runnable> arrayList = this.t;
        if (arrayList != null) {
            int size = arrayList.size();
            for (int i = 0; i < size; i++) {
                this.t.get(i).run();
            }
            this.t = null;
        }
    }

    void o(e.f fVar) {
        for (int i = 0; i < this.f495b.size(); i++) {
            a aVar = this.f495b.get(i);
            if (l(aVar)) {
                aVar.f501b.Y0(fVar);
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x0022  */
    /* JADX WARN: Removed duplicated region for block: B:14:0x0028  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    android.support.v4.app.e p(java.util.ArrayList<android.support.v4.app.e> r5, android.support.v4.app.e r6) {
        /*
            r4 = this;
            r0 = 0
        L1:
            java.util.ArrayList<android.support.v4.app.c$a> r1 = r4.f495b
            int r1 = r1.size()
            if (r0 >= r1) goto L30
            java.util.ArrayList<android.support.v4.app.c$a> r1 = r4.f495b
            java.lang.Object r1 = r1.get(r0)
            android.support.v4.app.c$a r1 = (android.support.v4.app.c.a) r1
            int r2 = r1.f500a
            r3 = 1
            if (r2 == r3) goto L28
            r3 = 3
            if (r2 == r3) goto L22
            switch(r2) {
                case 6: goto L22;
                case 7: goto L28;
                case 8: goto L20;
                case 9: goto L1d;
                default: goto L1c;
            }
        L1c:
            goto L2d
        L1d:
            android.support.v4.app.e r6 = r1.f501b
            goto L2d
        L20:
            r6 = 0
            goto L2d
        L22:
            android.support.v4.app.e r1 = r1.f501b
            r5.add(r1)
            goto L2d
        L28:
            android.support.v4.app.e r1 = r1.f501b
            r5.remove(r1)
        L2d:
            int r0 = r0 + 1
            goto L1
        L30:
            return r6
        */
        throw new UnsupportedOperationException("Method not decompiled: android.support.v4.app.c.p(java.util.ArrayList, android.support.v4.app.e):android.support.v4.app.e");
    }

    public String toString() {
        StringBuilder sb = new StringBuilder(128);
        sb.append("BackStackEntry{");
        sb.append(Integer.toHexString(System.identityHashCode(this)));
        if (this.l >= 0) {
            sb.append(" #");
            sb.append(this.l);
        }
        if (this.j != null) {
            sb.append(" ");
            sb.append(this.j);
        }
        sb.append("}");
        return sb.toString();
    }
}
