package com.tencent.mm.plugin.sns.ui.c.a;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.AccelerateInterpolator;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.bz.a;
import com.tencent.mm.plugin.sight.decode.a.b.f;
import com.tencent.mm.plugin.sight.decode.ui.SightPlayImageView;
import com.tencent.mm.plugin.sns.a.b.g;
import com.tencent.mm.plugin.sns.data.i;
import com.tencent.mm.plugin.sns.model.af;
import com.tencent.mm.plugin.sns.model.an;
import com.tencent.mm.plugin.sns.storage.b.h;
import com.tencent.mm.plugin.sns.storage.n;
import com.tencent.mm.plugin.sns.ui.MaskImageView;
import com.tencent.mm.plugin.sns.ui.aj;
import com.tencent.mm.plugin.sns.ui.d.b;
import com.tencent.mm.protocal.protobuf.TimeLineObject;
import com.tencent.mm.protocal.protobuf.bau;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.storage.az;
import com.tencent.mm.ui.widget.MMPinProgressBtn;
import com.tencent.mm.ui.widget.QImageView;
import com.tencent.mm.ui.widget.RoundedCornerRelativeLayout;
import com.tencent.mm.vfs.e;

public final class d extends a {
    Context context;
    public int currentIndex;
    boolean rEC = false;
    public View rHf;
    public View rHg;
    private int[] rHh = new int[]{2131827917, 2131827918};
    private final int rHi = 2131827919;
    g rqn;

    public d(TimeLineObject timeLineObject, n nVar, b bVar, g gVar) {
        AppMethodBeat.i(40109);
        this.timeLineObject = timeLineObject;
        this.ros = nVar;
        this.rqo = bVar;
        this.rqn = gVar;
        AppMethodBeat.o(40109);
    }

    public final void g(View view, View view2) {
        AppMethodBeat.i(40110);
        this.contentView = view;
        this.rpP = view2;
        this.context = view.getContext();
        WindowManager windowManager = (WindowManager) this.context.getSystemService("window");
        int min = ((((Math.min(windowManager.getDefaultDisplay().getWidth(), windowManager.getDefaultDisplay().getHeight()) - a.al(this.context, 2131428663)) - a.al(this.context, 2131427865)) - this.context.getResources().getDimensionPixelSize(2131427812)) - this.context.getResources().getDimensionPixelSize(2131427812)) - this.context.getResources().getDimensionPixelSize(2131427858);
        LayoutParams layoutParams = (LayoutParams) view.getLayoutParams();
        layoutParams.topMargin = this.context.getResources().getDimensionPixelOffset(2131427796);
        layoutParams.bottomMargin = 0;
        layoutParams.width = min;
        layoutParams.height = min;
        view.setLayoutParams(layoutParams);
        ((RoundedCornerRelativeLayout) view).setRadius(8.0f);
        if (view.getParent() instanceof ViewGroup) {
            ((ViewGroup) view.getParent()).setClipChildren(false);
            ((ViewGroup) view.getParent()).setClipToPadding(false);
        }
        for (int findViewById : this.rHh) {
            MaskImageView maskImageView = (MaskImageView) view.findViewById(findViewById);
            maskImageView.setVisibility(8);
            maskImageView.setOnTouchListener(new 1(this));
        }
        View findViewById2 = view.findViewById(this.rHi);
        findViewById2.setBackground(null);
        findViewById2.setVisibility(8);
        ((ViewGroup) findViewById2).setClipChildren(false);
        this.rGD = new aj();
        this.rGD.rnt = findViewById2;
        this.rGD.rns = this.rGD.rnt;
        this.rGD.qzM = (com.tencent.mm.plugin.sight.decode.a.a) this.rGD.rnt.findViewById(2131820629);
        this.rGD.raP = (ImageView) this.rGD.rnt.findViewById(2131820981);
        this.rGD.rnu = (MMPinProgressBtn) this.rGD.rnt.findViewById(2131821370);
        this.rGD.rnv = (TextView) this.rGD.rnt.findViewById(2131827571);
        this.rGD.raQ = (TextView) this.rGD.rnt.findViewById(2131827572);
        this.rGD.rnt.setTag(this);
        this.rGD.rnt.setOnClickListener(null);
        ((SightPlayImageView) this.rGD.qzM).qyI = true;
        ((SightPlayImageView) this.rGD.qzM).setScaleType(QImageView.a.zNT);
        this.rGD.qzM.fi(min, min);
        view.setLayerType(2, null);
        this.rHg = view.findViewById(2131827920);
        this.rHf = view.findViewById(2131827923);
        Eq(0);
        AppMethodBeat.o(40110);
    }

