├── .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 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_mask.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
9 |
10 |
13 |
14 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_data_empty.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
14 |
15 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_data_error.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
14 |
15 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_data_loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
15 |
16 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-RecyclerViewHelper/8c2a00575afdc459d0742d45f0251b055507a2ad/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-RecyclerViewHelper/8c2a00575afdc459d0742d45f0251b055507a2ad/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-RecyclerViewHelper/8c2a00575afdc459d0742d45f0251b055507a2ad/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-RecyclerViewHelper/8c2a00575afdc459d0742d45f0251b055507a2ad/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-RecyclerViewHelper/8c2a00575afdc459d0742d45f0251b055507a2ad/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-RecyclerViewHelper/8c2a00575afdc459d0742d45f0251b055507a2ad/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-RecyclerViewHelper/8c2a00575afdc459d0742d45f0251b055507a2ad/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-RecyclerViewHelper/8c2a00575afdc459d0742d45f0251b055507a2ad/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-RecyclerViewHelper/8c2a00575afdc459d0742d45f0251b055507a2ad/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-RecyclerViewHelper/8c2a00575afdc459d0742d45f0251b055507a2ad/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FF000000
4 | #FFFFFFFF
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Android-RecyclerViewHelper
3 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/app/src/test/java/com/jeanboy/app/test/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.jeanboy.app.test;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | plugins {
3 | id 'com.android.application' version '8.0.2' apply false
4 | id 'com.android.library' version '8.0.2' apply false
5 | }
--------------------------------------------------------------------------------
/component_pagination/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/component_pagination/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.library'
3 | }
4 |
5 | android {
6 | namespace 'com.jeanboy.component.pagination'
7 |
8 | compileSdk 33
9 |
10 | defaultConfig {
11 | minSdk 21
12 | targetSdk 33
13 |
14 | versionCode 1
15 | versionName "1.0.1"
16 | }
17 | }
18 |
19 | dependencies {
20 | api "androidx.recyclerview:recyclerview:1.2.1"
21 | }
22 |
--------------------------------------------------------------------------------
/component_pagination/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-RecyclerViewHelper/8c2a00575afdc459d0742d45f0251b055507a2ad/component_pagination/consumer-rules.pro
--------------------------------------------------------------------------------
/component_pagination/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
--------------------------------------------------------------------------------
/component_pagination/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
--------------------------------------------------------------------------------
/component_pagination/src/main/java/com/jeanboy/component/pagination/PaginationAdapter.java:
--------------------------------------------------------------------------------
1 | package com.jeanboy.component.pagination;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 |
8 | import androidx.annotation.LayoutRes;
9 | import androidx.annotation.NonNull;
10 | import androidx.recyclerview.widget.RecyclerView;
11 |
12 | import com.jeanboy.component.pagination.base.BaseViewHolder;
13 | import com.jeanboy.component.pagination.base.HolderLayout;
14 | import com.jeanboy.component.pagination.constants.ViewState;
15 | import com.jeanboy.component.pagination.constants.ViewType;
16 | import com.jeanboy.component.pagination.listener.LoadListener;
17 |
18 | import java.util.ArrayList;
19 | import java.util.List;
20 |
21 | /**
22 | * Created by jianbo on 2023/7/13 14:49.
23 | */
24 | public class PaginationAdapter extends RecyclerView.Adapter {
25 |
26 | private volatile int currentState = ViewState.EMPTY;
27 | private final List headerList = new ArrayList<>();
28 | private final List footerList = new ArrayList<>();
29 | private HolderLayout loadMoreLayout;
30 | private HolderLayout maskLayout;
31 |
32 | private LoadListener refreshListener;
33 | private LoadListener loadMoreListener;
34 |
35 | private final RecyclerView.Adapter itemAdapter;
36 |
37 | private volatile int lastItemCount = 0;
38 |
39 | public PaginationAdapter(@NonNull RecyclerView.Adapter itemAdapter) {
40 | this.itemAdapter = itemAdapter;
41 | }
42 |
43 | private View getLayoutView(ViewGroup parent, int layoutId) {
44 | return LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false);
45 | }
46 |
47 | @NonNull
48 | @Override
49 | public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
50 | if (ViewType.MASK == viewType) {
51 | return new BaseViewHolder(getLayoutView(parent, maskLayout.getLayoutId()));
52 | } else if (ViewType.LOAD_MORE == viewType) {
53 | return new BaseViewHolder(getLayoutView(parent, loadMoreLayout.getLayoutId()));
54 | } else if (ViewType.HEADER == viewType) {
55 | HolderLayout holderLayout = headerList.get(viewType >> ViewType.OFFSET);
56 | return new BaseViewHolder(getLayoutView(parent, holderLayout.getLayoutId()));
57 | } else if (ViewType.FOOTER == viewType) {
58 | HolderLayout holderLayout = footerList.get(viewType >> ViewType.OFFSET);
59 | return new BaseViewHolder(getLayoutView(parent, holderLayout.getLayoutId()));
60 | } else {
61 | return itemAdapter.createViewHolder(parent, viewType);
62 | }
63 | }
64 |
65 | @Override
66 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
67 | int viewType = getItemViewType(position);
68 | if (ViewType.MASK == viewType) {
69 | maskLayout.convert(holder, currentState, refreshListener);
70 | } else if (ViewType.LOAD_MORE == viewType) {
71 | loadMoreLayout.convert(holder, currentState, loadMoreListener);
72 | } else if (ViewType.HEADER == viewType) {
73 | HolderLayout holderLayout = headerList.get(viewType >> ViewType.OFFSET);
74 | holderLayout.convert(holder, currentState, null);
75 | } else if (ViewType.FOOTER == viewType) {
76 | HolderLayout holderLayout = footerList.get(viewType >> ViewType.OFFSET);
77 | holderLayout.convert(holder, currentState, null);
78 | } else {
79 | itemAdapter.onBindViewHolder(holder, position - getHeaderCount());
80 | }
81 | }
82 |
83 | @Override
84 | public int getItemViewType(int position) {
85 | if (itemAdapter.getItemCount() == 0 && getMaskCount() > 0) {
86 | return ViewType.MASK;
87 | }
88 |
89 | int headerCount = getHeaderCount();
90 | if (headerCount > 0 && position < headerCount) {
91 | return ViewType.HEADER + (position << ViewType.OFFSET);
92 | }
93 |
94 | int footerCount = getFooterCount();
95 | int footerBefore = headerCount + itemAdapter.getItemCount();
96 | if (footerCount > 0 && position >= footerBefore && position < (footerBefore + footerCount)) {
97 | return ViewType.FOOTER + ((position - footerBefore) << ViewType.OFFSET);
98 | }
99 |
100 | int nextCount = getLoadMoreCount();
101 | int nextBefore = footerBefore + footerCount;
102 | if (nextCount > 0 && position >= nextBefore && position < (nextBefore + nextCount)) {
103 | return ViewType.LOAD_MORE;
104 | }
105 |
106 | return itemAdapter.getItemViewType(position - headerCount);
107 | }
108 |
109 | @Override
110 | public int getItemCount() {
111 | if (itemAdapter.getItemCount() == 0) {
112 | return getMaskCount();
113 | }
114 |
115 | int headerCount = getHeaderCount();
116 | int footerCount = getFooterCount();
117 | int loadMoreCount = getLoadMoreCount();
118 |
119 | return headerCount + itemAdapter.getItemCount() + footerCount + loadMoreCount;
120 | }
121 |
122 | @SuppressLint("ResourceType")
123 | private int getViewCount(@LayoutRes int layoutId) {
124 | return layoutId > 0 ? 1 : 0;
125 | }
126 |
127 | public int getMaskCount() {
128 | if (maskLayout == null) return 0;
129 | return getViewCount(maskLayout.getLayoutId());
130 | }
131 |
132 | private int getLoadMoreCount() {
133 | if (loadMoreLayout == null) return 0;
134 | return getViewCount(loadMoreLayout.getLayoutId());
135 | }
136 |
137 | private int getHeaderCount() {
138 | return headerList.size();
139 | }
140 |
141 | private int getFooterCount() {
142 | return footerList.size();
143 | }
144 |
145 | public int getDataSize() {
146 | return itemAdapter.getItemCount();
147 | }
148 |
149 | public int getCurrentState() {
150 | return currentState;
151 | }
152 |
153 | public LoadListener getLoadMoreListener() {
154 | return loadMoreListener;
155 | }
156 |
157 | public void setLoading() {
158 | currentState = ViewState.LOADING;
159 | if (itemAdapter.getItemCount() == 0 && getMaskCount() == 1) {
160 | notifyDataSetChanged();
161 | } else {
162 | int positionStart = getPositionStart(1);
163 | notifyItemRangeChanged(positionStart, 1);
164 | }
165 | }
166 |
167 | public void setLoadError() {
168 | currentState = ViewState.ERROR;
169 | if (itemAdapter.getItemCount() == 0 && getMaskCount() == 1) {
170 | notifyDataSetChanged();
171 | } else {
172 | int positionStart = getPositionStart(1);
173 | notifyItemRangeChanged(positionStart, 1);
174 | }
175 | }
176 |
177 | public void setLoadCompleted(boolean hasMore) {
178 | setLoadCompleted(-1, hasMore);
179 | }
180 |
181 | public void setLoadCompleted(int changeSize, boolean hasMore) {
182 | int itemCount = itemAdapter.getItemCount();
183 | if (itemCount == 0 && getMaskCount() == 1) {
184 | currentState = ViewState.EMPTY;
185 | notifyDataSetChanged();
186 | } else {
187 | currentState = hasMore ? ViewState.DATA : ViewState.EMPTY;
188 | if (changeSize == -1) {
189 | notifyDataSetChanged();
190 | } else {
191 | if (itemCount < lastItemCount) { // 数据减少了,刷新的情况
192 | notifyDataSetChanged();
193 | } else {
194 | int positionStart = getPositionStart(changeSize);
195 | if (positionStart == 0) {
196 | notifyItemChanged(0);
197 | }
198 | if (changeSize > 0) {
199 | notifyItemRangeInserted(positionStart, changeSize);
200 | } else {
201 | notifyItemChanged(positionStart);
202 | }
203 | }
204 | }
205 | }
206 | lastItemCount = itemAdapter.getItemCount();
207 | }
208 |
209 | private int getPositionStart(int changeSize) {
210 | int itemCount = getItemCount();
211 | int positionStart = itemCount - changeSize - getLoadMoreCount() - getFooterCount();
212 | positionStart = Math.max(positionStart, 0);
213 | positionStart = Math.min(positionStart, itemCount - 1);
214 | return positionStart;
215 | }
216 |
217 | public void setMaskLayout(HolderLayout maskLayout) {
218 | this.maskLayout = maskLayout;
219 | }
220 |
221 | public void setLoadMoreLayout(HolderLayout loadMoreLayout) {
222 | this.loadMoreLayout = loadMoreLayout;
223 | }
224 |
225 | public void addHeader(HolderLayout headerLayout) {
226 | headerList.add(headerLayout);
227 | }
228 |
229 | public void addFooter(HolderLayout footerLayout) {
230 | footerList.add(footerLayout);
231 | }
232 |
233 | public void setRefreshListener(LoadListener refreshListener) {
234 | this.refreshListener = refreshListener;
235 | }
236 |
237 | public void setLoadMoreListener(LoadListener loadMoreListener) {
238 | this.loadMoreListener = loadMoreListener;
239 | }
240 | }
241 |
--------------------------------------------------------------------------------
/component_pagination/src/main/java/com/jeanboy/component/pagination/PaginationHelper.java:
--------------------------------------------------------------------------------
1 | package com.jeanboy.component.pagination;
2 |
3 | import android.os.Parcelable;
4 |
5 | import androidx.annotation.NonNull;
6 | import androidx.recyclerview.widget.LinearLayoutManager;
7 | import androidx.recyclerview.widget.RecyclerView;
8 | import androidx.recyclerview.widget.StaggeredGridLayoutManager;
9 |
10 | import com.jeanboy.component.pagination.base.HolderLayout;
11 | import com.jeanboy.component.pagination.constants.ViewState;
12 | import com.jeanboy.component.pagination.listener.LoadListener;
13 |
14 | /**
15 | * Created by jianbo on 2023/7/13 17:59.
16 | */
17 | public class PaginationHelper {
18 |
19 | private final RecyclerView recyclerView;
20 | private final RecyclerView.Adapter itemAdapter;
21 | private final PaginationAdapter paginationAdapter;
22 |
23 | public PaginationHelper(@NonNull RecyclerView recyclerView, RecyclerView.Adapter itemAdapter) {
24 | this.recyclerView = recyclerView;
25 | this.itemAdapter = itemAdapter;
26 | this.paginationAdapter = new PaginationAdapter(itemAdapter);
27 |
28 | if (recyclerView.getLayoutManager() == null) {
29 | recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
30 | }
31 | // 设置 item 固定宽高可提高性能
32 | recyclerView.setHasFixedSize(true);
33 | recyclerView.setAdapter(paginationAdapter);
34 |
35 | addWatcher(recyclerView);
36 | }
37 |
38 | private void addWatcher(RecyclerView recyclerView) {
39 | if (recyclerView == null) return;
40 | recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
41 | private int offsetY = 0;
42 |
43 | @Override
44 | public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
45 | super.onScrollStateChanged(recyclerView, newState);
46 |
47 | if (ViewState.LOADING == paginationAdapter.getCurrentState()) return;
48 | if (paginationAdapter.getDataSize() > 0 && ViewState.EMPTY == paginationAdapter.getCurrentState()) {
49 | return;
50 | }
51 |
52 | if (offsetY >= 0) { // 向上滑动,向后加载
53 | RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
54 | if (layoutManager != null) {
55 | int lastPosition = 0;
56 | if (layoutManager instanceof LinearLayoutManager) {
57 | LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
58 | lastPosition = linearLayoutManager.findLastCompletelyVisibleItemPosition();
59 | } else if (layoutManager instanceof StaggeredGridLayoutManager) {
60 | StaggeredGridLayoutManager gridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
61 | int[] lastPositions = new int[gridLayoutManager.getSpanCount()];
62 | int[] lastVisibleItemPositions = gridLayoutManager.findLastVisibleItemPositions(lastPositions);
63 | lastPosition = lastVisibleItemPositions[0];
64 | for (int value : lastVisibleItemPositions) {
65 | if (value > lastPosition) {
66 | lastPosition = value;
67 | }
68 | }
69 | }
70 |
71 | if (lastPosition >= layoutManager.getItemCount() - 1) {
72 | if (paginationAdapter.getDataSize() == 0 && paginationAdapter.getMaskCount() > 0) return;
73 | paginationAdapter.setLoading();
74 | LoadListener loadMoreListener = paginationAdapter.getLoadMoreListener();
75 | if (loadMoreListener != null) {
76 | loadMoreListener.onLoad(false);
77 | }
78 | }
79 | }
80 | }
81 |
82 | // if (offsetY >= 0) { // 向上滑动,向后加载
83 | // int verticalScrollExtent = recyclerView.computeVerticalScrollExtent();
84 | // int verticalScrollOffset = recyclerView.computeVerticalScrollOffset();
85 | // int verticalScrollRange = recyclerView.computeVerticalScrollRange();
86 | // if (verticalScrollExtent + verticalScrollOffset >= verticalScrollRange) {
87 | // if (dataList.isEmpty() && getMaskCount() > 0) return;
88 | // setLoading();
89 | // if (loadMoreListener != null) {
90 | // loadMoreListener.onLoad();
91 | // }
92 | // }
93 | // }
94 | }
95 |
96 | @Override
97 | public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
98 | super.onScrolled(recyclerView, dx, dy);
99 | offsetY = dy;
100 | }
101 | });
102 | }
103 |
104 | public void setLoading() {
105 | paginationAdapter.setLoading();
106 | }
107 |
108 | public void setLoadError() {
109 | paginationAdapter.setLoadError();
110 | }
111 |
112 | public void setLoadCompleted(boolean hasMore) {
113 | paginationAdapter.setLoadCompleted(hasMore);
114 | }
115 |
116 | public void setLoadCompleted(int changeSize, boolean hasMore) {
117 | Parcelable parcelable = null;
118 | RecyclerView.LayoutManager layoutManager = null;
119 | if (recyclerView != null) {
120 | layoutManager = recyclerView.getLayoutManager();
121 | if (layoutManager != null) {
122 | parcelable = layoutManager.onSaveInstanceState();
123 | }
124 | }
125 | paginationAdapter.setLoadCompleted(changeSize, hasMore);
126 | if (parcelable != null && layoutManager != null) {
127 | layoutManager.onRestoreInstanceState(parcelable);
128 | }
129 | }
130 |
131 | public void setMaskLayout(HolderLayout layout) {
132 | paginationAdapter.setMaskLayout(layout);
133 | }
134 |
135 | public void setLoadMoreLayout(HolderLayout layout) {
136 | paginationAdapter.setLoadMoreLayout(layout);
137 | }
138 |
139 | public void addHeader(HolderLayout layout) {
140 | paginationAdapter.addHeader(layout);
141 | }
142 |
143 | public void addFooter(HolderLayout layout) {
144 | paginationAdapter.addFooter(layout);
145 | }
146 |
147 | public void setRefreshListener(LoadListener refreshListener) {
148 | paginationAdapter.setRefreshListener(refreshListener);
149 | }
150 |
151 | public void setLoadMoreListener(LoadListener loadMoreListener) {
152 | paginationAdapter.setLoadMoreListener(loadMoreListener);
153 | }
154 | }
155 |
--------------------------------------------------------------------------------
/component_pagination/src/main/java/com/jeanboy/component/pagination/base/BaseViewHolder.java:
--------------------------------------------------------------------------------
1 | package com.jeanboy.component.pagination.base;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.content.res.Resources;
6 | import android.graphics.Bitmap;
7 | import android.graphics.drawable.Drawable;
8 | import android.util.SparseArray;
9 | import android.view.View;
10 | import android.widget.ImageView;
11 | import android.widget.TextView;
12 |
13 | import androidx.annotation.ColorInt;
14 | import androidx.annotation.DrawableRes;
15 | import androidx.annotation.IdRes;
16 | import androidx.annotation.StringRes;
17 | import androidx.recyclerview.widget.RecyclerView;
18 |
19 | /**
20 | * Created by jeanboy on 2020/04/01 16:50.
21 | */
22 | public class BaseViewHolder extends RecyclerView.ViewHolder {
23 |
24 | private final SparseArray views;
25 |
26 | public BaseViewHolder(View itemView) {
27 | super(itemView);
28 | this.views = new SparseArray<>();
29 | }
30 |
31 | public T getView(@IdRes int viewId) {
32 | View view = views.get(viewId);
33 | if (view == null) {
34 | view = itemView.findViewById(viewId);
35 | views.put(viewId, view);
36 | }
37 | return (T) view;
38 | }
39 |
40 | public Context getContext() {
41 | return itemView.getContext();
42 | }
43 |
44 | public Resources getResources() {
45 | return itemView.getResources();
46 | }
47 |
48 | public BaseViewHolder setText(@IdRes int viewId, CharSequence value) {
49 | TextView view = getView(viewId);
50 | if (view != null) {
51 | view.setText(value);
52 | }
53 | return this;
54 | }
55 |
56 | public BaseViewHolder setText(@IdRes int viewId, @StringRes int stringId) {
57 | TextView view = getView(viewId);
58 | if (view != null) {
59 | view.setText(stringId);
60 | }
61 | return this;
62 | }
63 |
64 | public BaseViewHolder setImageResource(@IdRes int viewId, @DrawableRes int resId) {
65 | ImageView view = getView(viewId);
66 | if (view != null) {
67 | view.setImageResource(resId);
68 | }
69 | return this;
70 | }
71 |
72 | public BaseViewHolder setBackgroundColor(@IdRes int viewId, @ColorInt int color) {
73 | View view = getView(viewId);
74 | if (view != null) {
75 | view.setBackgroundColor(color);
76 | }
77 | return this;
78 | }
79 |
80 | @SuppressLint("ResourceType")
81 | public BaseViewHolder setBackgroundRes(@IdRes int viewId, @DrawableRes int backgroundRes) {
82 | View view = getView(viewId);
83 | if (view != null) {
84 | if (backgroundRes > 0) {
85 | view.setBackgroundResource(backgroundRes);
86 | } else {
87 | view.setBackground(null);
88 | }
89 | }
90 | return this;
91 | }
92 |
93 | public BaseViewHolder setTextColor(@IdRes int viewId, @ColorInt int textColor) {
94 | TextView view = getView(viewId);
95 | if (view != null) {
96 | view.setTextColor(textColor);
97 | }
98 | return this;
99 | }
100 |
101 | public BaseViewHolder setImageDrawable(@IdRes int viewId, Drawable drawable) {
102 | ImageView view = getView(viewId);
103 | if (view != null) {
104 | view.setImageDrawable(drawable);
105 | }
106 | return this;
107 | }
108 |
109 | public BaseViewHolder setImageBitmap(@IdRes int viewId, Bitmap bitmap) {
110 | ImageView view = getView(viewId);
111 | if (view != null) {
112 | view.setImageBitmap(bitmap);
113 | }
114 | return this;
115 | }
116 |
117 | public BaseViewHolder setVisible(@IdRes int viewId, boolean visible) {
118 | View view = getView(viewId);
119 | if (view != null) {
120 | view.setVisibility(visible ? View.VISIBLE : View.GONE);
121 | }
122 | return this;
123 | }
124 |
125 | public BaseViewHolder setOnClickListener(@IdRes int viewId, View.OnClickListener listener) {
126 | View view = getView(viewId);
127 | if (view != null) {
128 | view.setOnClickListener(listener);
129 | }
130 | return this;
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/component_pagination/src/main/java/com/jeanboy/component/pagination/base/HolderLayout.java:
--------------------------------------------------------------------------------
1 | package com.jeanboy.component.pagination.base;
2 |
3 | import android.view.View;
4 |
5 | import androidx.recyclerview.widget.RecyclerView;
6 |
7 | import com.jeanboy.component.pagination.listener.LoadListener;
8 |
9 |
10 | /**
11 | * Created by jeanboy on 2020/04/01 16:50.
12 | */
13 | public abstract class HolderLayout {
14 |
15 | protected void convertListener(View view, final boolean isError, final LoadListener listener) {
16 | view.setOnClickListener(new View.OnClickListener() {
17 | @Override
18 | public void onClick(View v) {
19 | if (listener != null) {
20 | listener.onLoad(isError);
21 | }
22 | }
23 | });
24 | }
25 |
26 | public abstract int getLayoutId();
27 |
28 | public abstract void convert(RecyclerView.ViewHolder holder, int state, LoadListener listener);
29 | }
30 |
--------------------------------------------------------------------------------
/component_pagination/src/main/java/com/jeanboy/component/pagination/base/RecyclerBaseAdapter.java:
--------------------------------------------------------------------------------
1 | package com.jeanboy.component.pagination.base;
2 |
3 | import android.view.LayoutInflater;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 |
7 | import androidx.annotation.LayoutRes;
8 | import androidx.annotation.NonNull;
9 | import androidx.recyclerview.widget.RecyclerView;
10 |
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | /**
15 | * Created by jeanboy on 2020/04/01 16:50.
16 | */
17 | public abstract class RecyclerBaseAdapter extends RecyclerView.Adapter {
18 | protected List dataList;
19 | private final int itemLayoutId;
20 |
21 | public RecyclerBaseAdapter(List dataList, @LayoutRes int itemLayoutId) {
22 | if (dataList == null) {
23 | dataList = new ArrayList<>();
24 | }
25 | this.dataList = dataList;
26 | this.itemLayoutId = itemLayoutId;
27 | }
28 |
29 | @NonNull
30 | @Override
31 | public BaseViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
32 | return new BaseViewHolder(getLayoutView(parent, itemLayoutId));
33 | }
34 |
35 | @Override
36 | public void onBindViewHolder(@NonNull BaseViewHolder holder, int position) {
37 | convert(holder, dataList.get(position), holder.getAdapterPosition());
38 | }
39 |
40 | @Override
41 | public int getItemCount() {
42 | return dataList.size();
43 | }
44 |
45 | @Override
46 | public void onViewAttachedToWindow(@NonNull BaseViewHolder holder) {
47 | super.onViewAttachedToWindow(holder);
48 | setItemClickListener(holder);
49 | }
50 |
51 | @Override
52 | public void onViewDetachedFromWindow(@NonNull BaseViewHolder holder) {
53 | super.onViewDetachedFromWindow(holder);
54 | clearItemClickListener(holder);
55 | }
56 |
57 | protected View getLayoutView(ViewGroup parent, int layoutId) {
58 | return LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false);
59 | }
60 |
61 | protected void setItemClickListener(final BaseViewHolder holder) {
62 | if (onItemClickListener == null) {
63 | return;
64 | }
65 | if (dataList.isEmpty()) return;
66 | holder.itemView.setOnClickListener(new View.OnClickListener() {
67 | @Override
68 | public void onClick(View v) {
69 | if (onItemClickListener != null) {
70 | int position = holder.getAdapterPosition();
71 | onItemClickListener.onItemClick(v, holder, position);
72 | }
73 | }
74 | });
75 | }
76 |
77 | protected void clearItemClickListener(BaseViewHolder holder) {
78 | holder.itemView.setOnClickListener(null);
79 | }
80 |
81 | public abstract void convert(BaseViewHolder holder, T t, int position);
82 |
83 | protected OnItemClickListener onItemClickListener;
84 |
85 | public interface OnItemClickListener {
86 | void onItemClick(View view, BaseViewHolder holder, int position);
87 | }
88 |
89 | public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
90 | this.onItemClickListener = onItemClickListener;
91 | }
92 |
93 | public void addMoreData(List sourceList) {
94 | dataList.addAll(sourceList);
95 | notifyDataSetChanged();
96 | }
97 |
98 | public void setData(List sourceList) {
99 | dataList.clear();
100 | dataList.addAll(sourceList);
101 | notifyDataSetChanged();
102 | }
103 |
104 | public T getDataByPosition(int position) {
105 | return dataList.get(position);
106 | }
107 |
108 | public boolean contains(T t) {
109 | return dataList.contains(t);
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/component_pagination/src/main/java/com/jeanboy/component/pagination/constants/ViewState.java:
--------------------------------------------------------------------------------
1 | package com.jeanboy.component.pagination.constants;
2 |
3 | /**
4 | * Created by jeanboy on 2020/04/01 16:50.
5 | */
6 | public interface ViewState {
7 | int LOADING = 0x1122001; // 加载中
8 | int DATA = 0x1122002; // 显示中
9 | int EMPTY = 0x1122003; // 没有数据,全部加载完毕,没有更多
10 | int ERROR = 0x1122004; // 加载失败
11 | }
12 |
--------------------------------------------------------------------------------
/component_pagination/src/main/java/com/jeanboy/component/pagination/constants/ViewType.java:
--------------------------------------------------------------------------------
1 | package com.jeanboy.component.pagination.constants;
2 |
3 | /**
4 | * Created by jeanboy on 2020/04/01 16:50.
5 | */
6 | public interface ViewType {
7 | int ITEM = 0;
8 | int MASK = 0x10808001;
9 | int LOAD_MORE = 0x10808002;
10 | int HEADER = 0x10808003;
11 | int FOOTER = 0x10808004;
12 | // 偏移量
13 | int OFFSET = 5;
14 | }
15 |
16 |
--------------------------------------------------------------------------------
/component_pagination/src/main/java/com/jeanboy/component/pagination/decoration/SpaceItemDecoration.java:
--------------------------------------------------------------------------------
1 | package com.jeanboy.component.pagination.decoration;
2 |
3 | import android.graphics.Rect;
4 | import android.util.Log;
5 | import android.view.View;
6 |
7 | import androidx.annotation.IntDef;
8 | import androidx.annotation.NonNull;
9 | import androidx.recyclerview.widget.GridLayoutManager;
10 | import androidx.recyclerview.widget.LinearLayoutManager;
11 | import androidx.recyclerview.widget.RecyclerView;
12 | import androidx.recyclerview.widget.StaggeredGridLayoutManager;
13 |
14 | import java.lang.annotation.Retention;
15 | import java.lang.annotation.RetentionPolicy;
16 |
17 | /**
18 | * Created by jeanboy on 2020/04/27 14:50.
19 | */
20 | public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
21 | private final int edgeSpace; // 两边间距
22 | private final int itemSpace; // 中间间距
23 | private final int mode;
24 |
25 | public static final int HIDE_NONE = 0;
26 | public static final int HIDE_MIDDLE = 1;
27 | public static final int HIDE_HEAD = 1 << 2;
28 | public static final int HIDE_TAIL = 1 << 3;
29 |
30 | @IntDef({HIDE_NONE, HIDE_MIDDLE, HIDE_HEAD, HIDE_TAIL})
31 | @Retention(RetentionPolicy.SOURCE)
32 | @interface Mode {
33 | }
34 |
35 | public SpaceItemDecoration(int space) {
36 | this(space, HIDE_NONE);
37 | }
38 |
39 | public SpaceItemDecoration(int space, @Mode int mode) {
40 | this(space, space, mode);
41 | }
42 |
43 | public SpaceItemDecoration(int edgeSpace, int itemSpace, @Mode int mode) {
44 | this.edgeSpace = edgeSpace;
45 | this.itemSpace = itemSpace;
46 | this.mode = mode;
47 | }
48 |
49 | @Override
50 | public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
51 | super.getItemOffsets(outRect, view, parent, state);
52 |
53 | int position = parent.getChildAdapterPosition(view);
54 | int itemCount = parent.getAdapter() == null ? parent.getChildCount() : parent.getAdapter().getItemCount();
55 |
56 | RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
57 | if (layoutManager instanceof GridLayoutManager) {
58 | setGridLayoutOffsets(outRect, (GridLayoutManager) layoutManager, view, position, itemCount);
59 | } else if (layoutManager instanceof StaggeredGridLayoutManager) {
60 | setStaggeredGridLayoutOffsets(outRect, (StaggeredGridLayoutManager) layoutManager, view, position, itemCount);
61 | } else if (layoutManager instanceof LinearLayoutManager) {
62 | setLinearLayoutOffsets(outRect, (LinearLayoutManager) layoutManager, view, position, itemCount);
63 | }
64 | }
65 |
66 | private void setGridLayoutOffsets(Rect rect, GridLayoutManager layoutManager, View view, int position, int itemCount) {
67 | int headSpace = edgeSpace;
68 | int footSpace = edgeSpace;
69 | int centerSpace = itemSpace;
70 | if ((mode & HIDE_HEAD) == HIDE_HEAD) {
71 | headSpace = 0;
72 | }
73 | if ((mode & HIDE_TAIL) == HIDE_TAIL) {
74 | footSpace = 0;
75 | }
76 | if ((mode & HIDE_MIDDLE) == HIDE_MIDDLE) {
77 | centerSpace = 0;
78 | }
79 |
80 | GridLayoutManager.LayoutParams layoutParams = (GridLayoutManager.LayoutParams) view.getLayoutParams();
81 |
82 | int columnCount = layoutManager.getSpanCount(); // 列的数量
83 | int columnIndex = layoutParams.getSpanIndex(); // 当前列下标
84 | int spanSize = layoutParams.getSpanSize(); // 当前行跨的列数
85 |
86 | if (spanSize == columnCount) { // 跨列的情况
87 | if (position >= 0 && position < columnCount) { // 第一行
88 | rect.top = headSpace;
89 | } else if (position == (itemCount - 1)) { // 最后一行
90 | rect.top = centerSpace;
91 | rect.bottom = footSpace;
92 | }
93 | } else { // 不跨列
94 | if (position >= 0 && position < columnCount && position == columnIndex) { // 第一行
95 | rect.top = headSpace;
96 | } else if (position >= (itemCount - columnCount) && position <= itemCount) { // 最后一行
97 | rect.top = centerSpace;
98 | rect.bottom = footSpace;
99 | } else { // 中间行
100 | rect.top = centerSpace;
101 | }
102 | if (columnIndex >= 0 && columnIndex < columnCount) { // 每行列
103 | int halfCenterSpace = centerSpace / 2;
104 | rect.left = columnIndex == 0 ? 0 : halfCenterSpace;
105 | rect.right = columnIndex == (columnCount - 1) ? 0 : halfCenterSpace;
106 | }
107 | }
108 | }
109 |
110 | private void setStaggeredGridLayoutOffsets(Rect rect, StaggeredGridLayoutManager layoutManager, View view, int position, int itemCount) {
111 | int headSpace = edgeSpace;
112 | int footSpace = edgeSpace;
113 | int centerSpace = itemSpace;
114 | if ((mode & HIDE_HEAD) == HIDE_HEAD) {
115 | headSpace = 0;
116 | }
117 | if ((mode & HIDE_TAIL) == HIDE_TAIL) {
118 | footSpace = 0;
119 | }
120 | if ((mode & HIDE_MIDDLE) == HIDE_MIDDLE) {
121 | centerSpace = 0;
122 | }
123 |
124 | GridLayoutManager.LayoutParams layoutParams = (GridLayoutManager.LayoutParams) view.getLayoutParams();
125 |
126 | int columnCount = layoutManager.getSpanCount(); // 列的数量
127 | int columnIndex = layoutParams.getSpanIndex(); // 当前列下标
128 | int spanSize = layoutParams.getSpanSize(); // 当前行跨的列数
129 |
130 | Log.e(SpaceItemDecoration.class.getSimpleName(), itemCount + "----------------------------position--" + position
131 | + "-columnCount--" + columnCount
132 | + "-columnIndex--" + columnIndex
133 | + "-spanSize--" + spanSize);
134 |
135 | if (spanSize == columnCount) { // 跨列的情况
136 | if (position >= 0 && position < columnCount) { // 第一行
137 | rect.top = headSpace;
138 | } else if (position == (itemCount - 1)) { // 最后一行
139 | rect.top = centerSpace;
140 | rect.bottom = footSpace;
141 | }
142 | } else { // 不跨列
143 | if (position >= 0 && position < columnCount && position == columnIndex) { // 第一行
144 | rect.top = headSpace;
145 | } else if (position >= (itemCount - columnCount) && position <= itemCount) { // 最后一行
146 | rect.top = centerSpace;
147 | rect.bottom = footSpace;
148 | } else { // 中间行
149 | rect.top = centerSpace;
150 | }
151 | if (columnIndex >= 0 && columnIndex < columnCount) { // 每行列
152 | int halfCenterSpace = centerSpace / 2;
153 | rect.left = columnIndex == 0 ? 0 : halfCenterSpace;
154 | rect.right = columnIndex == (columnCount - 1) ? 0 : halfCenterSpace;
155 | }
156 | }
157 | }
158 |
159 | private void setLinearLayoutOffsets(Rect rect, LinearLayoutManager layoutManager, View view, int position, int itemCount) {
160 | int headSpace = edgeSpace;
161 | int footSpace = edgeSpace;
162 | int centerSpace = itemSpace;
163 | if ((mode & HIDE_HEAD) == HIDE_HEAD) {
164 | headSpace = 0;
165 | }
166 | if ((mode & HIDE_TAIL) == HIDE_TAIL) {
167 | footSpace = 0;
168 | }
169 | if ((mode & HIDE_MIDDLE) == HIDE_MIDDLE) {
170 | centerSpace = 0;
171 | }
172 |
173 | int orientation = layoutManager.getOrientation();
174 | if (orientation == LinearLayoutManager.VERTICAL) { // 垂直方向
175 | if (position == 0) { // 第一行
176 | rect.top = headSpace;
177 | } else if (position == (itemCount - 1)) { // 最后一行
178 | rect.top = centerSpace;
179 | rect.bottom = footSpace;
180 | } else { // 中间
181 | rect.top = centerSpace;
182 | }
183 | } else { // 水平方向
184 | if (position == 0) { // 第一行
185 | rect.left = headSpace;
186 | } else if (position == (itemCount - 1)) { // 最后一行
187 | rect.left = centerSpace;
188 | rect.right = footSpace;
189 | } else { // 中间
190 | rect.left = centerSpace;
191 | }
192 | }
193 | }
194 | }
195 |
--------------------------------------------------------------------------------
/component_pagination/src/main/java/com/jeanboy/component/pagination/layout/LoadMoreLayout.java:
--------------------------------------------------------------------------------
1 | package com.jeanboy.component.pagination.layout;
2 |
3 |
4 | import android.view.View;
5 | import android.widget.TextView;
6 |
7 | import androidx.recyclerview.widget.RecyclerView;
8 |
9 | import com.jeanboy.component.pagination.R;
10 | import com.jeanboy.component.pagination.base.HolderLayout;
11 | import com.jeanboy.component.pagination.constants.ViewState;
12 | import com.jeanboy.component.pagination.listener.LoadListener;
13 |
14 | /**
15 | * Created by jeanboy on 2020/04/01 16:50.
16 | */
17 | public class LoadMoreLayout extends HolderLayout {
18 |
19 | @Override
20 | public int getLayoutId() {
21 | return R.layout.pagination_default_item_load_more;
22 | }
23 |
24 | @Override
25 | public void convert(RecyclerView.ViewHolder holder, int state, LoadListener listener) {
26 | View pb_progress = holder.itemView.findViewById(R.id.pb_progress);
27 | TextView tv_text = holder.itemView.findViewById(R.id.tv_text);
28 | holder.itemView.setVisibility(View.GONE);
29 | pb_progress.setVisibility(View.GONE);
30 | switch (state) {
31 | case ViewState.LOADING:
32 | holder.itemView.setVisibility(View.VISIBLE);
33 | pb_progress.setVisibility(View.VISIBLE);
34 | tv_text.setText(R.string.data_loading);
35 | break;
36 | case ViewState.ERROR:
37 | holder.itemView.setVisibility(View.VISIBLE);
38 | pb_progress.setVisibility(View.GONE);
39 | tv_text.setText(R.string.data_error_retry);
40 | convertListener(holder.itemView, true, listener);
41 | break;
42 | case ViewState.EMPTY:
43 | holder.itemView.setVisibility(View.VISIBLE);
44 | pb_progress.setVisibility(View.GONE);
45 | tv_text.setText(R.string.data_no_more);
46 | break;
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/component_pagination/src/main/java/com/jeanboy/component/pagination/layout/MaskLayout.java:
--------------------------------------------------------------------------------
1 | package com.jeanboy.component.pagination.layout;
2 |
3 | import android.view.View;
4 | import android.widget.TextView;
5 |
6 | import androidx.recyclerview.widget.RecyclerView;
7 |
8 | import com.jeanboy.component.pagination.R;
9 | import com.jeanboy.component.pagination.base.HolderLayout;
10 | import com.jeanboy.component.pagination.constants.ViewState;
11 | import com.jeanboy.component.pagination.listener.LoadListener;
12 |
13 | /**
14 | * Created by jeanboy on 2020/04/01 16:50.
15 | */
16 | public class MaskLayout extends HolderLayout {
17 |
18 | @Override
19 | public int getLayoutId() {
20 | return R.layout.pagination_default_item_mask;
21 | }
22 |
23 | @Override
24 | public void convert(RecyclerView.ViewHolder holder, int state, LoadListener listener) {
25 | View pb_progress = holder.itemView.findViewById(R.id.pb_progress);
26 | TextView tv_text = holder.itemView.findViewById(R.id.tv_text);
27 | pb_progress.setVisibility(View.GONE);
28 | switch (state) {
29 | case ViewState.LOADING:
30 | pb_progress.setVisibility(View.VISIBLE);
31 | tv_text.setText(R.string.data_loading);
32 | break;
33 | case ViewState.EMPTY:
34 | pb_progress.setVisibility(View.GONE);
35 | tv_text.setText(R.string.data_empty);
36 | convertListener(holder.itemView, false, listener);
37 | break;
38 | case ViewState.ERROR:
39 | pb_progress.setVisibility(View.GONE);
40 | tv_text.setText(R.string.data_error_retry);
41 | convertListener(holder.itemView, true, listener);
42 | break;
43 | }
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/component_pagination/src/main/java/com/jeanboy/component/pagination/listener/LoadListener.java:
--------------------------------------------------------------------------------
1 | package com.jeanboy.component.pagination.listener;
2 |
3 | /**
4 | * Created by jeanboy on 2020/04/01 16:50.
5 | */
6 | public interface LoadListener {
7 | void onLoad(boolean isError);
8 | }
9 |
--------------------------------------------------------------------------------
/component_pagination/src/main/res/layout/pagination_default_item_load_more.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
21 |
--------------------------------------------------------------------------------
/component_pagination/src/main/res/layout/pagination_default_item_mask.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
22 |
23 |
--------------------------------------------------------------------------------
/component_pagination/src/main/res/values-zh/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 加载中,请稍候…
3 | 加载失败
4 | 暂无数据
5 | 暂无更多
6 | 重新加载
7 | 加载失败,点击重试
8 |
9 |
--------------------------------------------------------------------------------
/component_pagination/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Loading…
4 | Load Failed
5 | No data
6 | No more
7 | Reload
8 | Load Failed, Click Retry
9 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Enables namespacing of each library's R class so that its R class includes only the
19 | # resources declared in the library itself and none from the library's dependencies,
20 | # thereby reducing the size of the R class for that library
21 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-RecyclerViewHelper/8c2a00575afdc459d0742d45f0251b055507a2ad/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jul 14 16:42:37 CST 2023
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/resource/ScreenRecord.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jeanboydev/Android-RecyclerViewHelper/8c2a00575afdc459d0742d45f0251b055507a2ad/resource/ScreenRecord.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | google()
4 | mavenCentral()
5 | gradlePluginPortal()
6 | }
7 | }
8 | dependencyResolutionManagement {
9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
10 | repositories {
11 | google()
12 | mavenCentral()
13 | }
14 | }
15 | rootProject.name = "Android-RecyclerViewHelper"
16 | include ':app'
17 | include ':component_pagination'
18 |
--------------------------------------------------------------------------------