package xyz.stream.view.refresh.layout.simple;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import xyz.stream.view.refresh.layout.AutoRefreshLayout;
import xyz.stream.view.refresh.layout.api.RefreshComponent;
import xyz.stream.view.refresh.layout.api.RefreshFooter;
import xyz.stream.view.refresh.layout.api.RefreshHeader;
import xyz.stream.view.refresh.layout.api.RefreshKernel;
import xyz.stream.view.refresh.layout.api.RefreshLayout;
import xyz.stream.view.refresh.layout.constant.RefreshState;
import xyz.stream.view.refresh.layout.constant.SpinnerStyle;

/* JADX INFO: loaded from: classes3.dex */
public abstract class SimpleComponent extends RelativeLayout implements RefreshComponent {
    protected SpinnerStyle mSpinnerStyle;
    protected RefreshComponent mWrappedInternal;
    protected View mWrappedView;

    /* JADX WARN: Multi-variable type inference failed */
    public SimpleComponent(@NonNull View view) {
        this(view, view instanceof RefreshComponent ? (RefreshComponent) view : null);
    }

    public boolean autoOpen(int i10, float f10, boolean z10) {
        return false;
    }

    public boolean equals(Object obj) {
        if (super.equals(obj)) {
            return true;
        }
        return (obj instanceof RefreshComponent) && getView() == ((RefreshComponent) obj).getView();
    }

    @Override // xyz.stream.view.refresh.layout.api.RefreshComponent
    @NonNull
    public SpinnerStyle getSpinnerStyle() {
        int i10;
        SpinnerStyle spinnerStyle = this.mSpinnerStyle;
        if (spinnerStyle != null) {
            return spinnerStyle;
        }
        RefreshComponent refreshComponent = this.mWrappedInternal;
        if (refreshComponent != null && refreshComponent != this) {
            return refreshComponent.getSpinnerStyle();
        }
        View view = this.mWrappedView;
        if (view != null) {
            ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
            if (layoutParams instanceof AutoRefreshLayout.LayoutParams) {
                SpinnerStyle spinnerStyle2 = ((AutoRefreshLayout.LayoutParams) layoutParams).spinnerStyle;
                this.mSpinnerStyle = spinnerStyle2;
                if (spinnerStyle2 != null) {
                    return spinnerStyle2;
                }
            }
            if (layoutParams != null && ((i10 = layoutParams.height) == 0 || i10 == -1)) {
                for (SpinnerStyle spinnerStyle3 : SpinnerStyle.values) {
                    if (spinnerStyle3.scale) {
                        this.mSpinnerStyle = spinnerStyle3;
                        return spinnerStyle3;
                    }
                }
            }
        }
        SpinnerStyle spinnerStyle4 = SpinnerStyle.Translate;
        this.mSpinnerStyle = spinnerStyle4;
        return spinnerStyle4;
    }

    @Override // xyz.stream.view.refresh.layout.api.RefreshComponent
    @NonNull
    public View getView() {
        View view = this.mWrappedView;
        return view == null ? this : view;
    }

    @Override // xyz.stream.view.refresh.layout.api.RefreshComponent
    public boolean isSupportHorizontalDrag() {
        RefreshComponent refreshComponent = this.mWrappedInternal;
        return (refreshComponent == null || refreshComponent == this || !refreshComponent.isSupportHorizontalDrag()) ? false : true;
    }

    public int onFinish(@NonNull RefreshLayout refreshLayout, boolean z10) {
        RefreshComponent refreshComponent = this.mWrappedInternal;
        if (refreshComponent == null || refreshComponent == this) {
            return 0;
        }
        return refreshComponent.onFinish(refreshLayout, z10);
    }

    @Override // xyz.stream.view.refresh.layout.api.RefreshComponent
    public void onHorizontalDrag(float f10, int i10, int i11) {
        RefreshComponent refreshComponent = this.mWrappedInternal;
        if (refreshComponent == null || refreshComponent == this) {
            return;
        }
        refreshComponent.onHorizontalDrag(f10, i10, i11);
    }

