package com.ss.android.ugc.aweme.ecommerce.address.edit;

import X.0Bv;
import X.0CH;
import X.1hK;
import X.2Pr;
import X.2cN;
import X.2fU;
import X.2r2;
import X.2te;
import X.3BB;
import X.3Do;
import X.3QV;
import X.3SI;
import X.4EW;
import X.4FQ;
import X.4NX;
import X.4r1;
import X.5Am;
import X.5An;
import X.5vY;
import X.5wO;
import X.7Uj;
import X.7Ul;
import X.7he;
import X.B1N;
import X.B8T;
import X.C1835Aid;
import X.C4650Bmw;
import X.C5179BvT;
import X.C5180BvU;
import X.C5418BzK;
import X.C5619C6d;
import X.C5631C6p;
import X.C5649C7h;
import X.C5651C7j;
import X.C5652C7k;
import X.C5654C7m;
import X.C5656C7o;
import X.C5657C7p;
import X.C5669C8b;
import X.C5696C9c;
import X.C5697C9d;
import X.C5703C9j;
import X.C6474CbG;
import X.C65;
import X.C6754Cfm;
import X.C7O;
import X.C80;
import X.C82;
import X.C84;
import X.C85;
import X.C87;
import X.C89;
import X.C8B;
import X.C8C;
import X.C8D;
import X.C8F;
import X.C8S;
import X.C8X;
import X.C8Y;
import X.C94;
import X.C9X;
import X.C9Y;
import X.Crj;
import X.Cwt;
import X.Cwu;
import X.D1G;
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.Dri;
import X.HeD;
import X.KEM;
import X.LeS;
import X.Lea;
import X.Leb;
import X.Ls0;
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 X.S9B;
import android.content.Context;
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.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.abmock.SettingsManager;
import com.bytedance.jedi.arch.JediViewModel;
import com.bytedance.jedi.arch.lifecycleAwareLazy;
import com.google.gson.Gson;
import com.ss.android.ugc.aweme.ecommerce.address.AddressPageStarter;
import com.ss.android.ugc.aweme.ecommerce.address.dto.Address;
import com.ss.android.ugc.aweme.ecommerce.address.dto.InputItemData;
import com.ss.android.ugc.aweme.ecommerce.address.dto.Region;
import com.ss.android.ugc.aweme.ecommerce.util.KeyBoardVisibilityUtil;
import com.ss.android.ugc.aweme.utils.ActivityStack;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Objects;
import kotlin.h.b.n;
import kotlin.o.y;

public final class AddressEditFragment extends Fragment implements B1N<C1835Aid>, 5vY, C5180BvU, C5179BvT {
    public static final C5703C9j LJIIJ = new C5703C9j((byte) 0);
    public final C1835Aid LIZ = new C1835Aid();
    public final Ls2<2Pr> LIZIZ;
    public String LIZJ;
    public KeyBoardVisibilityUtil LIZLLL;
    public AddressPageStarter.AddressEditEnterParams LJ;
    public LsC<? super Cwu<String, Address>, 2Pr> LJFF;
    public Ls2<2Pr> LJI;
    public long LJII;
    public Ls2<2Pr> LJIIIIZZ;
    public boolean LJIIIZ;
    public final lifecycleAwareLazy LJIIJJI;
    public final Crj LJIIL;
    public final Crj LJIILIIL;
    public SparseArray LJIILJJIL;

    static {
        Covode.recordClassIndex(68059);
    }

    private final 3SI LJIIIIZZ() {
        return (3SI) this.LJIILIIL.getValue();
    }

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

    public final AddressEditViewModel LIZIZ() {
        return (AddressEditViewModel) this.LJIIJJI.getValue();
    }

    public final C5619C6d LIZJ() {
        return (C5619C6d) this.LJIIL.getValue();
    }

    public final boolean getUniqueOnlyGlobal() {
        return true;
    }

    public final /* bridge */ /* synthetic */ 0Bv be_() {
        return this.LIZ;
    }

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

