package com.bytedance.sdk.openadsdk.component.reward.view;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import androidx.annotation.Nullable;
import com.bytedance.sdk.component.adexpress.ro.onz;
import com.bytedance.sdk.component.utils.maa;
import com.bytedance.sdk.openadsdk.activity.single.IABLandingPageActivity;
import com.bytedance.sdk.openadsdk.activity.single.TTWebsiteActivity;
import com.bytedance.sdk.openadsdk.component.reward.fm.irt;
import com.bytedance.sdk.openadsdk.core.gof;
import com.bytedance.sdk.openadsdk.core.model.ai;
import com.bytedance.sdk.openadsdk.core.model.fhx;
import com.bytedance.sdk.openadsdk.core.model.lse;
import com.bytedance.sdk.openadsdk.core.model.wey;
import com.bytedance.sdk.openadsdk.core.widget.PAGLogoView;
import com.bytedance.sdk.openadsdk.utils.qhl;
import com.bytedance.sdk.openadsdk.utils.zan;
import java.util.concurrent.atomic.AtomicBoolean;

/* JADX INFO: loaded from: classes2.dex */
public class ku {
    ImageView ajl;
    irt dsz;
    RelativeLayout duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    View f6986ef;
    private final boolean gqi;

    @Nullable
    private com.bytedance.sdk.openadsdk.core.widget.ku hlt;
    public wey irt;
    ImageView jnr;
    ImageView ku;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    protected final com.bytedance.sdk.openadsdk.component.reward.fm.ro f6987lb;
    private yz lse;
    private boolean maa;
    com.bytedance.sdk.openadsdk.core.ajl.ajl qhl;
    final Activity ro;
    private int sds;
    PAGLogoView vt;
    private final String wey;
    FrameLayout wsy;
    View wu;
    final lse yz;
    int fm = 3;
    protected int onz = 0;
    protected final AtomicBoolean fhx = new AtomicBoolean(false);
    Runnable gof = new Runnable() { // from class: com.bytedance.sdk.openadsdk.component.reward.view.ku.2
        @Override // java.lang.Runnable
        public void run() {
            ImageView imageView;
            try {
                lse lseVar = ku.this.yz;
                if ((lseVar == null || !lseVar.bq()) && (imageView = ku.this.jnr) != null) {
                    int[] iArr = new int[2];
                    imageView.getLocationOnScreen(iArr);
                    ku.this.f6987lb.f6938ha.fm(iArr[0]);
                }
            } catch (Exception unused) {
            }
        }
    };

    public ku(com.bytedance.sdk.openadsdk.component.reward.fm.ro roVar) {
        this.f6987lb = roVar;
        this.ro = roVar.xgn;
        this.yz = roVar.ro;
        this.wey = roVar.jnr;
        this.gqi = roVar.yz;
    }

    private void gqi() {
        RelativeLayout relativeLayout;
        yz yzVar = (yz) this.f6987lb.f6937gc.findViewById(qhl.onz);
        this.lse = yzVar;
        yzVar.fm(this.f6987lb);
        com.bytedance.sdk.openadsdk.core.widget.ku kuVar = (com.bytedance.sdk.openadsdk.core.widget.ku) this.f6987lb.f6937gc.findViewById(qhl.po);
        this.hlt = kuVar;
        if (kuVar != null) {
            com.bytedance.sdk.openadsdk.component.reward.fm.ro roVar = this.f6987lb;
            kuVar.fm(roVar.ro, roVar.jnr, null);
        }
        this.vt = (PAGLogoView) this.f6987lb.f6937gc.findViewById(520093757);
        this.ku = (ImageView) this.f6987lb.f6937gc.findViewById(qhl.gfn);
        this.jnr = (ImageView) this.f6987lb.f6937gc.findViewById(520093708);
        this.ajl = (ImageView) this.f6987lb.f6937gc.findViewById(qhl.f7551cd);
        this.wsy = (FrameLayout) this.f6987lb.f6937gc.findViewById(qhl.dsz);
        this.wu = this.f6987lb.f6937gc.findViewById(qhl.gof);
        this.f6986ef = this.f6987lb.f6937gc.findViewById(qhl.vod);
        this.duv = (RelativeLayout) this.f6987lb.f6937gc.findViewById(qhl.nss);
        irt irtVar = this.dsz;
        if (irtVar == null || irtVar.ajl() == null || (relativeLayout = this.duv) == null) {
            return;
        }
        relativeLayout.addView(this.dsz.ajl(), new LinearLayout.LayoutParams(-1, -1));
        this.dsz.lb();
    }

