package com.ss.android.ugc.aweme.friendstab.service;

import X.070;
import X.1BZ;
import X.1hK;
import X.2Pr;
import X.2kf;
import X.2kq;
import X.2oV;
import X.2oW;
import X.2te;
import X.2th;
import X.2zj;
import X.3YB;
import X.46i;
import X.4K0;
import X.4K1;
import X.8Ze;
import X.C3735EPr;
import X.C4256Ee4;
import X.C4257Ee5;
import X.C4406EgU;
import X.C4416Ege;
import X.C4419Egh;
import X.C4439Eh1;
import X.C4440Eh2;
import X.C4442Eh4;
import X.C4444Eh6;
import X.C4445Eh7;
import X.C4446Eh8;
import X.C4447Eh9;
import X.C4448EhA;
import X.C4453EhF;
import X.C4454EhG;
import X.C4457EhJ;
import X.C4461EhN;
import X.C4464EhQ;
import X.C4467EhT;
import X.C4468EhU;
import X.C4474Eha;
import X.C4480Ehg;
import X.C4482Ehi;
import X.C4483Ehj;
import X.C4484Ehk;
import X.C4525EiP;
import X.C4566Ej4;
import X.C4685Ekz;
import X.C4737Elp;
import X.DJ5;
import X.DJB;
import X.DJD;
import X.DJE;
import X.Jb0;
import X.Lnj;
import X.Ls2;
import X.M12;
import X.MHz;
import X.PgU;
import X.PhE;
import X.PlI;
import X.Qeg;
import android.app.Activity;
import android.content.Context;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.View;
import androidx.fragment.app.Fragment;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.hox.Hox;
import com.ss.android.ugc.aweme.AccountService;
import com.ss.android.ugc.aweme.IAccountUserService;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.friendstab.tab.FriendsTab;
import com.ss.android.ugc.aweme.friendstab.tab.StateOwner;
import com.ss.android.ugc.aweme.friendstab.task.ColdStartFetchTask;
import com.ss.android.ugc.aweme.friendstab.ui.SocialFriendsTabFragment;
import com.ss.android.ugc.aweme.homepage.api.interaction.ScrollSwitchStateManager;
import com.ss.android.ugc.aweme.main.TabChangeManager;
import com.ss.android.ugc.aweme.profile.model.FriendsTabRelatedUserInfo;
import com.ss.android.ugc.aweme.profile.model.User;
import java.util.List;
import java.util.Set;
import kotlin.h.b.n;
import kotlin.o.z;

public final class FriendsTabServiceImpl implements IFriendsTabService {
    public static final C4480Ehg LIZ = new C4480Ehg((byte) 0);

    static {
        Covode.recordClassIndex(81549);
    }

    public final void LJIIIIZZ() {
        StateOwner.LJIIL = true;
    }

    public final void LJIIIZ() {
        StateOwner.LJIILIIL = true;
    }

    public final void LIZ(String str) {
        M12.LIZ(str);
        C4446Eh8.LIZIZ.LIZ(str, (String) null);
    }

    public final void LIZ() {
        C4447Eh9.LIZIZ = "";
    }

    public final /* synthetic */ 8Ze LIZIZ() {
        return new ColdStartFetchTask();
    }

    public final /* synthetic */ Fragment LIZLLL() {
        return new SocialFriendsTabFragment();
    }

    public final String LJ() {
        String str = C4447Eh9.LIZIZ;
        if (str == null) {
            return "";
        }
        return str;
    }

    public final int LIZJ() {
        int i;
        2oV r1 = 2oV.LIZIZ;
        Set set = 2oV.LIZ;
        if (set != null) {
            i = set.size();
        } else {
            i = 0;
        }
        r1.LIZ();
        return i;
    }

    public final int LJFF() {
        return C4461EhN.LIZIZ.LIZ().LIZ;
    }

    public final boolean LJIIJJI() {
        return ((Boolean) MHz.LIZIZ.getValue()).booleanValue();
    }

    public final boolean LJIILJJIL() {
        if (LJFF() >= 0) {
            return true;
        }
        return false;
    }

    public final boolean LJII() {
        1hK r1 = StateOwner.LIZ;
        if (r1 == null) {
            return false;
        }
        Fragment LJII = Hox.LJ.LIZ(r1).LJII("FRIEND");
        if (!(LJII instanceof C4482Ehi)) {
            LJII = null;
        }
        C4482Ehi ehi = (C4482Ehi) LJII;
        if (ehi != null) {
            return ehi.LJIILIIL();
        }
        return false;
    }

