package com.ss.android.ugc.aweme.recommend;

import X.0Bs;
import X.0Bv;
import X.0Bx;
import X.0By;
import X.0EF;
import X.0HH;
import X.1Bn;
import X.1hK;
import X.2GD;
import X.2HN;
import X.2K7;
import X.2UX;
import X.2nK;
import X.3BB;
import X.4ZZ;
import X.7df;
import X.7hc;
import X.7he;
import X.AkL;
import X.C0295Crj;
import X.C2761Dv3;
import X.C2765Dv7;
import X.C2766Dv8;
import X.C2782DvO;
import X.C2786DvS;
import X.C2788DvU;
import X.C2790DvW;
import X.C2791DvX;
import X.C2792DvY;
import X.C2793DvZ;
import X.C2796Dvc;
import X.C3038DzW;
import X.C3157E3l;
import X.C3158E3m;
import X.C3159E3n;
import X.CkK;
import X.CqM;
import X.E4U;
import X.EJ2;
import X.EJ3;
import X.EV1;
import X.HeD;
import X.LnI;
import X.M12;
import X.Qx3;
import android.app.Dialog;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.SparseArray;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;
import com.bytedance.covode.number.Covode;
import com.bytedance.router.SmartRoute;
import com.bytedance.router.SmartRouter;
import com.ss.android.ugc.aweme.common.ui.BaseDialogFragment;
import com.ss.android.ugc.aweme.friends.model.RecommendList;
import com.ss.android.ugc.aweme.friends.model.RecommendUserDialogList;
import com.ss.android.ugc.aweme.friends.model.RecommendUserHint;
import com.ss.android.ugc.aweme.profile.model.MatchedFriendStruct;
import com.ss.android.ugc.aweme.profile.model.RecommendCommonUserModel;
import com.ss.android.ugc.aweme.profile.model.User;
import com.ss.android.ugc.aweme.views.WrapLinearLayoutManager;
import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import kotlin.h.b.n;

public class RecommendUserDialogFragment extends BaseDialogFragment implements View.OnClickListener, C3038DzW<User>, EJ3 {
    public static final C2792DvY LJFF = new C2792DvY((byte) 0);
    public EJ2 LIZ;
    public boolean LIZIZ;
    public final C2765Dv7 LIZJ = new C2765Dv7();
    public RecommendUsersDialogViewModel LIZLLL;
    public long LJ = -1;
    public final C0295Crj LJI = 7he.LIZ(7hc.NONE, new C2788DvU(this));
    public final C0295Crj LJII = 7he.LIZ(7hc.NONE, new C2790DvW(this));
    public final C0295Crj LJIIIIZZ = 7he.LIZ(7hc.NONE, new C2791DvX(this));
    public boolean LJIIIZ;
    public SparseArray LJIIJ;

    static {
        Covode.recordClassIndex(102262);
    }

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

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

    public final String LIZIZ() {
        return (String) this.LJII.getValue();
    }

    public static boolean LIZJ() {
        try {
            return 2K7.LIZ.LIZJ();
        } catch (Exception unused) {
            return false;
        }
    }

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

    public void onResume() {
        RecommendUserDialogFragment.super.onResume();
        C2765Dv7 dv7 = this.LIZJ;
        if (!dv7.LIZJ) {
            dv7.LIZLLL = System.currentTimeMillis();
        }
    }

    public void onPause() {
        RecommendUserDialogFragment.super.onPause();
        C2765Dv7 dv7 = this.LIZJ;
        if (dv7.LIZJ) {
            dv7.LIZJ = false;
            dv7.LIZ += System.currentTimeMillis() - dv7.LIZLLL;
        }
    }

    public void dismiss() {
        String str;
        1Bn<Boolean> r1;
        try {
            RecommendUserDialogFragment.super.dismiss();
        } catch (IllegalStateException unused) {
            RecommendUserDialogFragment.super.dismissAllowingStateLoss();
        }
        if (this.LIZIZ) {
            7df.LJJJI().LJJI();
            this.LIZIZ = false;
        }
        C2766Dv8.LIZJ();
        this.LIZJ.LIZIZ();
        long currentTimeMillis = System.currentTimeMillis() - this.LJ;
        2UX r5 = new 2UX();
        r5.LIZ("enter_from", LIZIZ());
        if (this.LJIIIZ) {
            str = "button";
        } else {
            str = "blank";
        }
        r5.LIZ("click_method", str);
        r5.LIZ("duration", currentTimeMillis);
        2nK.LIZ("close_suggested_accounts_pop_up", r5.LIZ);
        this.LJ = -1;
        if (TextUtils.equals(LIZIZ(), "personal_collection") || TextUtils.equals(LIZIZ(), "personal_homepage")) {
            CqM.LIZ(new C2793DvZ());
        }
        RecommendUsersDialogViewModel recommendUsersDialogViewModel = this.LIZLLL;
        if (recommendUsersDialogViewModel != null && (r1 = recommendUsersDialogViewModel.LIZIZ) != null) {
            r1.postValue(false);
        }
    }

