package com.ss.android.ugc.aweme.view.editor;

import X.0CH;
import X.0HH;
import X.1hK;
import X.2HN;
import X.2Pr;
import X.2cN;
import X.3Du;
import X.3QV;
import X.4EW;
import X.4FQ;
import X.5Am;
import X.5An;
import X.5vY;
import X.5wO;
import X.7he;
import X.B8T;
import X.C2936JEx;
import X.C2950JFl;
import X.C2984JGt;
import X.C2985JGu;
import X.C2986JGv;
import X.C2987JGw;
import X.C2988JGx;
import X.C2989JGy;
import X.C2991JHa;
import X.C2992JHb;
import X.C2997JHg;
import X.Crj;
import X.Cwt;
import X.D4t;
import X.DRZ;
import X.DUT;
import X.DUy;
import X.DUz;
import X.DV0;
import X.DV9;
import X.DVU;
import X.JEJ;
import X.JF0;
import X.JG6;
import X.JG7;
import X.JG8;
import X.JH4;
import X.JH5;
import X.JH8;
import X.Ls2;
import X.LsC;
import X.LsD;
import X.LsE;
import X.LsF;
import X.Lsh;
import X.M12;
import X.PHD;
import android.os.Bundle;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bytedance.covode.number.Covode;
import com.bytedance.jedi.arch.JediViewModel;
import com.ss.android.ugc.aweme.viewModel.ProfileNaviEditorViewModel;
import com.ss.android.ugc.aweme.viewModel.ProfileNaviOnboardingViewModel;
import com.ss.android.ugc.aweme.viewModel.ProfileNaviSwitcherViewModel;
import java.util.List;
import java.util.Objects;
import kotlin.h.b.n;

public final class ProfileNaviEditorTemplateFragment extends Fragment implements 5vY, C2997JHg {
    public final Crj LIZ = 7he.LIZ(new JG7(this));
    public final Crj LIZIZ = 7he.LIZ(new JG6(this));
    public final Crj LIZJ = 7he.LIZ(new JG8(this));
    public SparseArray LIZLLL;

    static {
        Covode.recordClassIndex(123388);
    }

    private final ProfileNaviEditorViewModel LIZLLL() {
        return (ProfileNaviEditorViewModel) this.LIZIZ.getValue();
    }

    private final ProfileNaviSwitcherViewModel LJ() {
        return (ProfileNaviSwitcherViewModel) this.LIZJ.getValue();
    }

    private View LJI() {
        if (this.LIZLLL == null) {
            this.LIZLLL = new SparseArray();
        }
        View view = (View) this.LIZLLL.get(2131367954);
        if (view != null) {
            return view;
        }
        View view2 = getView();
        if (view2 == null) {
            return null;
        }
        View findViewById = view2.findViewById(2131367954);
        this.LIZLLL.put(2131367954, findViewById);
        return findViewById;
    }

    public final ProfileNaviOnboardingViewModel LIZIZ() {
        return (ProfileNaviOnboardingViewModel) this.LIZ.getValue();
    }

    public final boolean getUniqueOnlyGlobal() {
        return true;
    }

    public final /* bridge */ /* synthetic */ 5An getReceiver() {
        return this;
    }

    public final 0CH getLifecycleOwner() {
        5wO.LIZJ(this);
        return this;
    }

    public final DUz getLifecycleOwnerHolder() {
        5wO.LIZ(this);
        return this;
    }

    public final DUy<DVU> getReceiverHolder() {
        5wO.LIZIZ(this);
        return this;
    }

    public final void LIZ() {
        LIZ((Ls2<2Pr>) new JH4(this));
    }

    public final /* synthetic */ void onDestroyView() {
        ProfileNaviEditorTemplateFragment.super.onDestroyView();
        SparseArray sparseArray = this.LIZLLL;
        if (sparseArray != null) {
            sparseArray.clear();
        }
    }

    private final boolean LJFF() {
        if ((!LIZIZ().LIZ(this).getShouldShowAutoCreation() || !C2992JHb.LIZ) && !C2991JHa.LIZ) {
            return false;
        }
        return true;
    }

    public final C2989JGy LIZJ() {
        RecyclerView LJI = LJI();
        n.LIZIZ(LJI, "");
        if (!(LJI.getAdapter() instanceof C2989JGy)) {
            return null;
        }
        RecyclerView LJI2 = LJI();
        n.LIZIZ(LJI2, "");
        C2989JGy adapter = LJI2.getAdapter();
        Objects.requireNonNull(adapter, "null cannot be cast to non-null type com.ss.android.ugc.aweme.view.adapter.ProfileNaviStarterAvatarListAdapter");
        return adapter;
    }

    public final void onStart() {
        ProfileNaviEditorTemplateFragment.super.onStart();
        LIZ((List<C2988JGx>) null);
        LIZIZ().LIZLLL();
        DV0.LIZ(this, LIZIZ(), JH8.LIZ, new C2987JGw(this));
        DV0.LIZ(this, LIZIZ(), JH5.LIZ, new C2985JGu(this));
    }

    public final void LIZ(C2988JGx jGx) {
        M12.LIZ(jGx);
        LIZ((Ls2<2Pr>) new C2984JGt(this, jGx));
    }

    public final void LIZIZ(C2988JGx jGx) {
        LIZIZ().LIZ(jGx.LIZ());
        LJ().LIZ(new JF0((String) null, (String) null, (String) null, (List) null, jGx.LIZIZ, (List) null, 47, (2HN) null));
        LIZLLL().LIZ(true);
        LIZLLL().LIZIZ(false);
    }

