Skip to content

🔥🔥🔥 - 用装饰器模式给RecyclerView添加一个有加载状态的Adapter(loading,empty,error,retry)

Notifications You must be signed in to change notification settings

simplepeng/StateAdapter

Repository files navigation

StateAdapter

用装饰器模式给RecyclerView添加一个有加载状态布局的Adapter

默认

默认状态图片来源网络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:迁移到jitpackandroidx,增加直接register layoutId

  • v1.0.3:分离状态布局的写法,去耦合

  • v1.0.2:默认不show-loading

  • v1.0.1:fix type state bug

  • v1.0.0:初次提交

About

🔥🔥🔥 - 用装饰器模式给RecyclerView添加一个有加载状态的Adapter(loading,empty,error,retry)

Resources

Stars

Watchers

Forks

Packages

No packages published