package com.bytedance.sdk.component.adexpress.dynamic.dynamicview;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.LinearInterpolator;
import android.widget.FrameLayout;
import androidx.media3.common.C;

/* JADX INFO: loaded from: classes.dex */
public class wbw extends ajl {
    ObjectAnimator fm;
    private Runnable maa;
    ObjectAnimator ro;
    private boolean sds;
    private int wey;

    public wbw(Context context, DynamicRootView dynamicRootView, com.bytedance.sdk.component.adexpress.dynamic.yz.wu wuVar) {
        super(context, dynamicRootView, wuVar);
        this.wey = 0;
        this.sds = false;
        this.maa = new Runnable() { // from class: com.bytedance.sdk.component.adexpress.dynamic.dynamicview.wbw.1
            @Override // java.lang.Runnable
            public void run() {
                wbw.this.fm();
            }
        };
    }

    @Override // com.bytedance.sdk.component.adexpress.dynamic.dynamicview.ajl, com.bytedance.sdk.component.adexpress.dynamic.dynamicview.jnr, android.view.ViewGroup, android.view.View
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        for (int i10 = 0; i10 < getChildCount(); i10++) {
            View childAt = getChildAt(i10);
            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) childAt.getLayoutParams();
            layoutParams.topMargin = (this.wu - layoutParams.height) / 2;
            childAt.setLayoutParams(layoutParams);
            if (i10 != 0) {
                childAt.setVisibility(8);
            }
        }
        postDelayed(this.maa, 2500L);
    }

    @Override // com.bytedance.sdk.component.adexpress.dynamic.dynamicview.jnr, com.bytedance.sdk.component.adexpress.dynamic.dynamicview.hxv
    public void ro() {
        removeCallbacks(this.maa);
        ObjectAnimator objectAnimator = this.fm;
        if (objectAnimator != null) {
            objectAnimator.removeAllUpdateListeners();
            this.fm.cancel();
        }
        ObjectAnimator objectAnimator2 = this.ro;
        if (objectAnimator2 != null) {
            objectAnimator2.removeAllUpdateListeners();
            this.ro.cancel();
        }
        super.ro();
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void fm() {
        final View childAt;
        final View childAt2 = getChildAt(this.wey);
        int i10 = this.wey;
        if (i10 == 0) {
            this.sds = false;
        }
        boolean z10 = i10 + 1 >= getChildCount() || ((ViewGroup) getChildAt(this.wey + 1)).getChildCount() <= 0;
        if (this.dsz.vt().jnr().fm() || !z10) {
            View childAt3 = z10 ? getChildAt((this.wey + 2) % getChildCount()) : getChildAt((this.wey + 1) % getChildCount());
            this.fm = ObjectAnimator.ofFloat(childAt2, "translationY", 0.0f, (-(getChildAt(this.wey).getHeight() + this.wu)) / 2);
            if (z10) {
                this.wey++;
            }
            childAt = childAt3;
        } else {
            this.sds = true;
            childAt = getChildAt(this.wey - 1);
            this.fm = ObjectAnimator.ofFloat(childAt2, "translationY", 0.0f, (getChildAt(this.wey).getHeight() + this.wu) / 2);
        }
        this.fm.setInterpolator(new LinearInterpolator());
        this.fm.addListener(new Animator.AnimatorListener() { // from class: com.bytedance.sdk.component.adexpress.dynamic.dynamicview.wbw.2
            @Override // android.animation.Animator.AnimatorListener
            public void onAnimationCancel(Animator animator) {
            }

            @Override // android.animation.Animator.AnimatorListener
            public void onAnimationEnd(Animator animator) {
                childAt2.setVisibility(8);
            }

            @Override // android.animation.Animator.AnimatorListener
            public void onAnimationRepeat(Animator animator) {
            }

            @Override // android.animation.Animator.AnimatorListener
            public void onAnimationStart(Animator animator) {
            }
        });
        if (this.sds) {
            this.ro = ObjectAnimator.ofFloat(childAt, "translationY", (-(childAt.getHeight() + this.wu)) / 2, 0.0f);
        } else {
            this.ro = ObjectAnimator.ofFloat(childAt, "translationY", (childAt.getHeight() + this.wu) / 2, 0.0f);
        }
        this.ro.setInterpolator(new LinearInterpolator());
        this.ro.addListener(new Animator.AnimatorListener() { // from class: com.bytedance.sdk.component.adexpress.dynamic.dynamicview.wbw.3
            @Override // android.animation.Animator.AnimatorListener
            public void onAnimationCancel(Animator animator) {
            }

            @Override // android.animation.Animator.AnimatorListener
            public void onAnimationEnd(Animator animator) {
            }

            @Override // android.animation.Animator.AnimatorListener
            public void onAnimationRepeat(Animator animator) {
            }

            @Override // android.animation.Animator.AnimatorListener
            public void onAnimationStart(Animator animator) {
                childAt.setVisibility(0);
            }
        });
        this.fm.setDuration(500L);
        this.ro.setDuration(500L);
        this.fm.start();
        this.ro.start();
        if (this.sds) {
            this.wey--;
        } else {
            int i11 = this.wey + 1;
            this.wey = i11;
            this.wey = i11 % getChildCount();
        }
        postDelayed(this.maa, C.DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS);
    }
}