    public final void LIZIZ(RecommendList recommendList) {
        if (this.LJJJJZ && recommendList != null && (recommendList instanceof RecommendUserDialogList)) {
            List<User> recommendUsers = ((RecommendUserDialogList) recommendList).getRecommendUsers();
            EJ2 ej2 = this.LIZ;
            if (!(ej2 == null || ej2.LJFF() == 0)) {
                LIZ().setDataAfterLoadMore(recommendUsers);
                if (recommendList.hasMore()) {
                    LIZ().resetLoadMoreState();
                    return;
                }
            }
            LIZ().showLoadMoreEmpty();
        }
    }

    public void onCreate(Bundle bundle) {
        RecommendUserDialogFragment.super.onCreate(bundle);
        setStyle(1, 2131887000);
        1hK activity = getActivity();
        if (activity != null) {
            0Bx LIZ2 = 0By.LIZ(activity, (0Bv) null);
            if (2GD.LIZ) {
                0Bs.LIZ(LIZ2, activity);
            }
            this.LIZLLL = LIZ2.LIZ(RecommendUsersDialogViewModel.class);
        }
    }

    public Dialog onCreateDialog(Bundle bundle) {
        Dialog onCreateDialog = RecommendUserDialogFragment.super.onCreateDialog(bundle);
        n.LIZIZ(onCreateDialog, "");
        onCreateDialog.setCancelable(true);
        onCreateDialog.setCanceledOnTouchOutside(true);
        Window window = onCreateDialog.getWindow();
        if (window != null) {
            WindowManager.LayoutParams attributes = window.getAttributes();
            window.addFlags(67108864);
            window.setAttributes(attributes);
        }
        onCreateDialog.setOnShowListener(new C2761Dv3(this));
        return onCreateDialog;
    }

    public final void LIZ(RecommendList recommendList) {
        if (this.LJJJJZ && recommendList != null && (recommendList instanceof RecommendUserDialogList)) {
            RecommendUserDialogList recommendUserDialogList = (RecommendUserDialogList) recommendList;
            List<User> recommendUsers = recommendUserDialogList.getRecommendUsers();
            if (recommendUsers == null || recommendUsers.isEmpty()) {
                LIZ().clearData();
                LIZ().setShowFooter(false);
                return;
            }
            LIZ().setShowFooter(false);
            LIZ().setData(recommendUserDialogList.getRecommendUsers());
            if (recommendList.hasMore()) {
                LIZ().resetLoadMoreState();
            } else {
                LIZ().showLoadMoreEmpty();
            }
        }
    }

    public final void LIZ(Exception exc) {
        if (this.LJJJJZ) {
            List data = LIZ().getData();
            if (data == null || data.isEmpty()) {
                LIZ().setShowFooter(false);
                return;
            }
            LIZ().setShowFooter(false);
            LIZ().showPullUpLoadMore();
        }
    }

    public void onClick(View view) {
        Integer valueOf;
        if (view != null && (valueOf = Integer.valueOf(view.getId())) != null) {
            if (valueOf.intValue() == 2131365985) {
                if (this.LJJJJZ) {
                    this.LIZJ.LIZIZ = true;
                    C2796Dvc LIZ2 = LIZ();
                    RecyclerView LIZ3 = LIZ(2131369388);
                    n.LIZIZ(LIZ3, "");
                    0EF layoutManager = LIZ3.getLayoutManager();
                    if (LIZ2.mItems != null) {
                        List list = LIZ2.mItems;
                        n.LIZIZ(list, "");
                        Iterator it = list.iterator();
                        int i = 0;
                        while (true) {
                            if (!it.hasNext()) {
                                break;
                            } else if (!(it.next() instanceof RecommendUserHint)) {
                                i++;
                            } else if (i >= 0) {
                                if (i == 0) {
                                    if (i < LIZ2.mItems.size()) {
                                        LIZ2.mItems.remove(i);
                                        LIZ2.notifyItemRemoved(i);
                                    }
                                    LIZ2.LIZIZ = false;
                                    return;
                                }
                                return;
                            }
                        }
                        RecommendUserHint recommendUserHint = LIZ2.LIZ;
                        if (LIZ2.mItems != null) {
                            LIZ2.mItems.add(0, recommendUserHint);
                            LIZ2.notifyItemInserted(0);
                        }
                        LIZ2.LIZIZ = true;
                        if (layoutManager != null) {
                            layoutManager.LJ(0);
                        }
                    }
                }
            } else if (valueOf.intValue() == 2131363384) {
                this.LJIIIZ = true;
                dismiss();
            } else if (valueOf.intValue() == 2131366829) {
                dismiss();
            }
        }
    }

