├── .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 | [![Build Status](https://travis-ci.org/nukc/LoadMoreWrapper.svg?branch=master)](https://travis-ci.org/nukc/LoadMoreWrapper) 4 | [![Download](https://api.bintray.com/packages/nukc/maven/LoadMoreWrapper/images/download.svg) ](https://bintray.com/nukc/maven/LoadMoreWrapper/_latestVersion) 5 | [![](https://jitpack.io/v/nukc/LoadMoreWrapper.svg)](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 |