Skip to content

Commit

Permalink
update lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Sum-sdl committed Jul 23, 2018
1 parent eae907d commit 363e90d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
import android.view.ViewGroup;

/**
* Created by sdl on 2016/8/29.
* 统一预处理的数据源,对应一个缓存中的ViewType
*
* @author sdl
* @date 2016/8/29
*/
public abstract class RecyclerDataHolder<T> {
public abstract class BaseRecyclerDataHolder<T> {

private T mData;
private int mId;
private RecyclerAdapter mAdapter;

public RecyclerDataHolder(T data) {
public BaseRecyclerDataHolder(T data) {
mData = data;
mId = super.hashCode();
}
Expand All @@ -30,7 +32,6 @@ public int getId() {
*/
protected abstract int getItemViewLayoutId();

//统一创建viewHolder的content view
public View onCreateView(Context context, ViewGroup parent) {
return LayoutInflater.from(context).inflate(getItemViewLayoutId(), parent, false);
}
Expand All @@ -54,4 +55,8 @@ public int getType() {
public T getData() {
return mData;
}

public void updateData(T newData) {
mData = newData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import java.util.List;

/**
* Created by sdl on 2016/8/29.
* 统一适配器
* @author sdl
* @date 2016/8/29
* 全局通用适配器
*/
public class RecyclerAdapter<DataHolder extends RecyclerDataHolder> extends RecyclerView.Adapter<ViewHolder> {
public class RecyclerAdapter<DataHolder extends BaseRecyclerDataHolder> extends RecyclerView.Adapter<ViewHolder> {

private List<DataHolder> mHolders;
private int mCurPosition;
Expand All @@ -32,9 +33,9 @@ public RecyclerAdapter(List<DataHolder> holders) {
}

public void setDataHolders(List<DataHolder> holders) {
if (holders == null)
if (holders == null) {
mHolders = new ArrayList<>();
else {
} else {
mHolders = new ArrayList<>(holders.size() + 10);
mHolders.addAll(holders);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ public class RecyclerViewHolder extends RecyclerView.ViewHolder {

public Context mContext;

private View mParent;
private View mRootView;

public RecyclerViewHolder(View view) {
super(view);
mParent = view;
mRootView = view;
mContext = view.getContext();
}

public <T extends View> T findViewById(int id) {
return mParent.findViewById(id);
return mRootView.findViewById(id);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@
public abstract class OnPageScrollListener extends OnScrollListener {

private LinearLayoutManager mManager;
private int mRemainingCount;//用作提前几个到底部
/**
* 用作提前几个到底部
*/
private int mRemainingCount;

public OnPageScrollListener(LinearLayoutManager manager) {
this(manager, 0);
}

public OnPageScrollListener(LinearLayoutManager manager, int remainingCount) {
if (manager == null) throw new NullPointerException("manager == null");
if (remainingCount < 0) throw new IllegalArgumentException("remainingCount < 0");
if (manager == null) {
throw new NullPointerException("manager == null");
}
if (remainingCount < 0) {
throw new IllegalArgumentException("remainingCount < 0");
}
this.mManager = manager;
this.mRemainingCount = remainingCount;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
import android.view.ViewGroup;

import com.sum.lib.rvadapter.RecyclerAdapter;
import com.sum.lib.rvadapter.RecyclerDataHolder;
import com.sum.lib.rvadapter.BaseRecyclerDataHolder;

import java.util.List;

/**
* Created by Summer on 2016/8/27.
*/
public abstract class StickRecyclerAdapter<T> extends RecyclerAdapter<RecyclerDataHolder<T>> implements StickyHeadView {
public abstract class StickRecyclerAdapter<T> extends RecyclerAdapter<BaseRecyclerDataHolder<T>> implements StickyHeadView {

public StickRecyclerAdapter() {
super();
}

public StickRecyclerAdapter(List<RecyclerDataHolder<T>> recyclerDataHolders) {
public StickRecyclerAdapter(List<BaseRecyclerDataHolder<T>> recyclerDataHolders) {
super(recyclerDataHolders);
}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RecyclerView 通用适配器框架结构封装
Then, add the library to your module `build.gradle`
```gradle
dependencies {
implementation 'com.github.Sum-sdl:RvAdapter:1.0.7'
implementation 'com.github.Sum-sdl:RvAdapter:1.0.8'
}
```

Expand Down

0 comments on commit 363e90d

Please sign in to comment.