├── .gitignore
├── .travis.yml
├── LICENSE.txt
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── github
│ │ └── nukc
│ │ └── sample
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── nukc
│ │ │ └── sample
│ │ │ ├── AnotherActivity.java
│ │ │ ├── FlexboxActivity.java
│ │ │ ├── Issue9Activity.java
│ │ │ ├── MainActivity.java
│ │ │ ├── NotShowFooterWhenNotCoveredScreenActivity.java
│ │ │ ├── SampleActivity.java
│ │ │ ├── SampleFragment.java
│ │ │ └── ScrollingActivity.java
│ └── res
│ │ ├── layout
│ │ ├── activity_another.xml
│ │ ├── activity_flexbox.xml
│ │ ├── activity_issue9.xml
│ │ ├── activity_main.xml
│ │ ├── activity_sample.xml
│ │ ├── activity_scrolling.xml
│ │ ├── fragment_sample.xml
│ │ ├── item_flex.xml
│ │ ├── item_sample.xml
│ │ ├── view_flex_loading.xml
│ │ ├── view_flex_no_more.xml
│ │ ├── view_flex_retry.xml
│ │ └── view_footer.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ ├── values-zh
│ │ └── strings.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── github
│ └── nukc
│ └── sample
│ └── ExampleUnitTest.java
├── bintray.gradle
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── images
├── grid_custom.gif
├── item.gif
└── staggeredgrid.gif
├── loadmorewrapper
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── github
│ │ └── nukc
│ │ └── LoadMoreWrapper
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── github
│ │ │ └── nukc
│ │ │ └── LoadMoreWrapper
│ │ │ ├── LoadMoreAdapter.java
│ │ │ ├── LoadMoreHelper.java
│ │ │ └── LoadMoreWrapper.java
│ └── res
│ │ ├── layout
│ │ ├── base_footer.xml
│ │ ├── base_load_failed.xml
│ │ └── base_no_more.xml
│ │ ├── values-zh
│ │ └── strings.xml
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── github
│ └── nukc
│ └── recycleradapter
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
10 | .idea/
11 |
12 | *.iml
13 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 |
3 | jdk:
4 | - oraclejdk8
5 |
6 | notifications:
7 | email: false
8 |
9 | sudo: false
10 |
11 | android:
12 | components:
13 | - tools
14 | - platform-tools
15 | - tools
16 | - build-tools-28.0.3
17 | - android-28
18 | - android-21
19 | - extra-google-m2repository
20 | - extra-android-m2repository
21 | - extra-android-support
22 | - sys-img-armeabi-v7a-android-28
23 | - sys-img-armeabi-v7a-android-21
24 | licenses:
25 | - 'android-sdk-preview-license-52d11cd2'
26 | - 'android-sdk-license-.+'
27 | - 'google-gdk-license-.+'
28 |
29 | env:
30 | global:
31 | # install timeout in minutes (2 minutes by default)
32 | - ADB_INSTALL_TIMEOUT=10
33 | - GRADLE_OPTS="-Xms512m"
34 | # Emulator Management: Create, Start and Wait
35 | before_script:
36 | - echo no | android create avd --force -n test -t android-21 --abi armeabi-v7a
37 | - emulator -avd test -no-skin -no-audio -no-window &
38 | - android-wait-for-emulator
39 | - adb shell input keyevent 82 &
40 |
41 | before_install:
42 | - yes | sdkmanager "platforms;android-27"
43 |
44 | script: ./gradlew connectedAndroidTest
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # LoadMoreWrapper
2 |
3 | [](https://travis-ci.org/nukc/LoadMoreWrapper)
4 | [ ](https://bintray.com/nukc/maven/LoadMoreWrapper/_latestVersion)
5 | [](https://jitpack.io/#nukc/LoadMoreWrapper)
6 |
7 | make recyclerView supports load more and customize the footer view, without changes to the original adater of recyclerView.
8 |
9 | 在不改动 RecyclerView 原有 adapter 的情况下,使其拥有加载更多功能和自定义底部视图。
10 |
11 | - 支持当 item 未铺满屏幕的时候仍能够加载更多
12 | - 支持自定义加载视图
13 | - 当 layoutManager 为 Grid 和 StaggeredGrid 的时候, 加载更多视图 footerView 仍占据一行
14 | - 支持设置是否显示没有更多视图,可自定义
15 | - 支持设置加载失败视图,点击会自动触发加载更多事件
16 |
17 | 

18 |
19 | ## Installation
20 |
21 | JCenter:
22 |
23 | add the dependency to your build.gradle:
24 | ```gradle
25 | implementation 'com.github.nukc:loadmorewrapper:1.9.1'
26 | ```
27 |
28 |
29 | JitPack:
30 |
31 | Step 1. Add the JitPack repository to your build file
32 | Add it in your root build.gradle at the end of repositories:
33 | ```gradle
34 | allprojects {
35 | repositories {
36 | ...
37 | maven { url 'https://jitpack.io' }
38 | }
39 | }
40 | ```
41 |
42 | Step 2. Add the dependency
43 | ```gradle
44 | dependencies {
45 | implementation 'com.github.nukc:LoadMoreWrapper:v1.9.1'
46 | }
47 | ```
48 | AndroidX
49 | ```gradle
50 | dependencyResolutionManagement {
51 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
52 | repositories {
53 | ...
54 | maven("https://jitpack.io")
55 | }
56 | }
57 | ```
58 | ```gradle
59 | dependencies {
60 | implementation("com.github.nukc:LoadMoreWrapper:v1.9.3")
61 | }
62 | ```
63 |
64 | ## Usage
65 |
66 | ```java
67 | //the adapter is the original (这个 adapter 是原有的, 不改动它)
68 | LoadMoreWrapper.with(adapter)
69 | .setFooterView(...) // view or layout resource
70 | .setShowNoMoreEnabled(true) // enable show NoMoreView,default false
71 | .setListener(new LoadMoreAdapter.OnLoadMoreListener() {
72 | @Override
73 | public void onLoadMore(LoadMoreAdapter.Enabled enabled) {
74 | // do something
75 | // you can enabled.setLoadMoreEnabled(false) when do not need load more
76 | // you can enabled.setLoadFailed(true) when load failed
77 | })
78 | .into(recyclerView);
79 | ```
80 |
81 | or
82 |
83 | in the original adapter: [demo](https://github.com/nukc/LoadMoreWrapper/blob/master/app/src/main/java/com/github/nukc/sample/AnotherActivity.java)
84 | ```java
85 | private static class AnotherAdapter extends RecyclerView.Adapter {
86 |
87 | private LoadMoreWrapper mWrapper;
88 |
89 | // code..
90 |
91 | @Override
92 | public void onAttachedToRecyclerView(RecyclerView recyclerView) {
93 | super.onAttachedToRecyclerView(recyclerView);
94 |
95 | mWrapper = LoadMoreWrapper.with(this);
96 | mWrapper.setListener(
97 | new LoadMoreAdapter.OnLoadMoreListener() {
98 | @Override
99 | public void onLoadMore(LoadMoreAdapter.Enabled enabled) {
100 | // do something
101 | }
102 | })
103 | .setShowNoMoreEnabled(true)
104 | .into(recyclerView);
105 | }
106 |
107 | }
108 |
109 | ```
110 |
111 | 方法名 | 备注
112 | :------------- | :-------------
113 | setLoadMoreEnabled(boolean enabled) | 设置是否启用加载更多,默认 true
114 | setShowNoMoreEnabled(boolean enabled) | 设置全部加载完后是否显示没有更多视图,默认 false
115 | setLoadFailed(boolean isLoadFailed) | 设置是否加载失败,默认 false
116 | setNotShowFooterWhenNotCoveredScreen(boolean notShow) | 设置在 item 未铺满屏幕的时候是否不显示底部视图,默认 false
117 | getOriginalAdapter() | 获取原来的 adapter
118 | getFooterView | 获取加载更多视图
119 | getNoMoreView | 获取没有更多视图
120 | getLoadFailedView | 获取加载失败视图
121 |
122 | 注意:当加载完全部后且已 setLoadMoreEnabled(false),但如果由于生命周期或其他问题而导致 View 重建,mLoadMoreEnabled 依然为 true。
123 | 这时候应该需要保存 mLoadMoreEnabled 的状态,如果是 ViewPager + Fragment,可以使用 setOffscreenPageLimit 进行解决。
124 |
125 | ## License
126 |
127 | Copyright 2016 nukc
128 |
129 | Licensed under the Apache License, Version 2.0 (the "License");
130 | you may not use this file except in compliance with the License.
131 | You may obtain a copy of the License at
132 |
133 | http://www.apache.org/licenses/LICENSE-2.0
134 |
135 | Unless required by applicable law or agreed to in writing, software
136 | distributed under the License is distributed on an "AS IS" BASIS,
137 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138 | See the License for the specific language governing permissions and
139 | limitations under the License.
140 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 30
5 | buildToolsVersion '30.0.3'
6 |
7 | defaultConfig {
8 | applicationId "com.github.nukc.loadmorewrapper.sample"
9 | minSdkVersion 16
10 | targetSdkVersion 30
11 | versionCode 1
12 | versionName "1.0"
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | ext {
24 | supportLibVersion = '28.0.0'
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 | implementation 'androidx.appcompat:appcompat:1.3.0'
30 | implementation 'com.google.android.material:material:1.3.0'
31 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
32 | implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
33 | implementation 'com.google.android.flexbox:flexbox:3.0.0'
34 | implementation project(':loadmorewrapper')
35 | testImplementation 'junit:junit:4.13.2'
36 | androidTestImplementation 'androidx.test:runner:1.3.0'
37 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
38 | }
39 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/C/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/github/nukc/sample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.github.nukc.sample;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.assertEquals;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.github.nukc.loadmorewrapper.sample", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/nukc/sample/AnotherActivity.java:
--------------------------------------------------------------------------------
1 | package com.github.nukc.sample;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 |
9 | import androidx.appcompat.app.AppCompatActivity;
10 | import androidx.recyclerview.widget.LinearLayoutManager;
11 | import androidx.recyclerview.widget.RecyclerView;
12 |
13 | import com.github.nukc.LoadMoreWrapper.LoadMoreAdapter;
14 | import com.github.nukc.LoadMoreWrapper.LoadMoreWrapper;
15 |
16 | public class AnotherActivity extends AppCompatActivity {
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_another);
22 |
23 | RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
24 |
25 | recyclerView.setLayoutManager(new LinearLayoutManager(this));
26 | // recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
27 | recyclerView.setAdapter(new AnotherAdapter(0));
28 | }
29 |
30 | private static class AnotherAdapter extends RecyclerView.Adapter {
31 |
32 | private LoadMoreWrapper mWrapper;
33 | private int mCount;
34 | // use for demo, please ignore
35 | private boolean mShowLoadFailedEnabled = true;
36 |
37 | public AnotherAdapter(int count) {
38 | mCount = count;
39 | }
40 |
41 | @Override
42 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
43 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_sample, parent, false);
44 | return new AnotherHolder(view);
45 | }
46 |
47 | @Override
48 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
49 | ((AnotherHolder) holder).mTextView.setText(position + "");
50 | }
51 |
52 | @Override
53 | public int getItemCount() {
54 | return mCount;
55 | }
56 |
57 | @Override
58 | public void onAttachedToRecyclerView(final RecyclerView recyclerView) {
59 | super.onAttachedToRecyclerView(recyclerView);
60 |
61 | mWrapper = LoadMoreWrapper.with(this);
62 | mWrapper.setListener(
63 | new LoadMoreAdapter.OnLoadMoreListener() {
64 | @Override
65 | public void onLoadMore(LoadMoreAdapter.Enabled enabled) {
66 | recyclerView.postDelayed(new Runnable() {
67 | @Override
68 | public void run() {
69 | addItem(recyclerView);
70 | }
71 | }, 500);
72 | }
73 | })
74 | .setShowNoMoreEnabled(true)
75 | .into(recyclerView);
76 | }
77 |
78 | public void addItem(RecyclerView recyclerView) {
79 | if (mCount > 0 && mShowLoadFailedEnabled) {
80 | mShowLoadFailedEnabled = false;
81 | recyclerView.postDelayed(new Runnable() {
82 | @Override
83 | public void run() {
84 | mWrapper.setLoadFailed(true);
85 | }
86 | }, 800);
87 | } else {
88 | if (mCount > 30) {
89 | mWrapper.setLoadMoreEnabled(false);
90 | }
91 |
92 | final int positionStart = mCount;
93 | mCount += 5;
94 | notifyItemRangeInserted(positionStart, 5);
95 | }
96 | }
97 |
98 | static class AnotherHolder extends RecyclerView.ViewHolder {
99 | TextView mTextView;
100 |
101 | public AnotherHolder(View itemView) {
102 | super(itemView);
103 | mTextView = (TextView) itemView.findViewById(R.id.text);
104 | }
105 | }
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/nukc/sample/FlexboxActivity.java:
--------------------------------------------------------------------------------
1 | package com.github.nukc.sample;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 |
9 | import androidx.appcompat.app.AppCompatActivity;
10 | import androidx.recyclerview.widget.RecyclerView;
11 |
12 | import com.github.nukc.LoadMoreWrapper.LoadMoreWrapper;
13 | import com.google.android.flexbox.FlexDirection;
14 | import com.google.android.flexbox.FlexboxLayoutManager;
15 | import com.google.android.flexbox.JustifyContent;
16 |
17 | public class FlexboxActivity extends AppCompatActivity {
18 |
19 | private boolean mShowLoadFailedEnabled = true;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_flexbox);
25 |
26 | RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
27 | FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(this);
28 | layoutManager.setFlexDirection(FlexDirection.ROW);
29 | layoutManager.setJustifyContent(JustifyContent.FLEX_END);
30 | recyclerView.setLayoutManager(layoutManager);
31 |
32 | FlexAdapter flexAdapter = new FlexAdapter(20);
33 | // recyclerView.setAdapter(flexAdapter);
34 | LoadMoreWrapper.with(flexAdapter)
35 | // .setFooterView(R.layout.view_flex_loading)
36 | // .setNoMoreView(R.layout.view_flex_no_more)
37 | // .setLoadFailedView(R.layout.view_flex_retry)
38 | .setShowNoMoreEnabled(true)
39 | .setListener(enabled -> {
40 | int itemCount = flexAdapter.getItemCount();
41 | if (itemCount > 20 && mShowLoadFailedEnabled) {
42 | mShowLoadFailedEnabled = false;
43 | recyclerView.postDelayed(() -> enabled.setLoadFailed(true), 800);
44 | } else {
45 | //not enable load more
46 | if (itemCount >= 80) {
47 | enabled.setLoadMoreEnabled(false);
48 | }
49 |
50 | recyclerView.postDelayed(flexAdapter::addItem, 1200);
51 | }
52 | })
53 | .into(recyclerView);
54 | }
55 |
56 | private static class FlexAdapter extends RecyclerView.Adapter {
57 |
58 | private int mCount;
59 |
60 | public FlexAdapter(int count) {
61 | mCount = count;
62 | }
63 |
64 | @Override
65 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
66 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_flex, parent, false);
67 | return new SampleHolder(view);
68 | }
69 |
70 | @Override
71 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
72 | ((SampleHolder) holder).mTextView.setText(position + "");
73 | ViewGroup.LayoutParams lp = ((SampleHolder) holder).itemView.getLayoutParams();
74 | if (lp instanceof com.google.android.flexbox.FlexboxLayoutManager.LayoutParams) {
75 | ((FlexboxLayoutManager.LayoutParams) lp).setFlexGrow(1);
76 | }
77 | }
78 |
79 | @Override
80 | public int getItemCount() {
81 | return mCount;
82 | }
83 |
84 | public void addItem() {
85 | final int positionStart = mCount;
86 | mCount+= 5;
87 | notifyItemRangeInserted(positionStart, 5);
88 | }
89 |
90 | static class SampleHolder extends RecyclerView.ViewHolder {
91 | TextView mTextView;
92 |
93 | public SampleHolder(View itemView) {
94 | super(itemView);
95 | mTextView = (TextView) itemView.findViewById(R.id.text);
96 | }
97 | }
98 | }
99 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/github/nukc/sample/Issue9Activity.java:
--------------------------------------------------------------------------------
1 | package com.github.nukc.sample;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 |
9 | import androidx.appcompat.app.AppCompatActivity;
10 | import androidx.recyclerview.widget.LinearLayoutManager;
11 | import androidx.recyclerview.widget.RecyclerView;
12 | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
13 |
14 | import com.github.nukc.LoadMoreWrapper.LoadMoreAdapter;
15 | import com.github.nukc.LoadMoreWrapper.LoadMoreWrapper;
16 |
17 | public class Issue9Activity extends AppCompatActivity {
18 |
19 | private Issue9Adapter mIssue9Adapter;
20 |
21 | @Override
22 | protected void onCreate(Bundle savedInstanceState) {
23 | super.onCreate(savedInstanceState);
24 | setContentView(R.layout.activity_issue9);
25 |
26 | final SwipeRefreshLayout swipeRefreshLayout =
27 | (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
28 | final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
29 |
30 | swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
31 | @Override
32 | public void onRefresh() {
33 | mIssue9Adapter.clear();
34 | swipeRefreshLayout.setRefreshing(false);
35 | }
36 | });
37 | recyclerView.setLayoutManager(new LinearLayoutManager(this));
38 |
39 | mIssue9Adapter = new Issue9Adapter(5);
40 | recyclerView.setAdapter(mIssue9Adapter);
41 |
42 | LoadMoreWrapper.with(mIssue9Adapter)
43 | .setLoadMoreEnabled(true)
44 | .setListener(new LoadMoreAdapter.OnLoadMoreListener() {
45 | @Override
46 | public void onLoadMore(LoadMoreAdapter.Enabled enabled) {
47 | recyclerView.postDelayed(new Runnable() {
48 | @Override
49 | public void run() {
50 | mIssue9Adapter.addItem();
51 | }
52 | }, 1000);
53 | }
54 | })
55 | .into(recyclerView);
56 | }
57 |
58 | private static class Issue9Adapter extends RecyclerView.Adapter {
59 |
60 | private int mCount;
61 |
62 | public Issue9Adapter(int count) {
63 | mCount = count;
64 | }
65 |
66 | @Override
67 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
68 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_sample, parent, false);
69 | return new IssueHolder(view);
70 | }
71 |
72 | @Override
73 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
74 | ((IssueHolder) holder).mTextView.setText(position + "");
75 | }
76 |
77 | @Override
78 | public int getItemCount() {
79 | return mCount;
80 | }
81 |
82 | public void clear() {
83 | final int count = mCount;
84 | mCount = 0;
85 | notifyItemRangeRemoved(0, count);
86 |
87 | mCount = 15;
88 | notifyItemRangeInserted(0, mCount);
89 | }
90 |
91 | public void addItem() {
92 | final int positionStart = mCount;
93 | mCount+= 5;
94 | notifyItemRangeInserted(positionStart, 5);
95 | }
96 |
97 | static class IssueHolder extends RecyclerView.ViewHolder {
98 | TextView mTextView;
99 |
100 | public IssueHolder(View itemView) {
101 | super(itemView);
102 | mTextView = (TextView) itemView.findViewById(R.id.text);
103 | }
104 | }
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/nukc/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.github.nukc.sample;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.view.View;
6 |
7 | import androidx.appcompat.app.AppCompatActivity;
8 |
9 | public class MainActivity extends AppCompatActivity {
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_main);
15 | findViewById(R.id.btn_default).setOnClickListener(mOnClickListener);
16 | findViewById(R.id.btn_another).setOnClickListener(mOnClickListener);
17 | findViewById(R.id.btn_issues).setOnClickListener(mOnClickListener);
18 | findViewById(R.id.btn_not_show_footer_when_not_covered_screen).setOnClickListener(mOnClickListener);
19 | findViewById(R.id.btn_flex_box).setOnClickListener(mOnClickListener);
20 | }
21 |
22 | private View.OnClickListener mOnClickListener = new View.OnClickListener() {
23 | @Override
24 | public void onClick(View v) {
25 | Class> cls = null;
26 | switch (v.getId()) {
27 | case R.id.btn_default:
28 | cls = SampleActivity.class;
29 | break;
30 | case R.id.btn_another:
31 | cls = AnotherActivity.class;
32 | break;
33 | case R.id.btn_issues:
34 | cls = ScrollingActivity.class;
35 | break;
36 | case R.id.btn_not_show_footer_when_not_covered_screen:
37 | cls = NotShowFooterWhenNotCoveredScreenActivity.class;
38 | break;
39 | case R.id.btn_flex_box:
40 | cls = FlexboxActivity.class;
41 | break;
42 | }
43 | startActivity(new Intent(MainActivity.this, cls));
44 | }
45 | };
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/nukc/sample/NotShowFooterWhenNotCoveredScreenActivity.java:
--------------------------------------------------------------------------------
1 | package com.github.nukc.sample;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.TextView;
8 |
9 | import androidx.appcompat.app.AppCompatActivity;
10 | import androidx.recyclerview.widget.LinearLayoutManager;
11 | import androidx.recyclerview.widget.RecyclerView;
12 |
13 | import com.github.nukc.LoadMoreWrapper.LoadMoreAdapter;
14 | import com.github.nukc.LoadMoreWrapper.LoadMoreWrapper;
15 |
16 | public class NotShowFooterWhenNotCoveredScreenActivity extends AppCompatActivity {
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_another);
22 |
23 | RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
24 |
25 | recyclerView.setLayoutManager(new LinearLayoutManager(this));
26 | // recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
27 | recyclerView.setAdapter(new AnotherAdapter(0));
28 | }
29 |
30 | private static class AnotherAdapter extends RecyclerView.Adapter {
31 |
32 | private LoadMoreWrapper mWrapper;
33 | private int mCount;
34 | // use for demo, please ignore
35 | private boolean mShowLoadFailedEnabled = true;
36 |
37 | public AnotherAdapter(int count) {
38 | mCount = count;
39 | }
40 |
41 | @Override
42 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
43 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_sample, parent, false);
44 | return new AnotherHolder(view);
45 | }
46 |
47 | @Override
48 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
49 | ((AnotherHolder) holder).mTextView.setText(position + "");
50 | }
51 |
52 | @Override
53 | public int getItemCount() {
54 | return mCount;
55 | }
56 |
57 | @Override
58 | public void onAttachedToRecyclerView(final RecyclerView recyclerView) {
59 | super.onAttachedToRecyclerView(recyclerView);
60 |
61 | mWrapper = LoadMoreWrapper.with(this);
62 | mWrapper.setListener(
63 | new LoadMoreAdapter.OnLoadMoreListener() {
64 | @Override
65 | public void onLoadMore(LoadMoreAdapter.Enabled enabled) {
66 | recyclerView.postDelayed(new Runnable() {
67 | @Override
68 | public void run() {
69 | addItem(recyclerView);
70 | }
71 | }, 500);
72 | }
73 | })
74 | .setShowNoMoreEnabled(true)
75 | .setNotShowFooterWhenNotCoveredScreen(true)
76 | .into(recyclerView);
77 | }
78 |
79 | public void addItem(RecyclerView recyclerView) {
80 | if (mCount > 0 && mShowLoadFailedEnabled) {
81 | mShowLoadFailedEnabled = false;
82 | recyclerView.postDelayed(new Runnable() {
83 | @Override
84 | public void run() {
85 | mWrapper.setLoadFailed(true);
86 | }
87 | }, 800);
88 | } else {
89 | if (mCount > 30) {
90 | mWrapper.setLoadMoreEnabled(false);
91 | }
92 |
93 | final int positionStart = mCount;
94 | mCount += 5;
95 | notifyItemRangeInserted(positionStart, 5);
96 | }
97 | }
98 |
99 | static class AnotherHolder extends RecyclerView.ViewHolder {
100 | TextView mTextView;
101 |
102 | public AnotherHolder(View itemView) {
103 | super(itemView);
104 | mTextView = (TextView) itemView.findViewById(R.id.text);
105 | }
106 | }
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/nukc/sample/SampleActivity.java:
--------------------------------------------------------------------------------
1 | package com.github.nukc.sample;
2 |
3 | import android.os.Bundle;
4 |
5 | import androidx.appcompat.app.AppCompatActivity;
6 | import androidx.fragment.app.Fragment;
7 | import androidx.fragment.app.FragmentManager;
8 | import androidx.fragment.app.FragmentPagerAdapter;
9 | import androidx.viewpager.widget.ViewPager;
10 |
11 | import com.google.android.material.tabs.TabLayout;
12 |
13 | public class SampleActivity extends AppCompatActivity {
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_sample);
19 |
20 | TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
21 | ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
22 |
23 | String[] titles = getResources().getStringArray(R.array.tab_main);
24 | ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager(), titles);
25 | viewPager.setAdapter(viewPagerAdapter);
26 | viewPager.setOffscreenPageLimit(3);
27 | tabLayout.setupWithViewPager(viewPager);
28 | }
29 |
30 |
31 | private static class ViewPagerAdapter extends FragmentPagerAdapter {
32 |
33 | private String[] mTitles;
34 |
35 | public ViewPagerAdapter(FragmentManager fm, String[] titles) {
36 | super(fm);
37 | mTitles = titles;
38 | }
39 |
40 | @Override
41 | public Fragment getItem(int position) {
42 | int count;
43 | int managerMode = SampleFragment.MODE_LINEARLAYOUT;
44 | switch (position) {
45 | case 0:
46 | count = 2;
47 | break;
48 | case 1:
49 | count = 15;
50 | break;
51 | case 2:
52 | count = 20;
53 | managerMode = SampleFragment.MODE_GRIDLAYOUT;
54 | break;
55 | case 3:
56 | count = 30;
57 | managerMode = SampleFragment.MODE_STAGGEREDGRIDLAYOUT;
58 | break;
59 | default:
60 | throw new IndexOutOfBoundsException();
61 | }
62 |
63 | return SampleFragment.newInstance(count, managerMode);
64 | }
65 |
66 | @Override
67 | public int getCount() {
68 | return mTitles.length;
69 | }
70 |
71 | @Override
72 | public CharSequence getPageTitle(int position) {
73 | return mTitles[position];
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/nukc/sample/SampleFragment.java:
--------------------------------------------------------------------------------
1 | package com.github.nukc.sample;
2 |
3 |
4 | import android.os.Bundle;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.TextView;
9 |
10 | import androidx.annotation.IntDef;
11 | import androidx.annotation.Nullable;
12 | import androidx.fragment.app.Fragment;
13 | import androidx.recyclerview.widget.GridLayoutManager;
14 | import androidx.recyclerview.widget.LinearLayoutManager;
15 | import androidx.recyclerview.widget.RecyclerView;
16 | import androidx.recyclerview.widget.StaggeredGridLayoutManager;
17 |
18 | import com.github.nukc.LoadMoreWrapper.LoadMoreAdapter;
19 | import com.github.nukc.LoadMoreWrapper.LoadMoreWrapper;
20 |
21 | import java.lang.annotation.Retention;
22 | import java.lang.annotation.RetentionPolicy;
23 |
24 |
25 | /**
26 | * A simple {@link Fragment} subclass.
27 | */
28 | public class SampleFragment extends Fragment {
29 |
30 | private static final String TAG = SampleFragment.class.getSimpleName();
31 | private static final String ARGS_COUNT = "count";
32 | private static final String ARGS_MANAGER_MODE = "managerMode";
33 |
34 | public static final int MODE_LINEARLAYOUT = 1;
35 | public static final int MODE_GRIDLAYOUT = 2;
36 | public static final int MODE_STAGGEREDGRIDLAYOUT = 3;
37 |
38 | @IntDef({MODE_LINEARLAYOUT, MODE_GRIDLAYOUT, MODE_STAGGEREDGRIDLAYOUT})
39 | @Retention(RetentionPolicy.SOURCE)
40 | public @interface ManagerMode{}
41 |
42 | private SampleAdapter mSampleAdapter;
43 | // use for demo, please ignore
44 | private boolean mShowLoadFailedEnabled = true;
45 |
46 | public static SampleFragment newInstance(int count, @ManagerMode int managerMode) {
47 | Bundle args = new Bundle();
48 | args.putInt(ARGS_COUNT, count);
49 | args.putInt(ARGS_MANAGER_MODE, managerMode);
50 |
51 | SampleFragment fragment = new SampleFragment();
52 | fragment.setArguments(args);
53 | return fragment;
54 | }
55 |
56 | public SampleFragment() {
57 | // Required empty public constructor
58 | }
59 |
60 | @Override
61 | public void onCreate(@Nullable Bundle savedInstanceState) {
62 | super.onCreate(savedInstanceState);
63 |
64 | int count = getArguments().getInt(ARGS_COUNT, 0);
65 | mSampleAdapter = new SampleAdapter(count);
66 | }
67 |
68 | @Override
69 | public View onCreateView(final LayoutInflater inflater, ViewGroup container,
70 | Bundle savedInstanceState) {
71 | View view = inflater.inflate(R.layout.fragment_sample, container, false);
72 |
73 | final RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
74 | int managerMode = getArguments().getInt(ARGS_MANAGER_MODE);
75 |
76 | switch (managerMode) {
77 | case MODE_LINEARLAYOUT:
78 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(container.getContext());
79 | recyclerView.setLayoutManager(linearLayoutManager);
80 | break;
81 | case MODE_GRIDLAYOUT:
82 | GridLayoutManager gridLayoutManager = new GridLayoutManager(container.getContext(), 2);
83 | recyclerView.setLayoutManager(gridLayoutManager);
84 | break;
85 | case MODE_STAGGEREDGRIDLAYOUT:
86 | StaggeredGridLayoutManager staggeredGridLayoutManager =
87 | new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
88 | recyclerView.setLayoutManager(staggeredGridLayoutManager);
89 | break;
90 | default:
91 | throw new IllegalArgumentException();
92 | }
93 |
94 |
95 | // LoadMoreAdapter recyclerAdapter = new LoadMoreAdapter(mSampleAdapter);
96 | // recyclerView.setAdapter(recyclerAdapter);
97 | // recyclerAdapter.setLoadMoreListener(new LoadMoreAdapter.OnLoadMoreListener() {
98 | // @Override
99 | // public void onLoadMore(LoadMoreAdapter.Enabled enabled) {
100 | // //not enable load more
101 | // if (mSampleAdapter.getItemCount() >= 40) {
102 | // enabled.setLoadMoreEnabled(false);
103 | // }
104 | //
105 | // recyclerView.postDelayed(new Runnable() {
106 | // @Override
107 | // public void run() {
108 | // mSampleAdapter.addItem();
109 | // }
110 | // }, 1200);
111 | // }
112 | // });
113 | LoadMoreWrapper.with(mSampleAdapter)
114 | .setFooterView(managerMode == MODE_GRIDLAYOUT ? R.layout.view_footer : -1)
115 | // .setLoadMoreEnabled(false)
116 | .setShowNoMoreEnabled(true)
117 | .setListener(new LoadMoreAdapter.OnLoadMoreListener() {
118 | @Override
119 | public void onLoadMore(final LoadMoreAdapter.Enabled enabled) {
120 | int itemCount = mSampleAdapter.getItemCount();
121 | if (itemCount > 20 && mShowLoadFailedEnabled) {
122 | mShowLoadFailedEnabled = false;
123 | recyclerView.postDelayed(new Runnable() {
124 | @Override
125 | public void run() {
126 | enabled.setLoadFailed(true);
127 | }
128 | }, 800);
129 | } else {
130 | //not enable load more
131 | if (itemCount >= 40) {
132 | enabled.setLoadMoreEnabled(false);
133 | }
134 |
135 | recyclerView.postDelayed(new Runnable() {
136 | @Override
137 | public void run() {
138 | mSampleAdapter.addItem();
139 | }
140 | }, 1200);
141 | }
142 | }
143 | })
144 | .into(recyclerView);
145 |
146 | return view;
147 | }
148 |
149 | public static class SampleAdapter extends RecyclerView.Adapter {
150 |
151 | private int mCount;
152 |
153 | public SampleAdapter(int count) {
154 | mCount = count;
155 | }
156 |
157 | @Override
158 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
159 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_sample, parent, false);
160 | return new SampleHolder(view);
161 | }
162 |
163 | @Override
164 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
165 | ((SampleHolder) holder).mTextView.setText(position + "");
166 | }
167 |
168 | @Override
169 | public int getItemCount() {
170 | return mCount;
171 | }
172 |
173 | public void addItem() {
174 | final int positionStart = mCount;
175 | mCount+= 5;
176 | notifyItemRangeInserted(positionStart, 5);
177 | }
178 |
179 | static class SampleHolder extends RecyclerView.ViewHolder {
180 | TextView mTextView;
181 |
182 | public SampleHolder(View itemView) {
183 | super(itemView);
184 | mTextView = (TextView) itemView.findViewById(R.id.text);
185 | }
186 | }
187 | }
188 | }
189 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/nukc/sample/ScrollingActivity.java:
--------------------------------------------------------------------------------
1 | package com.github.nukc.sample;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 |
6 | import androidx.appcompat.app.AppCompatActivity;
7 | import androidx.appcompat.widget.Toolbar;
8 | import androidx.recyclerview.widget.LinearLayoutManager;
9 | import androidx.recyclerview.widget.RecyclerView;
10 |
11 | import com.github.nukc.LoadMoreWrapper.LoadMoreAdapter;
12 | import com.github.nukc.LoadMoreWrapper.LoadMoreWrapper;
13 | import com.google.android.material.floatingactionbutton.FloatingActionButton;
14 | import com.google.android.material.snackbar.Snackbar;
15 |
16 | public class ScrollingActivity extends AppCompatActivity {
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_scrolling);
22 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
23 | setSupportActionBar(toolbar);
24 |
25 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
26 | fab.setOnClickListener(new View.OnClickListener() {
27 | @Override
28 | public void onClick(View view) {
29 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
30 | .setAction("Action", null).show();
31 | }
32 | });
33 |
34 | final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
35 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
36 | recyclerView.setLayoutManager(linearLayoutManager);
37 | final SampleFragment.SampleAdapter sampleAdapter = new SampleFragment.SampleAdapter(15);
38 | LoadMoreWrapper.with(sampleAdapter)
39 | .setShowNoMoreEnabled(true)
40 | .setListener(new LoadMoreAdapter.OnLoadMoreListener() {
41 | @Override
42 | public void onLoadMore(final LoadMoreAdapter.Enabled enabled) {
43 | int itemCount = sampleAdapter.getItemCount();
44 | if (itemCount >= 40) {
45 | enabled.setLoadMoreEnabled(false);
46 | }
47 | recyclerView.postDelayed(new Runnable() {
48 | @Override
49 | public void run() {
50 | sampleAdapter.addItem();
51 | }
52 | }, 1200);
53 |
54 | }
55 | })
56 | .into(recyclerView);
57 | }
58 |
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_another.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_flexbox.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_issue9.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
17 |
18 |
25 |
26 |
33 |
34 |
41 |
42 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_sample.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_scrolling.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
25 |
26 |
32 |
33 |
34 |
35 |
36 |
41 |
42 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_sample.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_flex.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_sample.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_flex_loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_flex_no_more.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_flex_retry.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/view_footer.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nukc/LoadMoreWrapper/57d5ee597fa831cf9572c831c0c9d96ffbdb5723/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nukc/LoadMoreWrapper/57d5ee597fa831cf9572c831c0c9d96ffbdb5723/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nukc/LoadMoreWrapper/57d5ee597fa831cf9572c831c0c9d96ffbdb5723/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nukc/LoadMoreWrapper/57d5ee597fa831cf9572c831c0c9d96ffbdb5723/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nukc/LoadMoreWrapper/57d5ee597fa831cf9572c831c0c9d96ffbdb5723/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values-zh/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | LoadMoreWrapper
4 |
5 |
6 | - Default
7 | - Item not covered
8 | - GridLayoutManager
9 | - StaggeredGridLayoutManager
10 |
11 | 常见姿势
12 | 另一种姿势
13 | 用于重现 Issues
14 | RecyclerView item 未铺满屏幕的时候不显示 footerView
15 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 180dp
6 | 16dp
7 | 16dp
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | LoadMoreWrapper
3 |
4 |
5 | - Default
6 | - Item not covered
7 | - GridLayoutManager
8 | - StaggeredGridLayoutManager
9 |
10 |
11 | default_usage
12 | another_usage
13 | Issues
14 | Not Show Footer When Not Covered Screen
15 | ScrollingActivity
16 | Settings
17 | FlexboxLayoutManager
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/test/java/com/github/nukc/sample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.github.nukc.sample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/bintray.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.github.dcendents.android-maven'
2 | apply plugin: 'com.jfrog.bintray'
3 |
4 | def siteUrl = 'https://github.com/nukc/LoadMoreWrapper'
5 | def gitUrl = 'https://github.com/nukc/LoadMoreWrapper.git'
6 |
7 | group = "com.github.nukc"
8 | version = "1.9.1"
9 |
10 | install {
11 | repositories.mavenInstaller {
12 | // This generates POM.xml with proper parameters
13 | pom {
14 | project {
15 | packaging 'aar'
16 | // Add your description here
17 | name '在不改动 RecyclerView 原有 adapter 的情况下,使其拥有加载更多功能和自定义底部视图。'
18 | url siteUrl
19 | // Set your license
20 | licenses {
21 | license {
22 | name 'The Apache Software License, Version 2.0'
23 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
24 | }
25 | }
26 | developers {
27 | developer {
28 | id 'nukc' //填写的一些基本信息
29 | name 'c'
30 | email '353932158@qq.com'
31 | }
32 | }
33 | scm {
34 | connection gitUrl
35 | developerConnection gitUrl
36 | url siteUrl
37 | }
38 | }
39 | }
40 | }
41 | }
42 |
43 | task sourcesJar(type: Jar) {
44 | from android.sourceSets.main.java.srcDirs
45 | classifier = 'sources'
46 | }
47 |
48 | task javadoc(type: Javadoc) {
49 | source = android.sourceSets.main.java.srcDirs
50 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
51 | options.encoding = 'UTF-8'
52 | }
53 |
54 | task javadocJar(type: Jar, dependsOn: javadoc) {
55 | classifier = 'javadoc'
56 | from javadoc.destinationDir
57 | }
58 |
59 | artifacts {
60 | archives javadocJar
61 | archives sourcesJar
62 | }
63 |
64 | Properties properties = new Properties()
65 | boolean isHasFile = false
66 | File file = new File(project.rootDir.path + File.separator + "local.properties");
67 | if (file.exists()){
68 | isHasFile = true
69 | properties.load(file.newDataInputStream())
70 | }
71 | bintray {
72 | user = isHasFile ? properties.getProperty("bintray.user") : System.getenv("bintray.user")
73 | key = isHasFile ? properties.getProperty("bintray.apikey") : System.getenv("bintray.apikey")
74 | configurations = ['archives']
75 | pkg {
76 | repo = "maven"
77 | name = "LoadMoreWrapper"
78 | websiteUrl = siteUrl
79 | vcsUrl = gitUrl
80 | licenses = ["Apache-2.0"]
81 | publish = true
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | google()
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:4.2.1'
10 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
11 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | google()
20 | jcenter()
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 | android.useAndroidX=true
20 | android.enableJetifier=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nukc/LoadMoreWrapper/57d5ee597fa831cf9572c831c0c9d96ffbdb5723/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/images/grid_custom.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nukc/LoadMoreWrapper/57d5ee597fa831cf9572c831c0c9d96ffbdb5723/images/grid_custom.gif
--------------------------------------------------------------------------------
/images/item.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nukc/LoadMoreWrapper/57d5ee597fa831cf9572c831c0c9d96ffbdb5723/images/item.gif
--------------------------------------------------------------------------------
/images/staggeredgrid.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/nukc/LoadMoreWrapper/57d5ee597fa831cf9572c831c0c9d96ffbdb5723/images/staggeredgrid.gif
--------------------------------------------------------------------------------
/loadmorewrapper/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/loadmorewrapper/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 30
5 | buildToolsVersion '30.0.3'
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 30
10 | versionCode 30
11 | versionName "1.9.1"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 |
21 | lintOptions {
22 | checkReleaseBuilds false
23 | abortOnError false
24 | }
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 | testImplementation 'junit:junit:4.13.2'
30 | implementation "androidx.appcompat:appcompat:1.3.0"
31 | implementation "androidx.recyclerview:recyclerview:1.1.0"
32 | androidTestImplementation 'androidx.test:runner:1.3.0'
33 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
34 | }
35 |
36 | apply from: '../bintray.gradle'
--------------------------------------------------------------------------------
/loadmorewrapper/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/C/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/loadmorewrapper/src/androidTest/java/com/github/nukc/LoadMoreWrapper/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.github.nukc.LoadMoreWrapper;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.assertEquals;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.github.nukc.LoadMoreWrapper.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/loadmorewrapper/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/loadmorewrapper/src/main/java/com/github/nukc/LoadMoreWrapper/LoadMoreAdapter.java:
--------------------------------------------------------------------------------
1 | package com.github.nukc.LoadMoreWrapper;
2 |
3 | import android.view.View;
4 | import android.view.ViewGroup;
5 |
6 | import androidx.annotation.LayoutRes;
7 | import androidx.annotation.NonNull;
8 | import androidx.recyclerview.widget.GridLayoutManager;
9 | import androidx.recyclerview.widget.LinearLayoutManager;
10 | import androidx.recyclerview.widget.RecyclerView;
11 | import androidx.recyclerview.widget.StaggeredGridLayoutManager;
12 |
13 | import java.util.List;
14 |
15 | /**
16 | * 在不改动 RecyclerView 原有 adapter 的情况下,使其拥有加载更多功能和自定义底部视图。
17 | *
18 | * @author Nukc
19 | */
20 | public class LoadMoreAdapter extends RecyclerView.Adapter {
21 |
22 | private static final String TAG = LoadMoreAdapter.class.getSimpleName();
23 | private static final byte TYPE_FOOTER = -2;
24 | private static final byte TYPE_NO_MORE = -3;
25 | private static final byte TYPE_LOAD_FAILED = -4;
26 | private static final byte TYPE_EMPTY_VIEW = -5;
27 |
28 | private RecyclerView.Adapter mAdapter;
29 | private View mFooterView;
30 | private int mFooterResId = View.NO_ID;
31 | private View mNoMoreView;
32 | private int mNoMoreResId = View.NO_ID;
33 | private View mLoadFailedView;
34 | private int mLoadFailedResId = View.NO_ID;
35 |
36 | private RecyclerView mRecyclerView;
37 | private OnLoadMoreListener mOnLoadMoreListener;
38 |
39 | private Enabled mEnabled;
40 | private boolean mIsLoading;
41 | private boolean mShouldRemove;
42 | private boolean mShowNoMoreEnabled;
43 | private boolean mIsLoadFailed;
44 | private boolean mNotShowFooterWhenNotCoveredScreen = false;
45 |
46 | public LoadMoreAdapter(@NonNull RecyclerView.Adapter adapter) {
47 | registerAdapter(adapter);
48 | }
49 |
50 | public LoadMoreAdapter(@NonNull RecyclerView.Adapter adapter, View footerView) {
51 | registerAdapter(adapter);
52 | mFooterView = footerView;
53 | }
54 |
55 | public LoadMoreAdapter(@NonNull RecyclerView.Adapter adapter, @LayoutRes int resId) {
56 | registerAdapter(adapter);
57 | mFooterResId = resId;
58 | }
59 |
60 | private void registerAdapter(RecyclerView.Adapter adapter) {
61 | if (adapter == null) {
62 | throw new NullPointerException("adapter can not be null!");
63 | }
64 |
65 | mAdapter = adapter;
66 | mAdapter.registerAdapterDataObserver(mObserver);
67 | mEnabled = new Enabled(mOnEnabledListener);
68 | }
69 |
70 | public RecyclerView.Adapter getOriginalAdapter() {
71 | return mAdapter;
72 | }
73 |
74 | @Override
75 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
76 | if (viewType == TYPE_FOOTER) {
77 | if (mFooterResId != View.NO_ID) {
78 | mFooterView = LoadMoreHelper.inflate(parent, mFooterResId);
79 | }
80 | if (mFooterView != null) {
81 | return new FooterHolder(mFooterView);
82 | }
83 | View view = LoadMoreHelper.inflate(parent, R.layout.base_footer);
84 | return new FooterHolder(view);
85 | } else if (viewType == TYPE_NO_MORE) {
86 | if (mNoMoreResId != View.NO_ID) {
87 | mNoMoreView = LoadMoreHelper.inflate(parent, mNoMoreResId);
88 | }
89 | if (mNoMoreView != null) {
90 | return new NoMoreHolder(mNoMoreView);
91 | }
92 | View view = LoadMoreHelper.inflate(parent, R.layout.base_no_more);
93 | return new NoMoreHolder(view);
94 | } else if (viewType == TYPE_LOAD_FAILED) {
95 | if (mLoadFailedResId != View.NO_ID) {
96 | mLoadFailedView = LoadMoreHelper.inflate(parent, mLoadFailedResId);
97 | }
98 | View view = mLoadFailedView;
99 | if (view == null) {
100 | view = LoadMoreHelper.inflate(parent, R.layout.base_load_failed);
101 | }
102 | return new LoadFailedHolder(view, mEnabled, mOnLoadMoreListener);
103 | } else if (viewType == TYPE_EMPTY_VIEW) {
104 | return new EmptyHolder(new View(parent.getContext()));
105 | }
106 |
107 | return mAdapter.onCreateViewHolder(parent, viewType);
108 | }
109 |
110 | @Override
111 | public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
112 | }
113 |
114 | @SuppressWarnings("unchecked")
115 | @Override
116 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position, List