package com.ss.android.ugc.aweme.im.sdk.relations.ui.fragment;

import X.0By;
import X.0HH;
import X.1hK;
import X.C0864IXf;
import X.C0872IXn;
import X.C1023IbO;
import X.C1672Ilr;
import X.C1673Ils;
import X.C1687Im6;
import X.C2153Itc;
import X.C2275Iva;
import X.Frd;
import X.Frq;
import X.IYM;
import X.IZH;
import X.IZL;
import X.IZO;
import X.IZR;
import X.IZS;
import X.Ls0;
import X.M12;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.ss.android.ugc.aweme.base.fragment.AmeBaseFragment;
import com.ss.android.ugc.aweme.im.sdk.chat.data.model.BaseContent;
import com.ss.android.ugc.aweme.im.sdk.relations.viewmodel.RelationViewModel;
import com.ss.android.ugc.aweme.im.service.model.IMContact;
import com.ss.android.ugc.aweme.sharer.ui.SharePackage;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import kotlin.h.b.n;

public final class RelationSelectFragment extends AmeBaseFragment implements C1687Im6 {
    public static final C1023IbO LIZIZ = new C1023IbO((byte) 0);
    public C1672Ilr LIZ;
    public View LIZJ;
    public SharePackage LIZLLL;
    public boolean LJ;
    public LinkedHashSet<IMContact> LJIIIZ;
    public boolean LJIIJ;
    public BaseContent LJIIJJI;
    public boolean LJIIL;
    public String LJIILIIL = "";
    public int LJIILJJIL = -1;
    public RelationViewModel LJIILL;
    public HashMap LJIIZILJ;

    static {
        Covode.recordClassIndex(86880);
    }

    public final void LIZ() {
        RelationViewModel relationViewModel = this.LJIILL;
        if (relationViewModel != null) {
            relationViewModel.LIZJ.LJII();
        }
    }

    public final /* synthetic */ void onDestroyView() {
        RelationSelectFragment.super.onDestroyView();
        HashMap hashMap = this.LJIIZILJ;
        if (hashMap != null) {
            hashMap.clear();
        }
    }

    public final void onDestroy() {
        RelationSelectFragment.super.onDestroy();
        C1672Ilr ilr = this.LIZ;
        if (ilr != null) {
            ilr.LJIIL();
        }
        C1672Ilr ilr2 = this.LIZ;
        if (ilr2 != null) {
            ilr2.LJIIZILJ = null;
        }
        RelationViewModel relationViewModel = this.LJIILL;
        if (relationViewModel != null) {
            relationViewModel.LIZJ.LIZLLL();
            relationViewModel.LIZJ.LJIIL();
        }
    }

    public final void onResume() {
        RelationSelectFragment.super.onResume();
        C1672Ilr ilr = this.LIZ;
        if (ilr != null) {
            ilr.LJI();
        }
        RelationViewModel relationViewModel = this.LJIILL;
        if (relationViewModel != null) {
            List<IMContact> LJ2 = relationViewModel.LIZJ.LJ();
            relationViewModel.LIZ.setValue(new IZO(LJ2));
            if (!LJ2.isEmpty()) {
                Objects.requireNonNull(LJ2, "null cannot be cast to non-null type kotlin.collections.MutableList<com.ss.android.ugc.aweme.im.service.model.IMContact>");
                relationViewModel.LIZ((List<IMContact>) Ls0.LIZLLL(LJ2), relationViewModel.LIZJ.LJFF());
                return;
            }
            relationViewModel.LIZJ.LJI();
        }
    }

    public final void LIZ(String str) {
        M12.LIZ(str);
        RelationViewModel relationViewModel = this.LJIILL;
        if (relationViewModel != null) {
            M12.LIZ(str);
            if (str.length() == 0) {
                relationViewModel.LIZ.setValue(new IZL(relationViewModel.LIZJ.LJ()));
            } else {
                relationViewModel.LIZJ.LIZ(str.toString());
            }
        }
    }

    public final void onCreate(Bundle bundle) {
        RelationSelectFragment.super.onCreate(bundle);
        Bundle arguments = getArguments();
        if (arguments != null) {
            SharePackage sharePackage = (SharePackage) arguments.getParcelable("share_package");
            this.LIZLLL = sharePackage;
            if (sharePackage != null) {
                String string = sharePackage.LJIILJJIL.getString("author_user_name", "");
                n.LIZIZ(string, "");
                this.LJIILIIL = string;
                SharePackage sharePackage2 = this.LIZLLL;
                if (sharePackage2 == null) {
                    n.LIZIZ();
                }
                this.LJIILJJIL = sharePackage2.LJIILJJIL.getInt("share_im_limit_tip_type", -1);
            }
            this.LJIIJJI = (BaseContent) arguments.getSerializable("share_content");
            this.LJ = arguments.getBoolean("key_relation_list_use_sort", false);
            BaseContent.wrapForward(this.LJIIJJI, arguments.getLong("forward_origin_msgid"));
            this.LJIIJ = arguments.getBoolean("extra_no_title");
            this.LJIIIZ = (LinkedHashSet) arguments.getSerializable("key_selected_contact");
        }
        boolean LIZIZ2 = Frq.LIZIZ();
        this.LJIIL = LIZIZ2;
        SharePackage sharePackage3 = this.LIZLLL;
        boolean z = this.LJ;
        M12.LIZ(this);
        RelationViewModel LIZ2 = 0By.LIZ(this, new IYM(sharePackage3, z, LIZIZ2)).LIZ(RelationViewModel.class);
        n.LIZIZ(LIZ2, "");
        RelationViewModel relationViewModel = LIZ2;
        this.LJIILL = relationViewModel;
        if (relationViewModel != null) {
            relationViewModel.LIZJ.LIZ((C0864IXf<IMContact>) relationViewModel);
            relationViewModel.LIZJ.LIZ((C0872IXn) relationViewModel);
        }
        RelationViewModel relationViewModel2 = this.LJIILL;
        if (relationViewModel2 != null) {
            relationViewModel2.LIZ.observe(this, new IZR(relationViewModel2, this));
            relationViewModel2.LIZIZ.observe(this, new IZS(this));
        }
    }