    public final boolean LJFF() {
        LJ();
        return true;
    }

    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 LIZLLL() {
        if (LJIIIIZZ().isShowing()) {
            LJIIIIZZ().dismiss();
        }
    }

    public final void LJI() {
        C5652C7k c7k;
        if (!ActivityStack.isAppBackGround() && (c7k = LIZIZ().LJII) != null) {
            new 7Ul().LIZIZ(c7k.LIZ);
        }
        C5652C7k c7k2 = LIZIZ().LJII;
        if (c7k2 != null) {
            c7k2.LIZJ = SystemClock.elapsedRealtime();
        }
        C5656C7o LIZIZ2 = LIZIZ().LIZIZ();
        if (LIZIZ2 != null) {
            LIZIZ2.LIZIZ = SystemClock.elapsedRealtime();
        }
    }

    public final void onDestroy() {
        AddressEditFragment.super.onDestroy();
        C5652C7k c7k = LIZIZ().LJII;
        if (c7k != null) {
            new 7Uj(c7k.LIZIZ).LIZIZ(c7k.LIZ);
        }
        C5652C7k c7k2 = LIZIZ().LJII;
        if (c7k2 != null) {
            c7k2.LIZ = new LinkedHashMap();
            c7k2.LIZIZ = 0;
            c7k2.LIZJ = 0;
        }
    }

    public final void onDestroyView() {
        int i;
        AddressEditFragment.super.onDestroyView();
        if (this.LJIIIZ) {
            i = 0;
        } else {
            i = -1;
        }
        C5418BzK bzK = new C5418BzK("", i);
        M12.LIZ(bzK);
        4r1<? super C5418BzK> r0 = AddressPageStarter.LIZ;
        if (r0 != null) {
            2te.constructor-impl(bzK);
            r0.resumeWith(bzK);
        }
        AddressPageStarter.LIZ = null;
        this.LJIIIZ = false;
        SparseArray sparseArray = this.LJIILJJIL;
        if (sparseArray != null) {
            sparseArray.clear();
        }
    }

    public AddressEditFragment() {
        D1G LIZ2 = KEM.LIZ.LIZ(AddressEditViewModel.class);
        C8F c8f = new C8F(LIZ2);
        this.LJIIJJI = new lifecycleAwareLazy(this, c8f, new C8D(this, c8f, LIZ2, C8C.INSTANCE));
        this.LIZIZ = new C85(this);
        this.LJIIL = 7he.LIZ(new C5631C6p(this));
        this.LJIILIIL = 7he.LIZ(new C89(this));
        this.LJ = new AddressPageStarter.AddressEditEnterParams("");
        this.LJFF = C65.LIZ;
        this.LJII = -1;
    }