    public FrameLayout ajl() {
        return this.wsy;
    }

    public void dsz() {
        try {
            irt irtVar = this.dsz;
            if (irtVar != null) {
                irtVar.yz();
            }
            RelativeLayout relativeLayout = this.duv;
            if (relativeLayout != null) {
                relativeLayout.removeAllViews();
            }
        } catch (Throwable unused) {
            RelativeLayout relativeLayout2 = this.duv;
            if (relativeLayout2 != null) {
                relativeLayout2.setAlpha(0.0f);
            }
        }
    }

    public View duv() {
        return this.lse;
    }

    public boolean ef() {
        ImageView imageView = this.jnr;
        return imageView != null && imageView.getVisibility() == 0;
    }

    public void fhx() {
        wey weyVar = this.irt;
        if (weyVar != null) {
            weyVar.ajl();
        }
        ImageView imageView = this.jnr;
        if (imageView != null) {
            imageView.removeCallbacks(this.gof);
        }
    }

    public boolean fm() {
        return true;
    }

    public void gof() {
        com.bytedance.sdk.openadsdk.core.lb.jnr jnrVarJnr = this.f6987lb.nt.jnr();
        View view = this.lse;
        if (view == null) {
            view = this.f6987lb.f6937gc;
        }
        jnrVarJnr.onClick(view);
    }

    public void irt() {
        wey weyVar = this.irt;
        if (weyVar != null) {
            weyVar.wsy();
        }
    }

    public void jnr() {
        int iJn = this.yz.jn();
        this.fm = iJn;
        if (iJn == -200) {
            this.fm = gof.yz().irt(String.valueOf(this.yz.pg()));
        }
        if (this.fm != -1 || fm()) {
            return;
        }
        com.bytedance.sdk.openadsdk.component.reward.ro.ro roVar = this.f6987lb.so;
        if ((roVar instanceof com.bytedance.sdk.openadsdk.component.reward.ro.yz) || (roVar instanceof com.bytedance.sdk.openadsdk.component.reward.ro.lb)) {
            return;
        }
        ro(0);
    }

    public View ku() {
        return this.ajl;
    }

    public void lb() {
        this.wsy.removeAllViews();
    }

    public void onz() {
        try {
            Activity activity = this.f6987lb.xgn;
            Animation animationLoadAnimation = AnimationUtils.loadAnimation(activity, maa.ef(activity, "tt_fade_out"));
            if (animationLoadAnimation == null) {
                this.f6987lb.hxv.dsz();
            } else {
                animationLoadAnimation.setAnimationListener(new Animation.AnimationListener() { // from class: com.bytedance.sdk.openadsdk.component.reward.view.ku.3
                    @Override // android.view.animation.Animation.AnimationListener
                    public void onAnimationEnd(Animation animation) {
                        ku.this.f6987lb.hxv.dsz();
                    }

                    @Override // android.view.animation.Animation.AnimationListener
                    public void onAnimationRepeat(Animation animation) {
                    }

                    @Override // android.view.animation.Animation.AnimationListener
                    public void onAnimationStart(Animation animation) {
                    }
                });
                this.f6987lb.hxv.fm(animationLoadAnimation);
            }
        } catch (Throwable unused) {
            this.f6987lb.hxv.dsz();
        }
    }

    public void qhl() {
        wey weyVar = this.irt;
        if (weyVar != null) {
            weyVar.wu();
        }
    }

    public void ro() {
        if (this.maa) {
            return;
        }
        this.maa = true;
        this.sds = this.f6987lb.kwx;
        if (fm()) {
            com.bytedance.sdk.openadsdk.component.reward.fm.ro roVar = this.f6987lb;
            if (!roVar.bwv) {
                irt irtVar = new irt(roVar);
                this.dsz = irtVar;
                irtVar.fm();
            }
        }
        gqi();
        Activity activity = this.ro;
        lse lseVar = this.yz;
        String str = this.wey;
        FrameLayout frameLayout = this.wsy;
        com.bytedance.sdk.openadsdk.component.reward.fm.ro roVar2 = this.f6987lb;
        wey weyVar = new wey(activity, lseVar, str, frameLayout, roVar2.mon, roVar2.f6937gc);
        this.irt = weyVar;
        weyVar.fm();
    }

    public View vt() {
        return this.jnr;
    }

