package com.tencent.mm.plugin.appbrand.i;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.TextUtils;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.kernel.g;
import com.tencent.mm.modelappbrand.a.b;
import com.tencent.mm.modelappbrand.j;
import com.tencent.mm.plugin.appbrand.config.WxaAttributes;
import com.tencent.mm.plugin.appbrand.r.o;
import com.tencent.mm.plugin.appbrand.service.d;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.neattextview.textview.view.NeatTextView;
import com.tencent.ytcommon.BuildConfig;
import java.lang.ref.WeakReference;

public class a implements j {
    public final CharSequence a(String str, Bundle bundle, WeakReference<Context> weakReference, WeakReference<NeatTextView> weakReference2) {
        AppMethodBeat.i(132268);
        com.tencent.mm.af.a.a mk = com.tencent.mm.af.a.a.mk(str);
        if (((Context) weakReference.get()) == null) {
            ab.w("MicroMsg.WxaSubscribeMsgService", "context is null");
            AppMethodBeat.o(132268);
            return null;
        }
        String str2 = mk.content;
        if (bo.isNullOrNil(str2)) {
            ab.w("MicroMsg.WxaSubscribeMsgService", "content is null, return");
            AppMethodBeat.o(132268);
            return null;
        }
        String string = bundle.getString("conv_talker_username");
        int i = bundle.getInt("scene");
        long j = bundle.getLong("msg_sever_id");
        String string2 = bundle.getString("send_msg_username");
        CharSequence spannableString = new SpannableString(str2);
        spannableString.setSpan(new 1(this, mk, string, i, j, string2), str2.indexOf(mk.title), str2.indexOf(mk.title) + mk.title.length(), 17);
        ab.i("MicroMsg.WxaSubscribeMsgService", "wxaSubscribeSysContent.forbids:%d", new Object[]{Integer.valueOf(mk.fjV)});
        if (mk.fjV == 1) {
            AppMethodBeat.o(132268);
            return spannableString;
        }
        WxaAttributes zb = ((d) g.K(d.class)).zb(mk.username);
        String str3 = zb != null ? zb.field_brandIconURL : BuildConfig.FLAVOR;
        CharSequence concat;
        if (b.abR().a(str3, null) == null) {
            b.abR().a(new 2(this, weakReference2, weakReference, spannableString), str3, null);
            concat = TextUtils.concat(new CharSequence[]{a(r0, mk.fjW, null), spannableString});
            AppMethodBeat.o(132268);
            return concat;
        }
        concat = TextUtils.concat(new CharSequence[]{a(r0, mk.fjW, b.abR().a(str3, null)), spannableString});
        AppMethodBeat.o(132268);
        return concat;
    }

    private static SpannableString a(Context context, int i, Bitmap bitmap) {
        Drawable drawable;
        AppMethodBeat.i(132269);
        if (bitmap == null) {
            drawable = context.getResources().getDrawable(i == 1 ? 2131232002 : 2131232001);
        } else {
            drawable = new BitmapDrawable(context.getResources(), bitmap);
        }
        drawable.setBounds(0, 0, o.aNT(), o.aNT());
        com.tencent.mm.plugin.appbrand.widget.h.b bVar = new com.tencent.mm.plugin.appbrand.widget.h.b(drawable);
        SpannableString spannableString = new SpannableString("@ ");
        spannableString.setSpan(bVar, 0, 1, 33);
        AppMethodBeat.o(132269);
        return spannableString;
    }
}
