package com.ss.android.ugc.aweme.commercialize.views;

import X.2ha;
import X.3F7;
import X.3G1;
import X.7he;
import X.C3505LNw;
import X.C3506LNx;
import X.C3507LNy;
import X.C3508LNz;
import X.Crj;
import X.LO0;
import X.LO1;
import X.LO2;
import X.LO3;
import X.LO4;
import X.LO5;
import X.LO6;
import X.LO7;
import X.LO8;
import X.LO9;
import X.LOA;
import X.M12;
import X.M75;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.LinearInterpolator;
import com.bytedance.covode.number.Covode;
import java.util.ArrayList;
import java.util.Objects;
import kotlin.h.b.n;

public final class AdHalfWebPageContainer extends M75 {
    public static final LOA LJ = new LOA((byte) 0);
    public static final String LJII = AdHalfWebPageContainer.class.getSimpleName();
    public boolean LIZ;
    public boolean LIZIZ;
    public boolean LIZJ;
    public boolean LIZLLL;
    public boolean LJFF;
    public final Crj LJI;

    public AdHalfWebPageContainer(Context context) {
        this(context, (AttributeSet) null, 6);
    }

    public AdHalfWebPageContainer(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 4);
    }

    private final View getDecorView() {
        return (View) this.LJI.getValue();
    }

    private void LJI() {
        if (this.LJFF) {
            setZ(0.0f);
        }
        setVisibility(0);
    }

    public final void LIZJ() {
        setTranslationX(getToTransX());
        setTranslationY(0.0f);
    }

    public final void LIZLLL() {
        setAlpha(0.0f);
        setVisibility(8);
        LIZJ();
    }

    public final void LJ() {
        setAlpha(1.0f);
        LJI();
    }

    public final boolean getCanCollapse() {
        if (!this.LIZJ || this.LIZLLL) {
            return false;
        }
        return true;
    }

    public final boolean getCanExpand() {
        if (!this.LIZJ || this.LIZLLL) {
            return true;
        }
        return false;
    }

    static {
        Covode.recordClassIndex(59872);
    }

    private final int getScreenHeight() {
        View decorView = getDecorView();
        if (decorView != null) {
            return decorView.getHeight();
        }
        return 3G1.LIZ(getContext());
    }

    private final int getScreenWidth() {
        View decorView = getDecorView();
        if (decorView != null) {
            return decorView.getWidth();
        }
        return 3G1.LIZIZ(getContext());
    }

    public final boolean LIZ() {
        if (getVisibility() == 0 && getAlpha() == 1.0f) {
            return true;
        }
        return false;
    }

    public final void LIZIZ() {
        if (this.LJFF) {
            setZ(-1.0f);
            setVisibility(0);
            return;
        }
        setVisibility(4);
    }

    public final void LJFF() {
        setTranslationX((((float) (getScreenWidth() - getWidth())) / 2.0f) - ((float) getLeft()));
    }

    private final float getToTransX() {
        int i;
        if (3F7.LIZ(getContext())) {
            int width = getWidth();
            ViewGroup.LayoutParams layoutParams = getLayoutParams();
            Objects.requireNonNull(layoutParams, "null cannot be cast to non-null type android.view.ViewGroup.MarginLayoutParams");
            i = width + ((ViewGroup.MarginLayoutParams) layoutParams).rightMargin;
        } else {
            int width2 = getWidth();
            ViewGroup.LayoutParams layoutParams2 = getLayoutParams();
            Objects.requireNonNull(layoutParams2, "null cannot be cast to non-null type android.view.ViewGroup.MarginLayoutParams");
            i = -(width2 + ((ViewGroup.MarginLayoutParams) layoutParams2).leftMargin);
        }
        return (float) i;
    }

    public final void setCollapsed(boolean z) {
        this.LIZLLL = z;
    }

    public final void setExpanded(boolean z) {
        this.LIZJ = z;
    }

    public final void setUseZOrder(boolean z) {
        this.LJFF = z;
    }

    public final void setInCleanMode(boolean z) {
        int i;
        this.LIZIZ = z;
        if (z) {
            i = 4;
        } else {
            i = 0;
        }
        setVisibility(i);
    }

    public final void LIZ(Runnable runnable) {
        this.LIZLLL = true;
        animate().translationY((float) (getScreenHeight() - getTop())).withStartAction(new LO1(this)).withEndAction(new C3507LNy(this, runnable)).setDuration(400).start();
    }

    public final void LIZIZ(boolean z) {
        if (z) {
            animate().alpha(0.0f).translationY((float) 2ha.LIZ(15.0d)).withStartAction(new LO4(this)).setDuration(290).withEndAction(new C3508LNz(this)).start();
        } else {
            animate().alpha(0.0f).translationX(getToTransX()).withStartAction(new LO5(this)).setDuration(200).withEndAction(new LO0(this)).start();
        }
    }

    public final void LIZ(boolean z) {
        if (!this.LIZIZ) {
            LJI();
        }
        if (z) {
            setTranslationX(0.0f);
            setTranslationY((float) 2ha.LIZ(15.0d));
            animate().alpha(1.0f).translationY(0.0f).withStartAction(new LO6(this)).setInterpolator(new LinearInterpolator()).setDuration(290).withEndAction(new LO7(this)).start();
            return;
        }
        setTranslationX(getToTransX());
        setTranslationY(0.0f);
        animate().alpha(1.0f).translationX(0.0f).withStartAction(new LO8(this)).setDuration(200).withEndAction(new LO9(this)).start();
    }

    public final void LIZIZ(int i, int i2) {
        LIZ(i, i2, 0);
    }

    public final void LIZ(int i, int i2) {
        this.LIZJ = true;
        this.LIZLLL = false;
        LIZ(i, i2, 100);
        float screenWidth = (((((float) (getScreenWidth() - i)) / 2.0f) - ((float) getLeft())) + ((float) i)) - ((float) getWidth());
        animate().translationX(screenWidth).translationY((((((float) (getScreenHeight() - i2)) / 2.0f) - ((float) getTop())) + ((float) i2)) - ((float) getHeight())).withStartAction(new LO2(this)).withEndAction(new LO3(this)).setDuration(100).start();
    }

    /* JADX INFO: super call moved to the top of the method (can break code semantics) */
    public AdHalfWebPageContainer(Context context, AttributeSet attributeSet, byte b) {
        super(context, attributeSet, 0);
        M12.LIZ((Object) context);
        setAlpha(0.0f);
        setRadius(2ha.LIZ(4.0d));
        this.LJI = 7he.LIZ(new C3505LNw(context));
    }

    /* JADX INFO: this call moved to the top of the method (can break code semantics) */
    public /* synthetic */ AdHalfWebPageContainer(Context context, AttributeSet attributeSet, int i) {
        this(context, (i & 2) != 0 ? null : attributeSet, (byte) 0);
    }

    private void LIZ(int i, int i2, long j) {
        ViewWrapper viewWrapper = new ViewWrapper(this);
        int i3 = (j > 0 ? 1 : (j == 0 ? 0 : -1));
        if (i3 == 0) {
            if (i > 0 && viewWrapper.getWidth() != i) {
                viewWrapper.setWidth(i);
            }
            if (i2 > 0 && viewWrapper.getHeight() != i2) {
                viewWrapper.setHeight(i2);
            }
        } else if (i3 > 0) {
            ArrayList arrayList = new ArrayList();
            if (i > 0 && viewWrapper.getWidth() != i) {
                ObjectAnimator ofInt = ObjectAnimator.ofInt(viewWrapper, "width", new int[]{viewWrapper.getWidth(), i});
                n.LIZIZ(ofInt, "");
                arrayList.add(ofInt);
            }
            if (i2 > 0 && viewWrapper.getHeight() != i2) {
                ObjectAnimator ofInt2 = ObjectAnimator.ofInt(viewWrapper, "height", new int[]{viewWrapper.getHeight(), i2});
                n.LIZIZ(ofInt2, "");
                arrayList.add(ofInt2);
            }
            if (!arrayList.isEmpty()) {
                AnimatorSet animatorSet = new AnimatorSet();
                animatorSet.playTogether(arrayList);
                animatorSet.setDuration(j);
                animatorSet.addListener(new C3506LNx(this));
                animatorSet.start();
            }
        }
    }
}