    public void onInitialized(@NonNull RefreshKernel refreshKernel, int i10, int i11) {
        RefreshComponent refreshComponent = this.mWrappedInternal;
        if (refreshComponent != null && refreshComponent != this) {
            refreshComponent.onInitialized(refreshKernel, i10, i11);
            return;
        }
        View view = this.mWrappedView;
        if (view != null) {
            ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
            if (layoutParams instanceof AutoRefreshLayout.LayoutParams) {
                refreshKernel.requestDrawBackgroundFor(this, ((AutoRefreshLayout.LayoutParams) layoutParams).backgroundColor);
            }
        }
    }

    public void onMoving(boolean z10, float f10, int i10, int i11, int i12) {
        RefreshComponent refreshComponent = this.mWrappedInternal;
        if (refreshComponent == null || refreshComponent == this) {
            return;
        }
        refreshComponent.onMoving(z10, f10, i10, i11, i12);
    }

    public void onReleased(@NonNull RefreshLayout refreshLayout, int i10, int i11) {
        RefreshComponent refreshComponent = this.mWrappedInternal;
        if (refreshComponent == null || refreshComponent == this) {
            return;
        }
        refreshComponent.onReleased(refreshLayout, i10, i11);
    }

    public void onStartAnimator(@NonNull RefreshLayout refreshLayout, int i10, int i11) {
        RefreshComponent refreshComponent = this.mWrappedInternal;
        if (refreshComponent == null || refreshComponent == this) {
            return;
        }
        refreshComponent.onStartAnimator(refreshLayout, i10, i11);
    }

    public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState refreshState, @NonNull RefreshState refreshState2) {
        RefreshComponent refreshComponent = this.mWrappedInternal;
        if (refreshComponent == null || refreshComponent == this) {
            return;
        }
        if ((this instanceof RefreshFooter) && (refreshComponent instanceof RefreshHeader)) {
            if (refreshState.isFooter) {
                refreshState = refreshState.toHeader();
            }
            if (refreshState2.isFooter) {
                refreshState2 = refreshState2.toHeader();
            }
        } else if ((this instanceof RefreshHeader) && (refreshComponent instanceof RefreshFooter)) {
            if (refreshState.isHeader) {
                refreshState = refreshState.toFooter();
            }
            if (refreshState2.isHeader) {
                refreshState2 = refreshState2.toFooter();
            }
        }
        RefreshComponent refreshComponent2 = this.mWrappedInternal;
        if (refreshComponent2 != null) {
            refreshComponent2.onStateChanged(refreshLayout, refreshState, refreshState2);
        }
    }

    @SuppressLint({"RestrictedApi"})
    public boolean setNoMoreData(boolean z10) {
        RefreshComponent refreshComponent = this.mWrappedInternal;
        return (refreshComponent instanceof RefreshFooter) && ((RefreshFooter) refreshComponent).setNoMoreData(z10);
    }

    public void setPrimaryColors(@ColorInt int... iArr) {
        RefreshComponent refreshComponent = this.mWrappedInternal;
        if (refreshComponent == null || refreshComponent == this) {
            return;
        }
        refreshComponent.setPrimaryColors(iArr);
    }

    public SimpleComponent(@NonNull View view, @Nullable RefreshComponent refreshComponent) {
        super(view.getContext(), null, 0);
        this.mWrappedView = view;
        this.mWrappedInternal = refreshComponent;
        if ((this instanceof RefreshFooter) && (refreshComponent instanceof RefreshHeader) && refreshComponent.getSpinnerStyle() == SpinnerStyle.MatchLayout) {
            refreshComponent.getView().setScaleY(-1.0f);
            return;
        }
        if (this instanceof RefreshHeader) {
            RefreshComponent refreshComponent2 = this.mWrappedInternal;
            if ((refreshComponent2 instanceof RefreshFooter) && refreshComponent2.getSpinnerStyle() == SpinnerStyle.MatchLayout) {
                refreshComponent.getView().setScaleY(-1.0f);
            }
        }
    }

    public SimpleComponent(Context context, AttributeSet attributeSet, int i10) {
        super(context, attributeSet, i10);
    }
}
