Skip to content

mahdi-khosravi-sh/infinitepager

Repository files navigation

InfinitePager

Peek 2021-09-28 21-50

GitHub repo size GitHub language count GitHub top language GitHub last commit

A simple android infinite view pager

Table of Contents
  1. Getting Started
  2. Compatibility
  3. Stats
  4. Contributing
  5. License
  6. Contact

Getting Started

Download

Download the latest AAR from jitpack via Gradle:

  • Gradle

    Project build.gradle

    allprojects {
      repositories {
        ...
        maven { url 'https://jitpack.io' }
      }
    }

    app module build.gradle

    dependencies {
      implementation 'com.github.mahdidev78:infinitepager:TAG'
    }
  • Maven

    Add the JitPack repository to your build file

    <repositories>
      <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
      </repository>
    </repositories>

    Add the dependency

    <dependency>
      <groupId>com.github.mahdidev78</groupId>
      <artifactId>infinitepager</artifactId>
      <version>Tag</version>
    </dependency>

Usage

Step 1

Add the ScrollToTop to your layout :

<com.mahdikh.vision.infinitepager.widget.InfinitePager
  android:id="@+id/infinitePager"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:clipToPadding="false"
  android:paddingStart="40dp"
  android:paddingEnd="40dp"
  app:currentItem="first"/>

Step 2

Setup your code :

  • Kotlin
    val pager = findViewById<InfinitePager>(R.id.infinitePager)
    pager.adapter = adapter // extends InfiniteAdapter 
  • Java
    InfinitePager pager = findViewById(R.id.infinitePager);
    pager.setAdapter(adapter); // extends InfiniteAdapter

Advanced Step 3

  • kotlin
    val callback: Callback = object : Callback {
      override fun onPageScrolled(
          position: Int,
          positionOffset: Float,
          positionOffsetPixels: Int
      ) {
      }
    
      override fun onPageSelected(position: Int) {
    
      }
      override fun onPageScrollStateChanged(state: Int) {
    
      }
    }
    pager.registerCallback(callback)  // for register callback
    pager.unregisterCallback(callback)  // for unregister callback
    pager.unregisterCallbacks()  // unregister all calbacks
  • Java
    Callback callback = new Callback() {
      @Override
      public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    
      }
    
      @Override
      public void onPageSelected(int position) {
    
      }
    
      @Override
      public void onPageScrollStateChanged(int state) {
    
      }
    };
    pager.registerCallback(callback); // for register callback
    pager.unregisterCallback(callback); // for unregister callback    
    pager.unregisterCallbacks();  // unregister all calbacks

Attributes

attribute Description Options(examples)
currentItem set the current item first, center, last , 0, 1 , etc

Compatibility

  • Android KitKat 4.4+

Stats

Contributors Forks Stargazers Issues Apache License

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Copyright 2021, mahdidev78

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.

Contact

Mahdi Khosravi - mahdi.khosravi.dev78@gmail.com

Project Link: https://github.com/mahdidev78/infinitepager