Don't write a ViewPager Adapter! Hook up your ViewPager to your data model using Android Data Binding Framework. With Kotlin support!

Overview

BuddyBuild Release android min api size Android Arsenal MaterialUp

LastPagerAdapter Hero Banner

Don't write a ViewPager Adapter! Hook up your ViewPager to your data model using Android Data Binding Framework.

Show some ❤️

GitHub stars GitHub forks GitHub watchers GitHub followers
Twitter Follow

💋 Sweet and short library

Use the language of your choice.

// Java
new LastPagerAdapter(BR.model)
    .add(R.layout.layout_one, "First Layout Title", modelObject1)
    .add(R.layout.layout_two, "Second Layout Title", modelObject2)
    .into(viewPager);
// Kotlin
viewpager.lastPagerAdapter(BR.model) {
    add(R.layout.layout_one, "First Layout Title", modelObject1)
    add(R.layout.layout_two, "Second Layout Title", modelObject2)
}

Download the demo apk to play around with the LastPagerAdapter demo app.

Demo GIF

Or try the limited 1 min live app demo at Appetize.

👑 Features

LastPagerAdapter
🚝 Within a few lines easily hook up your data models with your ViewPager
🔗 Based on Android Data Binding
Written in Kotlin. A concise language you should definitely check out, if you haven't already.
✏️ No need to write any PagerAdapter (FragmentPagerAdapter, etc.)
Doesn't rely on Fragments. It has complex lifecycle and best be avoided. More reasons why
No need to modify your existing model classes
📃 Supports different View layouts and hooking it up with ViewPager is a breeze
👌 Super easy API. Concise syntax. Less Bugs for you to worry about. Boosted Productivity.
📝 Helpful error stacktraces
🚀 Very fast — no reflection
📱 Minimum Android SDK: Gingerbread API 9

🏛️ Build

Add this in your root build.gradle at the end of repositories:

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

Step 2. Add the dependency in your module's gradle file

// apply plugin: 'kotlin-kapt'  // this line only for Kotlin projects

android {
    ...
    dataBinding.enabled true
}

dependencies {
    compile 'com.github.rakshakhegde:LastPagerAdapter:1.2'
    // kapt 'com.android.databinding:compiler:GRADLE_PLUGIN_VERSION' // this line only for Kotlin projects
}

🤔 How to use

<layout> as root for your View layouts is a must:

<layout xmlns:android="http://schemas.android.com/apk/res/android" >

    <data>
        <variable name="model" type="io.github.rakshakhegde.lastpageradaptersample.TextModel" />
    </data>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@{model.text}" />

</layout>

It is important for all the model types to have the same variable name, in this case "model". This name is passed to the adapter constructor as BR.variableName, in this case BR.model:

// Java
new LastPagerAdapter(BR.model)
    .add(R.layout.text_layout, "Optional Layout Title", optionalTextModelObject, optionalWidth)
    .into(viewPager); // don't forget this line
// Kotlin
viewpager.lastPagerAdapter(BR.model) {
    add(R.layout.text_layout, "Optional Layout Title", optionalTextModelObject, optionalWidth)
}

Except the layoutId, everything else is optional

And that is how easy it is. Download the demo apk to play around with the LastPagerAdapter demo app.

👎 Known Issues

  • Customizability in terms of having independent names for models in XML is not present
  • API seems a bit verbose for large number of similar views. Could implement a version which accepts arrays. Anyways, a loop could be used there.
  • Callbacks for creation or destruction of Views is not implemented (I didn't implement them because personally my use case didn't require it). Feel free to Pull Request this one.

My Recommended Repos

Acknowledgements

Library and API Structure inspired from LastAdapter

Library Concept inspired from SmartTabLayout's Utils

Logo and Hero Banner created by Govindaraj Karthikeyan. Check him out on Bēhance

Core Logo created using Roman Nurik's awesome Android Asset Studio 🔥 🔥 🔥

🤸‍♂️ Author

Catch me at @rakshakhegde

Email | Twitter | Facebook | Google+ | Linked.in

🍴 Contribute

Please file bugs, suggest improvements and feel free to contribute

💋 Keep It Simple Silly

Changelog

  • v1.2
    • Documentation Update
    • Upgraded internal working
    • Updated library versions
    • Fix AndroidManifest

📝 License

Copyright 2017 Rakshak Hegde

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.
You might also like...
Android ViewPager template with cool animation.
Android ViewPager template with cool animation.

glazy-viewpager ViewPager template with cool animation. Preview Dependencies compile 'com.android.support:palette-v7:25.2.0' Usage Refer the implement

Android Parallax-ViewPager

ParallaxViewPager Demo Usage com.github.ybq.parallaxviewpager.ParallaxViewPager android:id="@+id/viewpager" android:layout_width="ma

Endless full-screen card ViewPager inspired by apple iBook for Android
Endless full-screen card ViewPager inspired by apple iBook for Android

FullScreenCardViewPager for Android Endless full-screen card ViewPager inspired by apple iBook for Android. ✅ We are open to any new feature request,

A custom ViewPager title strip which gives continuous feedback to the user when scrolling
A custom ViewPager title strip which gives continuous feedback to the user when scrolling

SmartTabLayout A custom ViewPager title strip which gives continuous feedback to the user when scrolling. This library has been added some features an

A Material Design ViewPager easy to use library
A Material Design ViewPager easy to use library

MaterialViewPager Material Design ViewPager easy to use library Sample And have a look on a sample Youtube Video : Youtube Link Download In your modul

A different beautiful ViewPager, with quick swipe controls
A different beautiful ViewPager, with quick swipe controls

