package com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.component;

import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Looper;
import android.support.v4.content.d;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.bz.a;
import com.tencent.mm.graphics.MMBitmapFactory;
import com.tencent.mm.plugin.sight.decode.ui.b;
import com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.component.widget.AdLandingVideoWrapper;
import com.tencent.mm.pluginsdk.ui.h;
import com.tencent.mm.pluginsdk.ui.tools.VideoPlayerSeekBar;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ag;
import com.tencent.mm.sdk.platformtools.ah;
import com.tencent.mm.sdk.platformtools.ak;
import com.tencent.mm.sdk.platformtools.al;
import com.tencent.mm.vfs.e;
import com.tencent.ytcommon.BuildConfig;
import org.json.JSONException;
import org.json.JSONObject;
import org.xwalk.core.XWalkFeature;

public final class z extends y implements b, h.b {
    private Context context;
    private ak fbD;
    private ProgressBar gtI;
    private View iVh;
    ImageView mOX;
    private long oKj = 0;
    private int playCount = 0;
    AdLandingVideoWrapper raL;
    private VideoPlayerSeekBar raM;
    private ImageView raN;
    boolean raO;
    private ImageView raP;
    private TextView raQ;
    private Runnable raR;
    boolean raS = false;
    boolean raT = false;
    boolean raU = false;
    boolean raV = true;
    boolean raW = true;
    private boolean raX = false;
    private boolean raY = true;
    private boolean raZ = false;
    private boolean rba = false;
    private boolean rbb = false;
    private boolean rbc = false;
    int rbd = 0;
    private int rbe = 0;
    private int rbf = 0;
    int rbg = 0;
    int rbh = 0;
    private ac rbi = null;
    private OnClickListener rbj = new 7(this);
    private OnClickListener rbk = new 8(this);
    private OnClickListener rbl = new 9(this);
    private OnClickListener rbm = new 10(this);

    static /* synthetic */ void b(z zVar) {
        AppMethodBeat.i(37332);
        zVar.bgC();
        AppMethodBeat.o(37332);
    }

    public z(final Context context, com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.z zVar, ViewGroup viewGroup) {
        super(context, zVar, viewGroup);
        AppMethodBeat.i(37314);
        this.context = context;
        this.fbD = new ak(Looper.getMainLooper());
        this.raR = new 1(this);
        this.rbi = new ac() {
            public final void lb(boolean z) {
                AppMethodBeat.i(37305);
                Intent intent = new Intent("com.tencent.mm.adlanding.video_progressbar_change");
                intent.putExtra("show", z ? 1 : 0);
                d.S(context).c(intent);
                AppMethodBeat.o(37305);
            }
        };
        AppMethodBeat.o(37314);
    }

    /* Access modifiers changed, original: protected|final */
    public final int getLayout() {
        return 2130970726;
    }

