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

import android.content.Context;
import android.content.Intent;
import android.util.Base64;
import com.google.android.gms.common.internal.ImagesContract;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.a.e;
import com.tencent.mm.a.g;
import com.tencent.mm.modelsfs.FileOp;
import com.tencent.mm.plugin.emoji.h.b;
import com.tencent.mm.plugin.emoji.model.EmojiLogic;
import com.tencent.mm.plugin.emoji.model.j;
import com.tencent.mm.plugin.webview.luggage.c.c;
import com.tencent.mm.plugin.webview.luggage.d;
import com.tencent.mm.plugin.webview.luggage.jsapi.bc.a;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.ui.MMActivity;
import com.tencent.ytcommon.BuildConfig;
import java.io.File;
import org.json.JSONObject;

public class aw extends bd<d> {
    static /* synthetic */ void a(aw awVar, Context context, String str, a aVar) {
        AppMethodBeat.i(6381);
        awVar.b(context, str, aVar);
        AppMethodBeat.o(6381);
    }

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

    public final int biG() {
        return 2;
    }

    public final void b(com.tencent.luggage.d.a.a aVar) {
    }

    public final void a(Context context, String str, a aVar) {
        AppMethodBeat.i(6379);
        ab.i("MicroMsg.JsApiShareEmotion", "invoke");
        JSONObject AI = c.AI(str);
        if (AI == null) {
            ab.e("MicroMsg.JsApiShareEmotion", "data is null");
            aVar.d("null_data", null);
            AppMethodBeat.o(6379);
            return;
        }
        String optString = AI.optString("base64DataString");
        String optString2 = AI.optString(ImagesContract.URL);
        String L;
        if (bo.isNullOrNil(optString)) {
            ab.i("MicroMsg.JsApiShareEmotion", "doShareEmoticon use url:%s", new Object[]{optString2});
            File file = new File(context.getCacheDir(), g.x(optString2.getBytes()));
            if (file.exists()) {
                optString2 = g.v(file);
                L = EmojiLogic.L(b.Yb(), BuildConfig.FLAVOR, optString2);
                if (!FileOp.ct(L)) {
                    FileOp.y(file.getAbsolutePath(), L);
                }
                b(context, optString2, aVar);
                AppMethodBeat.o(6379);
                return;
            }
            com.tencent.mm.at.a.a.c.a aVar2 = new com.tencent.mm.at.a.a.c.a();
            aVar2.ePH = true;
            aVar2.ePJ = file.getAbsolutePath();
            aVar2.eQd = new Object[]{file.getAbsolutePath()};
            j.bjW().a(optString2, null, aVar2.ahG(), new 1(this, optString2, context, aVar));
            AppMethodBeat.o(6379);
            return;
        }
        ab.i("MicroMsg.JsApiShareEmotion", "use base64DataString");
        int indexOf = optString.indexOf(";base64,");
        optString2 = BuildConfig.FLAVOR;
        if (indexOf != -1) {
            optString2 = optString.substring(indexOf + 8, optString.length());
        }
        try {
            byte[] decode = Base64.decode(optString2, 0);
            if (bo.cb(decode)) {
                aVar.d("fail", null);
                AppMethodBeat.o(6379);
                return;
            }
            optString = g.x(decode);
            L = EmojiLogic.L(b.Yb(), BuildConfig.FLAVOR, optString);
            if (!(e.ct(L) && g.cz(L).equalsIgnoreCase(optString))) {
                e.b(L, decode, decode.length);
            }
            b(context, optString, aVar);
            AppMethodBeat.o(6379);
        } catch (Exception e) {
            ab.e("MicroMsg.JsApiShareEmotion", "doShareEmoticon error:" + e.getMessage());
            aVar.d("base64_decode_fail", null);
            AppMethodBeat.o(6379);
        }
    }

    private void b(Context context, String str, a aVar) {
        AppMethodBeat.i(6380);
        Intent intent = new Intent();
        intent.putExtra("scene_from", 4);
        intent.putExtra("Select_Conv_Type", 3);
        intent.putExtra("select_is_ret", true);
        intent.putExtra("mutil_select_is_ret", true);
        intent.putExtra("Retr_Msg_Type", 5);
        intent.putExtra("Retr_Msg_thumb_path", str);
        intent.putExtra("MMActivity.OverrideEnterAnimation", 2131034180);
        if (context instanceof MMActivity) {
            ((MMActivity) context).ifE = new 2(this, context, aVar);
            com.tencent.mm.bp.d.b(context, ".ui.transmit.SelectConversationUI", intent, hashCode() & 65535);
        }
        AppMethodBeat.o(6380);
    }
}