    /* Access modifiers changed, original: final */
    public final void Eq(int i) {
        AppMethodBeat.i(40111);
        if (this.rHg == null || this.rHf == null) {
            AppMethodBeat.o(40111);
            return;
        }
        this.currentIndex = i;
        this.rHg.setVisibility(8);
        this.rHf.setVisibility(8);
        ((TextView) this.contentView.findViewById(2131827921)).setText(null);
        ((TextView) this.contentView.findViewById(2131827924)).setText(null);
        ((TextView) this.contentView.findViewById(2131827922)).setText(null);
        ((TextView) this.contentView.findViewById(2131827925)).setText(null);
        int[][] iArr = new int[][]{new int[]{2131827924, 2131827925}, new int[]{2131827921, 2131827922}, new int[]{2131827921, 2131827925}};
        com.tencent.mm.plugin.sns.storage.b cqo = this.ros.cqo();
        if (!(cqo.qUX == null || cqo.qUX.qVt == null || cqo.qUX.qVt.size() < 2)) {
            h hVar = (h) cqo.qUX.qVt.get(i);
            if (hVar.qVk >= 0 && hVar.qVk < 3) {
                int[] iArr2 = iArr[hVar.qVk];
                TextView textView = (TextView) this.contentView.findViewById(iArr2[0]);
                TextView textView2 = (TextView) this.contentView.findViewById(iArr2[1]);
                if (bo.isNullOrNil(hVar.title)) {
                    textView.setVisibility(8);
                } else {
                    textView.setVisibility(0);
                    textView.setText(hVar.title);
                }
                if (bo.isNullOrNil(hVar.desc)) {
                    textView2.setVisibility(8);
                } else {
                    textView2.setVisibility(0);
                    textView2.setText(hVar.desc);
                }
                ((View) textView.getParent()).setVisibility(0);
                ((View) textView2.getParent()).setVisibility(0);
            }
        }
        AppMethodBeat.o(40111);
    }

    public final void cuV() {
        AppMethodBeat.i(40112);
        if (this.timeLineObject.xfI.wbK.size() >= 2) {
            int i = this.ros.field_likeFlag == 1 ? 1 : 0;
            if (this.rqn != null && ((bau) this.timeLineObject.xfI.wbK.get(i)).jCt == 6) {
                this.rqn.x(this.ros.field_snsId, this.ros.field_likeFlag == 1);
            }
            if (this.rEC) {
                ab.i("MicroMsg.TurnCardAdDetailItem", "isPlayAnimation, return");
                AppMethodBeat.o(40112);
                return;
            }
            int i2;
            int i3;
            int i4;
            int i5;
            if (this.ros.field_likeFlag == 1) {
                i2 = 0;
                i3 = 1;
            } else {
                i2 = 1;
                i3 = 0;
            }
            bau bau = (bau) this.timeLineObject.xfI.wbK.get(i2);
            View a = a((bau) this.timeLineObject.xfI.wbK.get(i3), i3, false);
            View a2 = a(bau, i2, true);
            i = ((WindowManager) this.context.getSystemService("window")).getDefaultDisplay().getWidth();
            int[] iArr = new int[2];
            this.contentView.getLocationOnScreen(iArr);
            this.contentView.setPivotY((float) ((i / 2) - iArr[1]));
            this.contentView.setCameraDistance(8000.0f);
            float width = ((float) this.contentView.getWidth()) / 2.0f;
            float height = ((float) this.contentView.getHeight()) / 2.0f;
            if (this.ros.field_likeFlag == 1) {
                i4 = -90;
                i5 = 90;
            } else {
                i4 = 90;
                i5 = -90;
            }
            com.tencent.mm.plugin.sns.ui.widget.a aVar = new com.tencent.mm.plugin.sns.ui.widget.a(this.context, 0.0f, (float) i5, width, height, true);
            aVar.setDuration(187);
            aVar.setInterpolator(new AccelerateInterpolator());
            aVar.setAnimationListener(new 2(this, a2, a, i2, i4, width, height));
            this.contentView.startAnimation(aVar);
            this.rEC = true;
        }
        AppMethodBeat.o(40112);
    }

