LastPagerAdapter


Source link: https://github.com/rakshakhegde/LastPagerAdapter

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

Show some ❤?


💋 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.

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. 

Resources

A library that implements the persistent search bar seen on apps such as Google Now, Google Maps and Google Play.

DesignOverlay is an android app which displays a design image with grid lines to facilitate the tedious layout process. The grid is especially useful to align to baseline grids as described in Android Design Guidelines.

Coordinator is a Java library that is used to coordinate various asynchronous actions. Usually we found cases that you need to check if other thread is completed to execute an action, coordinator solves this problem without using flags.

Prime is an Android image loading library.

Simple, pretty and powerful logger for Android.

Load custom fonts easily just via layout parameters or styles. Uses static Typeface objects, load once - memory efficient. No more textView.setTypeface() calls!

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes