package com.bytedance.sdk.openadsdk.activity.single;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.SystemClock;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.FrameLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.media3.exoplayer.upstream.CmcdData;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.d1;
import androidx.recyclerview.widget.f2;
import androidx.recyclerview.widget.j2;
import androidx.recyclerview.widget.m1;
import androidx.recyclerview.widget.v1;
import androidx.recyclerview.widget.z0;
import com.bytedance.sdk.component.utils.maa;
import com.bytedance.sdk.component.utils.wey;
import com.bytedance.sdk.openadsdk.AdSlot;
import com.bytedance.sdk.openadsdk.CacheDirFactory;
import com.bytedance.sdk.openadsdk.activity.single.ro;
import com.bytedance.sdk.openadsdk.component.reward.fm.duv;
import com.bytedance.sdk.openadsdk.component.reward.top.TopLayoutDislike2;
import com.bytedance.sdk.openadsdk.core.fhx;
import com.bytedance.sdk.openadsdk.core.gof;
import com.bytedance.sdk.openadsdk.core.model.ai;
import com.bytedance.sdk.openadsdk.core.model.ha;
import com.bytedance.sdk.openadsdk.core.model.hi;
import com.bytedance.sdk.openadsdk.core.model.lse;
import com.bytedance.sdk.openadsdk.core.model.mq;
import com.bytedance.sdk.openadsdk.core.model.nt;
import com.bytedance.sdk.openadsdk.core.widget.PAGLogoView;
import com.bytedance.sdk.openadsdk.utils.xgn;
import com.bytedance.sdk.openadsdk.utils.zan;
import e6.a;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import org.json.JSONObject;
import y5.c;

/* JADX INFO: loaded from: classes2.dex */
public class yz extends com.bytedance.sdk.openadsdk.activity.single.lb implements Handler.Callback {
    private boolean ado;
    private boolean ai;
    private final RecyclerView ajl;
    private boolean bkb;
    private View bwv;
    private int bx;
    private final AtomicBoolean dsz;
    private final boolean duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private final TopLayoutDislike2 f6803ef;
    private final boolean fhx;

    /* JADX INFO: renamed from: gc, reason: collision with root package name */
    private com.bytedance.sdk.openadsdk.activity.single.jnr f6804gc;
    private final PAGLogoView gof;
    private final ArrayList<Message> gqi;
    private boolean gzf;

    /* JADX INFO: renamed from: ha, reason: collision with root package name */
    private ro.jnr f6805ha;
    private int hi;
    private boolean hlt;
    private int hxv;

    /* JADX INFO: renamed from: ib, reason: collision with root package name */
    private JSONObject f6806ib;
    private final boolean irt;
    private final FrameLayout ku;
    private long kwx;
    private boolean lmk;
    private int lse;
    private FrameLayout lz;
    private int maa;
    private ajl mj;
    private hi.fm mon;
    private boolean mpp;
    private int mq;

    /* JADX INFO: renamed from: ne, reason: collision with root package name */
    private long f6807ne;
    private boolean nt;
    private int ol;
    private final HashSet<String> onz;
    private long pcm;
    private int pkk;

    /* JADX INFO: renamed from: qf, reason: collision with root package name */
    private boolean f6808qf;
    private final HashSet<Integer> qhl;
    private boolean sds;
    private JSONObject si;
    private boolean so;
    private boolean tzk;
    private final Handler vt;
    private Message vvj;
    private wu wbw;
    private final boolean wey;
    private final fm wsy;
    private final LinearLayoutManager wu;
    private boolean xgn;
    private boolean ywr;
    private JSONObject zan;

    public static abstract class ajl implements Runnable {
        private final Handler fm = new Handler(Looper.getMainLooper());
        private long jnr;

        /* JADX INFO: renamed from: lb, reason: collision with root package name */
        private long f6814lb;
        private final long ro;
        private long yz;

        public ajl(long j10) {
            this.ro = j10;
        }

        public long ajl() {
            long jElapsedRealtime;
            long j10;
            if (this.f6814lb > this.jnr) {
                jElapsedRealtime = this.ro - (SystemClock.elapsedRealtime() - this.f6814lb);
                j10 = this.yz;
            } else {
                jElapsedRealtime = this.ro;
                j10 = this.yz;
            }
            long j11 = jElapsedRealtime - j10;
            if (j11 < 0) {
                return 0L;
            }
            return j11;
        }

        public abstract void fm();

        public void jnr() {
            this.fm.postDelayed(this, this.ro);
            this.f6814lb = SystemClock.elapsedRealtime();
        }

        public void lb() {
            long j10 = this.ro - this.yz;
            if (j10 < 0) {
                return;
            }
            this.fm.removeCallbacks(this);
            this.fm.postDelayed(this, j10);
            this.f6814lb = SystemClock.elapsedRealtime();
        }

        public void ro() {
            this.fm.removeCallbacks(this);
            if (this.jnr > this.f6814lb) {
                return;
            }
            this.yz = (SystemClock.elapsedRealtime() - this.f6814lb) + this.yz;
            this.jnr = SystemClock.elapsedRealtime();
        }

        @Override // java.lang.Runnable
        public void run() {
            fm();
        }

        public void yz() {
            this.fm.removeCallbacks(this);
        }
    }

    public static class fm extends d1 {
        private boolean jnr;

        /* JADX INFO: renamed from: lb, reason: collision with root package name */
        private final yz f6815lb;
        private boolean yz;
        private final ArrayList<C0049yz> fm = new ArrayList<>();
        private final ArrayList<wu> ro = new ArrayList<>();

        public fm(yz yzVar, List<lse> list) {
            this.f6815lb = yzVar;
            for (int i10 = 0; i10 < list.size(); i10++) {
                lse lseVar = list.get(i10);
                if (lseVar != null && yzVar != null) {
                    lseVar.xgn(yzVar.jnr);
                }
                this.fm.add(new C0049yz(lseVar));
            }
        }

        @Override // androidx.recyclerview.widget.d1
        @NonNull
        /* JADX INFO: renamed from: fm, reason: merged with bridge method [inline-methods] */
        public jnr onCreateViewHolder(@NonNull ViewGroup viewGroup, int i10) {
            if (i10 == -1) {
                com.bytedance.sdk.openadsdk.core.ajl.lb lbVar = new com.bytedance.sdk.openadsdk.core.ajl.lb(viewGroup.getContext());
                lbVar.setLayoutParams(new FrameLayout.LayoutParams(-1, -2));
                return new lb(lbVar);
            }
            com.bytedance.sdk.openadsdk.component.reward.view.ro roVar = new com.bytedance.sdk.openadsdk.component.reward.view.ro(viewGroup.getContext(), this.f6815lb.irt, this.f6815lb.fhx, zan.ro(viewGroup.getContext(), 10.0f));
            roVar.setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
            return new ro(this, roVar);
        }

        @Override // androidx.recyclerview.widget.d1
        public int getItemCount() {
            if (this.jnr) {
                return Integer.MAX_VALUE;
            }
            return this.fm.size();
        }

        @Override // androidx.recyclerview.widget.d1
        public int getItemViewType(int i10) {
            C0049yz c0049yz = this.fm.get(i10 % this.fm.size());
            if (c0049yz.fm != 0) {
                return -1;
            }
            ha haVarPo = c0049yz.ro.po();
            if (haVarPo == null) {
                return 1;
            }
            return (haVarPo.fm() + haVarPo.ro()).hashCode();
        }

        public List<lse> jnr() {
            ArrayList arrayList = new ArrayList();
            for (C0049yz c0049yz : this.fm) {
                if (c0049yz.fm == 0) {
                    arrayList.add(c0049yz.ro);
                }
            }
            return arrayList;
        }

        public boolean lb() {
            return this.jnr;
        }

        public ArrayList<wu> ro() {
            return this.ro;
        }

        public int yz() {
            return this.yz ? this.fm.size() - 1 : this.fm.size();
        }

        @Override // androidx.recyclerview.widget.d1
        /* JADX INFO: renamed from: lb, reason: merged with bridge method [inline-methods] */
        public void onViewRecycled(@NonNull jnr jnrVar) {
            super.onViewRecycled(jnrVar);
            if (jnrVar instanceof ro) {
                ro roVar = (ro) jnrVar;
                com.bytedance.sdk.openadsdk.activity.single.fm fmVar = roVar.f6816lb;
                if (!this.f6815lb.wey) {
                    fm(roVar, false);
                    return;
                }
                boolean zRo = ro(fmVar);
                if (fmVar != null) {
                    fm(roVar, zRo);
                }
            }
        }

        @Override // androidx.recyclerview.widget.d1
        /* JADX INFO: renamed from: ro, reason: merged with bridge method [inline-methods] */
        public void onViewDetachedFromWindow(@NonNull jnr jnrVar) {
            com.bytedance.sdk.openadsdk.activity.single.fm fmVar;
            super.onViewDetachedFromWindow(jnrVar);
            if (!(jnrVar instanceof ro) || (fmVar = ((ro) jnrVar).f6816lb) == null) {
                return;
            }
            fmVar.hlt().sds.si();
        }

        private boolean ro(wu wuVar) {
            return wuVar != null && wuVar.wbw();
        }

        @Override // androidx.recyclerview.widget.d1
        /* JADX INFO: renamed from: fm, reason: merged with bridge method [inline-methods] */
        public void onBindViewHolder(@NonNull jnr jnrVar, int i10) {
            if (i10 >= this.fm.size()) {
                i10 %= this.fm.size();
            }
            jnrVar.fm(this.f6815lb, this.fm.get(i10), i10);
        }

        @Override // androidx.recyclerview.widget.d1
        /* JADX INFO: renamed from: fm, reason: merged with bridge method [inline-methods] */
        public void onViewAttachedToWindow(@NonNull jnr jnrVar) {
            super.onViewAttachedToWindow(jnrVar);
        }

        public int fm() {
            int itemCount = getItemCount();
            return this.yz ? itemCount - 1 : itemCount;
        }

        public void fm(String str) {
            int size = this.fm.size();
            C0049yz c0049yz = size > 0 ? this.fm.get(size - 1) : null;
            boolean z10 = !TextUtils.isEmpty(str);
            if (c0049yz == null || c0049yz.fm != 1) {
                if (z10) {
                    this.fm.add(new C0049yz(str));
                    notifyItemInserted(size);
                    this.yz = true;
                    return;
                }
                return;
            }
            if (z10) {
                c0049yz.f6817lb = str;
                notifyItemChanged(size - 1);
            } else {
                this.fm.remove(c0049yz);
                notifyItemRemoved(size - 1);
                this.yz = false;
            }
        }

        public void fm(wu wuVar) {
            this.ro.add(wuVar);
        }

        public void fm(List<lse> list) {
            yz yzVar;
            int size = this.fm.size();
            if (this.yz) {
                size--;
            }
            for (int i10 = 0; i10 < list.size(); i10++) {
                lse lseVar = list.get(i10);
                if (lseVar != null && (yzVar = this.f6815lb) != null) {
                    lseVar.xgn(yzVar.jnr);
                }
                this.fm.add(size + i10, new C0049yz(lseVar));
                lseVar.fy();
            }
            notifyItemRangeInserted(size, list.size());
        }

        public void fm(int i10, int i11) {
            if (this.jnr) {
                return;
            }
            this.jnr = true;
            if (i10 < 0) {
                i10 = 0;
            }
            int size = this.fm.size();
            notifyItemRangeInserted(size, (Integer.MAX_VALUE - i11) - (size - i10));
            notifyItemRangeInserted(0, i11 - i10);
        }

        public void fm(ro roVar, boolean z10) {
            if (roVar.f6816lb == null) {
                return;
            }
            this.ro.remove(roVar.f6816lb);
            roVar.fm(z10);
        }
    }

    public static abstract class jnr extends j2 {
        public jnr(@NonNull View view) {
            super(view);
        }

        public abstract void fm(yz yzVar, C0049yz c0049yz, int i10);
    }

    public static class lb extends jnr {
        private final TextView fm;

        public lb(@NonNull View view) {
            super(view);
            com.bytedance.sdk.openadsdk.core.ajl.wu wuVar = new com.bytedance.sdk.openadsdk.core.ajl.wu(view.getContext());
            this.fm = wuVar;
            wuVar.setTextColor(Color.parseColor("#99FFFFFF"));
            wuVar.setTextSize(14.0f);
            wuVar.setGravity(17);
            wuVar.setPadding(0, 24, 0, 24);
            ((FrameLayout) view).addView(wuVar, new FrameLayout.LayoutParams(-1, -2));
        }

        @Override // com.bytedance.sdk.openadsdk.activity.single.yz.jnr
        public void fm(yz yzVar, C0049yz c0049yz, int i10) {
            this.fm.setText(c0049yz.f6817lb);
        }
    }

    public static class ro extends jnr {
        private final fm fm;

        /* JADX INFO: renamed from: lb, reason: collision with root package name */
        private com.bytedance.sdk.openadsdk.activity.single.fm f6816lb;
        private final com.bytedance.sdk.openadsdk.component.reward.view.ro ro;

        public ro(fm fmVar, @NonNull View view) {
            super(view);
            this.fm = fmVar;
            this.ro = (com.bytedance.sdk.openadsdk.component.reward.view.ro) view;
        }

        public wu fm() {
            return this.f6816lb;
        }

        @Override // com.bytedance.sdk.openadsdk.activity.single.yz.jnr
        public void fm(yz yzVar, C0049yz c0049yz, int i10) {
            int bindingAdapterPosition = getBindingAdapterPosition();
            Activity activity = yzVar.fm;
            if (com.bytedance.sdk.component.utils.ro.fm(activity)) {
                return;
            }
            lse lseVar = c0049yz.ro;
            com.bytedance.sdk.openadsdk.activity.single.fm fmVar = this.f6816lb;
            if (fmVar != null) {
                if (fm(fmVar, lseVar)) {
                    this.f6816lb.fm(lseVar, bindingAdapterPosition, i10);
                } else {
                    this.fm.fm(this, false);
                }
            }
            com.bytedance.sdk.openadsdk.activity.single.ro roVar = yzVar.yz;
            if (this.f6816lb == null) {
                this.f6816lb = lseVar.ii() ? new wsy(roVar, lseVar, bindingAdapterPosition, i10, false) : new com.bytedance.sdk.openadsdk.activity.single.ajl(roVar, lseVar, bindingAdapterPosition, i10, false);
            }
            ro.jnr jnrVar = new ro.jnr(1, null);
            jnrVar.yz = yzVar.ai;
            this.f6816lb.ro(activity, jnrVar);
            this.fm.fm(this.f6816lb);
            com.bytedance.sdk.openadsdk.component.reward.view.wu wuVarFm = this.f6816lb.fm();
            if (wuVarFm == null) {
                return;
            }
            ViewParent parent = wuVarFm.getParent();
            if (parent instanceof ViewGroup) {
                ((ViewGroup) parent).removeView(wuVarFm);
            }
            if (!yzVar.fhx) {
                float fXe = lseVar.xe();
                if (fXe > 0.0f) {
                    this.ro.setWidthAndHeightRatio(fXe);
                } else {
                    this.ro.setWidthOrHeightInParentRatio(0.8f);
                }
            }
            this.ro.fm(wuVarFm, new FrameLayout.LayoutParams(-1, -1));
            this.ro.setScene(this.f6816lb);
        }

        private boolean fm(wu wuVar, lse lseVar) {
            ha haVarPo;
            if (wuVar.wbw() && (haVarPo = wuVar.ajl.po()) != null) {
                ha haVarPo2 = lseVar.po();
                if (TextUtils.equals(haVarPo.fm(), haVarPo2.fm()) && TextUtils.equals(haVarPo.ro(), haVarPo2.ro()) && wuVar.ha()) {
                    return true;
                }
            }
            return false;
        }

        public void fm(boolean z10) {
            com.bytedance.sdk.openadsdk.activity.single.fm fmVar = this.f6816lb;
            if (fmVar == null) {
                return;
            }
            fmVar.ajl(z10);
            this.f6816lb.gqi();
            if (!z10) {
                this.f6816lb = null;
            }
            this.ro.fm();
        }
    }

    /* JADX INFO: renamed from: com.bytedance.sdk.openadsdk.activity.single.yz$yz, reason: collision with other inner class name */
    public static class C0049yz {
        public int fm = 0;

        /* JADX INFO: renamed from: lb, reason: collision with root package name */
        public String f6817lb;
        public lse ro;

        public C0049yz(lse lseVar) {
            this.ro = lseVar;
        }

        public C0049yz(String str) {
            this.f6817lb = str;
        }
    }