    public final void onViewCreated(View view, Bundle bundle) {
        FrameLayout frameLayout;
        LinkedHashSet<IMContact> linkedHashSet;
        String str;
        String str2;
        Bundle bundle2;
        Bundle bundle3;
        Bundle bundle4;
        Bundle bundle5;
        C1672Ilr ilr;
        List<Integer> list;
        List<String> list2;
        MethodCollector.i(3279);
        M12.LIZ(view);
        RelationSelectFragment.super.onViewCreated(view, bundle);
        View view2 = this.LIZJ;
        C2275Iva iva = null;
        if (C2153Itc.LIZ((Context) getActivity()) && view2 != null) {
            if (this.LJIIL) {
                1hK activity = getActivity();
                if (activity != null) {
                    boolean z = this.LJIIJ;
                    RelationViewModel relationViewModel = this.LJIILL;
                    if (relationViewModel != null) {
                        list = relationViewModel.LIZ();
                    } else {
                        list = null;
                    }
                    RelationViewModel relationViewModel2 = this.LJIILL;
                    if (relationViewModel2 != null) {
                        list2 = relationViewModel2.LIZIZ();
                    } else {
                        list2 = null;
                    }
                    ilr = new C1673Ils(activity, view2, z, list, list2);
                } else {
                    NullPointerException nullPointerException = new NullPointerException("null cannot be cast to non-null type android.app.Activity");
                    MethodCollector.o(3279);
                    throw nullPointerException;
                }
            } else {
                1hK activity2 = getActivity();
                if (activity2 != null) {
                    ilr = new C1672Ilr(activity2, view2, this.LJIIJ);
                } else {
                    NullPointerException nullPointerException2 = new NullPointerException("null cannot be cast to non-null type android.app.Activity");
                    MethodCollector.o(3279);
                    throw nullPointerException2;
                }
            }
            this.LIZ = ilr;
        }
        C1672Ilr ilr2 = this.LIZ;
        if (ilr2 != null) {
            ilr2.LJIIZILJ = this;
        }
        C1672Ilr ilr3 = this.LIZ;
        if (ilr3 != null) {
            ilr3.LJI = this.LIZLLL;
            SharePackage sharePackage = ilr3.LJI;
            if (sharePackage == null || (bundle5 = sharePackage.LJIILJJIL) == null) {
                str = null;
            } else {
                str = bundle5.getString("multi_share_msg");
            }
            ilr3.LJIILL = str;
            SharePackage sharePackage2 = ilr3.LJI;
            if (sharePackage2 == null || (bundle4 = sharePackage2.LJIILJJIL) == null || (str2 = bundle4.getString("aid", "")) == null) {
                str2 = "";
            }
            ilr3.LJIILLIIL = str2;
            SharePackage sharePackage3 = ilr3.LJI;
            if (!(sharePackage3 == null || (bundle3 = sharePackage3.LJIILJJIL) == null)) {
                bundle3.remove("multi_share_msg");
            }
            SharePackage sharePackage4 = ilr3.LJI;
            if (!(sharePackage4 == null || (bundle2 = sharePackage4.LJIILJJIL) == null)) {
                bundle2.remove("aid");
            }
            ilr3.LJIIIIZZ();
        }
        C1672Ilr ilr4 = this.LIZ;
        if (ilr4 != null) {
            ilr4.LJII = this.LJIIJJI;
        }
        C1672Ilr ilr5 = this.LIZ;
        if (!(ilr5 == null || (linkedHashSet = this.LJIIIZ) == null)) {
            Frd frd = ilr5.LJIILJJIL;
            if (frd != null) {
                frd.LJFF = linkedHashSet;
            }
            ilr5.LJIIIZ();
            ilr5.LJII();
            ilr5.LJI();
        }
        if (this.LJIILJJIL > 0 && !TextUtils.isEmpty(this.LJIILIIL)) {
            1hK activity3 = getActivity();
            if (activity3 != null) {
                n.LIZIZ(activity3, "");
                iva = new C2275Iva(activity3);
            }
            View view3 = this.LIZJ;
            if (!(view3 == null || (frameLayout = (FrameLayout) view3.findViewById(2131370193)) == null)) {
                frameLayout.addView(iva);
            }
            IZH izh = new IZH(this.LJIILIIL, this.LJIILJJIL);
            if (iva != null) {
                iva.LIZ(izh);
                MethodCollector.o(3279);
                return;
            }
        }
        MethodCollector.o(3279);
    }

    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View LIZ2;
        M12.LIZ(layoutInflater);
        if (this.LJIIL) {
            LIZ2 = 0HH.LIZ(layoutInflater, 2131559906, viewGroup, false);
        } else {
            LIZ2 = 0HH.LIZ(layoutInflater, 2131559905, viewGroup, false);
        }
        this.LIZJ = LIZ2;
        return LIZ2;
    }
}
