package com.tencent.mm.plugin.webview.luggage.jsapi;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import com.google.android.gms.common.internal.ImagesContract;
import com.tencent.luggage.d.a.a;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.g.a.cl;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;
import com.tencent.mm.plugin.webview.luggage.d;
import com.tencent.mm.plugin.webview.model.c;
import com.tencent.mm.plugin.webview.ui.tools.jsapi.k;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.ui.MMActivity;
import com.tencent.sqlitelint.config.SharePluginInfo;
import java.util.HashMap;
import org.json.JSONObject;

public class ap extends bd<d> {
    private static int cSP;

    public static void IF(int i) {
        cSP = i;
    }

    public static int cXn() {
        return cSP;
    }

    public static void cXo() {
        cSP = 0;
    }

    public final String name() {
        return "sendAppMessage";
    }

    public final int biG() {
        return 2;
    }

    public final void b(a aVar) {
    }

    public final void a(Context context, String str, bc.a aVar) {
        JSONObject jSONObject;
        AppMethodBeat.i(6369);
        ab.d("MicroMsg.JsApiSendAppMessage", "invokeInMM");
        try {
            jSONObject = new JSONObject(str);
        } catch (Exception e) {
            jSONObject = null;
        }
        if (jSONObject == null) {
            aVar.d("data is null", null);
            AppMethodBeat.o(6369);
            return;
        }
        switch (jSONObject.optInt("sendAppMessageScene", 0)) {
            case 1:
                ab.i("MicroMsg.JsApiSendAppMessage", "favoriteUrl");
                cl clVar = new cl();
                c.a aVar2 = new c.a();
                aVar2.url = jSONObject.optString("shareUrl");
                aVar2.thumbUrl = jSONObject.optString("img_url");
                aVar2.title = jSONObject.optString("title");
                aVar2.desc = jSONObject.optString(SharePluginInfo.ISSUE_KEY_DESC);
                aVar2.csB = jSONObject.optString("appid");
                if (context != null && (context instanceof MMActivity)) {
                    clVar.cvA.activity = (Activity) context;
                    clVar.cvA.cvH = 36;
                }
                clVar.cvA.cvJ = new 1(this, aVar);
                c.a(clVar, aVar2);
                com.tencent.mm.sdk.b.a.xxA.m(clVar);
                if (clVar.cvB.ret != 0) {
                    aVar.d("fail", null);
                }
                AppMethodBeat.o(6369);
                return;
            default:
                k.agC(jSONObject.optString("img_url"));
                HashMap hashMap = new HashMap();
                hashMap.put("img_url", jSONObject.optString("img_url"));
                hashMap.put(SharePluginInfo.ISSUE_KEY_DESC, jSONObject.optString(SharePluginInfo.ISSUE_KEY_DESC));
                hashMap.put("title", jSONObject.optString("title"));
                hashMap.put(ImagesContract.URL, jSONObject.optString("shareUrl"));
                Intent intent = new Intent();
                intent.putExtra("Select_Conv_Type", 3);
                intent.putExtra("scene_from", 2);
                intent.putExtra("mutil_select_is_ret", true);
                intent.putExtra("webview_params", hashMap);
                intent.putExtra("Retr_Msg_Type", 2);
                com.tencent.mm.bp.d.a((MMActivity) context, ".ui.transmit.SelectConversationUI", intent, 1, new 2(this, jSONObject, aVar, context));
                AppMethodBeat.o(6369);
                return;
        }
    }

    static /* synthetic */ WXMediaMessage aN(JSONObject jSONObject) {
        AppMethodBeat.i(6370);
        WXWebpageObject wXWebpageObject = new WXWebpageObject();
        wXWebpageObject.webpageUrl = jSONObject.optString("link");
        wXWebpageObject.extInfo = jSONObject.optString("review_data");
        WXMediaMessage wXMediaMessage = new WXMediaMessage();
        wXMediaMessage.mediaObject = wXWebpageObject;
        wXMediaMessage.title = jSONObject.optString("title");
        wXMediaMessage.description = jSONObject.optString(SharePluginInfo.ISSUE_KEY_DESC);
        AppMethodBeat.o(6370);
        return wXMediaMessage;
    }
}
