package com.tencent.mm.plugin.appbrand.share.a;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView.ScaleType;
import com.google.android.gms.common.internal.ImagesContract;
import com.tencent.magicbrush.c;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.at.o;
import com.tencent.mm.kernel.g;
import com.tencent.mm.modelappbrand.a.b.e;
import com.tencent.mm.modelappbrand.a.b.f;
import com.tencent.mm.modelappbrand.ac;
import com.tencent.mm.modelappbrand.i;
import com.tencent.mm.modelappbrand.i.b;
import com.tencent.mm.plugin.appbrand.dynamic.widget.IPCDynamicPageView;
import com.tencent.mm.plugin.appbrand.share.widget.WxaShareMessagePage;
import com.tencent.mm.plugin.appbrand.share.widget.WxaShareMessagePage.1;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.sdk.platformtools.d;
import com.tencent.ytcommon.BuildConfig;
import java.lang.ref.SoftReference;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import junit.framework.Assert;

public final class a implements i {
    private final Map<String, SoftReference<e>> iDL = new ConcurrentHashMap();
    private final Map<String, SoftReference<f>> iDM = new ConcurrentHashMap();
    private final Map<Integer, a> iDN = new ConcurrentHashMap();
    private final Map<Integer, Bundle> iDO = new ConcurrentHashMap();

    public a() {
        AppMethodBeat.i(132743);
        a(1, new 1(this));
        AppMethodBeat.o(132743);
    }

    public final View d(Context context, Bundle bundle) {
        AppMethodBeat.i(132744);
        Assert.assertNotNull(context);
        WxaShareMessagePage wxaShareMessagePage = new WxaShareMessagePage(context);
        if (bundle != null) {
            int i = bundle.getInt("key_biz", com.tencent.mm.af.j.a.fgj.ordinal());
            if (com.tencent.mm.af.j.a.isValid(i)) {
                String string;
                wxaShareMessagePage.iEa = true;
                LayoutParams layoutParams = wxaShareMessagePage.hYX.getLayoutParams();
                layoutParams.width = com.tencent.mm.bz.a.fromDPToPix(wxaShareMessagePage.getContext(), 112);
                layoutParams.height = com.tencent.mm.bz.a.fromDPToPix(wxaShareMessagePage.getContext(), 63);
                wxaShareMessagePage.hYX.setLayoutParams(layoutParams);
                wxaShareMessagePage.hYX.setScaleType(ScaleType.CENTER_CROP);
                layoutParams = wxaShareMessagePage.iDU.getLayoutParams();
                layoutParams.width = com.tencent.mm.bz.a.fromDPToPix(wxaShareMessagePage.getContext(), 112);
                layoutParams.height = com.tencent.mm.bz.a.fromDPToPix(wxaShareMessagePage.getContext(), 63);
                wxaShareMessagePage.iDU.setLayoutParams(layoutParams);
                layoutParams = wxaShareMessagePage.qQ.getLayoutParams();
                layoutParams.width = com.tencent.mm.bz.a.fromDPToPix(wxaShareMessagePage.getContext(), 112);
                layoutParams.height = com.tencent.mm.bz.a.fromDPToPix(wxaShareMessagePage.getContext(), 63);
                wxaShareMessagePage.qQ.setLayoutParams(layoutParams);
                if (com.tencent.mm.af.j.a.fgh.ordinal() == i) {
                    wxaShareMessagePage.iDX.setImageResource(2131231694);
                    wxaShareMessagePage.iDU.setImageResource(2131230907);
                } else if (com.tencent.mm.af.j.a.fgi.ordinal() == i) {
                    string = bundle.getString("key_footer_icon", BuildConfig.FLAVOR);
                    if (!c.isNullOrNil(string)) {
                        o.aho().a(string, new 1(wxaShareMessagePage));
                    }
                }
                string = bundle.getString("key_footer_text", BuildConfig.FLAVOR);
                String string2 = bundle.getString("key_footer_text_default", BuildConfig.FLAVOR);
                if (!string.isEmpty()) {
                    wxaShareMessagePage.iDY.setText(string);
                } else if (!string2.isEmpty()) {
                    wxaShareMessagePage.iDY.setText(string2);
                }
            }
        }
        AppMethodBeat.o(132744);
        return wxaShareMessagePage;
    }

    public final boolean a(String str, View view, Bundle bundle) {
        AppMethodBeat.i(132745);
        boolean a = a(str, view, bundle, null);
        AppMethodBeat.o(132745);
        return a;
    }

