package com.tencent.mm.plugin.record.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.m.g;
import com.tencent.mm.model.aw;
import com.tencent.mm.plugin.fav.a.b;
import com.tencent.mm.plugin.record.a.a;
import com.tencent.mm.plugin.record.a.d;
import com.tencent.mm.plugin.record.a.i;
import com.tencent.mm.plugin.record.b.l;
import com.tencent.mm.plugin.record.b.n;
import com.tencent.mm.pluginsdk.ui.tools.e;
import com.tencent.mm.pluginsdk.ui.tools.q;
import com.tencent.mm.protocal.b.a.c;
import com.tencent.mm.protocal.protobuf.aar;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ak;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.ui.MMActivity;
import com.tencent.mm.ui.MMImageView;
import com.tencent.mm.ui.base.h;
import com.tencent.mm.ui.base.p;
import com.tencent.ytcommon.BuildConfig;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;

public class RecordMsgFileUI extends MMActivity implements d {
    private aar cAv;
    private String cHr;
    private long cvx;
    private ak fbD;
    private TextView gxi;
    private TextView iqU;
    private e klq = null;
    private Button mlD;
    private Button mlE;
    private Button mlF;
    private MMImageView mlG;
    private TextView mlH;
    private View mlI;
    private View mlJ;
    private boolean mlN = false;
    private boolean mlR = false;
    private boolean mlS = false;
    private l pKH;
    private ProgressBar progressBar;

    public void onWindowFocusChanged(boolean z) {
        super.onWindowFocusChanged(z);
        AppMethodBeat.at(this, z);
    }

    static /* synthetic */ void e(RecordMsgFileUI recordMsgFileUI) {
        AppMethodBeat.i(24286);
        recordMsgFileUI.bnS();
        AppMethodBeat.o(24286);
    }

    static /* synthetic */ void f(RecordMsgFileUI recordMsgFileUI) {
        AppMethodBeat.i(24288);
        recordMsgFileUI.bwi();
        AppMethodBeat.o(24288);
    }

    static /* synthetic */ void g(RecordMsgFileUI recordMsgFileUI) {
        AppMethodBeat.i(24289);
        recordMsgFileUI.bwj();
        AppMethodBeat.o(24289);
    }

    static /* synthetic */ String m(RecordMsgFileUI recordMsgFileUI) {
        AppMethodBeat.i(24291);
        String ceR = recordMsgFileUI.ceR();
        AppMethodBeat.o(24291);
        return ceR;
    }

    static /* synthetic */ void p(RecordMsgFileUI recordMsgFileUI) {
        AppMethodBeat.i(24292);
        recordMsgFileUI.bwl();
        AppMethodBeat.o(24292);
    }

    static /* synthetic */ void q(RecordMsgFileUI recordMsgFileUI) {
        AppMethodBeat.i(24293);
        recordMsgFileUI.bwh();
        AppMethodBeat.o(24293);
    }

    public final int getLayoutId() {
        return 2130969546;
    }

    public final int getForceOrientation() {
        return 1;
    }

