Giter Site home page Giter Site logo

pwittchen / infinitescroll Goto Github PK

View Code? Open in Web Editor NEW
189.0 6.0 26.0 1.79 MB

Infinite Scroll (Endless Scrolling) for RecyclerView in Android

License: Apache License 2.0

Java 98.05% Shell 1.95%
android recyclerview endless-scroll infinite-scroll infinite endless scroll scrolling

infinitescroll's Introduction

InfiniteScroll Android Arsenal Build Status Maven Central

Infinite Scroll (Endless Scrolling) for RecyclerView in Android

JavaDoc is available at: http://pwittchen.github.io/InfiniteScroll/

Contents

Motivation

For a long time I couldn't find the right implementation of the infinite scroll AKA endless scroll for Android. A few solutions I've found weren't production ready, weren't working correctly or had too many features. I wanted to have small, easy and flexible solution to implement infinite scroll for Android, which works with RecyclerView from the newest Android API. That's why this project was created.

Examples

Sample app can be found in app directory.

Below, you can see an animation presenting, how sample application works.

Moreover, you can see examplary usage of this library in SearchTwitter app.

Demo

Usage

Create necessary fields in your Activity:

public RecyclerView recyclerView;
private LinearLayoutManager layoutManager;

Create new InfiniteScrollListener:

private InfiniteScrollListener createInfiniteScrollListener() {
  return new InfiniteScrollListener(maxItemsPerRequest, layoutManager) {
    @Override public void onScrolledToEnd(final int firstVisibleItemPosition) {
      // load your items here
      // logic of loading items will be different depending on your specific use case
      
      // when new items are loaded, combine old and new items, pass them to your adapter
      // and call refreshView(...) method from InfiniteScrollListener class to refresh RecyclerView
      refreshView(recyclerView, new MyAdapter(items), firstVisibleItemPosition);
    }
  }
}

Initialize RecyclerView and LinearLayoutManager in your Activity:

@Override protected void onCreate(Bundle savedInstanceState) {
  recyclerView = (RecyclerView) findViewById(R.id.recycler_view);

  layoutManager = new LinearLayoutManager(this);
  recyclerView.setHasFixedSize(true);
  recyclerView.setLayoutManager(layoutManager);
  
  // set your custom adapter
  recyclerView.setAdapter(new MyAdapter(items));
  
  // add InfiniteScrollListener as OnScrollListener
  recyclerView.addOnScrollListener(createInfiniteScrollListener());
}

If you want to display loading progress, you should add additional view for it, show it while loading starts and hide it when loading is finished. Check exemplary app in this repository to see concrete solution.

That's it!

Download

Latest version: Maven Central

replace x.y.z with the latest version

You can depend on the library through Maven:

<dependency>
    <groupId>com.github.pwittchen</groupId>
    <artifactId>infinitescroll</artifactId>
    <version>x.y.z</version>
</dependency>

or through Gradle:

dependencies {
  compile 'com.github.pwittchen:infinitescroll:x.y.z'
}

Tests

To execute unit tests run:

./gradlew test

Code style

Code style used in the project is called SquareAndroid from Java Code Styles repository by Square available at: https://github.com/square/java-code-styles.

Static Code Analysis

To run Static Code Analysis, type:

./gradlew check

Reports from analysis are generated in library/build/reports/ directory.

Who is using this library?

Are you using this library in your app and want to be listed here? Send me a Pull Request or an e-mail to [email protected]

License

Copyright 2016 Piotr Wittchen

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.

infinitescroll's People

Contributors

dependabot-preview[bot] avatar dotkebi avatar pwittchen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

infinitescroll's Issues

Add an example with loading items after click

Expected behaviour:

  1. User scrolls to the end of the list
  2. "Load more" option appears
  3. After clicking on "Load more" option, this option is hidden, more items are loaded and user can scroll them
  4. Repeat again from the step 1. until user reaches end of all items

Release 0.0.2