    public final boolean a(String str, View view, Bundle bundle, b bVar) {
        AppMethodBeat.i(132746);
        Assert.assertNotNull(view);
        Assert.assertNotNull(bundle);
        if (view instanceof WxaShareMessagePage) {
            ab.i("MicroMsg.WxaShareMessageService", "onBindView(%s, %s)", new Object[]{str, Integer.valueOf(view.hashCode())});
            WxaShareMessagePage wxaShareMessagePage = (WxaShareMessagePage) view;
            boolean z = bundle.getBoolean("is_dynamic_page");
            wxaShareMessagePage.setTitle(bundle.getString("title", BuildConfig.FLAVOR));
            if (z) {
                wxaShareMessagePage.getCoverImageView().setVisibility(4);
                IPCDynamicPageView widgetPageView = wxaShareMessagePage.getWidgetPageView();
                widgetPageView.setVisibility(0);
                bundle.putInt("view_init_width", wxaShareMessagePage.getWidgetWidth());
                bundle.putInt("view_init_height", wxaShareMessagePage.getWidgetHeight());
                ((com.tencent.mm.modelappbrand.e) g.K(com.tencent.mm.modelappbrand.e.class)).a(str, widgetPageView, bundle, new ac(new 2(this, wxaShareMessagePage)));
                a(bVar, 0);
            } else {
                Bitmap decodeByteArray;
                wxaShareMessagePage.getWidgetPageView().setVisibility(4);
                wxaShareMessagePage.getCoverImageView().setVisibility(0);
                byte[] byteArray = bundle.getByteArray(ImagesContract.IMAGE_DATA);
                if (byteArray != null && byteArray.length > 0) {
                    decodeByteArray = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
                    if (!(decodeByteArray == null || decodeByteArray.isRecycled())) {
                        wxaShareMessagePage.setImageData(decodeByteArray);
                        a(bVar, 0);
                        AppMethodBeat.o(132746);
                        return true;
                    }
                }
                String string = bundle.getString("delay_load_img_path");
                if (bo.isNullOrNil(string)) {
                    String string2 = bundle.getString("image_url");
                    if (string2 == null || !(string2.startsWith("http://") || string2.startsWith("https://"))) {
                        if (string2 != null && string2.startsWith("file://")) {
                            decodeByteArray = com.tencent.mm.modelappbrand.a.b.abR().a(string2, null);
                            if (!(decodeByteArray == null || decodeByteArray.isRecycled())) {
                                wxaShareMessagePage.setImageData(decodeByteArray);
                                a(bVar, 0);
                                AppMethodBeat.o(132746);
                                return true;
                            }
                        }
                        wxaShareMessagePage.mr();
                        a(bVar, 1);
                    } else {
                        wxaShareMessagePage.setOnLoadImageResult(bVar);
                        wxaShareMessagePage.setImageUrl(string2);
                    }
                } else {
                    decodeByteArray = null;
                    if (!string.startsWith("delayLoadFile://")) {
                        decodeByteArray = com.tencent.mm.modelappbrand.a.b.abR().a(string, null);
                        ab.i("MicroMsg.WxaShareMessageService", "findCachedLocal(%s)", new Object[]{string});
                    } else if (this.iDO.containsKey(Integer.valueOf(2))) {
                        decodeByteArray = d.aml(string.replace("delayLoadFile://", BuildConfig.FLAVOR));
                        ab.i("MicroMsg.WxaShareMessageService", "getBitmapNative(%s)", new Object[]{string});
                    }
                    if (decodeByteArray != null) {
                        if (decodeByteArray.isRecycled()) {
                            wxaShareMessagePage.setOnLoadImageResult(bVar);
                            wxaShareMessagePage.setImageUrl(string);
                        } else {
                            wxaShareMessagePage.setImageData(decodeByteArray);
                            a(bVar, 0);
                        }
                        AppMethodBeat.o(132746);
                        return true;
                    }
                    ab.i("MicroMsg.WxaShareMessageService", "delay loadImage(%s)", new Object[]{string});
                    wxaShareMessagePage.getLoadingView().setVisibility(0);
                    wxaShareMessagePage.getErrorImageView().setVisibility(4);
                    wxaShareMessagePage.getCoverImageView().setVisibility(4);
                    wxaShareMessagePage.getLoadingView().dKS();
                    a(2, new 3(this, wxaShareMessagePage, bVar));
                }
            }
            AppMethodBeat.o(132746);
            return true;
        }
        AppMethodBeat.o(132746);
        return false;
    }

    private static void a(b bVar, int i) {
        AppMethodBeat.i(132747);
        if (bVar != null) {
            bVar.kQ(i);
        }
        AppMethodBeat.o(132747);
    }