    public void onCreate(Bundle bundle) {
        AppMethodBeat.i(24272);
        super.onCreate(bundle);
        this.fbD = new ak();
        this.pKH = new l();
        this.cvx = getIntent().getLongExtra("message_id", -1);
        String stringExtra = getIntent().getStringExtra("record_data_id");
        c VI = n.VI(getIntent().getStringExtra("record_xml"));
        if (VI == null) {
            ab.w("MicroMsg.RecordMsgFileUI", "get record msg data error, empty");
            finish();
            AppMethodBeat.o(24272);
            return;
        }
        Iterator it = VI.fjr.iterator();
        while (it.hasNext()) {
            aar aar = (aar) it.next();
            if (aar.mnd.equals(stringExtra)) {
                this.cAv = aar;
            }
        }
        if (this.cAv == null) {
            ab.w("MicroMsg.RecordMsgFileUI", "get data error, empty");
            finish();
            AppMethodBeat.o(24272);
            return;
        }
        this.cHr = n.h(this.cAv.mnd, this.cvx, true);
        this.mlD = (Button) findViewById(2131823997);
        this.mlE = (Button) findViewById(2131823998);
        this.mlF = (Button) findViewById(2131822658);
        this.mlG = (MMImageView) findViewById(2131821226);
        this.gxi = (TextView) findViewById(2131821227);
        this.iqU = (TextView) findViewById(2131823800);
        this.mlJ = findViewById(2131821526);
        this.mlI = findViewById(2131821524);
        this.progressBar = (ProgressBar) findViewById(2131821525);
        this.mlH = (TextView) findViewById(2131823996);
        if (4 == getType()) {
            setMMTitle(2131299761);
        } else if (15 == getType()) {
            setMMTitle(2131299735);
            findViewById(2131823992).setBackgroundResource(2131689761);
        } else {
            setMMTitle(2131299641);
        }
        if (getType() == 4) {
            this.mlG.setImageResource(2131230817);
        } else {
            this.mlG.setImageResource(com.tencent.mm.pluginsdk.d.ail(this.cAv.wgo));
        }
        this.gxi.setText(this.cAv.title);
        setBackBtn(new 1(this));
        this.mlE.setOnClickListener(new 7(this));
        String str = this.cAv.wgg;
        if (!bo.isNullOrNil(str)) {
            this.mlD.setOnClickListener(new 8(this, str));
        }
        this.mlF.setOnClickListener(new 9(this));
        this.mlJ.setOnClickListener(new 10(this));
        if (getType() != 15 || bo.ank(g.Nu().getValue("SightForwardEnable")) == 1) {
            addIconOptionMenu(0, 2130839555, new 11(this));
        } else {
            ab.w("MicroMsg.RecordMsgFileUI", "can not retransmit sight msg");
        }
        boolean z = bo.isNullOrNil(this.cAv.wfZ) || bo.isNullOrNil(this.cAv.wgb);
        boolean z2;
        if (bo.isNullOrNil(this.cAv.whr) || bo.isNullOrNil(this.cAv.who)) {
            z2 = true;
        } else {
            z2 = false;
        }
        if (!z && !z2) {
            bwh();
        } else if (n.d(this.cAv, this.cvx)) {
            enableOptionMenu(true);
            bwl();
        } else {
            i VH = ((a) com.tencent.mm.kernel.g.M(a.class)).getRecordMsgCDNStorage().VH(this.cHr);
            if (VH == null || 2 == VH.field_status) {
                bwj();
            } else if (4 == VH.field_status) {
                bwh();
            } else if (VH.field_status == 0 || 1 == VH.field_status) {
                bwi();
            } else {
                ab.w("MicroMsg.RecordMsgFileUI", "other status, not done, downloading, uploading, downloadfail, uploadfail");
                bwj();
            }
            enableOptionMenu(false);
        }
        ((a) com.tencent.mm.kernel.g.M(a.class)).getRecordMsgCDNStorage().a(this);
        AppMethodBeat.o(24272);
    }

    private int getType() {
        int i = this.cAv.dataType;
        if (i == 15) {
            return 4;
        }
        return i;
    }

    private void bwh() {
        AppMethodBeat.i(24273);
        this.mlF.setVisibility(8);
        this.mlD.setVisibility(8);
        this.mlE.setVisibility(8);
        this.mlI.setVisibility(8);
        this.iqU.setVisibility(0);
        if (this.cAv.dataType == 4) {
            this.iqU.setGravity(17);
            this.iqU.setText(2131299678);
            AppMethodBeat.o(24273);
            return;
        }
        this.iqU.setGravity(17);
        this.iqU.setText(2131299677);
        AppMethodBeat.o(24273);
    }

    private void bwi() {
        AppMethodBeat.i(24274);
        this.mlF.setVisibility(8);
        this.mlD.setVisibility(8);
        this.mlE.setVisibility(8);
        this.iqU.setVisibility(8);
        this.mlI.setVisibility(0);
        c(((a) com.tencent.mm.kernel.g.M(a.class)).getRecordMsgCDNStorage().VH(this.cHr));
        AppMethodBeat.o(24274);
    }

    private void bwj() {
        AppMethodBeat.i(24275);
        this.mlI.setVisibility(8);
        this.mlE.setVisibility(8);
        if (bo.isNullOrNil(this.cAv.wgg)) {
            this.mlD.setVisibility(8);
        } else {
            this.mlD.setVisibility(0);
        }
        this.mlF.setVisibility(0);
        this.mlF.setText(2131299655);
        this.iqU.setVisibility(8);
        AppMethodBeat.o(24275);
    }