    private View a(bau bau, int i, boolean z) {
        AppMethodBeat.i(40113);
        int[] iArr = new int[]{2131827917, 2131827918};
        View findViewById;
        if (z) {
            findViewById = this.contentView.findViewById(iArr[i]);
            AppMethodBeat.o(40113);
            return findViewById;
        } else if (bau.jCt == 6) {
            findViewById = this.contentView.findViewById(2131827919);
            AppMethodBeat.o(40113);
            return findViewById;
        } else if (bau.jCt == 2) {
            findViewById = this.contentView.findViewById(iArr[i]);
            AppMethodBeat.o(40113);
            return findViewById;
        } else {
            AppMethodBeat.o(40113);
            return null;
        }
    }

    public final void refreshView() {
        AppMethodBeat.i(40114);
        this.ros = com.tencent.mm.plugin.sns.storage.h.YS(this.ros.cqA());
        ab.i("MicroMsg.TurnCardAdDetailItem", "refresh view");
        int width = (((((WindowManager) this.context.getSystemService("window")).getDefaultDisplay().getWidth() - a.fromDPToPix(this.context, 50)) - this.context.getResources().getDimensionPixelSize(2131427812)) - this.context.getResources().getDimensionPixelSize(2131427812)) - this.context.getResources().getDimensionPixelSize(2131427858);
        if (this.ros.cqu().xfI.wbK.size() >= 2) {
            int i;
            if (this.ros.field_likeFlag == 1) {
                i = 1;
            } else {
                i = 0;
            }
            Eq(i);
            int i2 = 0;
            while (true) {
                int i3 = i2;
                if (i3 >= 2) {
                    break;
                }
                bau bau = (bau) this.ros.cqu().xfI.wbK.get(i3);
                MaskImageView maskImageView = (MaskImageView) this.contentView.findViewById(this.rHh[i3]);
                ViewGroup.LayoutParams layoutParams = maskImageView.getLayoutParams();
                maskImageView.setTag(this);
                com.tencent.mm.plugin.sns.model.g cnC;
                if (bau.jCt == 2) {
                    cnC = af.cnC();
                    int hashCode = hashCode();
                    az dtk = az.dtk();
                    dtk.oyB = this.timeLineObject.pcX;
                    cnC.a(bau, maskImageView, -1, hashCode, dtk, 3);
                } else {
                    cnC = af.cnC();
                    int hashCode2 = hashCode();
                    az dtk2 = az.dtk();
                    dtk2.oyB = this.timeLineObject.pcX;
                    cnC.a(bau, maskImageView, hashCode2, dtk2);
                }
                maskImageView.setScaleType(QImageView.a.zNT);
                layoutParams.width = width;
                layoutParams.height = width;
                if (i == i3 && bau.jCt == 2) {
                    maskImageView.setVisibility(0);
                    maskImageView.setOnClickListener(new 3(this, i));
                } else {
                    maskImageView.setVisibility(8);
                    maskImageView.setOnClickListener(null);
                }
                if (bau.jCt == 6 && i == i3) {
                    final long j;
                    boolean z = i > 0;
                    long j2 = this.ros.field_snsId;
                    ViewGroup.LayoutParams layoutParams2 = this.rGD.rns.getLayoutParams();
                    layoutParams2.width = width;
                    layoutParams2.height = width;
                    this.rGD.qzM.fi(width, width);
                    this.rGD.rns.setVisibility(0);
                    af.cnC().a(this.ros, bau, this.rGD.qzM, this.context.hashCode(), 0, az.xYT, this.ros.DI(32), true);
                    this.rGD.rnw = true;
                    this.rGD.rnx = i3;
                    this.rGD.rnr = this.timeLineObject;
                    this.rGD.position = 0;
                    this.rGD.cwT = this.ros.cqU();
                    this.rGD.rnt.setOnClickListener(new 4(this, z));
                    this.rGD.qzM.setOnCompletionListener(new 5(this, j2, z));
                    if (this.rqn != null) {
                        if (this.rqn.jO(((long) i3) + j2)) {
                            this.rqn.c(j2, bo.yz(), z);
                        } else {
                            j = j2;
                            final boolean z2 = z;
                            final int i4 = i3;
                            this.rGD.qzM.setOnDecodeDurationListener(new f() {
                                public final void b(com.tencent.mm.plugin.sight.decode.a.b bVar, long j) {
                                    AppMethodBeat.i(40108);
                                    if (j >= 3) {
                                        int cle = (int) bVar.cle();
                                        if (d.this.rqn != null) {
                                            d.this.rqn.c(j, bo.yz(), z2);
                                            d.this.rqn.f(j, cle, z2);
                                            d.this.rqn.T(j, j + ((long) i4));
                                        }
                                        d.this.rGD.qzM.setOnDecodeDurationListener(null);
                                    }
                                    AppMethodBeat.o(40108);
                                }
                            });
                        }
                    }
                    this.rGD.a(this.timeLineObject, 0, this.ros.cqU(), this.ros.DI(32));
                    this.rGD.raQ.setVisibility(8);
                    com.tencent.mm.plugin.sns.model.g cnC2 = af.cnC();
                    j = System.nanoTime() - System.nanoTime();
                    ab.i("MicroMsg.TurnCardAdDetailItem", "isMediaSightExist %b duration %s", new Object[]{Boolean.valueOf(com.tencent.mm.plugin.sns.model.g.t(bau)), Long.valueOf(j)});
                    if (com.tencent.mm.plugin.sns.model.g.t(bau)) {
                        if (cnC2.u(bau)) {
                            this.rGD.raP.setVisibility(0);
                            this.rGD.rnu.setVisibility(8);
                            this.rGD.raP.setImageDrawable(a.g(this.context, 2131231923));
                            this.rGD.raP.setContentDescription(this.context.getString(2131301953));
                        } else if (cnC2.v(bau)) {
                            this.rGD.raP.setVisibility(8);
                            this.rGD.rnu.setVisibility(8);
                        } else if (cnC2.b(this.ros, null) <= 5) {
                            this.rGD.raP.setVisibility(8);
                            this.rGD.rnu.setVisibility(8);
                        } else {
                            cnC2.y(bau);
                            this.rGD.raP.setVisibility(0);
                            this.rGD.rnu.setVisibility(8);
                            this.rGD.raP.setImageDrawable(a.g(this.context, 2131231923));
                            this.rGD.raP.setContentDescription(this.context.getString(2131301953));
                        }
                        if (this.rGD.qzM.ckY()) {
                            ab.d("MicroMsg.TurnCardAdDetailItem", "play video error " + bau.Id + " " + bau.Url + " " + bau.wEH + " 0");
                            cnC2.y(bau);
                            this.rGD.raP.setVisibility(0);
                            this.rGD.rnu.setVisibility(8);
                            this.rGD.raP.setImageDrawable(a.g(this.context, 2131231923));
                            this.rGD.raP.setContentDescription(this.context.getString(2131301953));
                        }
                    } else if (cnC2.w(bau)) {
                        this.rGD.raP.setVisibility(8);
                        this.rGD.rnu.setVisibility(0);
                        this.rGD.rnu.dKB();
                    } else if (cnC2.b(this.ros, null) == 5) {
                        cnC2.A(bau);
                        this.rGD.raP.setVisibility(8);
                        this.rGD.rnu.setVisibility(0);
                        this.rGD.rnu.dKB();
                    } else if (cnC2.x(bau)) {
                        this.rGD.rnu.setVisibility(8);
                        this.rGD.raP.setImageResource(2130840197);
                        this.rGD.raP.setVisibility(0);
                    } else {
                        cnC2.y(bau);
                        this.rGD.raP.setVisibility(0);
                        this.rGD.rnu.setVisibility(8);
                        this.rGD.raP.setImageDrawable(a.g(this.context, 2131231923));
                        this.rGD.raP.setContentDescription(this.context.getString(2131301953));
                        if (cnC2.b(this.ros, null) == 4) {
                            this.rGD.raQ.setVisibility(0);
                        }
                    }
                    if (this.rqn != null) {
                        if (e.ct(an.fZ(af.getAccSnsPath(), bau.Id) + i.j(bau))) {
                            this.rqn.v(this.ros.field_snsId, true);
                        } else {
                            this.rqn.v(this.ros.field_snsId, false);
                        }
                        this.rqn.c(j2, af.cnC().b(this.ros, null) == 5, z);
                    }
                }
                i2 = i3 + 1;
            }
        }
        AppMethodBeat.o(40114);
    }
}