Release notes:

  • applied androidx.appcompat thanks to @dotkebi
  • applied com.google.android.material thanks to @dotkebi
  • bumped version of mockito-core and truth
  • applied nexus-staging-plugin for gradle
  • re-organized gradle build config

Things to do:

  • bump library version
  • upload Archives to Maven Central Repository
  • close and release artifact on Nexus (done experimentally by nexus staging plugin this time)
  • update gh-pages with JavaDoc
  • update CHANGELOG.md after Maven Sync
  • update Download section in README.md after Maven Sync
  • create GitHub release

Error adding dependency in gradle

I experiencing the following error:

Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to element at AndroidManifest.xml:9:5-97:19 to override.

My gradle:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.10'

    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:customtabs:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'

    // Testes
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    // Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.google.code.gson:gson:2.8.4'
    implementation 'com.github.mrmike:Ok2Curl:0.4.5'

    // Fabric
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
        transitive = true
    }

    // Architecture components
    implementation 'android.arch.lifecycle:extensions:1.1.1'
    implementation 'android.arch.paging:runtime:1.0.1'
    implementation 'android.arch.lifecycle:livedata:1.1.1'
    kapt 'android.arch.lifecycle:common-java8:1.1.1'
    kapt 'com.android.databinding:compiler:3.1.4'

    // AWS
    implementation 'com.amazonaws:aws-android-sdk-cognitoidentityprovider:2.8.4'
    implementation 'com.amazonaws:aws-android-sdk-s3:2.8.4'
    implementation 'com.amazonaws:aws-android-sdk-core:2.8.4'
    implementation 'com.amazonaws:aws-android-sdk-ddb:2.8.4'
//    implementation 'com.amazonaws:aws-android-sdk-ddb-document:2.8.4'

    // Others
    implementation 'com.github.sharish:CreditCardView:v1.0.4'
    implementation 'com.daimajia.swipelayout:library:1.2.0@aar'
    implementation 'pl.bclogic:pulsator4droid:1.0.3'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'me.relex:circleindicator:1.2.1@aar'
    implementation 'org.jetbrains.anko:anko:0.10.4'
    implementation 'com.github.santalu:mask-edittext:1.0.3'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.github.pwittchen:infinitescroll:0.0.2'

    implementation project(':room')
}

release 0.0.3

Release notes:

  • updated project dependencies
  • updated build configuration

Things to do:

  • bump library version
  • upload Archives to Maven Central Repository
  • close and release artifact on Nexus
  • update gh-pages with JavaDoc
  • update Download section in README.md after Maven Sync
  • update CHANGELOG.md after Maven Sync
  • create GitHub release

does not work with swipe to refresh layout

it works great on single use. but when i scroll down and go up again to refresh the contents then recyclerview starts from random index instead of starting from 0th index. while refreshing i am calling the same methods again these are
items = createItems();
initRecyclerView();

Prepare library for release

Things to do:

  • create gradle.properties file for main directory with appropriate content
  • create gradle.properties file for library directory with appropriate content
  • add gradle.properties file to main directory
  • add gradle.properties file to library directory
  • add maven_push.gradle script to main directory and
  • add reference to maven_push.gradle file in library/build.gradle file

Not loading items on Actual device

I have a serious issue, infinite loading is working when I am running on Android Emulator(Nexus 6) but on actual device it's not working.(I have tried on MI Note 3 and Moto G).

I am not even getting any error or exception.

Please suggest.

Tell me if any additional information is needed.

A problem with scrolling

The RecyclerView is keep repeating the same four items infinitely when scrolling and fetching them from server.

Release version 0.0.1

Initial release notes:
First release of the library

Things to do:

  • set library version to 0.0.1
  • upload Archives to Maven Central Repository
  • close and release artifact on Nexus
  • create gh-pages with JavaDoc
  • create CHANGELOG.md and add there release notes after Maven Sync
  • update Download section in README.md after Maven Sync
  • create first GitHub release

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.