package com.ss.android.ugc.aweme.fe.method;

import X.0CB;
import X.0CH;
import X.0CN;
import X.0Gf;
import X.0Gp;
import X.2GO;
import X.2HZ;
import X.2nK;
import X.3Ok;
import X.6Is;
import X.C0865KKi;
import X.C3368LIp;
import X.C3371LIs;
import X.C3700LVj;
import X.C3705LVo;
import X.C3711LVu;
import X.FIu;
import X.FNe;
import X.ISm;
import X.M12;
import X.Qx3;
import X.Rc9;
import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.fe.base.BaseCommonJavaMethod;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
import kotlin.h.b.n;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONObject;

public final class OpenFeedsFlowMethod extends BaseCommonJavaMethod implements 6Is, 2HZ, 2GO {
    public static final C3711LVu LIZ = new C3711LVu((byte) 0);
    public String LIZIZ;

    static {
        Covode.recordClassIndex(76124);
    }

    public OpenFeedsFlowMethod(byte b) {
        this();
    }

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

    public final void onStateChanged(0CH r2, 0CB r3) {
        super.onStateChanged(r2, r3);
        if (r3 == 0CB.ON_DESTROY) {
            onDestroy();
        }
    }

    public /* synthetic */ OpenFeedsFlowMethod() {
        this((C0865KKi) null);
    }

    @0CN(LIZ = 0CB.ON_DESTROY)
    public final void onDestroy() {
        EventBus.LIZ().LIZIZ(this);
    }

    public final C3371LIs LIZJ() {
        Activity activity = (Activity) getActContext();
        if (activity != null) {
            return (C3371LIs) activity.findViewById(16908290).getTag(2131362898);
        }
        return null;
    }

    public OpenFeedsFlowMethod(C0865KKi kKi) {
        super(kKi);
        this.LIZIZ = "";
        EventBus.LIZ(EventBus.LIZ(), this);
    }

    public final BaseCommonJavaMethod attach(WeakReference<Context> weakReference) {
        M12.LIZ((Object) weakReference);
        0CH r1 = (Context) weakReference.get();
        if (r1 instanceof 0CH) {
            r1.getLifecycle().LIZ(this);
        }
        super.attach(weakReference);
        n.LIZIZ(this, "");
        return this;
    }

    @ISm
    public final void onEvent(C3700LVj lVj) {
        M12.LIZ((Object) lVj);
        if (TextUtils.equals(lVj.LIZ, this.LIZIZ)) {
            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.LIZIZ);
            jSONObject.put("data", jSONObject2);
            jSONObject.put("eventName", "video_state_change");
            sendEvent("notification", jSONObject, 3);
        }
    }

    public final void handle(JSONObject jSONObject, FIu fIu) {
        String aid;
        3Ok r5 = new 3Ok();
        r5.element = false;
        int i = 1;
        if (jSONObject != null && jSONObject.has("react_id") && jSONObject.has("enter_from") && 1 != 0) {
            String optString = jSONObject.optString("react_id");
            n.LIZIZ(optString, "");
            this.LIZIZ = optString;
            C3371LIs LIZJ = LIZJ();
            if (LIZJ != null) {
                if (LIZJ.getItems().size() > 0) {
                    if (jSONObject.has("aweme_id")) {
                        aid = jSONObject.optString("aweme_id");
                    } else {
                        aid = ((Aweme) LIZJ.getItems().get(0)).getAid();
                    }
                    String optString2 = jSONObject.optString("enter_from");
                    FNe LIZ2 = FNe.LIZ("aweme://aweme/detail/".concat(String.valueOf(aid)));
                    LIZ2.LIZ("react_session_id", this.LIZIZ);
                    LIZ2.LIZ("page_type", optString2);
                    LIZ2.LIZ("refer", optString2);
                    LIZ2.LIZ("video_from", "from_feeds_operate");
                    LIZ2.LIZ("from_group_id", jSONObject.optString("from_group_id"));
                    LIZ2.LIZ("carrier_type", jSONObject.optString("carrier_type"));
                    LIZ2.LIZ("refer_commodity_id", jSONObject.optString("refer_commodity_id"));
                    LIZ2.LIZ("data_type", jSONObject.optString("data_type"));
                    LIZ2.LIZ("previous_page", jSONObject.optString("previous_page"));
                    LIZ2.LIZ("enter_method", jSONObject.optString("enter_method"));
                    LIZ2.LIZ("is_new_low_quality_user", ((C3368LIp) LIZJ.getData()).LIZJ ? 1 : 0);
                    if (jSONObject.has("current_time")) {
                        LIZ2.LIZ("video_current_position", (int) (jSONObject.optDouble("current_time") * 1000.0d));
                    }
                    0Gp.LIZ(new C3705LVo(LIZ2, this, r5), 0Gp.LIZIZ, (0Gf) null);
                    r5.element = true;
                } else if (TextUtils.equals(jSONObject.optString("enter_from"), "feed_low_quality")) {
                    2nK.onEventV3("ads_specialist_show_fail");
                    return;
                } else {
                    return;
                }
            } else {
                return;
            }
        }
        if (fIu != null) {
            JSONObject jSONObject2 = new JSONObject();
            if (!r5.element) {
                i = -1;
            }
            jSONObject2.put("code", i);
            fIu.LIZ(jSONObject2);
        }
    }
}
