package com.tencent.mm.plugin.sns.ui.item;

import android.annotation.TargetApi;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.bz.a;
import com.tencent.mm.plugin.sight.decode.ui.SightPlayImageView;
import com.tencent.mm.plugin.sns.model.af;
import com.tencent.mm.plugin.sns.model.an;
import com.tencent.mm.plugin.sns.model.g;
import com.tencent.mm.plugin.sns.storage.b;
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.au;
import com.tencent.mm.plugin.sns.ui.av;
import com.tencent.mm.plugin.sns.ui.item.BaseTimeLineItem.BaseViewHolder;
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 i extends BaseTimeLineItem {
    private static int[] rHh = new int[]{2131827917, 2131827918};
    private static int[] rIW = new int[]{2131827919};
    private static int[][] rIX = new int[][]{new int[]{2131827924, 2131827925}, new int[]{2131827921, 2131827922}, new int[]{2131827921, 2131827925}};
    public int mScreenHeight = 0;
    private int mScreenWidth = 0;
    private int rIV = 0;

    static /* synthetic */ void b(a aVar) {
        AppMethodBeat.i(40166);
        a(aVar);
        AppMethodBeat.o(40166);
    }

    public final void d(BaseViewHolder baseViewHolder) {
        AppMethodBeat.i(40162);
        if (this.mActivity != null) {
            DisplayMetrics displayMetrics = new DisplayMetrics();
            this.mActivity.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
            this.mScreenWidth = displayMetrics.widthPixels;
            this.mScreenHeight = displayMetrics.heightPixels;
            this.rIV = (((Math.min(this.mScreenWidth, this.mScreenHeight) - a.fromDPToPix(this.mActivity, 54)) - this.mActivity.getResources().getDimensionPixelSize(2131427786)) - this.mActivity.getResources().getDimensionPixelSize(2131427812)) - this.mActivity.getResources().getDimensionPixelSize(2131427858);
        }
        b bVar = (b) baseViewHolder;
        if (bVar.rHC != null && !bVar.rJg) {
            bVar.rHC.setLayoutResource(2130970822);
            if (!bVar.rJg) {
                bVar.rJf = bVar.rHC.inflate();
                bVar.rJg = true;
            }
        } else if (!bVar.rJg) {
            bVar.rJf = bVar.mRR.findViewById(2131827916);
            bVar.rJg = true;
        }
        LayoutParams layoutParams = bVar.rJf.getLayoutParams();
        layoutParams.width = this.rIV;
        layoutParams.height = this.rIV;
        ((RoundedCornerRelativeLayout) bVar.rJf).setRadius(8.0f);
        aj ajVar = bVar.rJi;
        ajVar.rnt = u(bVar.rJf, 0, 6);
        ajVar.rns = ajVar.rnt;
        ajVar.qzM = (com.tencent.mm.plugin.sight.decode.a.a) ajVar.rnt.findViewById(2131820629);
        ajVar.raP = (ImageView) ajVar.rnt.findViewById(2131820981);
        ajVar.rnu = (MMPinProgressBtn) ajVar.rnt.findViewById(2131821370);
        ajVar.rnv = (TextView) ajVar.rnt.findViewById(2131827571);
        ajVar.raQ = (TextView) ajVar.rnt.findViewById(2131827572);
        ((SightPlayImageView) ajVar.qzM).qyI = true;
        ((SightPlayImageView) ajVar.qzM).setScaleType(QImageView.a.zNT);
        ajVar.qzM.fi(this.rIV, this.rIV);
        bVar.rGQ = bVar.rJf.findViewById(2131827920);
        bVar.rGR = bVar.rJf.findViewById(2131827923);
        AppMethodBeat.o(40162);
    }

    @TargetApi(16)
    public final void a(BaseViewHolder baseViewHolder, int i, av avVar, TimeLineObject timeLineObject, int i2, au auVar) {
        AppMethodBeat.i(40163);
        ab.i("MiroMsg.TurnMediaTimeLineItem", "fill turn card ad item %d", new Object[]{Integer.valueOf(i)});
        if (baseViewHolder.eBB) {
            ab.i("MiroMsg.TurnMediaTimeLineItem", "holder is busy");
            AppMethodBeat.o(40163);
            return;
        }
        int hashCode;
        View findViewById;
        b bVar = (b) baseViewHolder;
        bVar.rJf.setTag(bVar);
        bVar.rJf.setVisibility(0);
        bVar.rJf.setLayerType(2, null);
        b bVar2 = bVar;
        for (int findViewById2 : rHh) {
            findViewById = bVar2.rJf.findViewById(findViewById2);
            if (findViewById != null) {
                findViewById.setVisibility(8);
            }
            if (findViewById instanceof MaskImageView) {
                ((MaskImageView) findViewById).setScaleType(QImageView.a.zNT);
            }
        }
        for (int findViewById22 : rIW) {
            findViewById = bVar2.rJf.findViewById(findViewById22);
            if (findViewById != null) {
                findViewById.setBackground(null);
                findViewById.setVisibility(8);
                if (findViewById instanceof ViewGroup) {
                    ((ViewGroup) findViewById).setClipChildren(false);
                }
            }
        }
        baseViewHolder.rHB.setLayoutParams(new LinearLayout.LayoutParams((((((WindowManager) this.mActivity.getSystemService("window")).getDefaultDisplay().getWidth() - a.fromDPToPix(this.mActivity, 54)) - this.mActivity.getResources().getDimensionPixelSize(2131427786)) - this.mActivity.getResources().getDimensionPixelSize(2131427812)) - this.mActivity.getResources().getDimensionPixelSize(2131427858), -2));
        if (avVar.rgZ && i2 == 11) {
            if (timeLineObject.xfI == null || timeLineObject.xfI.wbK == null || timeLineObject.xfI.wbK.size() < 2) {
                ab.e("MiroMsg.TurnMediaTimeLineItem", "not enough medias!");
                AppMethodBeat.o(40163);
                return;
            }
            int i3;
            if (bVar.rHu == 1) {
                i3 = 1;
            } else {
                i3 = 0;
            }
            a aVar = null;
            a aVar2 = null;
            int i4 = 0;
            while (i4 < Math.min(timeLineObject.xfI.wbK.size(), 2)) {
                a aVar3;
                a aVar4;
                bau bau = (bau) timeLineObject.xfI.wbK.get(i4);
                View u = u(bVar.rJf, i4, 2);
                u.setVisibility(4);
                if (u != null) {
                    LayoutParams layoutParams;
                    u.setTag(baseViewHolder);
                    u.setOnClickListener(auVar.qOL.rKn);
                    g cnC;
                    if (bau.jCt == 2) {
                        cnC = af.cnC();
                        hashCode = this.mActivity.hashCode();
                        az dtg = az.dtg();
                        dtg.oyB = timeLineObject.pcX;
                        cnC.a(bau, u, -1, hashCode, dtg, 3);
                    } else {
                        cnC = af.cnC();
                        int hashCode2 = this.mActivity.hashCode();
                        az dtg2 = az.dtg();
                        dtg2.oyB = timeLineObject.pcX;
                        cnC.a(bau, u, hashCode2, dtg2);
                    }
                    View view = null;
                    if (bau.jCt == 6 && i3 == i4) {
                        boolean z = i3 > 0;
                        long j = avVar.rAt;
                        aj ajVar = bVar.rJi;
                        n nVar = avVar.qBY;
                        View view2 = ajVar.rns;
                        ajVar.rnr = timeLineObject;
                        ajVar.qzM.setOnCompletionListener(new 1(this, auVar, j, z));
                        if (!auVar.rxP.rhm.jO(((long) i4) + j)) {
                            ajVar.qzM.setOnDecodeDurationListener(new 2(this, auVar, j, z, i4, ajVar));
                        } else if (!(auVar == null || auVar.rxP == null || auVar.rxP.rhm == null)) {
                            auVar.rxP.rhm.c(j, bo.yz(), z);
                        }
                        ajVar.a(timeLineObject, i, avVar.riA, avVar.rgZ);
                        ajVar.raQ.setVisibility(8);
                        g cnC2 = af.cnC();
                        long nanoTime = System.nanoTime() - System.nanoTime();
                        ab.i("MiroMsg.TurnMediaTimeLineItem", "isMediaSightExist %b duration %s", new Object[]{Boolean.valueOf(g.t(bau)), Long.valueOf(nanoTime)});
                        if (g.t(bau)) {
                            if (cnC2.u(bau)) {
                                ajVar.raP.setVisibility(0);
                                ajVar.rnu.setVisibility(8);
                                ajVar.raP.setImageDrawable(a.g(this.mActivity, 2131231923));
                                ajVar.raP.setContentDescription(this.mActivity.getString(2131301953));
                            } else if (cnC2.v(bau)) {
                                ajVar.raP.setVisibility(8);
                                ajVar.rnu.setVisibility(8);
                            } else if (cnC2.b(nVar, null) <= 5) {
                                ajVar.raP.setVisibility(8);
                                ajVar.rnu.setVisibility(8);
                            } else {
                                cnC2.y(bau);
                                ajVar.raP.setVisibility(0);
                                ajVar.rnu.setVisibility(8);
                                ajVar.raP.setImageDrawable(a.g(this.mActivity, 2131231923));
                                ajVar.raP.setContentDescription(this.mActivity.getString(2131301953));
                            }
                            if (ajVar.qzM.ckY()) {
                                ab.d("MiroMsg.TurnMediaTimeLineItem", "play video error " + bau.Id + " " + bau.Url + " " + bau.wEH + " " + i);
                                cnC2.y(bau);
                                ajVar.raP.setVisibility(0);
                                ajVar.rnu.setVisibility(8);
                                ajVar.raP.setImageDrawable(a.g(this.mActivity, 2131231923));
                                ajVar.raP.setContentDescription(this.mActivity.getString(2131301953));
                            }
                        } else if (cnC2.w(bau)) {
                            ajVar.raP.setVisibility(8);
                            ajVar.rnu.setVisibility(0);
                            ajVar.rnu.dKB();
                        } else if (cnC2.b(nVar, null) == 5) {
                            cnC2.A(bau);
                            ajVar.raP.setVisibility(8);
                            ajVar.rnu.setVisibility(0);
                            ajVar.rnu.dKB();
                        } else if (cnC2.x(bau)) {
                            ajVar.rnu.setVisibility(8);
                            ajVar.raP.setImageResource(2130840197);
                            ajVar.raP.setVisibility(0);
                        } else {
                            cnC2.y(bau);
                            ajVar.raP.setVisibility(0);
                            ajVar.rnu.setVisibility(8);
                            ajVar.raP.setImageDrawable(a.g(this.mActivity, 2131231923));
                            ajVar.raP.setContentDescription(this.mActivity.getString(2131301953));
                            if (cnC2.b(nVar, null) == 4) {
                                ajVar.raQ.setVisibility(0);
                            }
                        }
                        layoutParams = ajVar.rnv.getLayoutParams();
                        layoutParams.width = this.rIV;
                        layoutParams.height = this.rIV;
                        ajVar.rnv.setLayoutParams(layoutParams);
                        ajVar.qzM.setTagObject(ajVar);
                        com.tencent.mm.plugin.sight.decode.a.a aVar5 = ajVar.qzM;
                        int hashCode3 = this.mActivity.hashCode();
                        az dtg3 = az.dtg();
                        dtg3.oyB = timeLineObject.pcX;
                        cnC2.a(nVar, bau, aVar5, hashCode3, i, dtg3, avVar.rgZ, true);
                        view2.setVisibility(0);
                        ajVar.rnt.setTag(baseViewHolder);
                        final int i5 = i3;
                        final au auVar2 = auVar;
                        final b bVar3 = bVar;
                        ajVar.rnt.setOnClickListener(new OnClickListener() {
                            public final void onClick(View view) {
                                AppMethodBeat.i(40158);
                                if (i5 > 0) {
                                    auVar2.rxP.rhm.jQ(bVar3.rHt);
                                }
                                auVar2.qOL.rKn.onClick(view);
                                AppMethodBeat.o(40158);
                            }
                        });
                        if (e.ct(an.fZ(af.getAccSnsPath(), bau.Id) + com.tencent.mm.plugin.sns.data.i.j(bau))) {
                            auVar.rxP.rhm.a(avVar.rAt, 0, true, z);
                        } else {
                            auVar.rxP.rhm.a(avVar.rAt, 0, false, z);
                        }
                        auVar.rxP.rhm.c(avVar.rAt, af.cnC().b(nVar, null) == 5, z);
                        view = view2;
                    }
                    layoutParams = u.getLayoutParams();
                    layoutParams.width = this.rIV;
                    layoutParams.height = this.rIV;
                    u.setLayoutParams(layoutParams);
                    if (view != null) {
                        layoutParams = view.getLayoutParams();
                        layoutParams.width = this.rIV;
                        layoutParams.height = this.rIV;
                        view.setLayoutParams(layoutParams);
                    }
                    if (i3 == i4 && bau.jCt == 2) {
                        u.setVisibility(0);
                        u.setOnTouchListener(new 4(this));
                    }
                    a aVar6 = new a();
                    aVar6.index = i4;
                    if (view == null) {
                        view = u;
                    }
                    aVar6.view = view;
                    aVar6.rJc = u;
                    aVar6.rJd = bVar;
                    aVar6.qJh = bau;
                    aVar6.ros = avVar.qBY;
                    if (aVar != null) {
                        aVar.rJe = aVar6;
                        aVar3 = aVar2;
                    } else {
                        aVar3 = aVar6;
                    }
                    if (i4 == timeLineObject.xfI.wbK.size() - 1) {
                        aVar6.rJe = aVar3;
                    }
                    if (i4 == i3) {
                        bVar.rJh = aVar6;
                        a(aVar6);
                    }
                    aVar4 = aVar6;
                } else {
                    aVar3 = aVar2;
                    aVar4 = aVar;
                }
                i4++;
                aVar2 = aVar3;
                aVar = aVar4;
            }
            if (bVar.mRR != null && (bVar.mRR instanceof FrameLayout)) {
                ((FrameLayout) bVar.mRR).setClipChildren(false);
            }
            if (bVar.rHB != null) {
                bVar.rHB.setClipChildren(false);
            }
            if (bVar.rIt != null && (bVar.rIt instanceof LinearLayout)) {
                ((LinearLayout) bVar.rIt).setClipChildren(false);
            }
            bVar.rJf.setOnClickListener(new 5(this, auVar, i3, bVar));
        }
        AppMethodBeat.o(40163);
    }

    public static View u(View view, int i, int i2) {
        AppMethodBeat.i(40164);
        View findViewById;
        if (i2 == 6) {
            findViewById = view.findViewById(rIW[0]);
            AppMethodBeat.o(40164);
            return findViewById;
        }
        findViewById = view.findViewById(rHh[i]);
        AppMethodBeat.o(40164);
        return findViewById;
    }

    private static void a(a aVar) {
        AppMethodBeat.i(40165);
        aVar.rJd.rGQ.setVisibility(8);
        aVar.rJd.rGR.setVisibility(8);
        ((TextView) aVar.rJd.rJf.findViewById(2131827921)).setText(null);
        ((TextView) aVar.rJd.rJf.findViewById(2131827924)).setText(null);
        ((TextView) aVar.rJd.rJf.findViewById(2131827922)).setText(null);
        ((TextView) aVar.rJd.rJf.findViewById(2131827925)).setText(null);
        b cqo = aVar.ros.cqo();
        if (!(cqo.qUX == null || cqo.qUX.qVt == null || cqo.qUX.qVt.size() < 2)) {
            h hVar = (h) cqo.qUX.qVt.get(aVar.index);
            if (hVar.qVk >= 0 && hVar.qVk < rIX.length) {
                int[] iArr = rIX[hVar.qVk];
                TextView textView = (TextView) aVar.rJd.rJf.findViewById(iArr[0]);
                TextView textView2 = (TextView) aVar.rJd.rJf.findViewById(iArr[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(40165);
    }
}
