package com.ss.android.ugc.aweme.ecommerce.widget.regionpicker.fragment;

import X.0AA;
import X.0E3;
import X.2Pr;
import X.2uR;
import X.3SB;
import X.3c7;
import X.3cA;
import X.3cI;
import X.4r1;
import X.7he;
import X.9HM;
import X.C1U;
import X.C24;
import X.C25;
import X.C2B;
import X.C3782BXm;
import X.C4927BrP;
import X.C5502C1q;
import X.C5503C1r;
import X.C5507C1v;
import X.C5508C1w;
import X.C5511C1z;
import X.Crj;
import X.LeS;
import X.Lea;
import X.Leb;
import X.Ls2;
import X.LsC;
import X.M12;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.ecommerce.ab.EComLiveDegradeExperiment;
import com.ss.android.ugc.aweme.ecommerce.address.dto.Region;
import com.ss.android.ugc.aweme.ecommerce.common.ECAnimDowngradeFragment;
import com.ss.android.ugc.aweme.ecommerce.delivery.repo.dto.OrderSKUDTO;
import com.ss.android.ugc.aweme.ecommerce.widget.regionpicker.model.District;
import com.ss.android.ugc.aweme.utils.ActivityStack;
import java.util.ArrayList;
import java.util.List;
import kotlin.h.b.n;

public final class DistrictFragment extends ECAnimDowngradeFragment implements C1U {
    public static Boolean LJ;
    public static final C24 LJFF = new C24((byte) 0);
    public LsC<? super List<Region>, 2Pr> LIZ;
    public Ls2<2Pr> LIZIZ;
    public Ls2<2Pr> LIZJ;
    public LsC<? super List<Region>, 2Pr> LIZLLL;
    public final Crj LJI = 7he.LIZ(new C2B(this));
    public SparseArray LJII;

    static {
        Covode.recordClassIndex(72930);
    }

    public final View LIZ(int i) {
        if (this.LJII == null) {
            this.LJII = new SparseArray();
        }
        View view = (View) this.LJII.get(i);
        if (view != null) {
            return view;
        }
        View view2 = getView();
        if (view2 == null) {
            return null;
        }
        View findViewById = view2.findViewById(i);
        this.LJII.put(i, findViewById);
        return findViewById;
    }

    public final DistrictVm LIZ() {
        return (DistrictVm) this.LJI.getValue();
    }

    public final void LIZLLL() {
        SparseArray sparseArray = this.LJII;
        if (sparseArray != null) {
            sparseArray.clear();
        }
    }

    public final boolean LIZIZ() {
        return EComLiveDegradeExperiment.LIZ().getPageAnimDegrade();
    }

    public final LsC<List<Region>, 2Pr> LJ() {
        LsC<? super List<Region>, 2Pr> lsC = this.LIZ;
        if (lsC == null) {
            n.LIZ("");
        }
        return lsC;
    }

    public final void onDestroyView() {
        RecyclerView LIZ2 = LIZ(2131371006);
        n.LIZIZ(LIZ2, "");
        LIZ2.setAdapter((0E3) null);
        super.onDestroyView();
        LIZLLL();
    }

    public final void onResume() {
        DistrictFragment.super.onResume();
        LIZ().LIZIZ().LIZ = SystemClock.elapsedRealtime();
    }

    public final void onStop() {
        DistrictFragment.super.onStop();
        if (ActivityStack.isAppBackGround()) {
            DistrictVm LIZ2 = LIZ();
            0AA childFragmentManager = getChildFragmentManager();
            n.LIZIZ(childFragmentManager, "");
            List LJFF2 = childFragmentManager.LJFF();
            n.LIZIZ(LJFF2, "");
            LIZ2.LIZ(LeS.LIZ(LJFF2), "close");
        }
    }