    private final void LIZ(Ls2<2Pr> ls2) {
        ProfileNaviEditorViewModel LIZLLL2 = LIZLLL();
        1hK requireActivity = requireActivity();
        n.LIZIZ(requireActivity, "");
        if (LIZLLL2.LIZ(requireActivity).getHasEdited()) {
            1hK requireActivity2 = requireActivity();
            n.LIZIZ(requireActivity2, "");
            4EW r1 = new 4EW(requireActivity2);
            r1.LIZJ(2131821896);
            r1.LIZLLL(2131821893);
            r1.LIZ(true);
            3QV.LIZ(r1, new C2986JGv(ls2));
            4FQ.LIZ(r1.LIZ().LIZJ());
            return;
        }
        ls2.invoke();
    }

    public final void LIZ(List<C2988JGx> list) {
        C2989JGy LIZJ2 = LIZJ();
        if (LIZJ2 == null) {
            LIZJ2 = new C2989JGy(this, false, (byte) 0);
            RecyclerView LJI = LJI();
            if (LJI != null) {
                getActivity();
                LJI.setLayoutManager(new GridLayoutManager(2));
            }
            RecyclerView LJI2 = LJI();
            if (LJI2 != null) {
                LJI2.LIZ(new 3Du(getResources().getDimensionPixelSize(2131165915)));
            }
            RecyclerView LJI3 = LJI();
            if (LJI3 != null) {
                LJI3.setAdapter(LIZJ2);
            }
        }
        LIZJ2.LIZIZ = list;
        LIZJ2.LIZLLL = LJFF();
        LIZJ2.notifyDataSetChanged();
        if (list != null && !list.isEmpty()) {
            ProfileNaviOnboardingViewModel LIZIZ2 = LIZIZ();
            1hK requireActivity = requireActivity();
            n.LIZIZ(requireActivity, "");
            if (LIZIZ2.LIZ(requireActivity).getStarterAvatarId() == null) {
                ProfileNaviEditorViewModel LIZLLL2 = LIZLLL();
                1hK requireActivity2 = requireActivity();
                n.LIZIZ(requireActivity2, "");
                if (!LIZLLL2.LIZ(requireActivity2).getHasEdited()) {
                    LJ();
                    C2936JEx jEx = JEJ.LIZ;
                    if (jEx == null || jEx.LIZ == null) {
                        LIZIZ(list.get(0));
                    }
                }
            }
        }
    }

    public final <VM1 extends JediViewModel<S1>, S1 extends 5Am, R> R withState(VM1 vm1, LsC<? super S1, ? extends R> lsC) {
        M12.LIZ(vm1, lsC);
        return 5wO.LIZ(vm1, lsC);
    }

    public final <S extends 5Am> 2cN subscribe(JediViewModel<S> jediViewModel, DUT<S> dut, LsD<? super DVU, ? super S, 2Pr> lsD) {
        M12.LIZ(jediViewModel, dut, lsD);
        return 5wO.LIZ(this, jediViewModel, dut, lsD);
    }

    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        M12.LIZ(layoutInflater);
        C2950JFl.LIZIZ.LIZJ();
        return 0HH.LIZ(layoutInflater, 2131560862, viewGroup, false);
    }

    public final <S extends 5Am, A> 2cN selectSubscribe(JediViewModel<S> jediViewModel, PHD<S, ? extends A> phd, DUT<DRZ<A>> dut, LsD<? super DVU, ? super A, 2Pr> lsD) {
        M12.LIZ(jediViewModel, phd, dut, lsD);
        return 5wO.LIZ(this, jediViewModel, phd, dut, lsD);
    }

    public final <S extends 5Am, A, B> 2cN selectSubscribe(JediViewModel<S> jediViewModel, PHD<S, ? extends A> phd, PHD<S, ? extends B> phd2, DUT<Cwt<A, B>> dut, LsE<? super DVU, ? super A, ? super B, 2Pr> lsE) {
        M12.LIZ(jediViewModel, phd, phd2, dut, lsE);
        return 5wO.LIZ(this, jediViewModel, phd, phd2, dut, lsE);
    }

    public final <S extends 5Am, T> 2cN asyncSubscribe(JediViewModel<S> jediViewModel, PHD<S, ? extends B8T<? extends T>> phd, DUT<DRZ<B8T<T>>> dut, LsD<? super DVU, ? super Throwable, 2Pr> lsD, LsC<? super DVU, 2Pr> lsC, LsD<? super DVU, ? super T, 2Pr> lsD2) {
        M12.LIZ(jediViewModel, phd, dut);
        return 5wO.LIZ(this, jediViewModel, phd, dut, lsD, lsC, lsD2);
    }

    public final <S extends 5Am, A, B, C> 2cN selectSubscribe(JediViewModel<S> jediViewModel, PHD<S, ? extends A> phd, PHD<S, ? extends B> phd2, PHD<S, ? extends C> phd3, DUT<DV9<A, B, C>> dut, LsF<? super DVU, ? super A, ? super B, ? super C, 2Pr> lsF) {
        M12.LIZ(jediViewModel, phd, phd2, phd3, dut, lsF);
        return 5wO.LIZ(this, jediViewModel, phd, phd2, phd3, dut, lsF);
    }

    public final <S extends 5Am, A, B, C, D> 2cN selectSubscribe(JediViewModel<S> jediViewModel, PHD<S, ? extends A> phd, PHD<S, ? extends B> phd2, PHD<S, ? extends C> phd3, PHD<S, ? extends D> phd4, DUT<D4t<A, B, C, D>> dut, Lsh<? super DVU, ? super A, ? super B, ? super C, ? super D, 2Pr> lsh) {
        M12.LIZ(jediViewModel, phd, phd2, phd3, phd4, dut, lsh);
        return 5wO.LIZ(this, jediViewModel, phd, phd2, phd3, phd4, dut, lsh);
    }
}
