EasyHeaderFooterAdapter


Source link: https://github.com/rubengees/EasyHeaderFooterAdapter

easy-header-footer-adapter

Add a header and/or footer to your RecyclerView - the easy way.

You can download the latest sample app here.

Features

  • Completely hassle-free. You don't have to change your existing implementation.
  • Support for LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager.
  • LayoutParams of your Views are honoured.
  • The SpanSizeLookup of your GridLayoutManager continues to work without adjustments.
  • Support for stable ids.

Include in your Project

Add this to your root build.gradle (usually in the root of your project):

repositories {

  maven {
 url "https://jitpack.io" 
}
 
}

And this to your module build.gradle (usually in the app directory):

dependencies {

  compile 'com.github.rubengees:easy-header-footer-adapter:3.0.0@aar' 
}

If that doesn't work, look if there is a new version and the Readme was not updated yet.

Usage

There is almost zero configuration if you already have an adapter.
You wrap your adapter in the EasyHeaderFooterAdapter and set it to the RecyclerView like this:

YourAdapter adapter = new YourAdapter();
 EasyHeaderFooterAdapter easyHeaderFooterAdapter =

new EasyHeaderFooterAdapter(adapter);
  //Always set the LayoutManager BEFORE the adapter. recyclerView.setLayoutManager(new SomeLayoutManager());
 recyclerView.setAdapter(easyHeaderFooterAdapter);

You can then set a header or footer through the setHeader and setFooter methods:

headerFooterAdapter.setHeader(anyView);
 headerFooterAdapter.setFooter(anotherView);

Those can be removed by setting null to the aforementioned methods:

headerFooterAdapter.setHeader(null);
 headerFooterAdapter.setFooter(null);

And that's it! Easy right?

There are a view things to look out for though.

Positions

If you are using the positions returned by the ViewHolders getAdapterPosition method, you have to calculate the real position in your adapter. The method getRealPosition does exactly that:

adapter.setCallback(new MainAdapter.MainAdapterCallback() {

  @Override
  public void onItemClick(int position) {

int positionInYourDataSet = headerFooterAdapter.getRealPosition(position);

 // Do whatever you wanted to do with it.
  
}
 
}
);

You can find more info on that in the sample.

ViewTypes and Ids

The following ViewTypes and IDs are used internally, so don't use them yourself:

TYPE_HEADER = Integer.MIN_VALUE; TYPE_FOOTER = Integer.MIN_VALUE + 1; ID_HEADER = Long.MIN_VALUE; ID_FOOTER = Long.MIN_VALUE + 1;
Changing the LayoutManager at runtime

As the EasyHeaderFooterAdapter needs to configure your LayoutManager, you have to reset the adapter to the RecyclerView if you want to change the LayoutManager:

recycler.setLayoutManager(new YourNewLayoutManager());
  // Remember, always set if after the LayoutManager recycler.setAdapter(headerFooterAdapter);

Further reading

The sample features almost all use cases. Have a look here.
You can find the JavaDoc here.

Metrics

Contributions and contributors

A guide for contribution can be found here.

Resources

A library which can get phone number geo location and other information from local or network (baidu, juhe or custom api).

Detects gestures on Android with listener and RxJava Observable.

AndRouter is a android framework used to map url to activities or actions.

APT processor to generate update methods for POJOs.

This project aims to provide pretty cool equalizer for any Android audio project.

This is the real android video player view with fullscreen function.

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