hongyangAndroid/baseAdapter

LoadMoreWrapper

a120476536 opened this issue · 1 comments

Error:(16, 8) 错误: 类LoadMoreWrapper是公共的, 应在名为 LoadMoreWrapper.java 的文件中声明
这个类报错 大神
`package com.zhy.adapter.recyclerview.wrapper;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.view.ViewGroup;

import com.zhy.adapter.recyclerview.base.ViewHolder;
import com.zhy.adapter.recyclerview.utils.WrapperUtils;

/**

  • Created by zhy on 16/6/23.
    */
    public class LoadMoreWrapper extends RecyclerView.Adapter<RecyclerView.ViewHolder>
    {
    public static final int ITEM_TYPE_LOAD_MORE = Integer.MAX_VALUE - 2;

    private RecyclerView.Adapter mInnerAdapter;
    private View mLoadMoreView;
    private int mLoadMoreLayoutId;

    public LoadMoreWrapper(RecyclerView.Adapter adapter)
    {
    mInnerAdapter = adapter;
    }

    private boolean hasLoadMore()
    {
    return mLoadMoreView != null || mLoadMoreLayoutId != 0;
    }

    private boolean isShowLoadMore(int position)
    {
    return hasLoadMore() && (position >= mInnerAdapter.getItemCount());
    }

    @OverRide
    public int getItemViewType(int position)
    {
    if (isShowLoadMore(position))
    {
    return ITEM_TYPE_LOAD_MORE;
    }
    return mInnerAdapter.getItemViewType(position);
    }

    @OverRide
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
    {
    if (viewType == ITEM_TYPE_LOAD_MORE)
    {
    ViewHolder holder;
    if (mLoadMoreView != null)
    {
    holder = ViewHolder.createViewHolder(parent.getContext(), mLoadMoreView);
    } else
    {
    holder = ViewHolder.createViewHolder(parent.getContext(), parent, mLoadMoreLayoutId);
    }
    return holder;
    }
    return mInnerAdapter.onCreateViewHolder(parent, viewType);
    }

    @OverRide
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
    {
    if (isShowLoadMore(position))
    {
    if (mOnLoadMoreListener != null)
    {
    mOnLoadMoreListener.onLoadMoreRequested();
    }
    return;
    }
    mInnerAdapter.onBindViewHolder(holder, position);
    }

    @OverRide
    public void onAttachedToRecyclerView(RecyclerView recyclerView)
    {
    WrapperUtils.onAttachedToRecyclerView(mInnerAdapter, recyclerView, new WrapperUtils.SpanSizeCallback()
    {
    @OverRide
    public int getSpanSize(GridLayoutManager layoutManager, GridLayoutManager.SpanSizeLookup oldLookup, int position)
    {
    if (isShowLoadMore(position))
    {
    return layoutManager.getSpanCount();
    }
    if (oldLookup != null)
    {
    return oldLookup.getSpanSize(position);
    }
    return 1;
    }
    });
    }

    @OverRide
    public void onViewAttachedToWindow(RecyclerView.ViewHolder holder)
    {
    mInnerAdapter.onViewAttachedToWindow(holder);

     if (isShowLoadMore(holder.getLayoutPosition()))
     {
         setFullSpan(holder);
     }
    

    }

    private void setFullSpan(RecyclerView.ViewHolder holder)
    {
    ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();

     if (lp != null
             && lp instanceof StaggeredGridLayoutManager.LayoutParams)
     {
         StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp;
    
         p.setFullSpan(true);
     }
    

    }

    @OverRide
    public int getItemCount()
    {
    return mInnerAdapter.getItemCount() + (hasLoadMore() ? 1 : 0);
    }

    public interface OnLoadMoreListener
    {
    void onLoadMoreRequested();
    }

    private OnLoadMoreListener mOnLoadMoreListener;

    public LoadMoreWrapper setOnLoadMoreListener(OnLoadMoreListener loadMoreListener)
    {
    if (loadMoreListener != null)
    {
    mOnLoadMoreListener = loadMoreListener;
    }
    return this;
    }

    public LoadMoreWrapper setLoadMoreView(View loadMoreView)
    {
    mLoadMoreView = loadMoreView;
    return this;
    }

    public LoadMoreWrapper setLoadMoreView(int layoutId)
    {
    mLoadMoreLayoutId = layoutId;
    return this;
    }
    }
    `

修改文件的文件名为LoadMoreWrapper,原始为LoadmoreWrapper(m是小写的)。