├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── jeanboy │ │ └── app │ │ └── test │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── jeanboy │ │ │ └── app │ │ │ └── test │ │ │ ├── ListAdapter.java │ │ │ ├── MainActivity.java │ │ │ └── layout │ │ │ ├── FooterLayout.java │ │ │ ├── HeaderLayout.java │ │ │ └── MaskLayout.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable-xxhdpi │ │ └── bg.jpg │ │ ├── drawable │ │ ├── divider.xml │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── item_footer.xml │ │ ├── item_header.xml │ │ ├── item_list.xml │ │ ├── item_mask.xml │ │ ├── view_data_empty.xml │ │ ├── view_data_error.xml │ │ ├── view_data_loading.xml │ │ └── view_header.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── values-night │ │ └── themes.xml │ │ ├── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── themes.xml │ │ └── xml │ │ ├── backup_rules.xml │ │ └── data_extraction_rules.xml │ └── test │ └── java │ └── com │ └── jeanboy │ └── app │ └── test │ └── ExampleUnitTest.java ├── build.gradle ├── component_pagination ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── jeanboy │ │ └── component │ │ └── pagination │ │ ├── PaginationAdapter.java │ │ ├── PaginationHelper.java │ │ ├── base │ │ ├── BaseViewHolder.java │ │ ├── HolderLayout.java │ │ └── RecyclerBaseAdapter.java │ │ ├── constants │ │ ├── ViewState.java │ │ └── ViewType.java │ │ ├── decoration │ │ └── SpaceItemDecoration.java │ │ ├── layout │ │ ├── LoadMoreLayout.java │ │ └── MaskLayout.java │ │ └── listener │ │ └── LoadListener.java │ └── res │ ├── layout │ ├── pagination_default_item_load_more.xml │ └── pagination_default_item_mask.xml │ ├── values-zh │ └── strings.xml │ └── values │ └── strings.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── resource └── ScreenRecord.gif └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | local.properties 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Jeanboy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## RecyclerViewHelper 2 | 3 | ## 介绍 4 | 5 | 方便快捷的 RecyclerView 工具类,支持添加自定义的 header,footer 布局,加载 tips,分页加载。 6 | 7 | ## 使用 8 | 9 | - 导入 component_pagination 10 | - 具体使用 11 | 12 | ```java 13 | 14 | // 使用 helper 实现分页加载和加载中的提示 15 | paginationHelper = new PaginationHelper(list_container, listAdapter); 16 | // 设置加载中 View 17 | paginationHelper.setMaskLayout(new MaskLayout()); 18 | // 设置加载更多 View 19 | paginationHelper.setLoadMoreLayout(new FooterLayout()); 20 | 21 | // 设置刷新的接口 22 | paginationHelper.setRefreshListener(new LoadListener() { 23 | @Override 24 | public void onLoad(boolean isError) { 25 | if (isError) { 26 | toLoadData(); 27 | } else { 28 | toLoadData(); 29 | } 30 | } 31 | }); 32 | 33 | // 设置加载更多的接口 34 | paginationHelper.setLoadMoreListener(new LoadListener() { 35 | @Override 36 | public void onLoad(boolean isError) { 37 | toLoadMore(); 38 | } 39 | }); 40 | 41 | // 加载中 42 | paginationHelper.setLoading(); 43 | // 加载失败 44 | paginationHelper.setLoadError(); 45 | // 加载成功,是否还有下一页,没有下一页则显示为:没有更多数据 46 | paginationHelper.setLoadCompleted(true); 47 | ``` 48 | 49 | 50 | ## Demo 51 | 52 | ![演示][1] 53 | 54 | ## 感谢 55 | 56 | * [CymChad / BaseRecyclerViewAdapterHelper](https://github.com/CymChad/BaseRecyclerViewAdapterHelper) 57 | * [cundong / HeaderAndFooterRecyclerView](https://github.com/cundong/HeaderAndFooterRecyclerView) 58 | 59 | ## 关于我 60 | 61 | 如果对你有帮助,请 star 一下,然后 follow 我,给我增加一下分享动力,谢谢! 62 | 63 | 如果你有什么疑问或者问题,可以提交 issue 和 request,发邮件给我 jeanboy@foxmail.com 。 64 | 65 | 66 | 67 | [1]: https://github.com/freekite/Android-RecyclerViewHelper/blob/master/resource/ScreenRecord.gif 68 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | } 4 | 5 | android { 6 | namespace 'com.jeanboy.app.test' 7 | compileSdk 33 8 | 9 | defaultConfig { 10 | applicationId "com.jeanboy.app.test" 11 | minSdk 21 12 | targetSdk 33 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | compileOptions { 26 | sourceCompatibility JavaVersion.VERSION_1_8 27 | targetCompatibility JavaVersion.VERSION_1_8 28 | } 29 | } 30 | 31 | dependencies { 32 | testImplementation 'junit:junit:4.13.2' 33 | androidTestImplementation 'androidx.test.ext:junit:1.1.3' 34 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 35 | 36 | implementation 'androidx.appcompat:appcompat:1.4.1' 37 | implementation 'com.google.android.material:material:1.5.0' 38 | implementation 'androidx.constraintlayout:constraintlayout:2.1.3' 39 | implementation "androidx.recyclerview:recyclerview-selection:1.1.0" 40 | implementation "androidx.cardview:cardview:1.0.0" 41 | implementation project(':component_pagination') 42 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/src/androidTest/java/com/jeanboy/app/test/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.jeanboy.app.test; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.platform.app.InstrumentationRegistry; 6 | import androidx.test.ext.junit.runners.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); 24 | assertEquals("com.jeanboy.app.test", appContext.getPackageName()); 25 | } 26 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 15 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/jeanboy/app/test/ListAdapter.java: -------------------------------------------------------------------------------- 1 | package com.jeanboy.app.test; 2 | 3 | 4 | import androidx.annotation.NonNull; 5 | 6 | import com.jeanboy.component.pagination.base.BaseViewHolder; 7 | import com.jeanboy.component.pagination.base.RecyclerBaseAdapter; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * Created by Next on 2016/8/9. 13 | */ 14 | public class ListAdapter extends RecyclerBaseAdapter { 15 | 16 | public ListAdapter(@NonNull List dataList) { 17 | super(dataList, R.layout.item_list); 18 | } 19 | 20 | @Override 21 | public void convert(BaseViewHolder holder, String s, int position) { 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/jeanboy/app/test/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.jeanboy.app.test; 2 | 3 | import android.os.Bundle; 4 | 5 | import androidx.appcompat.app.AppCompatActivity; 6 | import androidx.recyclerview.widget.RecyclerView; 7 | 8 | import com.jeanboy.app.test.layout.FooterLayout; 9 | import com.jeanboy.app.test.layout.HeaderLayout; 10 | import com.jeanboy.app.test.layout.MaskLayout; 11 | import com.jeanboy.component.pagination.PaginationHelper; 12 | import com.jeanboy.component.pagination.layout.LoadMoreLayout; 13 | import com.jeanboy.component.pagination.listener.LoadListener; 14 | 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | 18 | public class MainActivity extends AppCompatActivity { 19 | 20 | private RecyclerView list_container; 21 | private final List dataList = new ArrayList<>(); 22 | private ListAdapter listAdapter; 23 | private PaginationHelper paginationHelper; 24 | private int loadCount = 0; 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | setContentView(R.layout.activity_main); 30 | list_container = findViewById(R.id.list_container); 31 | 32 | listAdapter = new ListAdapter(dataList); 33 | 34 | // 使用 helper 实现分页加载和加载中的提示 35 | paginationHelper = new PaginationHelper(list_container, listAdapter); 36 | // 设置加载中 View 37 | paginationHelper.setMaskLayout(new MaskLayout()); 38 | // 设置加载更多 View 39 | paginationHelper.setLoadMoreLayout(new LoadMoreLayout()); 40 | // paginationHelper.addHeader(new HeaderLayout()); 41 | // paginationHelper.addHeader(new HeaderLayout()); 42 | // paginationHelper.addFooter(new FooterLayout()); 43 | // paginationHelper.addFooter(new FooterLayout()); 44 | 45 | // 设置刷新的接口 46 | paginationHelper.setRefreshListener(new LoadListener() { 47 | @Override 48 | public void onLoad(boolean isError) { 49 | if (isError) { 50 | toLoadData(); 51 | } else { 52 | toLoadData(); 53 | } 54 | } 55 | }); 56 | 57 | // 设置加载更多的接口 58 | paginationHelper.setLoadMoreListener(new LoadListener() { 59 | @Override 60 | public void onLoad(boolean isError) { 61 | toLoadMore(); 62 | } 63 | }); 64 | 65 | // toLoadData(); 66 | paginationHelper.setLoading(); 67 | dataList.clear(); 68 | paginationHelper.setLoadCompleted(true); 69 | for (int i = 0; i < 10; i++) { 70 | dataList.add(String.valueOf(i)); 71 | } 72 | // 分页数据加载成功,还有下一页 73 | paginationHelper.setLoadCompleted(true); 74 | } 75 | 76 | private void toLoadMore() { 77 | paginationHelper.setLoading(); 78 | new Thread(new Runnable() { 79 | @Override 80 | public void run() { 81 | try { 82 | Thread.sleep(3000); 83 | } catch (InterruptedException e) { 84 | e.printStackTrace(); 85 | } 86 | 87 | runOnUiThread(new Runnable() { 88 | @Override 89 | public void run() { 90 | if (loadCount % 2 != 0) { 91 | // 分页数据加载失败 92 | paginationHelper.setLoadError(); 93 | } else if (loadCount < 7) { 94 | for (int i = 0; i < 3; i++) { 95 | dataList.add(String.valueOf(i)); 96 | } 97 | // 分页数据加载成功,还有下一页 98 | paginationHelper.setLoadCompleted(true); 99 | } else { 100 | // 分页数据加载成功,没有更多,即全部加载完成 101 | paginationHelper.setLoadCompleted(false); 102 | } 103 | loadCount++; 104 | } 105 | }); 106 | } 107 | }).start(); 108 | } 109 | 110 | private void toLoadData() { 111 | dataList.clear(); 112 | paginationHelper.setLoading(); 113 | new Thread(new Runnable() { 114 | @Override 115 | public void run() { 116 | try { 117 | Thread.sleep(1000); 118 | } catch (InterruptedException e) { 119 | e.printStackTrace(); 120 | } 121 | 122 | runOnUiThread(new Runnable() { 123 | @Override 124 | public void run() { 125 | if (loadCount == 0) { 126 | // 首次数据记载失败 127 | paginationHelper.setLoadError(); 128 | } else if (loadCount == 1) { 129 | // 首次加载数据成功 130 | paginationHelper.setLoadCompleted(true); 131 | } else { 132 | for (int i = 0; i < 2; i++) { 133 | dataList.add(String.valueOf(i)); 134 | } 135 | paginationHelper.setLoadCompleted(true); 136 | } 137 | loadCount++; 138 | } 139 | }); 140 | } 141 | }).start(); 142 | } 143 | } -------------------------------------------------------------------------------- /app/src/main/java/com/jeanboy/app/test/layout/FooterLayout.java: -------------------------------------------------------------------------------- 1 | package com.jeanboy.app.test.layout; 2 | 3 | import android.util.Log; 4 | 5 | import androidx.recyclerview.widget.RecyclerView; 6 | 7 | import com.jeanboy.app.test.R; 8 | import com.jeanboy.component.pagination.base.HolderLayout; 9 | import com.jeanboy.component.pagination.listener.LoadListener; 10 | 11 | /** 12 | * Created by jianbo on 2023/7/14 16:23. 13 | */ 14 | public class FooterLayout extends HolderLayout { 15 | @Override 16 | public int getLayoutId() { 17 | return R.layout.item_footer; 18 | } 19 | 20 | @Override 21 | public void convert(RecyclerView.ViewHolder holder, int state, LoadListener listener) { 22 | Log.e("jianbo", "FooterLayout"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/jeanboy/app/test/layout/HeaderLayout.java: -------------------------------------------------------------------------------- 1 | package com.jeanboy.app.test.layout; 2 | 3 | import android.util.Log; 4 | 5 | import androidx.recyclerview.widget.RecyclerView; 6 | 7 | import com.jeanboy.app.test.R; 8 | import com.jeanboy.component.pagination.base.HolderLayout; 9 | import com.jeanboy.component.pagination.listener.LoadListener; 10 | 11 | /** 12 | * Created by jianbo on 2023/7/14 16:23. 13 | */ 14 | public class HeaderLayout extends HolderLayout { 15 | @Override 16 | public int getLayoutId() { 17 | return R.layout.item_header; 18 | } 19 | 20 | @Override 21 | public void convert(RecyclerView.ViewHolder holder, int state, LoadListener listener) { 22 | Log.e("jianbo","HeaderLayout"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/jeanboy/app/test/layout/MaskLayout.java: -------------------------------------------------------------------------------- 1 | package com.jeanboy.app.test.layout; 2 | 3 | import android.view.View; 4 | 5 | import androidx.recyclerview.widget.RecyclerView; 6 | 7 | import com.jeanboy.app.test.R; 8 | import com.jeanboy.component.pagination.base.HolderLayout; 9 | import com.jeanboy.component.pagination.constants.ViewState; 10 | import com.jeanboy.component.pagination.listener.LoadListener; 11 | 12 | /** 13 | * Created by jianbo on 2023/7/14 16:23. 14 | */ 15 | public class MaskLayout extends HolderLayout { 16 | @Override 17 | public int getLayoutId() { 18 | return R.layout.item_mask; 19 | } 20 | 21 | @Override 22 | public void convert(RecyclerView.ViewHolder holder, int state, LoadListener listener) { 23 | View view_data_empty = holder.itemView.findViewById(R.id.view_data_empty); 24 | View view_data_error = holder.itemView.findViewById(R.id.view_data_error); 25 | View view_data_loading = holder.itemView.findViewById(R.id.view_data_loading); 26 | view_data_empty.setVisibility(View.GONE); 27 | view_data_error.setVisibility(View.GONE); 28 | view_data_loading.setVisibility(View.GONE); 29 | switch (state) { 30 | case ViewState.LOADING: 31 | view_data_loading.setVisibility(View.VISIBLE); 32 | break; 33 | case ViewState.EMPTY: 34 | view_data_empty.setVisibility(View.VISIBLE); 35 | // TODO: 2023/7/14 为了演示增加点击事件,一般不需要 36 | convertListener(holder.itemView, false, listener); 37 | break; 38 | case ViewState.ERROR: 39 | view_data_error.setVisibility(View.VISIBLE); 40 | convertListener(holder.itemView, true, listener); 41 | break; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jeanboydev/Android-RecyclerViewHelper/8c2a00575afdc459d0742d45f0251b055507a2ad/app/src/main/res/drawable-xxhdpi/bg.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/divider.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_footer.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_header.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_list.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 17 | 18 | 25 | 26 | 32 | 33 | 41 | 42 | 49 | 50 | 59 | 60 | 61 | 62 | 67 | 68 |