    public final boolean LJIIJ() {
        boolean LIZIZ = C4461EhN.LIZIZ.LIZIZ();
        if (MHz.LIZJ.LIZ()) {
            if (!((Boolean) MHz.LIZ.getValue()).booleanValue()) {
                return true;
            }
            return false;
        } else if (!LIZIZ || C4461EhN.LIZIZ.LIZ().LIZIZ != 0) {
            return false;
        } else {
            return true;
        }
    }

    public final boolean LJIILIIL() {
        boolean LIZIZ;
        if (LJIILJJIL()) {
            LIZIZ = true;
        } else {
            LIZIZ = MHz.LIZJ.LIZIZ();
        }
        IAccountUserService LJFF = AccountService.LIZ().LJFF();
        n.LIZIZ(LJFF, "");
        User curUser = LJFF.getCurUser();
        n.LIZIZ(curUser, "");
        int followerCount = curUser.getFollowerCount();
        if (!StateOwner.LJIIL || !LJIIL() || !LIZIZ || followerCount > 5000) {
            return false;
        }
        return true;
    }

    public static IFriendsTabService LJIILL() {
        MethodCollector.i(9793);
        IFriendsTabService iFriendsTabService = (IFriendsTabService) Lnj.LIZ(IFriendsTabService.class, false);
        if (iFriendsTabService != null) {
            MethodCollector.o(9793);
            return iFriendsTabService;
        }
        Object LIZIZ = Lnj.LIZIZ(IFriendsTabService.class, false);
        if (LIZIZ != null) {
            IFriendsTabService iFriendsTabService2 = (IFriendsTabService) LIZIZ;
            MethodCollector.o(9793);
            return iFriendsTabService2;
        }
        if (Lnj.LLLII == null) {
            synchronized (IFriendsTabService.class) {
                try {
                    if (Lnj.LLLII == null) {
                        Lnj.LLLII = new FriendsTabServiceImpl();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(9793);
                    throw th;
                }
            }
        }
        FriendsTabServiceImpl friendsTabServiceImpl = (FriendsTabServiceImpl) Lnj.LLLII;
        MethodCollector.o(9793);
        return friendsTabServiceImpl;
    }

    public final boolean LJI() {
        1hK r1;
        boolean z;
        if (!LJIIL() || (r1 = StateOwner.LIZ) == null) {
            return false;
        }
        Hox.LJ.LIZ(r1).LIZJ("FRIEND");
        String str = TabChangeManager.LJII.LIZ(r1).LIZLLL;
        Fragment LIZ2 = TabChangeManager.LJII.LIZ(r1).LIZ();
        if (!(LIZ2 instanceof C4566Ej4)) {
            LIZ2 = null;
        }
        C4566Ej4 ej4 = (C4566Ej4) LIZ2;
        if (ej4 != null) {
            z = ej4.LJIILL();
        } else {
            z = false;
        }
        if (!C4685Ekz.LIZ.LJIILJJIL()) {
            return n.LIZ(str, "FRIEND");
        }
        if (!n.LIZ(str, "HOME") || !z) {
            return false;
        }
        return true;
    }

    public final boolean LJIIL() {
        FriendsTabRelatedUserInfo friendsTabInfo;
        FriendsTabRelatedUserInfo friendsTabInfo2;
        IAccountUserService LJFF = 46i.LJFF();
        if (LJFF == null) {
            return false;
        }
        boolean LIZIZ = C4461EhN.LIZIZ.LIZIZ();
        LJFF.isLogin();
        MHz.LIZJ.LIZ();
        User curUser = LJFF.getCurUser();
        if (!(curUser == null || (friendsTabInfo2 = curUser.getFriendsTabInfo()) == null)) {
            Boolean.valueOf(friendsTabInfo2.getDisplayFriendsTab());
        }
        Jb0.LIZIZ.LIZ();
        if (MHz.LIZJ.LIZ()) {
            if (!LJFF.isLogin()) {
                return Jb0.LIZIZ.LIZ();
            }
            User curUser2 = LJFF.getCurUser();
            if (curUser2 == null || (friendsTabInfo = curUser2.getFriendsTabInfo()) == null || !friendsTabInfo.getDisplayFriendsTab()) {
                return false;
            }
            return true;
        } else if (!LIZIZ) {
            return false;
        } else {
            if (Jb0.LIZIZ.LIZ()) {
                return LJFF.isLogin();
            }
            return true;
        }
    }

    public final /* synthetic */ View LIZ(Context context) {
        M12.LIZ(context);
        return new C3735EPr(context, (byte) 0);
    }

    public final /* synthetic */ C4525EiP LIZIZ(Context context) {
        M12.LIZ(context);
        return new FriendsTab(context);
    }

    public final PgU<Integer> LIZ(List<String> list) {
        M12.LIZ(list);
        M12.LIZ(list);
        PgU LIZIZ = PgU.LIZ(new C4440Eh2(list)).LIZIZ(PhE.LIZIZ(PlI.LIZJ));
        n.LIZIZ(LIZIZ, "");
        PgU<Integer> LIZIZ2 = LIZIZ.LIZIZ(new DJD(list));
        n.LIZIZ(LIZIZ2, "");
        return LIZIZ2;
    }

    public final void LIZ(Fragment fragment) {
        M12.LIZ(fragment);
        StateOwner stateOwner = StateOwner.LJIILL;
        1hK requireActivity = fragment.requireActivity();
        n.LIZIZ(requireActivity, "");
        M12.LIZ(requireActivity);
        StateOwner.LIZ = requireActivity;
        1BZ r0 = 1BZ.LJIIIIZZ;
        n.LIZIZ(r0, "");
        r0.getLifecycle().LIZ(stateOwner);
        46i.LIZ();
        46i.LIZ.LIZ(stateOwner);
        TabChangeManager.LJII.LIZ(requireActivity).LIZ((C4737Elp) stateOwner);
        if (C4685Ekz.LIZ.LJIILJJIL()) {
            ScrollSwitchStateManager.LJIILL.LIZ(requireActivity).LJII(requireActivity, StateOwner.LJIILJJIL);
        }
        if (LJIIL()) {
            1hK r02 = StateOwner.LIZ;
            if (r02 != null) {
                r02.hashCode();
            }
            1hK r2 = StateOwner.LIZ;
            if (r2 != null) {
                StateOwner.LJI.observe(r2, new C4467EhT(r2));
                StateOwner.LJIIIIZZ.observe(r2, new C4468EhU());
                if (C4685Ekz.LIZ.LJIILIIL()) {
                    StateOwner.LJII.observe(r2, new C4257Ee5());
                }
            }
            C4446Eh8 eh8 = C4446Eh8.LIZIZ;
            1hK r22 = StateOwner.LIZ;
            if (r22 != null) {
                StateOwner.LIZJ.observe(r22, new C4464EhQ());
                StateOwner.LJFF.observe(r22, new C4454EhG());
                StateOwner.LJI.observe(r22, new C4448EhA());
                C4447Eh9.LJII.observe(r22, new C4416Ege());
                C4447Eh9.LJIIIIZZ.observe(r22, new C4474Eha());
                C4447Eh9.LJIIIZ.observe(r22, new C4256Ee4());
            }
            if (C4685Ekz.LIZ.LJIILJJIL()) {
                C4446Eh8.LIZ = new C4453EhF();
            }
            if (StateOwner.LJIILL.LIZ()) {
                eh8.LIZ();
            }
            if (C4685Ekz.LIZ.LJIIJJI()) {
                return;
            }
            if (C4685Ekz.LIZ.LJIIJ() || !StateOwner.LJIILL.LIZ()) {
                eh8.LIZIZ();
            }
        }
    }

    public final /* synthetic */ Object LIZ(Fragment fragment, View view) {
        M12.LIZ(fragment, view);
        return new 2oW(fragment, view);
    }

    public final PgU<Integer> LIZ(long j, long j2) {
        PgU LIZIZ = PgU.LIZ(new C4442Eh4(j, j2)).LIZIZ(PhE.LIZIZ(PlI.LIZJ));
        n.LIZIZ(LIZIZ, "");
        PgU<Integer> LIZIZ2 = LIZIZ.LIZIZ(DJE.LIZ);
        n.LIZIZ(LIZIZ2, "");
        return LIZIZ2;
    }

    public final String LIZ(Aweme aweme, Activity activity) {
        M12.LIZ(aweme, activity);
        try {
            Fragment LJII = Hox.LJ.LIZ((1hK) activity).LJII("FRIEND");
            Integer num = null;
            if (!(LJII instanceof C4482Ehi)) {
                LJII = null;
            }
            C4482Ehi ehi = (C4482Ehi) LJII;
            if (ehi != null) {
                num = Integer.valueOf(ehi.LIZ(aweme));
            }
            int dataLevel = C4406EgU.SORT.getDataLevel();
            if (num != null && num.intValue() == dataLevel) {
                return "new";
            }
            int dataLevel2 = C4406EgU.HISTORY_UNVIEWED.getDataLevel();
            if (num != null && num.intValue() == dataLevel2) {
                return "historical_unread";
            }
            int dataLevel3 = C4406EgU.HISTORY_VIEWED.getDataLevel();
            if (num != null) {
                if (num.intValue() == dataLevel3) {
                    return "historical_read";
                }
            }
            return "";
        } catch (Throwable th) {
            Object LIZ2 = 2th.LIZ(th);
            2te.constructor-impl(LIZ2);
            Throwable r0 = 2te.exceptionOrNull-impl(LIZ2);
            if (r0 != null) {
                2kf.LIZ("getFeedSourceType error ".concat(String.valueOf(r0)));
            }
            return "";
        }
    }

    public final void LIZ(int i, Aweme aweme) {
        M12.LIZ(aweme);
        String aid = aweme.getAid();
        n.LIZIZ(aid, "");
        long currentTimeMillis = System.currentTimeMillis();
        IAccountUserService LJFF = 46i.LJFF();
        n.LIZIZ(LJFF, "");
        String curUserId = LJFF.getCurUserId();
        n.LIZIZ(curUserId, "");
        int i2 = i;
        C4457EhJ ehJ = new C4457EhJ(aid, currentTimeMillis, i2, false, curUserId);
        String str = ehJ.LIZ;
        M12.LIZ(str);
        PgU LIZIZ = PgU.LIZ(new C4439Eh1(str)).LIZIZ(PhE.LIZIZ(PlI.LIZJ));
        n.LIZIZ(LIZIZ, "");
        LIZIZ.LIZ(new C4419Egh(ehJ), false).LIZ(new C4445Eh7(ehJ), C4444Eh6.LIZ);
        if (i2 != 31) {
            String aid2 = aweme.getAid();
            n.LIZIZ(aid2, "");
            M12.LIZ(aid2);
            if (C4447Eh9.LJFF.contains(aid2)) {
                C4447Eh9.LJI.remove(aid2);
                DJB djb = DJB.LJII;
                M12.LIZ(aid2);
                djb.LIZ().submit(new DJ5(aid2));
                if (C4685Ekz.LIZ.LJI()) {
                    return;
                }
                if (C4685Ekz.LIZ.LJIIJ()) {
                    C4447Eh9.LJIIIZ.postValue("guide dot fallback to guide dot in onOutSideAwemeRead: ".concat(String.valueOf(aid2)));
                } else {
                    C4447Eh9.LJII.postValue(Integer.valueOf(C4447Eh9.LJI.size()));
                }
            }
        }
    }

    public final void LIZ(1hK r12, Ls2<2Pr> ls2) {
        M12.LIZ(ls2);
        if (r12 != null) {
            2kq r3 = new 2kq(r12, (byte) 0);
            4K0 r4 = new 4K0(r3);
            M12.LIZ(r3, r4);
            Qeg LIZ2 = r3.LIZ(2131365222);
            n.LIZIZ(LIZ2, "");
            LIZ2.setMovementMethod(LinkMovementMethod.getInstance());
            Qeg LIZ3 = r3.LIZ(2131365222);
            n.LIZIZ(LIZ3, "");
            LIZ3.setHighlightColor(070.LIZJ(r3.getContext(), 2131099762));
            Context context = r3.getContext();
            n.LIZIZ(context, "");
            String string = context.getResources().getString(2131825319);
            n.LIZIZ(string, "");
            Context context2 = r3.getContext();
            n.LIZIZ(context2, "");
            String string2 = context2.getResources().getString(2131825318, new Object[]{string});
            n.LIZIZ(string2, "");
            int LIZ4 = z.LIZ(string2, string, 0, false, 6);
            int length = string.length() + LIZ4;
            SpannableString spannableString = new SpannableString(string2);
            if (!TextUtils.isEmpty(string2) && !TextUtils.isEmpty(string) && LIZ4 >= 0) {
                spannableString.setSpan(new 2zj(r3), LIZ4, length, 34);
            }
            Qeg LIZ5 = r3.LIZ(2131365222);
            n.LIZIZ(LIZ5, "");
            LIZ5.setText(spannableString);
            r3.LIZ(2131365219).setOnClickListener(new C4483Ehj(r4));
            r3.LIZ(2131365220).setOnClickListener(new C4484Ehk(r4));
            3YB r1 = new 3YB();
            r1.LIZ(0);
            r1.LIZ(r3);
            r1.LIZ(new 4K1(ls2));
            r1.LIZ.show(r12.getSupportFragmentManager(), "FriendsTabIntroPanel");
        }
    }
}
