Skip to content

Commit

Permalink
feat: func setHasStableIds and setOnStableIdCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
nukc committed Nov 25, 2018
1 parent a1980ba commit 0f5274a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 5 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ JCenter:

add the dependency to your build.gradle:
```gradle
implementation 'com.github.nukc:loadmorewrapper:1.7.1'
implementation 'com.github.nukc:loadmorewrapper:1.8.1'
```


Expand All @@ -42,7 +42,7 @@ Add it in your root build.gradle at the end of repositories:
Step 2. Add the dependency
```gradle
dependencies {
implementation 'com.github.nukc:LoadMoreWrapper:v1.7.1'
implementation 'com.github.nukc:LoadMoreWrapper:v1.8.1'
}
```

Expand Down Expand Up @@ -98,6 +98,8 @@ in the original adapter: [demo](https://github.com/nukc/LoadMoreWrapper/blob/mas
setLoadMoreEnabled(boolean enabled) | 设置是否启用加载更多,默认 true
setShowNoMoreEnabled(boolean enabled) | 设置全部加载完后是否显示没有更多视图,默认 false
setLoadFailed(boolean isLoadFailed) | 设置是否加载失败,默认 false
setHasStableIds(boolean hasStableIds) | Whether items in data set have unique identifiers or not
setOnStableIdCallback(OnStableIdCallback callback) | Return the stable ID for the item at position
getOriginalAdapter() | 获取原来的 adapter
getFooterView | 获取加载更多视图
getNoMoreView | 获取没有更多视图
Expand Down
2 changes: 1 addition & 1 deletion bintray.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def siteUrl = 'https://github.com/nukc/LoadMoreWrapper'
def gitUrl = 'https://github.com/nukc/LoadMoreWrapper.git'

group = "com.github.nukc"
version = "1.7.1"
version = "1.8.1"

install {
repositories.mavenInstaller {
Expand Down
4 changes: 2 additions & 2 deletions loadmorewrapper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 23
versionName "1.7.1"
versionCode 27
versionName "1.8.1"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class LoadMoreAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde

private RecyclerView mRecyclerView;
private OnLoadMoreListener mOnLoadMoreListener;
private OnStableIdCallback mOnStableIdCallback;

private Enabled mEnabled;
private boolean mIsLoading;
Expand Down Expand Up @@ -148,6 +149,16 @@ public int getItemViewType(int position) {
return mAdapter.getItemViewType(position);
}

@Override
public long getItemId(int position) {
final int itemViewType = getItemViewType(position);
if (mOnStableIdCallback != null && itemViewType != TYPE_FOOTER &&
itemViewType != TYPE_LOAD_FAILED && itemViewType != TYPE_NO_MORE) {
return mOnStableIdCallback.getItemId(position);
}
return super.getItemId(position);
}

public boolean canScroll() {
if (mRecyclerView == null) {
throw new NullPointerException("mRecyclerView is null, you should setAdapter(recyclerAdapter);");
Expand Down Expand Up @@ -319,6 +330,10 @@ public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
mRecyclerView = null;
}

public void setOnStableIdCallback(OnStableIdCallback callback) {
mOnStableIdCallback = callback;
}

public void setLoadMoreListener(OnLoadMoreListener listener) {
mOnLoadMoreListener = listener;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public View getLoadFailedView() {

/**
* 监听加载更多触发事件
*
* @param listener {@link com.github.nukc.LoadMoreWrapper.LoadMoreAdapter.OnLoadMoreListener}
*/
public LoadMoreWrapper setListener(LoadMoreAdapter.OnLoadMoreListener listener) {
Expand All @@ -73,6 +74,7 @@ public LoadMoreWrapper setListener(LoadMoreAdapter.OnLoadMoreListener listener)

/**
* 设置是否启用加载更多
*
* @param enabled default true
*/
public LoadMoreWrapper setLoadMoreEnabled(boolean enabled) {
Expand All @@ -85,13 +87,27 @@ public LoadMoreWrapper setLoadMoreEnabled(boolean enabled) {

/**
* 设置全部加载完后是否显示没有更多视图
*
* @param enabled default false
*/
public LoadMoreWrapper setShowNoMoreEnabled(boolean enabled) {
mLoadMoreAdapter.setShowNoMoreEnabled(enabled);
return this;
}

/**
* @param hasStableIds Whether items in data set have unique identifiers or not.
*/
public LoadMoreWrapper setHasStableIds(boolean hasStableIds) {
mLoadMoreAdapter.setHasStableIds(hasStableIds);
return this;
}

public LoadMoreWrapper setOnStableIdCallback(OnStableIdCallback callback) {
mLoadMoreAdapter.setOnStableIdCallback(callback);
return this;
}

/**
* 设置加载失败
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.github.nukc.LoadMoreWrapper;

public interface OnStableIdCallback {
long getItemId(int position);
}

0 comments on commit 0f5274a

Please sign in to comment.