    public void onViewCreated(View view, Bundle bundle) {
        1Bn<Boolean> r1;
        M12.LIZ(view);
        RecommendUserDialogFragment.super.onViewCreated(view, bundle);
        RecommendUsersDialogViewModel recommendUsersDialogViewModel = this.LIZLLL;
        if (!(recommendUsersDialogViewModel == null || (r1 = recommendUsersDialogViewModel.LIZIZ) == null)) {
            r1.postValue(true);
        }
        int LIZ2 = (int) (((float) HeD.LIZ(getContext())) * 0.92f);
        View findViewById = view.findViewById(2131366823);
        n.LIZIZ(findViewById, "");
        ViewGroup.LayoutParams layoutParams = findViewById.getLayoutParams();
        Resources system = Resources.getSystem();
        n.LIZIZ(system, "");
        layoutParams.width = Qx3.LIZLLL(LIZ2, LnI.LIZ(TypedValue.applyDimension(1, 360.0f, system.getDisplayMetrics())));
        Resources system2 = Resources.getSystem();
        n.LIZIZ(system2, "");
        layoutParams.height = Qx3.LIZLLL((int) (((float) HeD.LIZIZ(getContext())) * 0.84f), LnI.LIZ(TypedValue.applyDimension(1, 480.0f, system2.getDisplayMetrics())));
        findViewById.requestLayout();
        RecyclerView LIZ3 = LIZ(2131369388);
        if (LIZ3 != null) {
            LIZ3.getContext();
            LIZ3.setLayoutManager(new WrapLinearLayoutManager());
            LIZ3.setAdapter(LIZ());
            LIZ3.LIZ(new C2782DvO(this));
        }
        RecyclerView LIZ4 = LIZ(2131369388);
        if (LIZ4 != null) {
            new EV1(LIZ4, new C2786DvS(this));
        }
        4ZZ LIZ5 = LIZ(2131365985);
        if (LIZ5 != null) {
            LIZ5.setOnClickListener(this);
        }
        4ZZ LIZ6 = LIZ(2131363384);
        if (LIZ6 != null) {
            LIZ6.setOnClickListener(this);
        }
        FrameLayout frameLayout = (FrameLayout) LIZ(2131366829);
        if (frameLayout != null) {
            frameLayout.setOnClickListener(this);
        }
        ConstraintLayout LIZ7 = LIZ(2131366823);
        if (LIZ7 != null) {
            LIZ7.setOnClickListener(this);
        }
        if (this.LIZ == null) {
            RecommendCommonUserModel recommendCommonUserModel = new RecommendCommonUserModel();
            Bundle arguments = getArguments();
            Serializable serializable = null;
            if (arguments != null) {
                serializable = arguments.getSerializable("data");
            }
            Objects.requireNonNull(serializable, "null cannot be cast to non-null type com.ss.android.ugc.aweme.friends.model.RecommendUserDialogList");
            recommendCommonUserModel.setRecommendList((RecommendUserDialogList) serializable);
            EJ2 ej2 = new EJ2(recommendCommonUserModel, this);
            this.LIZ = ej2;
            LIZ(ej2.LIZ());
            CkK ckK = RecommendUsersDialogViewModel.LIZLLL;
            1hK requireActivity = requireActivity();
            n.LIZIZ(requireActivity, "");
            ckK.LIZ(requireActivity).LIZJ.LIZLLL();
        }
    }

    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        M12.LIZ(layoutInflater);
        return 0HH.LIZ(layoutInflater, 2131559563, viewGroup, false);
    }

    public final /* synthetic */ void LIZ(int i, Object obj, int i2) {
        boolean z;
        String str;
        RecommendList LIZ2;
        User user = (User) obj;
        if (user != null) {
            int i3 = i;
            int i4 = i2;
            if (i3 == 100) {
                this.LIZJ.LIZIZ = true;
                if (this.LJJJJZ) {
                    getContext();
                    if (!LIZJ()) {
                        3BB r1 = new 3BB(getContext());
                        r1.LIZIZ(2131827476);
                        r1.LIZIZ();
                        return;
                    }
                    if (user.getFollowStatus() != 0) {
                        z = true;
                    } else {
                        z = false;
                    }
                    boolean z2 = !z;
                    LIZ().LIZ(user, user.getFollowStatus());
                    if (z2) {
                        LIZ("follow", user, i4);
                        C3157E3l e3l = new C3157E3l();
                        e3l.LIZ(LIZIZ());
                        e3l.LJIILL("auto_pop_up");
                        e3l.LIZ = E4U.POP_UP;
                        e3l.LIZIZ = C3159E3n.FOLLOW;
                        e3l.LIZ(user);
                        e3l.LJFF();
                        return;
                    }
                    LIZ("follow_cancel", user, i4);
                    C3157E3l e3l2 = new C3157E3l();
                    e3l2.LIZ(LIZIZ());
                    e3l2.LJIILL("auto_pop_up");
                    e3l2.LIZ = E4U.POP_UP;
                    e3l2.LIZIZ = C3159E3n.FOLLOW_CANCEL;
                    e3l2.LIZ(user);
                    e3l2.LJFF();
                }
            } else if (i3 == 101) {
                this.LIZJ.LIZIZ = true;
                SmartRoute buildRoute = SmartRouter.buildRoute(getActivity(), "aweme://user/profile/" + user.getUid());
                buildRoute.withParam("sec_user_id", user.getSecUid());
                buildRoute.withParam("from_recommend_card", 1);
                buildRoute.withParam("enter_from", "suggest_account_pop_up");
                buildRoute.withParam("extra_previous_page_position", LIZIZ());
                buildRoute.withParam("recommend_from_type", "list");
                buildRoute.withParam("extra_mutual_relation", user.getMutualStruct());
                buildRoute.withParam("extra_from_mutual", true);
                EJ2 ej2 = this.LIZ;
                String str2 = "";
                if (ej2 == null || (LIZ2 = ej2.LIZ()) == null || (str = LIZ2.getRid()) == null) {
                    str = str2;
                }
                buildRoute.withParam("enter_from_request_id", str);
                String LIZIZ2 = LIZIZ();
                E4U e4u = E4U.POP_UP;
                String recType = user.getRecType();
                AkL LIZ3 = C3158E3m.Companion.LIZ(user);
                String uid = user.getUid();
                String requestId = user.getRequestId();
                if (requestId != null) {
                    str2 = requestId;
                }
                buildRoute.withParam("recommend_enter_profile_params", new C3158E3m(LIZIZ2, (String) null, e4u, recType, LIZ3, uid, (String) null, (String) null, str2, (String) null, user.getFriendTypeStr(), user.getSocialInfo(), (MatchedFriendStruct) null, 4096, (2HN) null));
                buildRoute.open();
                2UX r6 = new 2UX();
                r6.LIZ("enter_from", "suggest_account_pop_up");
                r6.LIZ("previous_page", LIZIZ());
                r6.LIZ("to_user_id", user.getUid());
                r6.LIZ("rec_type", user.getRecType());
                r6.LIZ("impr_order", i4);
                2nK.LIZ("enter_personal_detail", r6.LIZ);
                C3157E3l e3l3 = new C3157E3l();
                e3l3.LIZ(LIZIZ());
                e3l3.LJIILL("auto_pop_up");
                e3l3.LIZ = E4U.POP_UP;
                e3l3.LIZIZ = C3159E3n.ENTER_PROFILE;
                e3l3.LIZ(user);
                e3l3.LJFF();
            }
        }
    }

    public final void LIZ(String str, User user, int i) {
        2UX r2 = new 2UX();
        r2.LIZ("enter_from", "suggest_account_pop_up");
        r2.LIZ("previous_page", LIZIZ());
        r2.LIZ("rec_type", user.getRecType());
        r2.LIZ("rec_uid", user.getUid());
        r2.LIZ("impr_order", i);
        r2.LIZ("relation_type", user.getFriendTypeStr());
        2nK.LIZ(str, r2.LIZ);
    }
}