    public final boolean LJIIIIZZ() {
        if (!isAdded()) {
            return false;
        }
        0AA childFragmentManager = getChildFragmentManager();
        n.LIZIZ(childFragmentManager, "");
        if (childFragmentManager.LJII()) {
            return true;
        }
        0AA childFragmentManager2 = getChildFragmentManager();
        n.LIZIZ(childFragmentManager2, "");
        List LJFF2 = childFragmentManager2.LJFF();
        n.LIZIZ(LJFF2, "");
        int LIZ2 = LeS.LIZ(LJFF2);
        if (LIZ2 <= 0) {
            return false;
        }
        LIZ().LJ = LIZ2 - 1;
        LIZ().LIZ(LIZ2, "return");
        getChildFragmentManager().LIZJ();
        return true;
    }

    public final void LIZ(Ls2<2Pr> ls2) {
        M12.LIZ(ls2);
        this.LIZIZ = ls2;
    }

    public final void LIZ(LsC<? super List<Region>, 2Pr> lsC) {
        M12.LIZ(lsC);
        this.LIZ = lsC;
    }

    public final void onViewCreated(View view, Bundle bundle) {
        M12.LIZ(view);
        Bundle arguments = getArguments();
        if (arguments == null) {
            n.LIZIZ();
        }
        n.LIZIZ(arguments, "");
        List<District> list = LIZ().LIZIZ;
        ArrayList parcelableArrayList = arguments.getParcelableArrayList("current_selected_region_list");
        if (parcelableArrayList == null) {
            n.LIZIZ();
        }
        n.LIZIZ(parcelableArrayList, "");
        Leb.LIZ(list, parcelableArrayList);
        LIZ().LIZ = arguments.getInt("level_count", Integer.MAX_VALUE);
        LIZ().LIZJ = (OrderSKUDTO) arguments.getParcelable("order_sku");
        DistrictVm LIZ2 = LIZ();
        C4927BrP brP = new C4927BrP(arguments.getString("page_info"));
        M12.LIZ(brP);
        LIZ2.LJI = brP;
        3c7 LIZ3 = LIZ(2131371248);
        2uR r6 = new 2uR();
        3cA r1 = new 3cA();
        r1.LIZ(2131755170);
        r1.LIZ(2Pr.LIZ);
        r1.LIZ(new C5508C1w(this));
        r6.LIZ(new 3cI[]{r1});
        3cI[] r2 = new 3cI[1];
        3cA r12 = new 3cA();
        r12.LIZ(2131755735);
        Ls2<2Pr> ls2 = this.LIZIZ;
        if (ls2 == null) {
            n.LIZ("");
        }
        r12.LIZ(ls2);
        r2[0] = r12;
        r6.LIZIZ(r2);
        LIZ3.setNavActions(r6);
        LIZ().LJFF.observe(getViewLifecycleOwner(), new C25(this));
        DistrictVm LIZ4 = LIZ();
        C3782BXm bXm = new C3782BXm(new C5503C1r(this));
        M12.LIZ(bXm);
        LIZ4.LIZLLL = bXm;
        C3782BXm LIZ5 = LIZ().LIZ();
        List<District> LIZJ2 = Lea.LIZJ(LIZ().LIZIZ, 1);
        ArrayList arrayList = new ArrayList(9HM.LIZ(LIZJ2, 10));
        for (District district : LIZJ2) {
            arrayList.add(district.LIZLLL);
        }
        LIZ5.LIZ(arrayList);
        LIZ().LJ = LeS.LIZ(LIZ().LIZIZ) - 1;
        RecyclerView LIZ6 = LIZ(2131371006);
        n.LIZIZ(LIZ6, "");
        LIZ6.setAdapter(LIZ().LIZ());
        getChildFragmentManager().LIZ(new C5511C1z(this));
        3SB.LIZ(this, new C5507C1v(this, (4r1) null));
    }

    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        M12.LIZ(layoutInflater);
        if (viewGroup != null) {
            return C5502C1q.LIZ((View) viewGroup, 2131559035, false);
        }
        return null;
    }
}