    private void bwl() {
        AppMethodBeat.i(24276);
        if (!(getType() != 15 || this.cAv.wgZ == null || bo.isNullOrNil(this.cAv.wgZ.fiG) || bo.isNullOrNil(this.cAv.wgZ.fiK))) {
            this.mlS = true;
            this.mlG.setVisibility(8);
            this.mlI.setVisibility(8);
            this.mlF.setVisibility(8);
            this.mlD.setVisibility(8);
            this.mlE.setVisibility(8);
            this.iqU.setVisibility(8);
            String c = n.c(this.cAv, this.cvx);
            ab.d("MicroMsg.RecordMsgFileUI", com.tencent.mm.compatible.util.g.Mp() + " initView: fullpath:" + c);
            ViewGroup viewGroup = (ViewGroup) findViewById(2131823992);
            this.klq = q.fT(this.mController.ylL);
            LayoutParams layoutParams = new LayoutParams(-1, -2);
            layoutParams.addRule(13);
            viewGroup.addView((View) this.klq, 0, layoutParams);
            this.klq.setVideoCallback(new 12(this));
            ab.d("MicroMsg.RecordMsgFileUI", com.tencent.mm.compatible.util.g.Mp() + " initView :" + c);
            if (c != null) {
                this.klq.stop();
                this.klq.setVideoPath(c);
            }
            ab.d("MicroMsg.RecordMsgFileUI", com.tencent.mm.compatible.util.g.Mp() + " initView");
            if (aw.Cc() != null) {
                aw.Cc().Id();
            }
        }
        if (getType() != 15 && getType() != 4) {
            this.mlI.setVisibility(8);
            this.mlF.setVisibility(4);
            if (bo.isNullOrNil(this.cAv.wgg)) {
                this.mlD.setVisibility(8);
            } else {
                this.mlD.setVisibility(0);
            }
            this.mlE.setVisibility(0);
            this.iqU.setVisibility(0);
        } else if (!this.mlS) {
            this.mlI.setVisibility(8);
            this.mlF.setVisibility(8);
            this.mlD.setVisibility(8);
            this.mlE.setVisibility(0);
            this.mlE.setText(2131299657);
            this.iqU.setVisibility(8);
            bnS();
            AppMethodBeat.o(24276);
            return;
        }
        AppMethodBeat.o(24276);
    }

    public void onDestroy() {
        AppMethodBeat.i(24277);
        if (this.klq != null) {
            this.klq.setVideoCallback(null);
            this.klq.stop();
            this.klq.onDetach();
            if (aw.Cc() != null) {
                aw.Cc().Ic();
            }
        }
        super.onDestroy();
        ((a) com.tencent.mm.kernel.g.M(a.class)).getRecordMsgCDNStorage().b(this);
        this.pKH.destory();
        AppMethodBeat.o(24277);
    }

    public void onResume() {
        AppMethodBeat.i(24278);
        super.onResume();
        if (this.klq != null) {
            this.klq.start();
        }
        AppMethodBeat.o(24278);
    }

    public void onPause() {
        AppMethodBeat.i(24279);
        super.onPause();
        if (this.klq != null) {
            this.klq.stop();
        }
        AppMethodBeat.o(24279);
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        AppMethodBeat.i(24280);
        super.onActivityResult(i, i2, intent);
        com.tencent.mm.pluginsdk.ui.tools.a.a(this, i, i2, intent, true, 2131298926, 2131298927, 5);
        if (i2 != -1) {
            AppMethodBeat.o(24280);
            return;
        }
        if (i == 1001) {
            String str;
            String stringExtra = intent == null ? null : intent.getStringExtra("Select_Conv_User");
            if (intent == null) {
                str = null;
            } else {
                str = intent.getStringExtra("custom_send_text");
            }
            p b = h.b(this.mController.ylL, getString(2131299643), false, null);
            ab.d("MicroMsg.RecordMsgFileUI", "do share msg, fav msg type %d", new Object[]{Integer.valueOf(getType())});
            13 13 = new 13(this, b);
            if (bo.isNullOrNil(stringExtra)) {
                AppMethodBeat.o(24280);
                return;
            }
            ArrayList P = bo.P(stringExtra.split(","));
            if (getType() == 4 || getType() == 15) {
                aw.RS().aa(new 14(this, P, str, 13));
                AppMethodBeat.o(24280);
                return;
            }
            aw.RS().aa(new 2(this, P, str, 13));
        }
        AppMethodBeat.o(24280);
    }

