用装饰器模式给RecyclerView添加一个有加载状态布局的Adapter
- 完美支持原生RecyclerView.Adapter
- 完美支持BaseRecyclerViewAdapterHelper
- 完美支持MultiType
默认状态图片来源网络AC娘表情包,如需使用最好自定义,嘻嘻...
Loading | Empty | Error | Retry |
---|---|---|---|
maven { url 'https://jitpack.io' }
implementation 'com.github.simplepeng:StateAdapter:v1.0.4'
realAdapter = new RealAdapter();
stateAdapter = StateAdapter.newBuilder()
.registerEmpty(R.layout.adapter_empty_view)
.registerLoading(R.layout.adapter_loading_view)
.registerError(R.layout.adapter_error_view)
.registerRetry(R.layout.adapter_retry_view)
.registerCustom("login", R.layout.layout_login)
.wrap(realAdapter);
//可用方法
stateAdapter.showLoading();
stateAdapter.showEmpty();
stateAdapter.showError();
stateAdapter.showRetry();
stateAdapter.showCustom(key);
stateAdapter.showContent();//or realAdapter.notifyDataSetChanged
//设置状态布局里控件的点击事件
stateAdapter.setOnItemViewClickListener(int viewId, View.OnClickListener listener)
-keep me.simple.state_adapter.** { *; }
-keepnames me.simple.state_adapter.** { *; }
-keep class androidx.recyclerview.widget.**{*;}
-
v1.0.4:迁移到
jitpack
,androidx
,增加直接register layoutId
-
v1.0.3:分离状态布局的写法,去耦合
-
v1.0.2:默认不
show-loading
-
v1.0.1:fix type state bug
-
v1.0.0:初次提交