Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.canaanai:mugen:v1.0.5'
}
dependencies {
implementation("com.github.canaanai:mugen:v1.0.5")
}
<dependency>
<groupId>com.github.canaanai</groupId>
<artifactId>mugen</artifactId>
<version>v1.0.5</version>
</dependency>
libraryDependencies += "com.github.canaanai" % "mugen" % "v1.0.5"
:dependencies [[com.github.canaanai/mugen "v1.0.5"]]
mugen is a microlibrary for implementing infinite scroll on Android.
AbsListView
and RecyclerView
! Which means it's one single library to enable infinite scroll for ListView
, GridView
and RecyclerView
instances. //mCollectionView can be a ListView, GridView, RecyclerView or any instance of AbsListView!
BaseAttacher attacher = Mugen.with(mCollectionView, new MugenCallbacks() {
@Override
public void onLoadMore() {
/* Will be triggered when the next page has to be loaded.
*
* Do your load operation here.
* Note: this is NOT asynchronous!
*/
}
@Override
public boolean isLoading() {
/* Return true if a load operation is ongoing. This will
* be used as an optimization to prevent further triggers
* if the user scrolls up and scrolls back down before
* the load operation finished.
*
* If there is no load operation ongoing, return false
*/
return isLoading;
}
@Override
public boolean hasLoadedAllItems() {
/*
* If every item has been loaded from the data store, i.e., no more items are
* left to fetched, you can start returning true here to prevent any more
* triggers of the load more method as a form of optimization.
*
* This is useful when say, the data is being fetched from the network
*/
return false;
}
}).start();
/* Use this to dynamically turn infinite scroll on or off. It is enabled by default */
attacher.setLoadMoreEnabled(true);
/* Use this to change when the onLoadMore() function is called.
* By default, it is called when the scroll reaches 2 items from the bottom */
attacher.setLoadMoreOffset(4);
/*
* mugen uses an internal OnScrollListener to detect and trigger load events.
* If you need to listen to scroll events yourself, you can set this and
* mugen will automatically forward all scroll events to the listener.
*/
attacher.setOnScrollListener(listener);
mugen will only start working AFTER there are enough items in the list to make it scrollable. Ensure that you load at least enough data first so that the list becomes scrollable.
There are two ways you can install mugen.
Add the line compile 'com.vinaysshenoy:mugen:1.0.2'
to your dependencies
section in your build.gradle
script
library
folder into your project root.include ':library'
to your settings.gradle
filecompile project(':library')
to the build.gradle
file in your main project.Copyright 2014 Vinay S Shenoy
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.