package com.ss.android.ugc.aweme.bullet.bridge.framework;

import X.0CB;
import X.0CH;
import X.2GO;
import X.2HZ;
import X.4UQ;
import X.6Is;
import X.7he;
import X.80p;
import X.9HM;
import X.C0651KCc;
import X.C3700LVj;
import X.C3701LVk;
import X.C3702LVl;
import X.C3703LVm;
import X.C4105Lea;
import X.C4949LsC;
import X.Crj;
import X.ISm;
import X.KT7;
import X.M12;
import X.Qx2;
import X.Qx3;
import X.Rc9;
import X.SXm;
import X.SXn;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.bytedance.router.SmartRoute;
import com.bytedance.router.SmartRouter;
import com.ss.android.ugc.aweme.bullet.bridge.BaseBridgeMethod;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import kotlin.h.b.n;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public final class OpenShortVideoMethod extends BaseBridgeMethod implements 6Is, 2HZ, 2GO {
    public static final C3703LVm LIZIZ = new C3703LVm((byte) 0);
    public final Map<String, String> LIZJ = new LinkedHashMap();
    public final String LIZLLL = "open_short_video";
    public C0651KCc LJ = C0651KCc.PRIVATE;
    public String LJFF = "";
    public final Crj LJI;

    static {
        Covode.recordClassIndex(55118);
    }

    private final C3702LVl LJIIIZ() {
        return (C3702LVl) this.LJI.getValue();
    }

    public final Map<Integer, Object> getSubscriberEventTypes() {
        HashMap hashMap = new HashMap();
        hashMap.put(4, new Rc9(OpenShortVideoMethod.class, "onEvent", C3700LVj.class, ThreadMode.POSTING, 0, false));
        return hashMap;
    }

    public final void onStateChanged(0CH r1, 0CB r2) {
        super.onStateChanged(r1, r2);
    }

    public final C0651KCc LIZIZ() {
        return this.LJ;
    }

    public final String LIZLLL() {
        return this.LIZLLL;
    }

    public final void LIZ() {
        EventBus.LIZ().LIZIZ(this);
    }

    public final void LIZ(C0651KCc kCc) {
        M12.LIZ((Object) kCc);
        this.LJ = kCc;
    }

    /* JADX INFO: super call moved to the top of the method (can break code semantics) */
    public OpenShortVideoMethod(KT7 kt7) {
        super(kt7);
        M12.LIZ((Object) kt7);
        this.LJI = 7he.LIZ(new C3701LVk(kt7));
        EventBus.LIZ(EventBus.LIZ(), this);
    }

    private final Map<String, String> LIZIZ(JSONObject jSONObject) {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        Iterator<String> keys = jSONObject.keys();
        while (keys.hasNext()) {
            String next = keys.next();
            n.LIZIZ(next, "");
            String string = jSONObject.getString(next);
            n.LIZIZ(string, "");
            linkedHashMap.put(next, string);
        }
        return linkedHashMap;
    }

    @ISm
    public final void onEvent(C3700LVj lVj) {
        M12.LIZ((Object) lVj);
        if (TextUtils.equals(lVj.LIZ, this.LJFF)) {
            JSONObject jSONObject = new JSONObject();
            JSONObject jSONObject2 = new JSONObject();
            jSONObject2.put("play_state", lVj.LIZIZ);
            jSONObject2.put("current_time", Float.valueOf(((float) Qx3.LIZ(lVj.LIZJ, 0)) / 1000.0f));
            jSONObject2.put("current_item_id", lVj.LIZLLL);
            jSONObject2.put("react_id", this.LJFF);
            jSONObject.put("data", jSONObject2);
            jSONObject.put("eventName", "video_state_change");
            LIZ("notification", jSONObject);
        }
    }

    public final void LIZ(JSONObject jSONObject, 4UQ r27) {
        Context LJ2;
        C3702LVl LJIIIZ;
        JSONObject jSONObject2 = jSONObject;
        4UQ r24 = r27;
        M12.LIZ((Object) jSONObject2, (Object) r24);
        if ((jSONObject2.has("current_item_id") && jSONObject2.has("item_ids") && jSONObject2.has("react_id")) || ((LJIIIZ = LJIIIZ()) != null && LJIIIZ.LIZ(jSONObject2))) {
            JSONObject jSONObject3 = jSONObject2;
            this.LJFF = jSONObject3.optString("react_id");
            String optString = jSONObject3.optString("current_item_id");
            JSONArray optJSONArray = jSONObject3.optJSONArray("item_ids");
            JSONArray optJSONArray2 = jSONObject3.optJSONArray("task_status_list");
            String optString2 = jSONObject3.optString("last_client_page");
            String optString3 = jSONObject3.optString("enter_from");
            Bundle bundle = new Bundle();
            bundle.putString("id", optString);
            bundle.putString("react_session_id", this.LJFF);
            int length = optJSONArray.length();
            if (length > 0) {
                Qx2 LIZIZ2 = Qx3.LIZIZ(0, length);
                ArrayList arrayList = new ArrayList(9HM.LIZ(LIZIZ2, 10));
                80p it = LIZIZ2.iterator();
                while (it.hasNext()) {
                    arrayList.add(optJSONArray.get(it.LIZ()));
                }
                bundle.putString("ids", C4105Lea.LIZ((Iterable) arrayList, (CharSequence) ",", (CharSequence) null, (CharSequence) null, 0, (CharSequence) null, (C4949LsC) null, 62));
            }
            if (optJSONArray2 != null && optJSONArray2.length() > 0) {
                Qx2 LIZIZ3 = Qx3.LIZIZ(0, optJSONArray2.length());
                ArrayList arrayList2 = new ArrayList(9HM.LIZ(LIZIZ3, 10));
                80p it2 = LIZIZ3.iterator();
                while (it2.hasNext()) {
                    arrayList2.add(optJSONArray2.get(it2.LIZ()));
                }
                bundle.putString("task_status_list", C4105Lea.LIZ((Iterable) arrayList2, (CharSequence) ",", (CharSequence) null, (CharSequence) null, 0, (CharSequence) null, (C4949LsC) null, 62));
            }
            if (!optString2.equals("")) {
                bundle.putString("last_client_page", optString2);
            }
            if (jSONObject3.has("current_time")) {
                bundle.putString("video_current_position", String.valueOf(jSONObject3.optDouble("current_time") * 1000.0d));
            }
            bundle.putString("enter_from", optString3);
            if (jSONObject3.has("tracker_data")) {
                bundle.putString("tracker_data", jSONObject3.optString("tracker_data"));
                try {
                    this.LIZJ.putAll(LIZIZ(new JSONObject(jSONObject3.optString("tracker_data"))));
                } catch (JSONException unused) {
                }
            }
            bundle.putString("video_from", "general_search");
            bundle.putString("from_group_id", jSONObject3.optString("from_group_id"));
            bundle.putString("carrier_type", jSONObject3.optString("carrier_type"));
            bundle.putString("refer_commodity_id", jSONObject3.optString("refer_commodity_id"));
            bundle.putString("data_type", jSONObject3.optString("data_type"));
            bundle.putString("previous_page", jSONObject3.optString("previous_page"));
            bundle.putString("enter_method", jSONObject3.optString("enter_method"));
            bundle.putString("enter_method", jSONObject3.optString("enter_method"));
            bundle.putString("auto_route_schema", jSONObject3.optString("auto_route_schema"));
            JSONObject optJSONObject = jSONObject3.optJSONObject("log");
            if (optJSONObject != null) {
                bundle.putString("search_result_id", optJSONObject.optString("search_result_id"));
                bundle.putString("impr_id", optJSONObject.optString("impr_id"));
                bundle.putString("playlist_search_id", optJSONObject.optString("search_id"));
                bundle.putInt("is_from_video", optJSONObject.optInt("is_from_video"));
                bundle.putString("key_search_type", optJSONObject.optString("search_type"));
                bundle.putInt("item_size", length);
                if (optJSONObject.has("token_type")) {
                    HashMap hashMap = new HashMap();
                    String optString4 = optJSONObject.optString("token_type");
                    n.LIZIZ(optString4, "");
                    hashMap.put("token_type", optString4);
                    bundle.putSerializable("feed_param_extra", hashMap);
                }
                this.LIZJ.putAll(LIZIZ(optJSONObject));
            }
            C3702LVl LJIIIZ2 = LJIIIZ();
            if ((LJIIIZ2 == null || !LJIIIZ2.LIZ(jSONObject3, bundle)) && (LJ2 = LJ()) != null) {
                SmartRoute buildRoute = SmartRouter.buildRoute(LJ2, "aweme://aweme/detaillist/".concat(String.valueOf(optString)));
                buildRoute.withParam(bundle);
                buildRoute.open();
            }
            SXm.LIZ(SXn.LIZJ, this.LIZJ);
        }
        JSONObject jSONObject4 = new JSONObject();
        jSONObject4.put("code", 1);
        r24.LIZ(jSONObject4);
    }
}