    private String ceR() {
        String absolutePath;
        AppMethodBeat.i(24281);
        File file = new File(n.f(this.cAv, this.cvx));
        if (file.exists()) {
            absolutePath = file.getAbsolutePath();
        } else {
            StringBuilder stringBuilder = new StringBuilder();
            aw.ZK();
            absolutePath = stringBuilder.append(com.tencent.mm.model.c.Yg()).append("web/").append(com.tencent.mm.a.g.x(bo.bc(this.cAv.cvq, BuildConfig.FLAVOR).getBytes())).toString();
        }
        AppMethodBeat.o(24281);
        return absolutePath;
    }

    private void c(i iVar) {
        int i;
        int i2;
        int i3;
        AppMethodBeat.i(24282);
        if (iVar != null) {
            int max = (int) ((((float) iVar.field_offset) / ((float) Math.max(1, iVar.field_totalLen))) * 100.0f);
            i = iVar.field_offset;
            i2 = iVar.field_totalLen;
            i3 = max;
        } else {
            i2 = (int) this.cAv.wgu;
            i = 0;
            i3 = 0;
        }
        this.fbD.post(new 3(this, i3, i, i2));
        AppMethodBeat.o(24282);
    }

    public final void a(int i, i iVar) {
        AppMethodBeat.i(24283);
        if (iVar == null) {
            ab.w("MicroMsg.RecordMsgFileUI", "on cdn info changed, but cdn info is null");
            AppMethodBeat.o(24283);
            return;
        }
        ab.v("MicroMsg.RecordMsgFileUI", "cur mediaid[%s], notify mediaid[%s]", new Object[]{this.cHr, iVar.field_mediaId});
        if (this.cHr.equals(iVar.field_mediaId)) {
            switch (iVar.field_status) {
                case 2:
                    this.fbD.post(new 4(this));
                    AppMethodBeat.o(24283);
                    return;
                case 3:
                    this.fbD.post(new 6(this));
                    AppMethodBeat.o(24283);
                    return;
                case 4:
                    this.fbD.post(new 5(this));
                    AppMethodBeat.o(24283);
                    return;
                default:
                    c(iVar);
                    AppMethodBeat.o(24283);
                    return;
            }
        }
        AppMethodBeat.o(24283);
    }

    private void bnS() {
        AppMethodBeat.i(24284);
        if (this.mlR) {
            AppMethodBeat.o(24284);
            return;
        }
        this.mlR = true;
        Intent intent = new Intent();
        intent.putExtra("key_detail_fav_path", n.c(this.cAv, this.cvx));
        intent.putExtra("key_detail_fav_thumb_path", n.f(this.cAv, this.cvx));
        intent.putExtra("key_detail_fav_video_duration", this.cAv.duration);
        intent.putExtra("key_detail_statExtStr", this.cAv.cMn);
        intent.putExtra("key_detail_fav_video_scene_from", 1);
        b.b(this, ".ui.detail.FavoriteVideoPlayUI", intent);
        finish();
        AppMethodBeat.o(24284);
    }

    static /* synthetic */ void h(RecordMsgFileUI recordMsgFileUI) {
        int i = 1;
        AppMethodBeat.i(24290);
        Intent intent = new Intent();
        intent.putExtra("Select_Conv_Type", 3);
        intent.putExtra("select_is_ret", true);
        intent.putExtra("mutil_select_is_ret", true);
        if (recordMsgFileUI.getType() == 15) {
            i = 11;
            intent.putExtra("image_path", recordMsgFileUI.ceR());
        } else if (recordMsgFileUI.getType() == 4) {
            intent.putExtra("image_path", recordMsgFileUI.ceR());
        } else {
            intent.putExtra("desc_title", recordMsgFileUI.cAv.title);
            i = 3;
        }
        intent.putExtra("Retr_Msg_Type", i);
        com.tencent.mm.bp.d.b(recordMsgFileUI, ".ui.transmit.SelectConversationUI", intent, 1001);
        AppMethodBeat.o(24290);
    }
}