    /* JADX WARNING: Removed duplicated region for block: B:8:0x00bb  */
    /* JADX WARNING: Removed duplicated region for block: B:20:0x01aa  */
    /* JADX WARNING: Removed duplicated region for block: B:11:0x00c1  */
    /* JADX WARNING: Removed duplicated region for block: B:14:0x0103  */
    public final void cpk() {
        /*
        r12 = this;
        r11 = 37315; // 0x91c3 float:5.229E-41 double:1.8436E-319;
        r10 = 8;
        r9 = 4;
        r3 = 1;
        r4 = 0;
        com.tencent.matrix.trace.core.AppMethodBeat.i(r11);
        r0 = r12.contentView;
        r1 = 2131821333; // 0x7f110315 float:1.9275406E38 double:1.0532596837E-314;
        r1 = r0.findViewById(r1);
        r0 = -16777216; // 0xffffffffff000000 float:-1.7014118E38 double:NaN;
        r1.setBackgroundColor(r0);
        r5 = r12.ieu;
        r2 = r12.iev;
        r0 = r12.qZo;
        r0 = (com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.z) r0;
        r0 = r0.qXw;
        if (r0 != r3) goto L_0x0041;
    L_0x0025:
        r0 = r12.qZo;
        r0 = (com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.z) r0;
        r0 = r0.width;
        r0 = (int) r0;
        if (r0 <= 0) goto L_0x0060;
    L_0x002e:
        r0 = r12.qZo;
        r0 = (com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.z) r0;
        r0 = r0.height;
        r0 = (int) r0;
        r2 = r5 * r0;
        r0 = r12.qZo;
        r0 = (com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.z) r0;
        r0 = r0.width;
        r0 = (int) r0;
        r0 = r2 / r0;
        r2 = r0;
    L_0x0041:
        r0 = r12.qZo;
        r0 = (com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.z) r0;
        r0 = r0.qWS;
        r6 = (int) r0;
        r0 = r12.qZo;
        r0 = (com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.z) r0;
        r0 = r0.qWQ;
        r7 = (int) r0;
        r0 = r12.qZo;
        r0 = (com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.z) r0;
        r0 = r0.qWT;
        r8 = (int) r0;
        r0 = r12.qZo;
        r0 = (com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.z) r0;
        r0 = r0.qWR;
        r0 = (int) r0;
        r1.setPadding(r6, r7, r8, r0);
    L_0x0060:
        r0 = new android.widget.RelativeLayout$LayoutParams;
        r0.<init>(r5, r2);
        r1.setLayoutParams(r0);
        r1.setMinimumHeight(r2);
        r0 = 2131821402; // 0x7f11035a float:1.9275546E38 double:1.053259718E-314;
        r0 = r1.findViewById(r0);
        r0 = (com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.component.widget.AdLandingVideoWrapper) r0;
        r12.raL = r0;
        r0 = r12.raL;
        r0.setIMMVideoViewCallback(r12);
        r0 = r12.raL;
        r2 = r12.rbm;
        r0.setOnClickListener(r2);
        r2 = r12.raL;
        r0 = r12.qZo;
        r0 = (com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.z) r0;
        r0 = r0.qWH;
        r2.c(r4, r0, r4);
        r0 = r12.raL;
        r0.setIsShowBasicControls(r3);
        r0 = 2131821219; // 0x7f1102a3 float:1.9275175E38 double:1.0532596274E-314;
        r0 = r1.findViewById(r0);
        r0 = (android.widget.ProgressBar) r0;
        r12.gtI = r0;
        r0 = 2131821511; // 0x7f1103c7 float:1.9275767E38 double:1.0532597717E-314;
        r0 = r1.findViewById(r0);
        r0 = (android.widget.ImageView) r0;
        r12.mOX = r0;
        r2 = "adId";
        r0 = r12.qZo;
        r0 = (com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.z) r0;
        r0 = r0.qXv;
        r0 = com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.h.gj(r2, r0);
        r2 = com.tencent.mm.vfs.e.ct(r0);
        if (r2 != 0) goto L_0x00bd;
    L_0x00bb:
        r12.rbb = r4;
    L_0x00bd:
        r2 = r12.rbb;
        if (r2 == 0) goto L_0x01aa;
    L_0x00c1:
        r2 = r12.mOX;
        r0 = com.tencent.mm.graphics.MMBitmapFactory.decodeFile(r0);
        r2.setImageBitmap(r0);
    L_0x00ca:
        r0 = 2131827572; // 0x7f111b74 float:1.928806E38 double:1.053262766E-314;
        r0 = r1.findViewById(r0);
        r0 = (android.widget.TextView) r0;
        r12.raQ = r0;
        r0 = r12.raQ;
        r2 = r12.context;
        r6 = 2131298922; // 0x7f090a6a float:1.821583E38 double:1.0530015784E-314;
        r2 = r2.getString(r6);
        r0.setText(r2);
        r0 = 2131827636; // 0x7f111bb4 float:1.928819E38 double:1.053262798E-314;
        r0 = r1.findViewById(r0);
        r12.iVh = r0;
        r0 = r12.iVh;
        r0.setVisibility(r9);
        r0 = new com.tencent.mm.pluginsdk.ui.tools.VideoPlayerSeekBar;
        r2 = r12.context;
        r0.<init>(r2);
        r12.raM = r0;
        r0 = r12.raM;
        r0.setVisibility(r9);
        r0 = r12.rbi;
        if (r0 == 0) goto L_0x0111;
    L_0x0103:
        r2 = r12.rbi;
        r0 = r12.raM;
        r0 = r0.getVisibility();
        if (r0 != 0) goto L_0x01c0;
    L_0x010d:
        r0 = r3;
    L_0x010e:
        r2.lb(r0);
    L_0x0111:
        r0 = r12.raM;
        r0.setIplaySeekCallback(r12);
        r0 = r12.raM;
        r2 = r12.rbj;
        r0.setOnPlayButtonClickListener(r2);
        r2 = new android.widget.RelativeLayout$LayoutParams;
        r0 = r12.context;
        r3 = 30;
        r0 = com.tencent.mm.bz.a.fromDPToPix(r0, r3);
        r0 = r5 - r0;
        r3 = -2;
        r2.<init>(r0, r3);
        r0 = 12;
        r2.addRule(r0);
        r0 = r12.raM;
        r0.setLayoutParams(r2);
        r0 = r12.raL;
        r3 = r12.raM;
        r0.setVideoFooterView(r3);
        r0 = 2131827637; // 0x7f111bb5 float:1.9288192E38 double:1.0532627983E-314;
        r0 = r1.findViewById(r0);
        r0 = (android.widget.ImageView) r0;
        r12.raN = r0;
        r0 = r12.raN;
        r0.setVisibility(r9);
        r0 = r12.raN;
        r3 = r12.rbk;
        r0.setOnClickListener(r3);
        r0 = r12.raN;
        r3 = r12.context;
        r3 = com.tencent.mm.bz.a.fromDPToPix(r3, r10);
        r0.setPadding(r4, r4, r3, r4);
        r0 = 2131820981; // 0x7f1101b5 float:1.9274692E38 double:1.05325951E-314;
        r0 = r1.findViewById(r0);
        r0 = (android.widget.ImageView) r0;
        r12.raP = r0;
        r0 = r12.raP;
        r3 = r12.context;
        r5 = 2131231923; // 0x7f0804b3 float:1.807994E38 double:1.0529684765E-314;
        r3 = com.tencent.mm.bz.a.g(r3, r5);
        r0.setImageDrawable(r3);
        r0 = r12.raP;
        r0.setVisibility(r10);
        r0 = r12.raP;
        r3 = r12.rbl;
        r0.setOnClickListener(r3);
        r0 = r12.raM;
        r0 = r0.getParent();
        r0 = (android.view.ViewGroup) r0;
        r3 = r12.raM;
        r0.removeView(r3);
        r2.bottomMargin = r4;
        r0 = r1;
        r0 = (android.view.ViewGroup) r0;
        r1 = r12.raM;
        r0.addView(r1, r2);
        r0 = r12.raL;
        r1 = new com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.component.z$6;
        r1.<init>(r12);
        r0.setVideoPlayCallback(r1);
        com.tencent.matrix.trace.core.AppMethodBeat.o(r11);
        return;
    L_0x01aa:
        r2 = "adId";
        r0 = r12.qZo;
        r0 = (com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.z) r0;
        r0 = r0.qXv;
        r6 = 1000000001; // 0x3b9aca01 float:0.004723788 double:4.940656463E-315;
        r7 = new com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.component.z$5;
        r7.<init>();
        com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.h.c(r2, r0, r4, r6, r7);
        goto L_0x00ca;
    L_0x01c0:
        r0 = r4;
        goto L_0x010e;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.component.z.cpk():void");
    }

    /* Access modifiers changed, original: protected|final */
    public final void cpp() {
    }

    private void bgC() {
        AppMethodBeat.i(37316);
        ab.d("MicroMsg.Sns.AdLandingPageStreamVideoPlayerComponent", "starting play");
        if (this.rba) {
            ab.i("MicroMsg.Sns.AdLandingPageStreamVideoPlayerComponent", "last download fail ,try again");
            this.raL.c(false, ((com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.z) this.qZo).qWH, 0);
            Dp(0);
            this.raL.cpT();
            AppMethodBeat.o(37316);
            return;
        }
        this.fbD.post(new 11(this));
        this.oKj = System.currentTimeMillis();
        this.playCount++;
        AppMethodBeat.o(37316);
    }

    /* Access modifiers changed, original: final */
    public final void cpN() {
        AppMethodBeat.i(37317);
        ab.d("MicroMsg.Sns.AdLandingPageStreamVideoPlayerComponent", "pause play");
        this.fbD.post(new Runnable() {
            public final void run() {
                AppMethodBeat.i(37303);
                z.this.raL.pause();
                AppMethodBeat.o(37303);
            }
        });
        if (this.oKj != 0) {
            this.rbe = (int) (((long) this.rbe) + (System.currentTimeMillis() - this.oKj));
            this.oKj = 0;
        }
        AppMethodBeat.o(37317);
    }

    /* Access modifiers changed, original: final */
    public final void la(boolean z) {
        AppMethodBeat.i(37318);
        if (z) {
            this.raM.setVisibility(0);
            this.raN.setVisibility(0);
            this.iVh.setVisibility(0);
            if (this.rbi != null) {
                this.rbi.lb(true);
            }
            this.fbD.postDelayed(this.raR, 5000);
            AppMethodBeat.o(37318);
            return;
        }
        this.raU = false;
        this.raM.setVisibility(4);
        this.raN.setVisibility(8);
        this.iVh.setVisibility(4);
        if (this.rbi != null) {
            this.rbi.lb(false);
        }
        this.fbD.removeCallbacks(this.raR);
        AppMethodBeat.o(37318);
    }

    /* Access modifiers changed, original: final */
    public final void Dp(int i) {
        AppMethodBeat.i(37319);
        if (this.raL != null) {
            this.raP.setVisibility(8);
            if (this.mOX.getVisibility() == 0) {
                this.gtI.setVisibility(0);
            }
            this.raL.e((double) i, true);
        }
        AppMethodBeat.o(37319);
    }

    public final void coY() {
        AppMethodBeat.i(37320);
        super.coY();
        this.raN.setImageDrawable(a.g(this.context, 2130839142));
        this.raL.setMute(true);
        this.raV = true;
        AppMethodBeat.o(37320);
    }

    public final void cpd() {
        AppMethodBeat.i(37321);
        super.cpd();
        this.raN.setImageDrawable(a.g(this.context, 2130839143));
        this.raL.setMute(false);
        this.raV = false;
        AppMethodBeat.o(37321);
    }

    public final void cpa() {
        AppMethodBeat.i(37322);
        super.cpa();
        AppMethodBeat.o(37322);
    }

    public final void cpb() {
        AppMethodBeat.i(37323);
        super.cpb();
        cpN();
        if (this.raX || this.raY) {
            this.raY = false;
            this.raX = false;
            if (this.rbd == 1) {
                this.rbd = 2;
            }
            AppMethodBeat.o(37323);
            return;
        }
        AppMethodBeat.o(37323);
    }

    public final void coZ() {
        AppMethodBeat.i(37324);
        super.coZ();
        this.raL.aEX();
        AppMethodBeat.o(37324);
    }

    public final void cpc() {
        AppMethodBeat.i(37325);
        super.cpc();
        int cpw = cpw();
        int height = getView().getHeight();
        ab.d("MicroMsg.Sns.AdLandingPageStreamVideoPlayerComponent", "inScreenHeight %d, height %d", new Object[]{Integer.valueOf(cpw), Integer.valueOf(height)});
        if (cpw == 0 || height == 0) {
            AppMethodBeat.o(37325);
        } else if (cpw < 0) {
            AppMethodBeat.o(37325);
        } else if (((float) cpw) < ((float) height) * 0.5f) {
            this.raY = false;
            this.raX = false;
            cpN();
            if (this.rbd == 1) {
                this.rbd = 2;
            }
            AppMethodBeat.o(37325);
        } else if (!this.raX || this.raY) {
            this.raY = false;
            this.raX = true;
            this.mOX.setVisibility(0);
            NetworkInfo activeNetworkInfo = ((ConnectivityManager) ah.getContext().getSystemService("connectivity")).getActiveNetworkInfo();
            if (!this.raW || (this.raW && activeNetworkInfo != null && activeNetworkInfo.getType() == 1)) {
                la(true);
                al.n(new 3(this), 3000);
            }
            if (this.raW) {
                if (activeNetworkInfo == null || !(activeNetworkInfo == null || activeNetworkInfo.getType() == 1)) {
                    this.raP.setVisibility(0);
                    this.raZ = false;
                    this.raW = false;
                    AppMethodBeat.o(37325);
                    return;
                }
                this.raZ = true;
                this.raW = false;
            }
            if (this.rbd == 0) {
                if (activeNetworkInfo != null && activeNetworkInfo.getType() == 1) {
                    if (this.raV) {
                        coY();
                    } else {
                        cpd();
                    }
                    this.rbd = 1;
                }
                AppMethodBeat.o(37325);
            } else if (this.rbd == 2) {
                if (this.raV) {
                    coY();
                } else {
                    cpd();
                }
                bgC();
                this.rbd = 1;
                AppMethodBeat.o(37325);
                return;
            } else {
                if (this.rbd == 3) {
                    if (this.raV) {
                        coY();
                    } else {
                        cpd();
                    }
                }
                AppMethodBeat.o(37325);
            }
            bgC();
            AppMethodBeat.o(37325);
        } else {
            AppMethodBeat.o(37325);
        }
    }

    public final boolean al(JSONObject jSONObject) {
        AppMethodBeat.i(37326);
        if (super.al(jSONObject)) {
            try {
                String ck;
                JSONObject jSONObject2;
                jSONObject.put("streamVideoDuraion", this.raL.getVideoDurationSec() * XWalkFeature.INTERFACE_GEO_LOCATION_PERMISSION);
                jSONObject.put("playTimeInterval", this.rbe);
                jSONObject.put("playCount", this.playCount);
                jSONObject.put("playCompletedCount", this.rbf);
                jSONObject.put("clickPlayControlCount", this.rbg);
                jSONObject.put("clickVoiceControlCount", this.rbh);
                jSONObject.put("isAutoPlay", this.raZ ? "1" : "0");
                if (!this.rbb) {
                    ck = ag.ck(((com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.z) this.qZo).qXv);
                    jSONObject2 = new JSONObject();
                    jSONObject2.put("urlMd5", ck);
                    jSONObject2.put("needDownload", 1);
                    jSONObject.put("thumbUrlInfo", jSONObject2);
                }
                if (!this.rbc) {
                    ck = ag.ck(((com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.z) this.qZo).qWH);
                    jSONObject2 = new JSONObject();
                    jSONObject2.put("urlMd5", ck);
                    jSONObject2.put("needDownload", 1);
                    jSONObject.put("streamVideoUrlInfo", jSONObject2);
                }
                AppMethodBeat.o(37326);
                return true;
            } catch (JSONException e) {
                ab.printErrStackTrace("MicroMsg.Sns.AdLandingPageStreamVideoPlayerComponent", e, BuildConfig.FLAVOR, new Object[0]);
                AppMethodBeat.o(37326);
                return false;
            }
        }
        AppMethodBeat.o(37326);
        return false;
    }

    public final void aFw() {
        this.raU = true;
    }

    public final void oA(int i) {
        AppMethodBeat.i(37327);
        ab.i("MicroMsg.Sns.AdLandingPageStreamVideoPlayerComponent", "onSeek time ".concat(String.valueOf(i)));
        if (this.raV) {
            coY();
        } else {
            cpe();
            cpd();
        }
        Dp(i);
        AppMethodBeat.o(37327);
    }

    public final void cp(String str, String str2) {
        this.rba = false;
    }

    public final void cq(String str, String str2) {
        AppMethodBeat.i(37328);
        this.rbf++;
        la(true);
        this.raL.rcg.stopTimer();
        if (this.oKj != 0) {
            this.rbe = (int) (((long) this.rbe) + (System.currentTimeMillis() - this.oKj));
            this.oKj = 0;
        }
        this.rbd = 5;
        this.raL.akV();
        AppMethodBeat.o(37328);
    }

    public final void cr(String str, String str2) {
    }

    public final void cs(String str, String str2) {
        AppMethodBeat.i(37329);
        this.mOX.setVisibility(8);
        this.gtI.setVisibility(8);
        AppMethodBeat.o(37329);
    }

    public final void d(String str, String str2, int i, int i2) {
    }

    public final void c(String str, String str2, String str3, int i, int i2) {
        AppMethodBeat.i(37330);
        ab.e("MicroMsg.Sns.AdLandingPageStreamVideoPlayerComponent", "online play error, %s", new Object[]{str3});
        this.rba = true;
        AppMethodBeat.o(37330);
    }

    public final void ct(String str, String str2) {
    }

    public final void cu(String str, String str2) {
    }

    public final void cpA() {
        AppMethodBeat.i(37331);
        super.cpA();
        cpN();
        String gj = com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.h.gj("adId", ((com.tencent.mm.plugin.sns.storage.AdLandingPagesStorage.AdLandingPageComponent.z) this.qZo).qXv);
        if (e.ct(gj)) {
            this.mOX.setImageBitmap(MMBitmapFactory.decodeFile(gj));
            this.mOX.setVisibility(0);
        }
        AppMethodBeat.o(37331);
    }
}
