Skip to content

Commit

Permalink
add 新增setPageData(boolean isFirstPage, List<T> data)方法,可单独设置emptyView
Browse files Browse the repository at this point in the history
  • Loading branch information
youlookwhat committed May 31, 2024
1 parent ad5e59b commit 6231a1a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public abstract class BaseByRecyclerViewAdapter<T, K extends BaseByViewHolder> e

private ByRecyclerView mRecyclerView;
private List<T> mData = new ArrayList<>();
private View mStateView;

protected BaseByRecyclerViewAdapter() {
}
Expand Down Expand Up @@ -219,6 +220,34 @@ private void checkNoNull() {
}
}

/**
* 设置空布局(状态布局),在 setPageData() 时使用到
*/
public void setEmptyView(View emptyView) {
this.mStateView = emptyView;
}

/**
* 设置空布局(状态布局),在 setPageData() 时使用到
*/
public void setEmptyView(int emptyLayoutId) {
if (mRecyclerView == null) {
return;
}
this.mStateView = mRecyclerView.getLayoutView(emptyLayoutId);
}

/**
* 设置数据和处理空视图。空视图是在 setEmptyView() 设置的。
* 如果想列表上方显示状态视图(StateView),不能使用这个方法。
*
* @param isFirstPage 是否是第一页
* @param data 需要设置的数据
*/
public void setPageData(boolean isFirstPage, List<T> data) {
setPageData(isFirstPage, data, mStateView);
}

/**
* 设置数据和处理空视图。
* 如果想列表上方显示状态视图(StateView),不能使用这个方法。
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "me.jingbin.byrecyclerview"
minSdkVersion 21
targetSdkVersion 30
versionCode 11
versionName "1.4.0"
versionCode 12
versionName "1.4.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private void initAdapter() {
@Override
public void onRefresh() {
page = 1;
mAdapter.setNewData(DataUtil.getMultiData(getActivity(), 20));
mAdapter.setPageData(true, DataUtil.getMultiData(getActivity(), 20));
}
});
binding.recyclerView.setOnLoadMoreListener(new ByRecyclerView.OnLoadMoreListener() {
Expand All @@ -98,8 +98,7 @@ public void onLoadMore() {
return;
}
page++;
mAdapter.addData(DataUtil.getMultiData(getActivity(), 50));
binding.recyclerView.loadMoreComplete();
mAdapter.setPageData(page == 1, DataUtil.getMultiData(getActivity(), 50));
}
}, 500);
binding.recyclerView.setOnItemClickListener(new ByRecyclerView.OnItemClickListener() {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ buildscript {
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.3'
classpath 'com.android.tools.build:gradle:3.6.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
// NOTE: Do not place your application dependencies here; they belong
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip

0 comments on commit 6231a1a

Please sign in to comment.