    public void wsy() {
        if (this.ku.getVisibility() == 0) {
            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) this.ku.getLayoutParams();
            marginLayoutParams.setMargins(0, 0, 11, 16);
            marginLayoutParams.setMarginStart(0);
            marginLayoutParams.setMarginEnd(11);
            this.ku.setLayoutParams(marginLayoutParams);
        }
    }

    public void wu() {
        yz yzVar = this.lse;
        if (yzVar == null) {
            return;
        }
        yzVar.fm();
    }

    public void yz() {
        if (this.f6987lb.ro.uui() && ai.lb(this.f6987lb.ro)) {
            return;
        }
        zan.fm((View) this.wsy, 8);
        zan.fm((View) this.hlt, 8);
        zan.fm(this.wu, 8);
        zan.fm(this.f6986ef, 8);
        ro(8);
        zan.fm((View) this.jnr, 8);
        zan.fm((View) this.ajl, 8);
        zan.fm((View) this.vt, 8);
        zan.fm((View) this.duv, 8);
        zan.fm((View) this.ku, 8);
    }

    public void ajl(int i10) {
        zan.fm((View) this.jnr, i10);
    }

    public void lb(int i10) {
        lse lseVar = this.yz;
        if (lseVar != null && lseVar.uui() && ai.lb(this.yz)) {
            zan.fm((View) this.hlt, i10);
        }
    }

    public void fm(boolean z10) {
        zan.fm((View) this.vt, ai.lb(this.yz) ? 8 : 0);
        zan.fm((View) this.ku, (this.yz.zn() && this.yz.lse()) ? 0 : 8);
        ro(z10);
        if (this.gqi) {
            jnr();
        }
    }

    public void jnr(int i10) {
        int i11 = this.fm;
        if (i11 == -1 || i10 != i11 || this.fhx.get()) {
            return;
        }
        ro(0);
        this.fhx.set(true);
        wu();
    }

    public void fm(int i10) {
        if (this.qhl == null) {
            this.qhl = new com.bytedance.sdk.openadsdk.core.ajl.ajl(this.f6987lb.xgn);
            FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(120, 120);
            layoutParams.gravity = 17;
            this.qhl.setLayoutParams(layoutParams);
            this.qhl.setIndeterminateDrawable(com.bytedance.sdk.openadsdk.utils.ku.fm(this.f6987lb.xgn, "tt_video_loading_progress_bar"));
            this.f6987lb.hxv.ajl().addView(this.qhl);
        }
        this.qhl.setVisibility(i10);
    }

    public void ro(boolean z10) {
        int iFm;
        int iFm2;
        if (this.sds != 1 && z10) {
            ImageView imageView = this.jnr;
            ViewGroup.LayoutParams layoutParams = imageView != null ? imageView.getLayoutParams() : null;
            ImageView imageView2 = this.ajl;
            ViewGroup.LayoutParams layoutParams2 = imageView2 != null ? imageView2.getLayoutParams() : null;
            if ((layoutParams instanceof ViewGroup.MarginLayoutParams) && (iFm2 = fm("navigation_bar_height")) > 0) {
                ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
                if (iFm2 > marginLayoutParams.rightMargin) {
                    marginLayoutParams.rightMargin = iFm2;
                }
            }
            if ((layoutParams2 instanceof ViewGroup.MarginLayoutParams) && (iFm = fm("navigation_bar_height")) > 0) {
                ViewGroup.MarginLayoutParams marginLayoutParams2 = (ViewGroup.MarginLayoutParams) layoutParams2;
                if (iFm > marginLayoutParams2.rightMargin) {
                    marginLayoutParams2.rightMargin = iFm;
                }
            }
        }
        com.bytedance.sdk.openadsdk.component.reward.ro.ro roVar = this.f6987lb.so;
        if ((roVar instanceof com.bytedance.sdk.openadsdk.component.reward.ro.yz) || (roVar instanceof com.bytedance.sdk.openadsdk.component.reward.ro.lb)) {
            return;
        }
        ro(0);
    }

    public void yz(int i10) {
        zan.fm((View) this.vt, i10);
    }

    public void fm(int i10, int i11) {
        FrameLayout frameLayout;
        if (this.yz.daz() == 1 && (frameLayout = this.wsy) != null && (frameLayout.getLayoutParams() instanceof RelativeLayout.LayoutParams)) {
            int iLb = zan.lb((Context) this.ro);
            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) this.wsy.getLayoutParams();
            layoutParams.width = iLb;
            int i12 = (iLb * 9) / 16;
            layoutParams.height = i12;
            this.wsy.setLayoutParams(layoutParams);
            this.onz = (zan.jnr(this.ro) - i12) / 2;
        }
    }

    public void ro(int i10) {
        lse lseVar = this.yz;
        if (lseVar != null && lseVar.zn() && fhx.fm(this.yz)) {
            zan.fm((View) this.lse, 8);
        } else {
            zan.fm((View) this.lse, i10);
        }
    }

    public void fm(com.bytedance.sdk.openadsdk.core.lb.lb lbVar, View.OnTouchListener onTouchListener, View.OnClickListener onClickListener) {
        View view;
        View view2;
        lse lseVar;
        if (this.wsy != null && (lseVar = this.yz) != null && lseVar.qph() != null) {
            if (this.yz.qph().ajl && !wey.ro(this.yz)) {
                fm((View.OnClickListener) lbVar);
                fm(lbVar);
            } else {
                fm(onClickListener);
            }
        }
        lse lseVar2 = this.yz;
        if (lseVar2 != null && lseVar2.daz() == 1) {
            if (this.yz.qph() != null && (view2 = this.wu) != null) {
                zan.fm(view2, 0);
                RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) this.wu.getLayoutParams();
                layoutParams.height = this.onz;
                this.wu.setLayoutParams(layoutParams);
                if (this.yz.qph().ro) {
                    this.wu.setOnClickListener(lbVar);
                    this.wu.setOnTouchListener(onTouchListener);
                } else {
                    this.wu.setOnClickListener(onClickListener);
                }
            }
            if (this.yz.qph() != null && (view = this.f6986ef) != null) {
                zan.fm(view, 0);
                RelativeLayout.LayoutParams layoutParams2 = (RelativeLayout.LayoutParams) this.f6986ef.getLayoutParams();
                layoutParams2.height = this.onz;
                this.f6986ef.setLayoutParams(layoutParams2);
                if (this.yz.qph().yz) {
                    this.f6986ef.setOnClickListener(lbVar);
                    this.f6986ef.setOnTouchListener(onTouchListener);
                } else {
                    this.f6986ef.setOnClickListener(onClickListener);
                }
            }
        }
        PAGLogoView pAGLogoView = this.vt;
        if (pAGLogoView != null) {
            pAGLogoView.setOnClickListener(new View.OnClickListener() { // from class: com.bytedance.sdk.openadsdk.component.reward.view.ku.1
                @Override // android.view.View.OnClickListener
                public void onClick(View view3) {
                    try {
                        if (com.bytedance.sdk.openadsdk.utils.ro.jnr() && gof.yz().ai()) {
                            ku kuVar = ku.this;
                            IABLandingPageActivity.fm(kuVar.ro, kuVar.yz, kuVar.wey);
                        } else {
                            ku kuVar2 = ku.this;
                            TTWebsiteActivity.fm(kuVar2.ro, kuVar2.yz, kuVar2.wey);
                        }
                    } catch (Throwable th) {
                        com.bytedance.sdk.component.utils.wey.lb("TTAD.RFullVideoLayout", th.getMessage());
                    }
                }
            });
        }
        ImageView imageView = this.ku;
        if (imageView != null) {
            imageView.setClickable(true);
            com.bytedance.sdk.openadsdk.wey.ro.ro().fm((int) zan.fm(gof.fm(), 14.0f, true), this.ku, this.f6987lb.ro);
        }
    }

    private int fm(String str) {
        Resources resources = this.ro.getResources();
        if (resources != null) {
            return resources.getDimensionPixelSize(resources.getIdentifier(str, "dimen", "android"));
        }
        return 0;
    }

    public void fm(View.OnClickListener onClickListener) {
        zan.fm(this.wsy, onClickListener, "TTBaseVideoActivity#mVideoNativeFrame");
    }

    private void fm(com.bytedance.sdk.openadsdk.core.lb.lb lbVar) {
        zan.fm((View) this.wsy, (View.OnTouchListener) lbVar, "TTBaseVideoActivity#mVideoNativeFrame");
    }

    public void fm(float f10) {
        zan.fm(this.jnr, f10);
    }

    public void fm(Animation animation) {
        RelativeLayout relativeLayout = this.duv;
        if (relativeLayout != null) {
            relativeLayout.startAnimation(animation);
        }
    }

    public void fm(int i10, onz onzVar) {
        wey weyVar = this.irt;
        if (weyVar != null) {
            weyVar.fm(i10, onzVar);
        }
    }
}
