package com.bytedance.ies.uikit.recyclerview;

import X.0EG;
import X.0HH;
import X.1CV;
import X.S8P;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
import com.bytedance.covode.number.Covode;

public abstract class LoadMoreRecyclerViewAdapter extends RecyclerViewWithFooterAdapter {
    public ILoadMore mLoadMoreListener;
    public LoadMoreViewHolder mLoadMoreViewHolder;

    public interface ILoadMore {
        static {
            Covode.recordClassIndex(31205);
        }

        void loadMore(boolean z);
    }

    static {
        Covode.recordClassIndex(31202);
    }

    public int getErrorLayoutForLoadMore() {
        return -1;
    }

    public int getLoadingLayoutForLoadMore() {
        return 2131560416;
    }

    public class LoadMoreViewHolder extends RecyclerView.ViewHolder {
        static {
            Covode.recordClassIndex(31206);
        }

        public void reset() {
            ((S8P) this.itemView).reset();
        }

        public void showError() {
            ((S8P) this.itemView).showError();
        }

        public void showLoading() {
            ((S8P) this.itemView).showLoading();
        }

        public void bind() {
            if (((S8P) this.itemView).isReset() && LoadMoreRecyclerViewAdapter.this.mLoadMoreListener != null) {
                LoadMoreRecyclerViewAdapter.this.mLoadMoreListener.loadMore(false);
            }
        }

        public LoadMoreViewHolder(View view) {
            super(view);
        }
    }

    public final int getItemCount() {
        if (getBasicItemCount() == 0) {
            return 0;
        }
        return LoadMoreRecyclerViewAdapter.super.getItemCount();
    }

    public void resetLoadMoreState() {
        LoadMoreViewHolder loadMoreViewHolder = this.mLoadMoreViewHolder;
        if (loadMoreViewHolder != null) {
            loadMoreViewHolder.reset();
        }
    }

    public void showLoadMoreError() {
        LoadMoreViewHolder loadMoreViewHolder = this.mLoadMoreViewHolder;
        if (loadMoreViewHolder != null) {
            loadMoreViewHolder.showError();
        }
    }

    public void showLoadMoreLoading() {
        LoadMoreViewHolder loadMoreViewHolder = this.mLoadMoreViewHolder;
        if (loadMoreViewHolder != null) {
            loadMoreViewHolder.showLoading();
        }
    }

    public void setLoadMoreListener(ILoadMore iLoadMore) {
        this.mLoadMoreListener = iLoadMore;
    }

    public int getFooterHeight(View view) {
        return view.getResources().getDimensionPixelSize(2131165496);
    }

    public void onBindFooterViewHolder(RecyclerView.ViewHolder viewHolder) {
        if (viewHolder instanceof LoadMoreViewHolder) {
            ((LoadMoreViewHolder) viewHolder).bind();
            1CV r2 = (0EG) this.mLoadMoreViewHolder.itemView.getLayoutParams();
            if (r2 instanceof 1CV) {
                r2.LIZIZ = true;
            }
            this.mLoadMoreViewHolder.itemView.setLayoutParams(r2);
        }
    }

    public RecyclerView.ViewHolder onCreateFooterViewHolder(ViewGroup viewGroup) {
        S8P s8p = new S8P(viewGroup.getContext());
        int footerHeight = getFooterHeight(viewGroup);
        int dimensionPixelSize = viewGroup.getResources().getDimensionPixelSize(2131165497);
        s8p.setLayoutParams(getFooterLayoutParams(-1, footerHeight));
        LoadingStatusView$Builder loadingStatusView$Builder = new LoadingStatusView$Builder(viewGroup.getContext());
        loadingStatusView$Builder.setUseProgressBar(dimensionPixelSize);
        loadingStatusView$Builder.setErrorText(2131826712, new View.OnClickListener() {
            static {
                Covode.recordClassIndex(31203);
            }

            public void onClick(View view) {
                if (LoadMoreRecyclerViewAdapter.this.mLoadMoreListener != null) {
                    LoadMoreRecyclerViewAdapter.this.mLoadMoreListener.loadMore(true);
                }
            }
        });
        if (getErrorLayoutForLoadMore() > 0) {
            View LIZ = 0HH.LIZ(LayoutInflater.from(viewGroup.getContext()), getErrorLayoutForLoadMore(), viewGroup, false);
            LIZ.setOnClickListener(new View.OnClickListener() {
                static {
                    Covode.recordClassIndex(31204);
                }

                public void onClick(View view) {
                    if (LoadMoreRecyclerViewAdapter.this.mLoadMoreListener != null) {
                        LoadMoreRecyclerViewAdapter.this.mLoadMoreListener.loadMore(true);
                    }
                }
            });
            loadingStatusView$Builder.setErrorView(LIZ);
        }
        loadingStatusView$Builder.setLoadingView(0HH.LIZ(LayoutInflater.from(viewGroup.getContext()), getLoadingLayoutForLoadMore(), viewGroup, false));
        s8p.setBuilder(loadingStatusView$Builder);
        LoadMoreViewHolder loadMoreViewHolder = new LoadMoreViewHolder(s8p);
        this.mLoadMoreViewHolder = loadMoreViewHolder;
        return loadMoreViewHolder;
    }

    public 0EG getFooterLayoutParams(int i, int i2) {
        return new 0EG(i, i2);
    }
}