    public yz(final Activity activity, final lse lseVar, final com.bytedance.sdk.openadsdk.activity.single.ro roVar) {
        hi hiVarKu;
        super(activity, lseVar, roVar);
        this.vt = new Handler(Looper.getMainLooper(), this);
        this.dsz = new AtomicBoolean(false);
        this.onz = new HashSet<>();
        this.qhl = new HashSet<>();
        this.gqi = new ArrayList<>();
        this.maa = 5;
        this.lse = 3;
        this.ol = -1;
        int i10 = 1;
        this.f6805ha = new ro.jnr(1, null);
        boolean z10 = lseVar.ywr() == 44;
        this.fhx = z10;
        boolean zIi = lseVar.ii();
        this.duv = zIi;
        this.irt = duv.fm(activity, lseVar) == 1;
        com.bytedance.sdk.openadsdk.core.ajl.lb lbVar = new com.bytedance.sdk.openadsdk.core.ajl.lb(activity) { // from class: com.bytedance.sdk.openadsdk.activity.single.yz.1
            @Override // android.view.ViewGroup, android.view.View
            public boolean dispatchTouchEvent(MotionEvent motionEvent) {
                yz.this.si = null;
                try {
                    return super.dispatchTouchEvent(motionEvent);
                } catch (Exception unused) {
                    return false;
                }
            }
        };
        this.ku = lbVar;
        if (Build.VERSION.SDK_INT >= 35) {
            lbVar.setFitsSystemWindows(true);
        }
        activity.setContentView(lbVar);
        this.jnr = String.valueOf(activity.hashCode());
        com.bytedance.sdk.openadsdk.core.model.fm fmVarYz = lseVar.yz();
        if (fmVarYz != null && (hiVarKu = fmVarYz.ku()) != null) {
            this.xgn = hiVarKu.fhx();
            this.mon = hiVarKu.ajl();
            int iMax = Math.max(0, hiVarKu.ef());
            this.pkk = iMax;
            this.hxv = iMax;
            this.gzf = hiVarKu.onz();
            this.nt = hiVarKu.ku();
            this.hi = hiVarKu.wu();
            this.zan = hiVarKu.duv();
            this.hlt = hiVarKu.vt();
            this.sds = hiVarKu.fm();
            this.tzk = this.hi > 0;
            this.maa = hiVarKu.yz();
            this.lse = hiVarKu.jnr();
            this.si = hiVarKu.ro();
            this.f6806ib = hiVarKu.lb();
            if (!this.nt) {
                this.xgn = false;
            }
        }
        if (zIi) {
            this.mq = (int) ((1.0f - (Math.max(0, Math.min(100, lseVar.lcp() < 0 ? gof.yz().mq(String.valueOf(lseVar.pg())).ajl : r3)) / 100.0f)) * this.pkk);
        }
        RecyclerView recyclerView = new RecyclerView(activity);
        this.ajl = recyclerView;
        hi.fm fmVar = this.mon;
        if (fmVar != null) {
            int iLb = fmVar.lb();
            int iYz = this.mon.yz();
            if (iLb > 0 || iYz > 0) {
                recyclerView.setPadding(zan.ro(activity, iLb), 0, zan.ro(activity, iYz), 0);
            }
            int iRo = this.mon.ro();
            int iFm = this.mon.fm();
            int iJnr = this.mon.jnr();
            if (iRo > 0 || iJnr > 0 || iFm > 0) {
                final int iRo2 = zan.ro(activity, iRo);
                final int iRo3 = zan.ro(activity, iFm);
                final int iRo4 = zan.ro(activity, iJnr);
                recyclerView.addItemDecoration(new m1() { // from class: com.bytedance.sdk.openadsdk.activity.single.yz.11
                    @Override // androidx.recyclerview.widget.m1
                    public void getItemOffsets(@NonNull Rect rect, @NonNull View view, @NonNull RecyclerView recyclerView2, @NonNull f2 f2Var) {
                        int childAdapterPosition = recyclerView2.getChildAdapterPosition(view);
                        int itemCount = recyclerView2.getAdapter().getItemCount();
                        if (childAdapterPosition == 0) {
                            rect.top = iRo2;
                        } else {
                            rect.top = iRo4 / 2;
                        }
                        if (childAdapterPosition == itemCount - 1) {
                            rect.bottom = iRo3;
                        } else {
                            rect.bottom = iRo4 / 2;
                        }
                    }
                });
            }
        }
        lbVar.addView(recyclerView, new FrameLayout.LayoutParams(-1, -1));
        TopLayoutDislike2 topLayoutDislike2 = new TopLayoutDislike2(activity);
        this.f6803ef = topLayoutDislike2;
        lbVar.addView(topLayoutDislike2, new FrameLayout.LayoutParams(-1, -2));
        topLayoutDislike2.load(lseVar);
        topLayoutDislike2.setShowDislike(true);
        topLayoutDislike2.setShowSound(true);
        boolean zGof = gof.yz().gof(String.valueOf(lseVar.pg()));
        this.ai = zGof;
        topLayoutDislike2.setSoundMute(zGof);
        topLayoutDislike2.setListener(new com.bytedance.sdk.openadsdk.component.reward.top.ro() { // from class: com.bytedance.sdk.openadsdk.activity.single.yz.12
            @Override // com.bytedance.sdk.openadsdk.component.reward.top.ro
            public void fm(View view) {
                com.bytedance.sdk.openadsdk.core.onz.yz yzVarFm;
                lse lseVar2 = lseVar;
                com.bytedance.sdk.openadsdk.yz.lb.fm("skip", lseVar2, lseVar2.jnr(), (Map<String, Object>) null);
                com.bytedance.sdk.openadsdk.core.model.yz yzVarKl = lseVar.kl();
                if (yzVarKl != null && (yzVarFm = yzVarKl.fm()) != null) {
                    yzVarFm.ajl(0L);
                    yzVarFm.jnr(0L);
                }
                yz.this.hi();
            }

            @Override // com.bytedance.sdk.openadsdk.component.reward.top.ro
            public void lb(View view) {
                roVar.wsy();
            }

            @Override // com.bytedance.sdk.openadsdk.component.reward.top.ro
            public void ro(View view) {
                if (yz.this.wbw != null) {
                    yz.this.wbw.e_();
                }
            }

            @Override // com.bytedance.sdk.openadsdk.component.reward.top.ro
            public void yz(View view) {
            }

            @Override // com.bytedance.sdk.openadsdk.component.reward.top.ro
            public void fm(View view, String str) {
                if (yz.this.wbw != null) {
                    yz.this.wbw.fm(str);
                    yz.this.ai = !r1.ai;
                }
            }
        });
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(activity, i10, z) { // from class: com.bytedance.sdk.openadsdk.activity.single.yz.13
            {
                super(i10, z);
            }

            @Override // androidx.recyclerview.widget.LinearLayoutManager
            public void calculateExtraLayoutSpace(@NonNull f2 f2Var, @NonNull int[] iArr) {
                super.calculateExtraLayoutSpace(f2Var, iArr);
                int height = yz.this.ajl.getHeight();
                iArr[0] = height;
                iArr[1] = height;
            }
        };
        this.wu = linearLayoutManager;
        recyclerView.setLayoutManager(linearLayoutManager);
        fm fmVar2 = new fm(this, lseVar.afy());
        this.wsy = fmVar2;
        recyclerView.setAdapter(fmVar2);
        if (!this.tzk && !this.hlt) {
            fmVar2.fm(maa.fm(activity, "tt_list_end_tip"));
        }
        if (z10) {
            new z0().attachToRecyclerView(recyclerView);
        } else if (this.nt) {
            new com.bytedance.sdk.openadsdk.component.reward.view.fm().attachToRecyclerView(recyclerView);
        }
        recyclerView.addOnScrollListener(new v1() { // from class: com.bytedance.sdk.openadsdk.activity.single.yz.14
            private int jnr;

            /* JADX INFO: renamed from: lb, reason: collision with root package name */
            private final Rect f6811lb = new Rect();
            private int yz = -1;

            /* JADX WARN: Removed duplicated region for block: B:22:0x006b  */
            /*
                Code decompiled incorrectly, please refer to instructions dump.
            */
            private void fm() {
                int iYz2;
                View viewFindViewByPosition;
                if (yz.this.sds && (iYz2 = yz.this.wsy.yz()) != 0) {
                    int iFindFirstVisibleItemPosition = yz.this.wu.findFirstVisibleItemPosition();
                    int iFindLastVisibleItemPosition = yz.this.wu.findLastVisibleItemPosition();
                    if (iFindLastVisibleItemPosition % iYz2 > this.yz) {
                        for (int i11 = iFindFirstVisibleItemPosition; i11 <= iFindLastVisibleItemPosition; i11++) {
                            int i12 = i11 % iYz2;
                            if (i12 > this.yz) {
                                if ((i11 == iFindFirstVisibleItemPosition || i11 == iFindLastVisibleItemPosition) && (viewFindViewByPosition = yz.this.wu.findViewByPosition(i11)) != null) {
                                    this.f6811lb.setEmpty();
                                    viewFindViewByPosition.getGlobalVisibleRect(this.f6811lb);
                                    int height = viewFindViewByPosition.getHeight();
                                    if (height > 0 && (this.f6811lb.height() * 1.0f) / height >= 0.5f) {
                                        j2 j2VarFindViewHolderForAdapterPosition = yz.this.ajl.findViewHolderForAdapterPosition(i11);
                                        if (j2VarFindViewHolderForAdapterPosition instanceof ro) {
                                            ro roVar2 = (ro) j2VarFindViewHolderForAdapterPosition;
                                            if (roVar2.f6816lb != null) {
                                                roVar2.f6816lb.pcm();
                                            }
                                        }
                                        if (i12 > this.yz) {
                                            this.yz = i12;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            @Override // androidx.recyclerview.widget.v1
            public void onScrollStateChanged(@NonNull RecyclerView recyclerView2, int i11) {
                if (com.bytedance.sdk.component.utils.ro.fm(activity)) {
                    return;
                }
                int iFindFirstCompletelyVisibleItemPosition = yz.this.wu.findFirstCompletelyVisibleItemPosition();
                yz.this.wu.findFirstVisibleItemPosition();
                int iFindLastVisibleItemPosition = yz.this.wu.findLastVisibleItemPosition();
                if (iFindFirstCompletelyVisibleItemPosition < 0) {
                    return;
                }
                if (i11 == 0 && iFindFirstCompletelyVisibleItemPosition != yz.this.ol) {
                    boolean z11 = iFindFirstCompletelyVisibleItemPosition == yz.this.bx;
                    yz yzVar = yz.this;
                    yzVar.fm(iFindFirstCompletelyVisibleItemPosition, yzVar.xgn && z11);
                    if (yz.this.xgn && !z11 && yz.this.gzf) {
                        yz.this.xgn = false;
                    }
                    if (yz.this.mj != null) {
                        yz.this.mj.yz();
                        yz.this.mj = null;
                    }
                }
                if (i11 == 0) {
                    yz.this.bx = -1;
                }
                if (!yz.this.tzk || yz.this.hi <= 0 || iFindLastVisibleItemPosition < yz.this.wsy.fm() - yz.this.hi) {
                    return;
                }
                yz.this.maa();
            }

            @Override // androidx.recyclerview.widget.v1
            public void onScrolled(@NonNull RecyclerView recyclerView2, int i11, int i12) {
                super.onScrolled(recyclerView2, i11, i12);
                if (i12 == 0 || com.bytedance.sdk.component.utils.ro.fm(activity)) {
                    return;
                }
                fm();
                int iFindLastVisibleItemPosition = yz.this.wu.findLastVisibleItemPosition();
                if (i12 > 0 && yz.this.tzk && yz.this.hi > 0 && iFindLastVisibleItemPosition >= yz.this.wsy.fm() - yz.this.hi) {
                    yz.this.maa();
                }
                if (this.jnr != iFindLastVisibleItemPosition) {
                    this.jnr = iFindLastVisibleItemPosition;
                    if (!yz.this.qhl.isEmpty() && yz.this.qhl.contains(Integer.valueOf(iFindLastVisibleItemPosition))) {
                        yz.this.qhl.remove(Integer.valueOf(iFindLastVisibleItemPosition));
                        j2 j2VarFindViewHolderForAdapterPosition = recyclerView2.findViewHolderForAdapterPosition(iFindLastVisibleItemPosition);
                        if (j2VarFindViewHolderForAdapterPosition instanceof ro) {
                            ro roVar2 = (ro) j2VarFindViewHolderForAdapterPosition;
                            roVar2.f6816lb.jnr(true);
                            roVar2.f6816lb.mq();
                            return;
                        }
                        return;
                    }
                    if (yz.this.lmk) {
                        yz.this.lmk = false;
                        j2 j2VarFindViewHolderForAdapterPosition2 = recyclerView2.findViewHolderForAdapterPosition(iFindLastVisibleItemPosition);
                        if (j2VarFindViewHolderForAdapterPosition2 instanceof ro) {
                            ro roVar3 = (ro) j2VarFindViewHolderForAdapterPosition2;
                            if (roVar3.f6816lb instanceof com.bytedance.sdk.openadsdk.activity.single.fm) {
                                roVar3.f6816lb.jnr(true);
                                roVar3.f6816lb.nt();
                            }
                        }
                    }
                }
            }
        });
        wbw();
        final int iSds = sds();
        recyclerView.post(new Runnable() { // from class: com.bytedance.sdk.openadsdk.activity.single.yz.15
            @Override // java.lang.Runnable
            public void run() {
                if (com.bytedance.sdk.component.utils.ro.fm(activity)) {
                    return;
                }
                yz.this.fm(iSds, true);
            }
        });
        PAGLogoView pAGLogoViewCreatePAGLogoViewByMaterial = PAGLogoView.createPAGLogoViewByMaterial(activity, lseVar);
        this.gof = pAGLogoViewCreatePAGLogoViewByMaterial;
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-2, -2);
        layoutParams.gravity = 83;
        layoutParams.leftMargin = zan.ro(activity, 16.0f);
        lbVar.addView(pAGLogoViewCreatePAGLogoViewByMaterial, layoutParams);
        pAGLogoViewCreatePAGLogoViewByMaterial.setOnClickListener(new View.OnClickListener() { // from class: com.bytedance.sdk.openadsdk.activity.single.yz.16
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                if (com.bytedance.sdk.openadsdk.utils.ro.jnr() && gof.yz().ai()) {
                    Context context = view.getContext();
                    lse lseVar2 = lseVar;
                    IABLandingPageActivity.fm(context, lseVar2, lseVar2.jnr());
                } else {
                    Context context2 = view.getContext();
                    lse lseVar3 = lseVar;
                    TTWebsiteActivity.fm(context2, lseVar3, lseVar3.jnr());
                }
            }
        });
        this.wey = com.bytedance.sdk.openadsdk.hlt.jnr.fm("draw_feed_item_reuse", 0) == 1;
    }

    private void ai() {
        if (this.si == null) {
            return;
        }
        new com.bytedance.sdk.openadsdk.core.dsz.ef.fm(this.fm).fm(this.si, com.bytedance.sdk.openadsdk.core.vt.ro.lb.ro(), this.f6806ib, new com.bytedance.sdk.openadsdk.core.dsz.wsy.yz() { // from class: com.bytedance.sdk.openadsdk.activity.single.yz.8
            @Override // com.bytedance.sdk.openadsdk.core.dsz.wsy.yz
            public void fm(int i10, String str) {
                yz.this.ywr = true;
            }

            @Override // com.bytedance.sdk.openadsdk.core.dsz.wsy.yz
            public void fm(com.bytedance.adsdk.ugeno.ro.lb<View> lbVar) {
                View viewKu = lbVar.ku();
                ViewGroup viewGroup = (ViewGroup) viewKu.getParent();
                if (viewGroup != null) {
                    viewGroup.removeView(viewKu);
                }
                yz.this.bwv = viewKu;
                if (yz.this.lz != null) {
                    yz.this.lz.addView(viewKu, new FrameLayout.LayoutParams(-1, -1));
                }
            }
        });
    }

    private void gzf() {
        if (this.f6808qf || this.si == null) {
            return;
        }
        this.vt.removeMessages(3);
        this.vt.sendEmptyMessageDelayed(3, ((long) this.maa) * 1000);
    }

    private boolean ha() {
        FrameLayout frameLayout = this.lz;
        return (frameLayout == null || frameLayout.getParent() == null) ? false : true;
    }

    private void hxv() {
        if (this.so) {
            this.pcm = System.currentTimeMillis();
        }
        this.vt.removeMessages(1);
        ajl ajlVar = this.mj;
        if (ajlVar != null) {
            ajlVar.ro();
        }
    }

    private void mq() {
        wu wuVar;
        if (!this.duv || this.yz.qhl() || (wuVar = this.wbw) == null) {
            return;
        }
        wuVar.kwx();
    }

    private void nt() {
        FrameLayout frameLayout = this.lz;
        if (frameLayout == null) {
            return;
        }
        ViewParent parent = frameLayout.getParent();
        if (parent instanceof ViewGroup) {
            ((ViewGroup) parent).removeView(this.lz);
        }
        this.lz = null;
        wu wuVar = this.wbw;
        if (wuVar instanceof com.bytedance.sdk.openadsdk.activity.single.fm) {
            ((com.bytedance.sdk.openadsdk.activity.single.fm) wuVar).ai();
        }
        pkk();
        Message message = this.vvj;
        if (message != null) {
            handleMessage(message);
            this.vvj = null;
        }
    }

    private void ol() {
        if (this.lz != null || this.si == null || this.ywr) {
            return;
        }
        this.f6808qf = true;
        this.lz = new com.bytedance.sdk.openadsdk.core.ajl.lb(this.fm) { // from class: com.bytedance.sdk.openadsdk.activity.single.yz.9
            @Override // android.view.ViewGroup, android.view.View
            public boolean dispatchTouchEvent(MotionEvent motionEvent) {
                yz.this.vt.removeMessages(4);
                yz.this.vt.sendEmptyMessage(4);
                try {
                    return super.dispatchTouchEvent(motionEvent);
                } catch (Exception unused) {
                    return false;
                }
            }
        };
        View view = this.bwv;
        if (view != null && view.getParent() == null) {
            this.lz.addView(this.bwv, new FrameLayout.LayoutParams(-1, -1));
        }
        this.ku.addView(this.lz, new FrameLayout.LayoutParams(-1, -1));
        this.vt.sendEmptyMessageDelayed(4, ((long) this.lse) * 1000);
        wu wuVar = this.wbw;
        if (wuVar instanceof com.bytedance.sdk.openadsdk.activity.single.fm) {
            ((com.bytedance.sdk.openadsdk.activity.single.fm) wuVar).gzf();
        }
        hxv();
    }

    private void pkk() {
        if (this.pcm != 0) {
            wu wuVar = this.wbw;
            if (wuVar != null && ai.ro(wuVar.ajl)) {
                int iCurrentTimeMillis = this.pkk - ((int) ((System.currentTimeMillis() - this.pcm) / 1000));
                this.pkk = iCurrentTimeMillis;
                if (iCurrentTimeMillis < 0) {
                    this.pkk = 0;
                }
            }
            this.pcm = 0L;
        }
        if (this.pkk >= 0) {
            this.vt.removeMessages(1);
            this.vt.sendEmptyMessage(1);
        }
        ajl ajlVar = this.mj;
        if (ajlVar != null) {
            ajlVar.lb();
        }
    }

    private void wbw() {
        hi hiVarKu;
        com.bytedance.sdk.openadsdk.core.model.fm fmVarYz = this.ro.yz();
        if (fmVarYz == null || (hiVarKu = fmVarYz.ku()) == null || TextUtils.isEmpty(hiVarKu.wsy())) {
            return;
        }
        this.f6804gc = new com.bytedance.sdk.openadsdk.activity.single.jnr(this.yz, this.ro, -1, 1, false, false, true);
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public com.bytedance.sdk.openadsdk.component.reward.top.lb duv() {
        return null;
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public void fm(int i10) {
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public void gof() {
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public void gqi() {
    }

    @Override // android.os.Handler.Callback
    public boolean handleMessage(@NonNull Message message) {
        if (this.mpp) {
            this.gqi.add(this.vt.obtainMessage(message.what, message.arg1, message.arg2, message.obj));
            return false;
        }
        int i10 = message.what;
        if (i10 == 1) {
            int i11 = this.pkk;
            if (i11 > 0) {
                if (i11 <= this.mq) {
                    mq();
                }
                int i12 = this.hxv;
                int i13 = (int) ((((double) (i12 - this.pkk)) * 100.0d) / ((double) i12));
                TopLayoutDislike2 topLayoutDislike2 = this.f6803ef;
                StringBuilder sb = new StringBuilder();
                int i14 = this.pkk;
                this.pkk = i14 - 1;
                sb.append(i14);
                sb.append(CmcdData.STREAMING_FORMAT_SS);
                topLayoutDislike2.setCountDownFor1InN(sb.toString(), i13);
                if (this.pkk >= 0) {
                    this.vt.removeMessages(message.what);
                    this.vt.sendEmptyMessageDelayed(message.what, 1000L);
                }
            } else {
                mq();
                if (yz()) {
                    this.f6803ef.showSkipButton();
                } else {
                    this.f6803ef.showCloseButton();
                }
            }
        } else if (i10 == 3) {
            ol();
        } else if (i10 == 4) {
            nt();
        }
        return false;
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public boolean jnr() {
        return this.ai;
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public wu ku() {
        return this.wbw;
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public int wu() {
        return this.pkk;
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public boolean yz() {
        return this.f6804gc != null;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void hi() {
        com.bytedance.sdk.openadsdk.activity.single.jnr jnrVar = this.f6804gc;
        if (jnrVar == null || !jnrVar.lse()) {
            this.yz.wsy();
            return;
        }
        ro(this.f6804gc);
        this.ku.removeView(this.ajl);
        this.f6803ef.setVisibility(8);
        this.gof.setVisibility(8);
    }

    private void hlt() {
        xgn.fm(new Runnable() { // from class: com.bytedance.sdk.openadsdk.activity.single.yz.4
            @Override // java.lang.Runnable
            public void run() {
                if (com.bytedance.sdk.component.utils.ro.fm(yz.this.fm)) {
                    return;
                }
                yz.this.dsz.set(false);
                if (!yz.this.hlt) {
                    yz.this.wsy.fm(maa.fm(gof.fm(), "tt_list_end_tip"));
                } else {
                    yz.this.wsy.fm("");
                    yz.this.lse();
                }
            }
        });
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void lse() {
        if (this.tzk) {
            return;
        }
        if (this.hlt) {
            sds();
        } else {
            xgn.fm(new Runnable() { // from class: com.bytedance.sdk.openadsdk.activity.single.yz.18
                @Override // java.lang.Runnable
                public void run() {
                    if (com.bytedance.sdk.component.utils.ro.fm(yz.this.fm)) {
                        return;
                    }
                    yz.this.wsy.fm(maa.fm(gof.fm(), "tt_list_end_tip"));
                }
            });
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void maa() {
        if (this.dsz.compareAndSet(false, true)) {
            AdSlot adSlotCpu = this.ro.cpu();
            mq mqVar = new mq();
            mqVar.ajl = true;
            if (this.ro.zzn() != null || this.ro.po() != null) {
                mqVar.f7209ef = 2;
            }
            mqVar.wsy = this.zan;
            this.wsy.fm(maa.fm(this.fm, "tt_loading_more"));
            gof.lb().fm(adSlotCpu, mqVar, this.ro.tmm(), new com.bytedance.sdk.openadsdk.core.maa() { // from class: com.bytedance.sdk.openadsdk.activity.single.yz.17
                @Override // com.bytedance.sdk.openadsdk.core.maa, com.bytedance.sdk.openadsdk.core.lse.fm
                public void fm(int i10, String str) {
                    yz.this.fm(i10, str);
                }

                @Override // com.bytedance.sdk.openadsdk.core.maa, com.bytedance.sdk.openadsdk.core.lse.fm
                public void fm(com.bytedance.sdk.openadsdk.core.model.fm fmVar, com.bytedance.sdk.openadsdk.core.model.lb lbVar) {
                    yz.this.fm(fmVar, lbVar);
                }
            });
        }
    }

    private int sds() {
        if (!this.hlt || this.wsy.lb() || this.dsz.get() || this.tzk) {
            return 0;
        }
        int iFm = fm(this.ol, this.wsy.yz(), 1073741823);
        this.wsy.fm(this.ol, iFm);
        if (this.ol < 0) {
            this.ajl.scrollToPosition(iFm);
        } else {
            this.ol = iFm;
        }
        return iFm;
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public List<lse> fhx() {
        return this.wsy.jnr();
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public boolean fm(wu wuVar, int i10) {
        com.bytedance.sdk.openadsdk.activity.single.jnr jnrVar = this.f6804gc;
        return jnrVar != null && jnrVar == wuVar;
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public void irt() {
        if (this.bkb) {
            return;
        }
        this.bkb = true;
        final long jElapsedRealtime = SystemClock.elapsedRealtime() - this.kwx;
        long jCurrentTimeMillis = System.currentTimeMillis();
        lse lseVar = this.ro;
        com.bytedance.sdk.openadsdk.yz.lb.fm(jCurrentTimeMillis, lseVar, lseVar.jnr(), "first_ad_loaded", new com.bytedance.sdk.openadsdk.irt.ro.fm() { // from class: com.bytedance.sdk.openadsdk.activity.single.yz.10
            @Override // com.bytedance.sdk.openadsdk.irt.ro.fm, com.bytedance.sdk.openadsdk.irt.ro.ro
            public JSONObject ro() {
                JSONObject jSONObject = new JSONObject();
                try {
                    jSONObject.put("duration", jElapsedRealtime);
                } catch (Throwable unused) {
                }
                return jSONObject;
            }
        });
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public void qhl() {
        super.qhl();
        this.so = true;
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public int vt() {
        return this.onz.size();
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    /* JADX INFO: renamed from: wey, reason: merged with bridge method [inline-methods] */
    public com.bytedance.sdk.openadsdk.activity.single.fm dsz() {
        j2 j2VarFindViewHolderForAdapterPosition = this.ajl.findViewHolderForAdapterPosition(this.ol + 1);
        if (!(j2VarFindViewHolderForAdapterPosition instanceof ro)) {
            return null;
        }
        wu wuVarFm = ((ro) j2VarFindViewHolderForAdapterPosition).fm();
        if (wuVarFm instanceof com.bytedance.sdk.openadsdk.activity.single.fm) {
            return (com.bytedance.sdk.openadsdk.activity.single.fm) wuVarFm;
        }
        return null;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void lb(wu wuVar) {
        wu wuVar2 = this.wbw;
        if (wuVar != wuVar2) {
            return;
        }
        if (this.xgn) {
            if (this.ol < this.wsy.fm() - 1) {
                int i10 = this.ol + 1;
                this.bx = i10;
                if (this.fhx) {
                    this.ajl.smoothScrollToPosition(i10);
                } else {
                    ro(i10);
                }
            } else {
                this.bx = 0;
                this.ajl.scrollToPosition(0);
                this.ajl.post(new Runnable() { // from class: com.bytedance.sdk.openadsdk.activity.single.yz.7
                    @Override // java.lang.Runnable
                    public void run() {
                        if (com.bytedance.sdk.component.utils.ro.fm(yz.this.fm)) {
                            return;
                        }
                        yz yzVar = yz.this;
                        yzVar.fm(yzVar.bx, true);
                    }
                });
            }
        } else if (this.ado) {
            wuVar2.lb();
        } else {
            wuVar2.gc();
        }
        this.mj = null;
        this.ado = false;
    }

    private void ro(wu wuVar) {
        for (wu wuVar2 : this.wsy.ro()) {
            if (wuVar2 != wuVar) {
                wuVar2.fm(this.wbw, wuVar, this.f6805ha);
            }
        }
        com.bytedance.sdk.openadsdk.activity.single.jnr jnrVar = this.f6804gc;
        if (jnrVar != null && jnrVar != wuVar) {
            jnrVar.fm(this.wbw, wuVar, this.f6805ha);
        }
        wu wuVar3 = this.wbw;
        this.wbw = wuVar;
        if (wuVar3 != null) {
            wuVar3.duv = false;
            wuVar3.onz();
            wuVar3.yz();
        }
        wuVar.duv = true;
        wuVar.ro(this.fm, new ro.jnr(1, null));
        com.bytedance.sdk.openadsdk.component.reward.view.wu wuVarFm = wuVar.fm();
        if (wuVarFm.getVisibility() != 0) {
            wuVarFm.setVisibility(0);
        }
        if (wuVarFm.getParent() == null) {
            this.ku.addView(wuVarFm, new FrameLayout.LayoutParams(-1, -1));
        }
        this.yz.ro(wuVar);
        if (wuVar.f_() != this.ai) {
            wuVar.fm("card_sync");
        }
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public void lb() {
        super.lb();
        this.mpp = true;
        wu wuVar = this.wbw;
        if (wuVar != null) {
            wuVar.onz();
        }
        hxv();
        this.ado = this.mj != null;
        this.vt.removeMessages(3);
    }

    private static int fm(int i10, int i11, int i12) {
        if (i10 < 0) {
            i10 = 0;
        }
        for (int i13 = 0; i13 < i11; i13++) {
            int i14 = i12 + i13;
            if (i14 % i11 != i10) {
                i14 = i12 - i13;
                if (i14 % i11 != i10) {
                }
            }
            return i14;
        }
        return i12;
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public void fm(Bundle bundle) {
        super.fm(bundle);
        ai();
        com.bytedance.sdk.openadsdk.lse.fm.fm.fm(this.fm, this.ku, com.bytedance.sdk.openadsdk.lse.fm.fm.fm(this.ro.ss()));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void fm(int i10, String str) {
        this.tzk = false;
        hlt();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void fm(com.bytedance.sdk.openadsdk.core.model.fm fmVar, com.bytedance.sdk.openadsdk.core.model.lb lbVar) {
        this.tzk = false;
        if (fmVar.jnr() != null && !fmVar.jnr().isEmpty()) {
            fm(fmVar);
            return;
        }
        lbVar.fm(-3);
        lbVar.lb(1);
        com.bytedance.sdk.openadsdk.core.model.lb.fm(lbVar);
        hlt();
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public void ro(Activity activity) {
        super.ro(activity);
        zan.fm(activity);
    }

    private void ro(int i10) {
        j2 j2VarFindViewHolderForAdapterPosition;
        int iFindFirstVisibleItemPosition = this.wu.findFirstVisibleItemPosition();
        int iFindLastVisibleItemPosition = this.wu.findLastVisibleItemPosition();
        if (i10 < iFindFirstVisibleItemPosition) {
            this.ajl.smoothScrollToPosition(i10);
            return;
        }
        if (i10 <= iFindLastVisibleItemPosition) {
            int i11 = i10 - iFindFirstVisibleItemPosition;
            int childCount = this.ajl.getChildCount();
            if (i11 <= 0 || i11 >= childCount || (j2VarFindViewHolderForAdapterPosition = this.ajl.findViewHolderForAdapterPosition(i10 - 1)) == null) {
                return;
            }
            this.ajl.smoothScrollBy(0, j2VarFindViewHolderForAdapterPosition.itemView.getBottom());
            return;
        }
        this.ajl.smoothScrollToPosition(this.bx);
    }

    private void fm(final com.bytedance.sdk.openadsdk.core.model.fm fmVar) {
        hi hiVarKu = fmVar.ku();
        if (hiVarKu != null) {
            this.zan = hiVarKu.duv();
            this.tzk = hiVarKu.dsz();
        }
        if (!this.fhx) {
            for (lse lseVar : fmVar.jnr()) {
                if (lseVar.ex() != null && lse.jnr(lseVar)) {
                    com.bytedance.sdk.openadsdk.core.fhx.fm.ro roVarFm = lse.fm(((a) CacheDirFactory.getICacheDir(lseVar.il())).b(), lseVar);
                    roVarFm.fm("material_meta", lseVar);
                    roVarFm.fm("ad_slot", lseVar.cpu());
                    com.bytedance.sdk.openadsdk.core.fhx.jnr.fm.fm(roVarFm, new c() { // from class: com.bytedance.sdk.openadsdk.activity.single.yz.2
                        @Override // y5.a
                        public void fm(com.bykv.vk.openvk.fm.fm.fm.lb.lb lbVar, int i10) {
                        }

                        @Override // y5.a
                        public void fm(com.bykv.vk.openvk.fm.fm.fm.lb.lb lbVar, int i10, String str) {
                        }
                    });
                }
            }
        }
        xgn.fm(new Runnable() { // from class: com.bytedance.sdk.openadsdk.activity.single.yz.3
            @Override // java.lang.Runnable
            public void run() {
                if (com.bytedance.sdk.component.utils.ro.fm(yz.this.fm)) {
                    return;
                }
                yz.this.dsz.set(false);
                yz.this.wsy.fm("");
                yz.this.wsy.fm(fmVar.jnr());
                yz.this.lse();
            }
        });
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public void ro() {
        super.ro();
        this.mpp = false;
        this.so = false;
        wu wuVar = this.wbw;
        if (wuVar != null && !this.ado) {
            wuVar.lb();
        }
        if (this.kwx == 0) {
            this.kwx = SystemClock.elapsedRealtime();
        }
        pkk();
        gzf();
        Iterator<Message> it = this.gqi.iterator();
        while (it.hasNext()) {
            handleMessage(it.next());
        }
        this.gqi.clear();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void fm(int i10, boolean z10) {
        int i11;
        j2 j2VarFindViewHolderForAdapterPosition = this.ajl.findViewHolderForAdapterPosition(i10);
        if (j2VarFindViewHolderForAdapterPosition == null || !(j2VarFindViewHolderForAdapterPosition instanceof ro) || (i11 = this.ol) == i10) {
            return;
        }
        fm(i11, i10, z10);
        this.ol = i10;
        this.f6807ne = SystemClock.elapsedRealtime();
        wu wuVarFm = ((ro) j2VarFindViewHolderForAdapterPosition).fm();
        if (wuVarFm == null) {
            return;
        }
        ro(wuVarFm);
        this.onz.add(wuVarFm.ajl.ib());
        if (this.tzk && this.hi > 0 && this.ol >= this.wsy.fm() - this.hi) {
            maa();
        }
        com.bytedance.sdk.openadsdk.activity.single.fm fmVarDsz = dsz();
        if (fmVarDsz == null) {
            this.lmk = true;
            return;
        }
        if (!this.fhx && this.wu.findLastVisibleItemPosition() >= this.ol + 1) {
            fmVarDsz.jnr(true);
        }
        this.qhl.add(Integer.valueOf(this.ol + 1));
        fmVarDsz.nt();
        this.lmk = false;
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public void ro(wu wuVar, int i10) {
        wu wuVar2 = this.wbw;
        if (wuVar != wuVar2) {
            return;
        }
        if (i10 == 2) {
            hxv();
            return;
        }
        if (i10 == 1) {
            if (ha()) {
                wu wuVar3 = this.wbw;
                if (wuVar3 instanceof com.bytedance.sdk.openadsdk.activity.single.fm) {
                    ((com.bytedance.sdk.openadsdk.activity.single.fm) wuVar3).gzf();
                    return;
                }
                return;
            }
            pkk();
            return;
        }
        if (i10 == 3 || i10 == 4) {
            try {
                wuVar2.hlt().sds.ha();
            } catch (Throwable th) {
                wey.lb("CardsLayoutManager", th);
            }
        }
    }

    private void fm(int i10, int i11, boolean z10) {
        if (i10 < 0 || i11 < 0 || i10 == i11) {
            return;
        }
        final String str = z10 ? "auto_down" : i11 > i10 ? "down" : "up";
        final long jElapsedRealtime = (SystemClock.elapsedRealtime() - this.f6807ne) / 1000;
        List<lse> listJnr = this.wsy.jnr();
        final int size = i10 % listJnr.size();
        final int size2 = i11 % listJnr.size();
        lse lseVar = listJnr.get(size);
        com.bytedance.sdk.openadsdk.yz.lb.fm(System.currentTimeMillis(), lseVar, lseVar.jnr(), "slide", new com.bytedance.sdk.openadsdk.irt.ro.fm() { // from class: com.bytedance.sdk.openadsdk.activity.single.yz.5
            @Override // com.bytedance.sdk.openadsdk.irt.ro.fm, com.bytedance.sdk.openadsdk.irt.ro.ro
            public JSONObject fm() {
                try {
                    JSONObject jSONObject = new JSONObject();
                    jSONObject.put("from", size + 1);
                    jSONObject.put("to", size2 + 1);
                    jSONObject.put("direction", str);
                    jSONObject.put("click_user_remaining", jElapsedRealtime);
                    return jSONObject;
                } catch (Exception unused) {
                    return null;
                }
            }
        });
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public void fm(final wu wuVar, wu wuVar2, ro.jnr jnrVar) {
        long jYz;
        if (wuVar != this.wbw) {
            return;
        }
        if (wuVar.hi() || ai.ro(wuVar.ajl)) {
            jYz = 500;
        } else {
            nt ntVarJd = wuVar.ajl.jd();
            jYz = ntVarJd != null ? ((long) ntVarJd.yz()) * 1000 : 0L;
        }
        ajl ajlVar = this.mj;
        if (ajlVar != null) {
            ajlVar.yz();
        }
        ajl ajlVar2 = new ajl(Math.max(500L, jYz)) { // from class: com.bytedance.sdk.openadsdk.activity.single.yz.6
            @Override // com.bytedance.sdk.openadsdk.activity.single.yz.ajl
            public void fm() {
                if (com.bytedance.sdk.component.utils.ro.fm(yz.this.fm)) {
                    return;
                }
                yz.this.lb(wuVar);
            }
        };
        this.mj = ajlVar2;
        ajlVar2.jnr();
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public void fm(boolean z10) {
        super.fm(z10);
        wu wuVar = this.wbw;
        if (wuVar != null) {
            wuVar.lb(z10);
        }
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public void fm(View view) {
        super.fm(view);
        if (view.getParent() != null) {
            return;
        }
        view.setVisibility(4);
        this.ku.addView(view, 0);
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public void fm(Activity activity) {
        super.fm(activity);
        wu wuVar = this.wbw;
        if (wuVar != null) {
            wuVar.ro(activity);
        }
        com.bytedance.sdk.openadsdk.activity.single.jnr jnrVar = this.f6804gc;
        if (jnrVar != null) {
            jnrVar.gqi();
        }
        Iterator<wu> it = this.wsy.ro().iterator();
        while (it.hasNext()) {
            it.next().gqi();
        }
        this.vt.removeCallbacksAndMessages(null);
        ajl ajlVar = this.mj;
        if (ajlVar != null) {
            ajlVar.yz();
            this.mj = null;
        }
        wu wuVar2 = this.wbw;
        if (wuVar2 == null || wuVar2.maa() || this.ro.emt()) {
            return;
        }
        fhx.ro().post(new ro.lb(this.ro));
    }

    @Override // com.bytedance.sdk.openadsdk.activity.single.lb
    public void fm(Map<String, Object> map, wu wuVar, float f10, float f11) {
        Object jSONObject = map.get("pag_json_data");
        if (jSONObject == null) {
            jSONObject = new JSONObject();
        }
        if (jSONObject instanceof JSONObject) {
            try {
                com.bytedance.sdk.openadsdk.component.reward.view.wu wuVarFm = wuVar.fm();
                ((JSONObject) jSONObject).put("width", wuVarFm.getWidth());
                ((JSONObject) jSONObject).put("height", wuVarFm.getHeight());
                int i10 = wuVar.vt;
                ((JSONObject) jSONObject).put("click_feed_top", i10 == this.wu.findFirstVisibleItemPosition() ? 1 : 0);
                ((JSONObject) jSONObject).put("click_on_final", i10 == this.wsy.yz() ? 1 : 0);
                ((JSONObject) jSONObject).put("click_countdown_remaining", this.pkk);
                ((JSONObject) jSONObject).put("click_user_remaining", i10 == this.ol ? (SystemClock.elapsedRealtime() - this.f6807ne) / 1000 : 0L);
                map.put("pag_json_data", jSONObject.toString());
            } catch (Exception unused) {
            }
        }
    }
}
