package com.ss.android.ugc.aweme.feed.survey.layoutmanager;

import X.0EF;
import X.0EG;
import X.0EL;
import X.0EQ;
import X.M12;
import X.Q39;
import android.view.View;
import com.bytedance.covode.number.Covode;
import java.util.Objects;
import kotlin.h.b.n;

public final class SurveyFlexLayoutManager extends 0EF {
    static {
        Covode.recordClassIndex(79447);
    }

    public final boolean LJFF() {
        return false;
    }

    public final boolean LJI() {
        return false;
    }

    public final boolean Q_() {
        return true;
    }

    public final 0EG LIZIZ() {
        return new 0EG(-2, -2);
    }

    private final int LIZ(View view, 0EG r4) {
        LJIILIIL(view);
        return LJIILJJIL(view) + r4.getMarginStart() + r4.getMarginEnd();
    }

    public final void LIZJ(0EL r25, 0EQ r26) {
        View view;
        int i;
        int i2;
        0EL r8 = r25;
        M12.LIZ(r8);
        for (int LJIJI = LJIJI() - 1; LJIJI >= 0; LJIJI--) {
            View LJI = LJI(LJIJI);
            if (LJI != null) {
                LJIIIZ(LJI);
            }
        }
        int i3 = this.LJJIJIL;
        int i4 = i3 / 2;
        int LJJIII = LJJIII();
        int i5 = 0;
        int i6 = 0;
        int i7 = 0;
        int i8 = 0;
        while (i5 < LJJIII) {
            View LIZJ = r8.LIZJ(i5);
            n.LIZIZ(LIZJ, Q39.LIZJ);
            0EG layoutParams = LIZJ.getLayoutParams();
            Objects.requireNonNull(layoutParams, "null cannot be cast to non-null type androidx.recyclerview.widget.RecyclerView.LayoutParams");
            0EG r2 = layoutParams;
            int LIZ = LIZ(LIZJ, r2);
            int marginStart = r2.getMarginStart() + r2.getMarginEnd();
            i5++;
            if (i5 < LJJIII()) {
                view = r8.LIZJ(i5);
                if (view != null) {
                    i = LIZ(view, r2);
                }
                i = 0;
            } else {
                view = null;
                i = 0;
            }
            int i9 = i6 % this.LJJIJIL;
            int i10 = i3 - i9;
            if (LIZ <= i4) {
                if (LIZ > i10 || i9 <= 0) {
                    i2 = i4 - marginStart;
                } else {
                    i2 = i10 - marginStart;
                }
                r2.width = i2;
            } else {
                r2.width = LIZ - marginStart;
                i10 -= LIZ;
            }
            if (view != null && i9 == 0 && i >= i10) {
                r2.width = i3 - marginStart;
            }
            LJ(LIZJ);
            LJIILIIL(LIZJ);
            int LJIILJJIL = LJIILJJIL(LIZJ) + r2.getMarginStart() + r2.getMarginEnd();
            int LJIILL = LJIILL(LIZJ) + r2.topMargin + r2.bottomMargin;
            i6 += LJIILJJIL;
            if (i6 <= this.LJJIJIL) {
                LIZ(LIZJ, (i6 - LJIILJJIL) + r2.getMarginStart(), i7 + r2.topMargin, i6 - r2.getMarginEnd(), (i7 + LJIILL) - r2.bottomMargin);
                i8 = Math.max(i8, LJIILL);
            } else {
                if (i8 == 0) {
                    i8 = LJIILL;
                }
                i7 += i8;
                LIZ(LIZJ, r2.getMarginStart(), i7 + r2.topMargin, LJIILJJIL - r2.getMarginEnd(), (i7 + LJIILL) - r2.bottomMargin);
                i6 = LJIILJJIL;
                i8 = LJIILL;
            }
        }
    }
}
