package com.ss.android.ugc.aweme.ml.common;

import X.0Gp;
import X.2YN;
import X.C0699RQx;
import X.C1118Rcw;
import X.C1120Rcy;
import X.LnV;
import X.Lnj;
import X.M12;
import X.RRE;
import X.RRI;
import X.RRJ;
import X.RRK;
import X.RRL;
import X.RRM;
import X.RRN;
import X.RRO;
import X.RRP;
import X.RRQ;
import X.RRR;
import android.os.Bundle;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.ml.api.IMLCommonService;
import com.ss.android.ugc.aweme.ml.api.MLCommonService;
import com.ss.android.ugc.aweme.profile.model.User;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
import kotlin.h.b.n;
import org.json.JSONObject;

public final class MLCommonServiceImpl extends MLCommonService {
    public RRR LIZ;
    public boolean LIZIZ;
    public boolean LIZJ;
    public final ConcurrentHashMap<String, ArrayList<RRQ>> LIZLLL = new ConcurrentHashMap<>();
    public int LJ;
    public final 2YN<Boolean> LJFF = new RRI(this);

    static {
        Covode.recordClassIndex(92897);
    }

    public final void runInMainActivityOnCreate() {
    }

    public final void runInMainActivityOnDestroy() {
    }

    public final RRR getAwemeAdapter() {
        return this.LIZ;
    }