HollyViewPager Usage Add a HollyViewPager in your layout com.github.florent37.hollyviewpager.HollyViewPager android:id="@+id/hollyViewPager"

An interactive indicator to navigate between the different pages of a ViewPager
An interactive indicator to navigate between the different pages of a ViewPager

Android PagerSlidingTabStrip (default Material Design) This library is not maintained anymore and there will be no further releases. For most of the c

Combine ViewPager and Animations to provide a simple way to create applications' guide pages.
Combine ViewPager and Animations to provide a simple way to create applications' guide pages.

WoWoViewPager WoWoViewPager combines ViewPager and Animations to provide a simple way to create applications' guide pages. When users are dragging WoW

ViewPager that slides vertically.
ViewPager that slides vertically.

ExpandablePager Layout that contains a ViewPager and can slide vertically between 2 states (expanded and collapsed). #Requirements Android 4.0+ (Ice C

Comments
  • gradle build fails, Manifest merger failed

    gradle build fails, Manifest merger failed

    Error:Execution failed for task ':app:processDebugManifest'.
    > Manifest merger failed : Attribute application@supportsRtl value=(false) from AndroidManifest.xml:11:9-36
      	is also present at [com.github.rakshakhegde:LastPagerAdapter:1.1.0] AndroidManifest.xml:14:9-35 value=(true).
      	Suggestion: add 'tools:replace="android:supportsRtl"' to <application> element at AndroidManifest.xml:5:5-70:19 to override.
    

    tools:replace="android:supportsRtl should not be necessary

    opened by artworkad 3
  • Add a Gitter chat badge to README.MD

    Add a Gitter chat badge to README.MD

    rakshakhegde/LastPagerAdapter now has a Chat Room on Gitter

    @rakshakhegde has just created a chat room. You can visit it here: https://gitter.im/LastPagerAdapter/Lobby.

    This pull-request adds this badge to your README.MD:

    Gitter

    If my aim is a little off, please let me know.

    Happy chatting.

    PS: Click here if you would prefer not to receive automatic pull-requests from Gitter in future.

    opened by gitter-badger 0
Releases(1.2)
  • 1.2(May 3, 2017)

    • Documentation Update
    • Upgraded internal working
    • Updated library versions
    • Fix AndroidManifest, thanks to @ArtworkAD

    See build details and artifacts at buddybuild: https://dashboard.buddybuild.com/apps/5895d7a1e0b5980100192b42/build/590a247daf4a8c0001f248e6

    Source code(tar.gz)
    Source code(zip)
    release.apk(833.06 KB)
  • 1.1.0(Feb 5, 2017)

    See build details and artifacts at buddybuild: https://dashboard.buddybuild.com/apps/5895d7a1e0b5980100192b42/build/5896edde544a860100bfd631

    • View Source file from Android Studio
    • Proguard Support. You don't have to do anything. Library will take care of applying the correct rules.
    Source code(tar.gz)
    Source code(zip)
  • v0.1-alpha(Feb 2, 2017)

Owner
Rakshak R.Hegde
Android Dev in Bengaluru My awesome app: https://goo.gl/XWur09
Rakshak R.Hegde
Pixplicity 915 Nov 8, 2022
Persons cards list viewpager - Persons cards list viewpager using kotlin

persons_cards_list_viewpager Дизайн и условие взяты из https://github.com/appKOD

Mironov Ury 1 Mar 1, 2022
UltraViewPager is an extension for ViewPager to provide multiple features in a single ViewPager.

UltraViewPager 中文文档 ProjectUltraViewPager is a ViewPager extension that encapsulates multiple features, mainly to provide a unified solution for multi

Alibaba 5k Dec 20, 2022
Paging indicator widgets compatible with the ViewPager from the Android Support Library and ActionBarSherlock.

Android ViewPagerIndicator Paging indicator widgets that are compatible with the ViewPager from the Android Support Library to improve discoverability

Jake Wharton 10.2k Jan 3, 2023
Paging indicator widgets compatible with the ViewPager from the Android Support Library and ActionBarSherlock.

Android ViewPagerIndicator Paging indicator widgets that are compatible with the ViewPager from the Android Support Library to improve discoverability

Jake Wharton 10.2k Jan 5, 2023
Library containing common animations needed for transforming ViewPager scrolling for Android v13+.

ViewPagerTransforms Library containing common animations needed for transforming ViewPager scrolling on Android v13+. This library is a rewrite of the

Ian Thomas 2.5k Dec 31, 2022
An android ViewPager extension allowing infinite scrolling

NO LONGER MAINTAINED LoopingViewPager An android ViewPager extension allowing infinite scrolling. You can use it with "standart" PagerAdapter (inflati

Leszek Mzyk 992 Nov 10, 2022
Augment Android's ViewPager with wrap-around functionality.

Infinite View Pager Augment Android's ViewPager with wrap-around functionality. Original StackOverflow question: http://stackoverflow.com/questions/75

Antony Tran 692 Dec 14, 2022
[Development stopped in 2014. Unfinished and not stable - not recommended to use.] An easy-to-use ViewPager subclass with parallax background effect for Android apps.

Development stopped in 2014 Not developed since 2014. Unfinished and not stable - not recommended to use. ParallaxViewPager An easy-to-use ViewPager s

Andras Kindler 437 Dec 29, 2022
Android - A ViewPager page indicator that displays the current page number and (optionally) the page count

NumericPageIndicator A ViewPager page indicator that displays the current page number and (optionally) the page count. It can also display buttons to

Manuel Peinado Gallego 253 Nov 16, 2022