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

import X.0EB;
import X.2Pr;
import X.C2874AzO;
import X.C2881AzV;
import X.C2882AzW;
import X.C2883AzX;
import X.C2884AzY;
import X.C2885AzZ;
import X.C2886Aza;
import X.C2887Azb;
import X.C2889Azd;
import X.C2890Aze;
import X.CCV;
import X.CCW;
import X.DZp;
import X.DaU;
import X.Lnj;
import X.LsC;
import X.LsE;
import X.M12;
import android.content.Context;
import android.content.Intent;
import android.text.Editable;
import android.view.View;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.ss.android.ugc.aweme.mention.ui.CommentMentionCell;
import com.ss.android.ugc.aweme.profile.model.User;
import java.util.Objects;

public final class MentionDataServiceImpl implements IMentionDataService {
    static {
        Covode.recordClassIndex(92088);
    }

    public static IMentionDataService LIZ() {
        MethodCollector.i(16644);
        IMentionDataService iMentionDataService = (IMentionDataService) Lnj.LIZ(IMentionDataService.class, false);
        if (iMentionDataService != null) {
            MethodCollector.o(16644);
            return iMentionDataService;
        }
        Object LIZIZ = Lnj.LIZIZ(IMentionDataService.class, false);
        if (LIZIZ != null) {
            IMentionDataService iMentionDataService2 = (IMentionDataService) LIZIZ;
            MethodCollector.o(16644);
            return iMentionDataService2;
        }
        if (Lnj.f == null) {
            synchronized (IMentionDataService.class) {
                try {
                    if (Lnj.f == null) {
                        Lnj.f = new MentionDataServiceImpl();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(16644);
                    throw th;
                }
            }
        }
        MentionDataServiceImpl mentionDataServiceImpl = (MentionDataServiceImpl) Lnj.f;
        MethodCollector.o(16644);
        return mentionDataServiceImpl;
    }

    public final User LIZ(Intent intent) {
        if (intent == null) {
            return null;
        }
        User serializableExtra = intent.getSerializableExtra("extra_data");
        Objects.requireNonNull(serializableExtra, "null cannot be cast to non-null type com.ss.android.ugc.aweme.profile.model.User");
        return serializableExtra;
    }

    public final void LIZ(C2883AzX azX) {
        M12.LIZ(azX);
        M12.LIZ(azX);
        int i = C2882AzW.LIZ[azX.ordinal()];
        if (i == 2) {
            C2889Azd azd = C2884AzY.LIZIZ;
            if (azd != null) {
                azd.setItemActionListener((C2890Aze) null);
            }
        } else if (i == 3) {
            C2884AzY.LIZ = new CCW();
        }
    }

    public final void LIZ(int i, Editable editable) {
        CCV ccv;
        C2874AzO mentionSearchLayout;
        C2889Azd azd = C2884AzY.LIZIZ;
        if (azd == null || (mentionSearchLayout = azd.getMentionSearchLayout()) == null || !mentionSearchLayout.LIZJ) {
            String LIZ = C2885AzZ.LIZ.LIZ(i, editable, true);
            if (LIZ == null) {
                CCW ccw = C2884AzY.LIZ;
                if (ccw != null && (ccv = ccw.LIZ) != null) {
                    ccv.LIZ();
                    return;
                }
                return;
            }
            CCW ccw2 = C2884AzY.LIZ;
            if (ccw2 != null) {
                M12.LIZ(LIZ);
                ccw2.LIZLLL = LIZ;
            }
            CCW ccw3 = C2884AzY.LIZ;
            if (ccw3 != null) {
                ccw3.LIZ().LIZLLL.LIZLLL();
            }
        }
    }

    public final String LIZ(int i, Editable editable, boolean z) {
        return C2885AzZ.LIZ.LIZ(i, editable, z);
    }

    public final void LIZ(Context context, Fragment fragment, View.OnClickListener onClickListener, LsC<? super User, 2Pr> lsC, LsE<? super User, ? super Integer, ? super String, Boolean> lsE, LsC<? super String, Boolean> lsC2) {
        DZp mentionList;
        DaU<Boolean> LIZ;
        Fragment fragment2 = fragment;
        Context context2 = context;
        View.OnClickListener onClickListener2 = onClickListener;
        LsC<? super User, 2Pr> lsC3 = lsC;
        LsC<? super String, Boolean> lsC4 = lsC2;
        LsE<? super User, ? super Integer, ? super String, Boolean> lsE2 = lsE;
        M12.LIZ(context2, fragment2, onClickListener2, lsC3, lsE2, lsC4);
        M12.LIZ(context2, fragment2, onClickListener2, lsC3, lsE2, lsC4);
        if (C2884AzY.LIZ == null) {
            C2884AzY.LIZ = new CCW();
        }
        C2889Azd azd = C2884AzY.LIZIZ;
        if (!(azd == null || (mentionList = azd.getMentionList()) == null)) {
            mentionList.setLayoutManager(new LinearLayoutManager());
            mentionList.LIZ(new Class[]{CommentMentionCell.class});
            mentionList.setItemAnimator((0EB) null);
            CCW ccw = C2884AzY.LIZ;
            if (!(ccw == null || (LIZ = ccw.LIZ()) == null)) {
                mentionList.LIZ(LIZ);
            }
            mentionList.LIZ(new C2881AzV(context2, fragment2));
        }
        CCW ccw2 = C2884AzY.LIZ;
        if (ccw2 != null) {
            ccw2.LIZ = new C2886Aza(onClickListener2, lsC4);
        }
        C2889Azd azd2 = C2884AzY.LIZIZ;
        if (azd2 != null) {
            azd2.setItemActionListener(new C2887Azb(fragment2, lsE2, context2, lsC3));
        }
    }
}