    public final void a(String str, View view) {
        AppMethodBeat.i(132748);
        Assert.assertNotNull(view);
        if (view instanceof WxaShareMessagePage) {
            ab.i("MicroMsg.WxaShareMessageService", "onUnbindView(%s, %s)", new Object[]{str, Integer.valueOf(view.hashCode())});
            ((com.tencent.mm.modelappbrand.e) g.K(com.tencent.mm.modelappbrand.e.class)).a(str, ((WxaShareMessagePage) view).getWidgetPageView());
            this.iDN.remove(Integer.valueOf(2));
            AppMethodBeat.o(132748);
            return;
        }
        AppMethodBeat.o(132748);
    }

    public final synchronized void d(int i, Bundle bundle) {
        AppMethodBeat.i(132749);
        a aVar = (a) this.iDN.get(Integer.valueOf(i));
        if (aVar != null) {
            aVar.C(bundle);
        }
        this.iDO.put(Integer.valueOf(i), bundle);
        ab.i("MicroMsg.WxaShareMessageService", "onAction(%d, %s)", new Object[]{Integer.valueOf(i), bundle});
        AppMethodBeat.o(132749);
    }

    public final e cq(int i, int i2) {
        AppMethodBeat.i(132750);
        e a = a(i, i2, com.tencent.mm.modelappbrand.i.a.fpF);
        AppMethodBeat.o(132750);
        return a;
    }