    /* JADX WARNING: Removed duplicated region for block: B:15:0x003a A[Catch:{ all -> 0x0053 }] */
    /* JADX WARNING: Removed duplicated region for block: B:18:0x0048 A[Catch:{ all -> 0x0053 }] */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final void LJII() {
        /*
            r7 = this;
            com.ss.android.ugc.aweme.ecommerce.address.edit.AddressEditViewModel r0 = r7.LIZIZ()
            X.C7k r6 = r0.LJII
            if (r6 == 0) goto L_0x0014
            long r4 = r6.LIZIZ
            long r2 = android.os.SystemClock.elapsedRealtime()
            long r0 = r6.LIZJ
            long r2 = r2 - r0
            long r4 = r4 + r2
            r6.LIZIZ = r4
        L_0x0014:
            com.ss.android.ugc.aweme.ecommerce.address.edit.AddressEditViewModel r0 = r7.LIZIZ()     // Catch:{ all -> 0x0053 }
            X.C7o r5 = r0.LIZIZ()     // Catch:{ all -> 0x0053 }
            if (r5 == 0) goto L_0x004d
            r0 = 2131370607(0x7f0a226f, float:1.8361225E38)
            android.view.View r0 = r7.LIZIZ(r0)     // Catch:{ all -> 0x0053 }
            X.OQg r0 = (X.OQg) r0     // Catch:{ all -> 0x0053 }
            if (r0 == 0) goto L_0x0032
            int r0 = r0.getVisibility()     // Catch:{ all -> 0x0053 }
            if (r0 == 0) goto L_0x0030
            goto L_0x0032
        L_0x0030:
            r4 = 0
            goto L_0x0033
        L_0x0032:
            r4 = 1
        L_0x0033:
            java.lang.String r3 = r7.LIZJ     // Catch:{ all -> 0x0053 }
            r2 = 0
            r7.LIZJ = r2     // Catch:{ all -> 0x0053 }
            if (r3 != 0) goto L_0x003c
            java.lang.String r3 = "close"
        L_0x003c:
            com.ss.android.ugc.aweme.ecommerce.address.edit.AddressEditViewModel r0 = r7.LIZIZ()     // Catch:{ all -> 0x0053 }
            com.ss.android.ugc.aweme.ecommerce.address.dto.Address r1 = r0.LJII()     // Catch:{ all -> 0x0053 }
            com.ss.android.ugc.aweme.ecommerce.address.AddressPageStarter$AddressEditEnterParams r0 = r7.LJ     // Catch:{ all -> 0x0053 }
            if (r0 == 0) goto L_0x004a
            java.lang.String r2 = r0.LJIIJ     // Catch:{ all -> 0x0053 }
        L_0x004a:
            r5.LIZ((boolean) r4, (java.lang.String) r3, (com.ss.android.ugc.aweme.ecommerce.address.dto.Address) r1, (java.lang.String) r2)     // Catch:{ all -> 0x0053 }
        L_0x004d:
            X.2Pr r0 = X.2Pr.LIZ     // Catch:{ all -> 0x0053 }
            X.2te.constructor-impl(r0)     // Catch:{ all -> 0x0053 }
            return
        L_0x0053:
            r0 = move-exception
            java.lang.Object r0 = X.2th.LIZ(r0)
            X.2te.constructor-impl(r0)
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.ecommerce.address.edit.AddressEditFragment.LJII():void");
    }

    public final void LJ() {
        String str;
        String string;
        C5652C7k c7k = LIZIZ().LJII;
        if (c7k != null) {
            c7k.LIZ("back", (Boolean) null, (String) null);
        }
        if (!LIZIZ().LJ) {
            this.LIZJ = "return";
            1hK activity = getActivity();
            if (activity != null) {
                activity.finish();
                return;
            }
            return;
        }
        1hK activity2 = getActivity();
        if (activity2 != null) {
            n.LIZIZ(activity2, "");
            4EW r1 = new 4EW(activity2);
            r1.LIZJ(2131824342);
            if (this.LJ.LJIIIZ != null) {
                string = this.LJ.LJIIIZ;
            } else {
                string = getString(2131824341);
            }
            r1.LIZJ(string);
            3QV.LIZ(r1, new C80(this));
            r1.LIZ(true);
            4FQ.LIZ(r1.LIZ().LIZJ());
        }
        C5656C7o LIZIZ2 = LIZIZ().LIZIZ();
        if (LIZIZ2 != null) {
            if (this.LJ.LJIIIZ == null) {
                str = "quit_editing_address";
            } else {
                str = "quit_checkout";
            }
            LIZIZ2.LIZLLL(str);
        }
    }

    public final void LIZ(AddressPageStarter.AddressEditEnterParams addressEditEnterParams) {
        M12.LIZ(addressEditEnterParams);
        this.LJ = addressEditEnterParams;
    }

    public final void onSaveInstanceState(Bundle bundle) {
        M12.LIZ(bundle);
        AddressEditFragment.super.onSaveInstanceState(bundle);
        bundle.putParcelable("enter_params", this.LJ);
    }

    public final void LIZ(int i) {
        List LIZ2 = Dri.LIZ(LIZJ());
        Objects.requireNonNull(LIZ2, "null cannot be cast to non-null type kotlin.collections.MutableList<kotlin.Any>");
        List LIZLLL2 = Ls0.LIZLLL(LIZ2);
        int LIZ3 = LeS.LIZ(LIZLLL2);
        Object obj = LIZLLL2.get(LIZ3);
        if (i > 0) {
            if (!(obj instanceof Integer)) {
                LIZLLL2.add(Integer.valueOf(i));
                LIZJ().notifyItemInserted(LIZ3 + 1);
            } else if (i != ((Integer) obj).intValue()) {
                LIZLLL2.set(LIZ3, Integer.valueOf(i));
                LIZJ().notifyItemChanged(LIZ3);
            }
        } else if (obj instanceof Integer) {
            C5619C6d LIZJ2 = LIZJ();
            List LJII2 = Lea.LJII(LIZLLL2);
            Leb.LJ(LJII2);
            LIZJ2.LIZ(LJII2);
        }
    }

    public final void onCreate(Bundle bundle) {
        Address address;
        Address address2;
        String str;
        List<Region> list;
        String str2;
        AddressPageStarter.AddressEditEnterParams addressEditEnterParams;
        if (!(bundle == null || (addressEditEnterParams = (AddressPageStarter.AddressEditEnterParams) bundle.getParcelable("enter_params")) == null)) {
            n.LIZIZ(addressEditEnterParams, "");
            this.LJ = addressEditEnterParams;
        }
        AddressEditFragment.super.onCreate(bundle);
        AddressEditViewModel LIZIZ2 = LIZIZ();
        AddressPageStarter.AddressEditEnterParams addressEditEnterParams2 = this.LJ;
        C5652C7k c7k = new C5652C7k(this.LJ);
        C5656C7o c7o = new C5656C7o(this.LJ);
        M12.LIZ(c7o);
        LIZIZ2.LJIILIIL = addressEditEnterParams2;
        LIZIZ2.LJII = c7k;
        LIZIZ2.LJIIJJI = c7o;
        if (addressEditEnterParams2 != null) {
            address = addressEditEnterParams2.LIZIZ;
        } else {
            address = null;
        }
        LIZIZ2.LIZIZ = address;
        if (addressEditEnterParams2 != null) {
            address2 = addressEditEnterParams2.LIZIZ;
        } else {
            address2 = null;
        }
        LIZIZ2.LJIILLIIL = address2;
        if (addressEditEnterParams2 == null || (str = addressEditEnterParams2.LIZJ) == null) {
            str = "";
        }
        LIZIZ2.LJFF = str;
        if (!(addressEditEnterParams2 == null || (str2 = addressEditEnterParams2.LIZLLL) == null)) {
            LIZIZ2.LJI = (HashMap) new Gson().LIZ(str2, new C8X().type);
        }
        Address address3 = LIZIZ2.LIZIZ;
        if (address3 != null) {
            LIZIZ2.LIZ = address3.LIZJ;
            LIZIZ2.LIZLLL = address3.LIZ;
        } else {
            if (!(addressEditEnterParams2 == null || (list = addressEditEnterParams2.LIZ) == null)) {
                ArrayList arrayList = new ArrayList();
                for (T next : list) {
                    if (next != null) {
                        arrayList.add(next);
                    }
                }
                List<Region> list2 = arrayList;
                if (!list2.isEmpty()) {
                    LIZIZ2.LIZJ = list2;
                    LIZIZ2.LIZ = list2.get(0);
                }
            }
            String LIZ2 = SettingsManager.LIZ().LIZ("priority_region", "");
            n.LIZIZ(LIZ2, "");
            if (y.LIZ(LIZ2)) {
                LIZ2 = S9B.LIZ();
                n.LIZIZ(LIZ2, "");
            }
            LIZIZ2.LIZ = new Region((String) null, (String) null, LIZ2, 3);
        }
        LIZIZ().LJIIZILJ = this.LJII;
        LIZIZ().LJIJ = this.LJIIIIZZ;
    }

    /* JADX WARNING: type inference failed for: r1v14, types: [android.view.View, java.lang.Object, X.CbG] */
    /* JADX WARNING: type inference failed for: r0v19, types: [android.view.View$OnClickListener, X.C7m] */
    public final void onActivityCreated(Bundle bundle) {
        AddressEditFragment.super.onActivityCreated(bundle);
        AddressPageStarter.AddressEditEnterParams addressEditEnterParams = this.LJ;
        1hK activity = getActivity();
        if (activity != null) {
            RecyclerView LIZIZ2 = LIZIZ(2131369388);
            n.LIZIZ(LIZIZ2, "");
            LIZIZ2.setAdapter(LIZJ());
            LIZIZ(2131364467).LIZ(new 3Do((int) HeD.LIZIZ(getActivity(), 12.0f), (int) HeD.LIZIZ(getActivity(), 16.0f)));
            if (addressEditEnterParams != null && addressEditEnterParams.LJIIIIZZ == 1) {
                C6474CbG cbG = (C6474CbG) LIZIZ(2131369794);
                n.LIZIZ(cbG, "");
                cbG.setText(getString(2131824369));
            }
            ? r1 = (C6474CbG) LIZIZ(2131369794);
            n.LIZIZ(r1, "");
            r1.setOnClickListener(new C5654C7m(this, addressEditEnterParams));
            if (LIZIZ().LIZIZ != null) {
                LIZIZ(2131371248).setEndBtnIcon(2131231731);
            }
            LIZIZ(2131371248).setOnTitleBarClickListener(new C5657C7p(activity, this, addressEditEnterParams));
            if (addressEditEnterParams != null) {
                Integer num = addressEditEnterParams.LJ;
                Integer num2 = addressEditEnterParams.LJFF;
                if (!(num == null || num2 == null)) {
                    LIZIZ(2131370655).setTotalStep(num2.intValue());
                    LIZIZ(2131370655).setLightStep(num.intValue());
                    4NX LIZIZ3 = LIZIZ(2131370655);
                    n.LIZIZ(LIZIZ3, "");
                    LIZIZ3.setVisibility(0);
                }
            }
            n.LIZIZ(activity, "");
            this.LIZLLL = new KeyBoardVisibilityUtil(activity, 16, new C5651C7j(this, addressEditEnterParams));
        }
        DV0.LIZ(this, LIZIZ(), C8Y.LIZ, new C84(this));
        DV0.LIZ(this, LIZIZ(), C5669C8b.LIZ, new C87(this));
        DV0.LIZ(this, LIZIZ(), C9X.LIZ, new C82(this));
        DV0.LIZ(this, LIZIZ(), C9Y.LIZ, new C8B(this));
        DV0.LIZ(this, LIZIZ(), C5697C9d.LIZ, new C4650Bmw(this));
        DV0.LIZ(this, LIZIZ(), C8S.LIZ, new 2r2(this));
        DV0.LIZ(this, LIZIZ(), C5696C9c.LIZ, new C5649C7h(this));
        InputItemData inputItemData = this.LJ.LJI;
        if (inputItemData != null) {
            LIZIZ().LIZ(inputItemData);
            return;
        }
        InputItemData inputItemData2 = C7O.LIZ;
        if (inputItemData2 != null) {
            LIZIZ().LIZ(inputItemData2);
        } else {
            LIZIZ().LIZJ();
        }
    }

    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 void LIZ(Integer num, Ls2<2Pr> ls2) {
        if (num != null) {
            if (num.intValue() == -1) {
                LIZLLL();
                ls2.invoke();
            } else if (num.intValue() == 0) {
                3SI LJIIIIZZ2 = LJIIIIZZ();
                LJIIIIZZ2.show();
                2fU.LIZ.LIZ(LJIIIIZZ2);
            } else if (num.intValue() == 2) {
                LIZLLL();
                3BB r1 = new 3BB(getActivity());
                r1.LIZ(getString(2131832594));
                r1.LIZIZ();
            }
        }
    }

    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);
        if (viewGroup == null) {
            return null;
        }
        C94 c94 = C6754Cfm.LIZLLL;
        Context context = layoutInflater.getContext();
        n.LIZIZ(context, "");
        return c94.LIZ(context, 2131559000, viewGroup);
    }

    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);
    }
}
