package o;

import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.Comparator;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.Qz, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C0440Qz implements Comparator {
    public final ZQ a;
    public final C0713aR b;
    public final ZQ c;
    public final QQ d;

    public C0440Qz(C0387Oy c0387Oy) {
        long[] jArr = AbstractC3064z40.a;
        this.a = new ZQ();
        int i = A40.a;
        this.b = new C0713aR();
        this.c = new ZQ();
        QQ qq = AbstractC1097eT.a;
        this.d = new QQ();
    }

    public final void a(ArrayList arrayList, ViewGroup viewGroup) {
        QQ qq;
        int size = arrayList.size();
        int i = 0;
        while (true) {
            qq = this.d;
            if (i >= size) {
                break;
            }
            qq.h(i, (View) arrayList.get(i));
            i++;
        }
        int size2 = arrayList.size() - 1;
        C0713aR c0713aR = this.b;
        ZQ zq = this.a;
        if (size2 >= 0) {
            while (true) {
                int i2 = size2 - 1;
                View view = (View) arrayList.get(size2);
                int nextFocusForwardId = view.getNextFocusForwardId();
                View viewK = (nextFocusForwardId == 0 || nextFocusForwardId == -1) ? null : As0.k(view, viewGroup, 2);
                if (viewK != null && qq.d(viewK) >= 0) {
                    zq.m(view, viewK);
                    c0713aR.a(viewK);
                }
                if (i2 < 0) {
                    break;
                } else {
                    size2 = i2;
                }
            }
        }
        int size3 = arrayList.size() - 1;
        if (size3 < 0) {
            return;
        }
        while (true) {
            int i3 = size3 - 1;
            View view2 = (View) arrayList.get(size3);
            if (((View) zq.g(view2)) != null && !c0713aR.c(view2)) {
                View view3 = view2;
                while (view2 != null) {
                    ZQ zq2 = this.c;
                    View view4 = (View) zq2.g(view2);
                    if (view4 != null) {
                        if (view4 == view3) {
                            break;
                        }
                        view2 = view3;
                        view3 = view4;
                    }
                    zq2.m(view2, view3);
                    view2 = (View) zq.g(view2);
                }
            }
            if (i3 < 0) {
                return;
            } else {
                size3 = i3;
            }
        }
    }

    @Override // java.util.Comparator
    public final int compare(Object obj, Object obj2) {
        View view = (View) obj;
        View view2 = (View) obj2;
        if (view == view2) {
            return 0;
        }
        if (view == null) {
            return -1;
        }
        if (view2 == null) {
            return 1;
        }
        ZQ zq = this.c;
        View view3 = (View) zq.g(view);
        View view4 = (View) zq.g(view2);
        if (view3 == view4 && view3 != null) {
            if (view == view3) {
                return -1;
            }
            return (view2 == view3 || this.a.g(view) == null) ? 1 : -1;
        }
        if (view3 != null) {
            view = view3;
        }
        if (view4 != null) {
            view2 = view4;
        }
        if (view3 == null && view4 == null) {
            return 0;
        }
        QQ qq = this.d;
        return qq.e(view) < qq.e(view2) ? -1 : 1;
    }
}