    /* JADX WARNING: Missing block: B:3:0x002e, code skipped:
            if (r1 == null) goto L_0x0030;
     */
    /* JADX WARNING: Missing block: B:9:0x0041, code skipped:
            if (r1 == null) goto L_0x0043;
     */
    public final com.tencent.mm.modelappbrand.a.b.e a(int r7, int r8, com.tencent.mm.modelappbrand.i.a r9) {
        /*
        r6 = this;
        r5 = 132751; // 0x2068f float:1.86024E-40 double:6.55877E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.i(r5);
        r1 = "%d-%d-dp";
        r2 = 2;
        r2 = new java.lang.Object[r2];
        r3 = 0;
        r4 = java.lang.Integer.valueOf(r7);
        r2[r3] = r4;
        r3 = 1;
        r4 = java.lang.Integer.valueOf(r8);
        r2[r3] = r4;
        r3 = java.lang.String.format(r1, r2);
        r1 = r6.iDL;
        r1 = r1.get(r3);
        r1 = (java.lang.ref.SoftReference) r1;
        if (r1 == 0) goto L_0x0030;
    L_0x0028:
        r1 = r1.get();
        r1 = (com.tencent.mm.modelappbrand.a.b.e) r1;
        if (r1 != 0) goto L_0x006a;
    L_0x0030:
        monitor-enter(r6);
        r1 = r6.iDL;	 Catch:{ all -> 0x006e }
        r1 = r1.get(r3);	 Catch:{ all -> 0x006e }
        r1 = (java.lang.ref.SoftReference) r1;	 Catch:{ all -> 0x006e }
        if (r1 == 0) goto L_0x0043;
    L_0x003b:
        r1 = r1.get();	 Catch:{ all -> 0x006e }
        r1 = (com.tencent.mm.modelappbrand.a.b.e) r1;	 Catch:{ all -> 0x006e }
        if (r1 != 0) goto L_0x0069;
    L_0x0043:
        r1 = com.tencent.mm.sdk.platformtools.ah.getContext();	 Catch:{ all -> 0x006e }
        r1 = com.tencent.mm.bz.a.fromDPToPix(r1, r7);	 Catch:{ all -> 0x006e }
        r2 = com.tencent.mm.sdk.platformtools.ah.getContext();	 Catch:{ all -> 0x006e }
        r4 = com.tencent.mm.bz.a.fromDPToPix(r2, r8);	 Catch:{ all -> 0x006e }
        r2 = new com.tencent.mm.plugin.appbrand.share.a;	 Catch:{ all -> 0x006e }
        r2.<init>(r1, r4);	 Catch:{ all -> 0x006e }
        r0 = r2;
        r0 = (com.tencent.mm.plugin.appbrand.share.a) r0;	 Catch:{ all -> 0x006e }
        r1 = r0;
        r1.iDJ = r9;	 Catch:{ all -> 0x006e }
        r1 = r6.iDL;	 Catch:{ all -> 0x006e }
        r4 = new java.lang.ref.SoftReference;	 Catch:{ all -> 0x006e }
        r4.<init>(r2);	 Catch:{ all -> 0x006e }
        r1.put(r3, r4);	 Catch:{ all -> 0x006e }
        r1 = r2;
    L_0x0069:
        monitor-exit(r6);	 Catch:{ all -> 0x006e }
    L_0x006a:
        com.tencent.matrix.trace.core.AppMethodBeat.o(r5);
        return r1;
    L_0x006e:
        r1 = move-exception;
        monitor-exit(r6);	 Catch:{ all -> 0x006e }
        com.tencent.matrix.trace.core.AppMethodBeat.o(r5);
        throw r1;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.mm.plugin.appbrand.share.a.a.a(int, int, com.tencent.mm.modelappbrand.i$a):com.tencent.mm.modelappbrand.a.b$e");
    }

    /* JADX WARNING: Missing block: B:3:0x0032, code skipped:
            if (r0 == null) goto L_0x0034;
     */
    /* JADX WARNING: Missing block: B:9:0x0045, code skipped:
            if (r0 == null) goto L_0x0047;
     */
    public final com.tencent.mm.modelappbrand.a.b.f abB() {
        /*
        r6 = this;
        r3 = 112; // 0x70 float:1.57E-43 double:5.53E-322;
        r5 = 90;
        r4 = 132752; // 0x20690 float:1.86025E-40 double:6.5588E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.i(r4);
        r0 = "%d-%d-dp";
        r1 = 2;
        r1 = new java.lang.Object[r1];
        r2 = 0;
        r3 = java.lang.Integer.valueOf(r3);
        r1[r2] = r3;
        r2 = 1;
        r3 = java.lang.Integer.valueOf(r5);
        r1[r2] = r3;
        r1 = java.lang.String.format(r0, r1);
        r0 = r6.iDM;
        r0 = r0.get(r1);
        r0 = (java.lang.ref.SoftReference) r0;
        if (r0 == 0) goto L_0x0034;
    L_0x002c:
        r0 = r0.get();
        r0 = (com.tencent.mm.modelappbrand.a.b.f) r0;
        if (r0 != 0) goto L_0x006b;
    L_0x0034:
        monitor-enter(r6);
        r0 = r6.iDM;	 Catch:{ all -> 0x006f }
        r0 = r0.get(r1);	 Catch:{ all -> 0x006f }
        r0 = (java.lang.ref.SoftReference) r0;	 Catch:{ all -> 0x006f }
        if (r0 == 0) goto L_0x0047;
    L_0x003f:
        r0 = r0.get();	 Catch:{ all -> 0x006f }
        r0 = (com.tencent.mm.modelappbrand.a.b.f) r0;	 Catch:{ all -> 0x006f }
        if (r0 != 0) goto L_0x006a;
    L_0x0047:
        r0 = com.tencent.mm.sdk.platformtools.ah.getContext();	 Catch:{ all -> 0x006f }
        r2 = 112; // 0x70 float:1.57E-43 double:5.53E-322;
        r2 = com.tencent.mm.bz.a.fromDPToPix(r0, r2);	 Catch:{ all -> 0x006f }
        r0 = com.tencent.mm.sdk.platformtools.ah.getContext();	 Catch:{ all -> 0x006f }
        r3 = 90;
        r3 = com.tencent.mm.bz.a.fromDPToPix(r0, r3);	 Catch:{ all -> 0x006f }
        r0 = new com.tencent.mm.plugin.appbrand.share.b;	 Catch:{ all -> 0x006f }
        r0.<init>(r2, r3);	 Catch:{ all -> 0x006f }
        r2 = r6.iDM;	 Catch:{ all -> 0x006f }
        r3 = new java.lang.ref.SoftReference;	 Catch:{ all -> 0x006f }
        r3.<init>(r0);	 Catch:{ all -> 0x006f }
        r2.put(r1, r3);	 Catch:{ all -> 0x006f }
    L_0x006a:
        monitor-exit(r6);	 Catch:{ all -> 0x006f }
    L_0x006b:
        com.tencent.matrix.trace.core.AppMethodBeat.o(r4);
        return r0;
    L_0x006f:
        r0 = move-exception;
        monitor-exit(r6);	 Catch:{ all -> 0x006f }
        com.tencent.matrix.trace.core.AppMethodBeat.o(r4);
        throw r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.mm.plugin.appbrand.share.a.a.abB():com.tencent.mm.modelappbrand.a.b$f");
    }

    private void a(int i, a aVar) {
        AppMethodBeat.i(132753);
        this.iDN.put(Integer.valueOf(i), aVar);
        if (this.iDO.containsKey(Integer.valueOf(i))) {
            aVar.C((Bundle) this.iDO.get(Integer.valueOf(i)));
        }
        AppMethodBeat.o(132753);
    }
}