    public static IMLCommonService LIZ() {
        MethodCollector.i(17846);
        IMLCommonService iMLCommonService = (IMLCommonService) Lnj.LIZ(IMLCommonService.class, false);
        if (iMLCommonService != null) {
            MethodCollector.o(17846);
            return iMLCommonService;
        }
        Object LIZIZ2 = Lnj.LIZIZ(IMLCommonService.class, false);
        if (LIZIZ2 != null) {
            IMLCommonService iMLCommonService2 = (IMLCommonService) LIZIZ2;
            MethodCollector.o(17846);
            return iMLCommonService2;
        }
        if (Lnj.k == null) {
            synchronized (IMLCommonService.class) {
                try {
                    if (Lnj.k == null) {
                        Lnj.k = new MLCommonServiceImpl();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(17846);
                    throw th;
                }
            }
        }
        MLCommonService mLCommonService = (MLCommonService) Lnj.k;
        MethodCollector.o(17846);
        return mLCommonService;
    }

    public final void onBeforeLoadMore(String str) {
        ArrayList<RRQ> LIZ2;
        if (TextUtils.equals("homepage_hot", str) && (LIZ2 = LIZ("before_recommend_load_more")) != null) {
            0Gp.LIZ(new RRM(LIZ2, this, str));
        }
    }

    public final ArrayList<RRQ> LIZ(String str) {
        MethodCollector.i(17760);
        ArrayList arrayList = this.LIZLLL.get(str);
        if (arrayList != null) {
            n.LIZIZ(arrayList, "");
            if (!arrayList.isEmpty()) {
                ArrayList<RRQ> arrayList2 = new ArrayList<>();
                synchronized (arrayList) {
                    try {
                        arrayList2.addAll(arrayList);
                    } finally {
                        MethodCollector.o(17760);
                    }
                }
                return arrayList2;
            }
        }
        MethodCollector.o(17760);
        return null;
    }

    public final void onPlayFinishFirst(Aweme aweme, String str) {
        if (MLCommonService.debug && aweme != null) {
            aweme.getAid();
            User author = aweme.getAuthor();
            if (author != null) {
                author.getNickname();
            }
        }
        LIZ("play_finish_first", aweme, str);
    }

    public final void onPlayFirstFrame(Aweme aweme, String str) {
        if (MLCommonService.debug && aweme != null) {
            aweme.getAid();
            User author = aweme.getAuthor();
            if (author != null) {
                author.getNickname();
            }
        }
        LIZ("play_first_frame", aweme, str);
    }

    public final void onPlayResume(Aweme aweme, String str) {
        if (MLCommonService.debug && aweme != null) {
            aweme.getAid();
            User author = aweme.getAuthor();
            if (author != null) {
                author.getNickname();
            }
        }
        LIZ("play_resume", aweme, str);
    }

    public final void traceMobClickEventBundle(String str, Bundle bundle) {
        String LIZ2;
        LnV lnV = LnV.LIZLLL;
        if (LnV.LIZ && str != null && bundle != null && (LIZ2 = lnV.LIZ(str)) != null) {
            bundle.putString("ext_portraits", LIZ2);
        }
    }

    public final void traceMobClickEvent(String str, JSONObject jSONObject) {
        String LIZ2;
        LnV lnV = LnV.LIZLLL;
        if (!(!LnV.LIZ || str == null || jSONObject == null || (LIZ2 = lnV.LIZ(str)) == null)) {
            jSONObject.putOpt("ext_portraits", LIZ2);
        }
        if (C1120Rcy.LIZIZ && str != null && jSONObject != null && C1120Rcy.LIZJ.contains(str)) {
            C0699RQx.LIZ.LIZ(new C1118Rcw(str, jSONObject));
        }
    }

    public final void addCommonEventListener(String str, RRQ rrq) {
        MethodCollector.i(17683);
        M12.LIZ(str);
        if (rrq == null) {
            MethodCollector.o(17683);
            return;
        }
        if (this.LIZLLL.get(str) == null) {
            this.LIZLLL.put(str, new ArrayList());
        }
        ArrayList arrayList = this.LIZLLL.get(str);
        if (arrayList != null) {
            n.LIZIZ(arrayList, "");
            synchronized (arrayList) {
                try {
                    if (!arrayList.contains(rrq)) {
                        arrayList.add(rrq);
                    }
                } finally {
                    MethodCollector.o(17683);
                }
            }
            return;
        }
        MethodCollector.o(17683);
    }

    public final void LIZ(String str, Aweme aweme, String str2) {
        String str3 = str;
        ArrayList<RRQ> LIZ2 = LIZ(str3);
        if (LIZ2 != null) {
            0Gp.LIZ(new RRJ(LIZ2, this, aweme, str2, str3));
        }
    }

    public final void onPlayPause(Aweme aweme, String str, boolean z) {
        Aweme aweme2 = aweme;
        if (MLCommonService.debug && aweme2 != null) {
            aweme2.getAid();
            User author = aweme2.getAuthor();
            if (author != null) {
                author.getNickname();
            }
        }
        ArrayList<RRQ> LIZ2 = LIZ("play_pause");
        if (LIZ2 != null) {
            0Gp.LIZ(new RRN(LIZ2, this, aweme2, str, z));
        }
    }

    public final void onPlayPrepare(Aweme aweme, String str, RRR rrr) {
        this.LJ++;
        if (!n.LIZ(rrr, this.LIZ)) {
            this.LIZ = rrr;
        }
        if (MLCommonService.debug && aweme != null) {
            aweme.getAid();
            User author = aweme.getAuthor();
            if (author != null) {
                author.getNickname();
            }
        }
        if (!this.LIZJ) {
            this.LIZJ = true;
            0Gp.LIZ(new RRE(this, aweme, str));
            return;
        }
        LIZ("play_prepare", aweme, str);
    }

    public final void onPlayStop(String str, Aweme aweme, String str2) {
        Aweme LIZ2;
        User author;
        Aweme aweme2 = aweme;
        String str3 = str;
        if (MLCommonService.debug) {
            RRR rrr = this.LIZ;
            if (!(rrr == null || (LIZ2 = rrr.LIZ(str3)) == null || (author = LIZ2.getAuthor()) == null)) {
                author.getNickname();
            }
            if (aweme2 != null) {
                aweme2.getAid();
                User author2 = aweme2.getAuthor();
                if (author2 != null) {
                    author2.getNickname();
                }
            }
        }
        ArrayList<RRQ> LIZ3 = LIZ("play_stop");
        if (LIZ3 != null) {
            0Gp.LIZ(new RRL(LIZ3, this, str3, str2, aweme2));
        }
    }

    public final void onPlayStopCallPlayTime(Aweme aweme, long j, String str) {
        Aweme aweme2 = aweme;
        if (MLCommonService.debug && aweme2 != null) {
            aweme2.getAid();
            User author = aweme2.getAuthor();
            if (author != null) {
                author.getNickname();
            }
        }
        ArrayList<RRQ> LIZ2 = LIZ("play_call_playtime");
        if (LIZ2 != null) {
            0Gp.LIZ(new RRO(LIZ2, this, aweme2, str, j));
        }
    }

    public final void LIZ(String str, RRP rrp, ArrayList<RRQ> arrayList) {
        Aweme aweme;
        User author;
        if (MLCommonService.debug) {
            arrayList.size();
            if (!(rrp == null || (aweme = rrp.LJFF) == null || (author = aweme.getAuthor()) == null)) {
                author.getNickname();
            }
        }
        Iterator<RRQ> it = arrayList.iterator();
        while (it.hasNext()) {
            it.next().LIZ(str, rrp);
        }
    }

    public final void onViewPagerSelected(Aweme aweme, String str, int i, JSONObject jSONObject) {
        Aweme aweme2 = aweme;
        if (MLCommonService.debug && aweme2 != null) {
            aweme2.getAid();
            User author = aweme2.getAuthor();
            if (author != null) {
                author.getNickname();
            }
        }
        ArrayList<RRQ> LIZ2 = LIZ("on_view_pager_selected");
        if (LIZ2 != null) {
            0Gp.LIZ(new RRK(LIZ2, this, aweme2, str, i, jSONObject));
        }
    }
}
