Convert Figma logo to code with AI

davideas logoFlexibleAdapter

Fast and versatile Adapter for RecyclerView which regroups several features into one library to considerably improve the user experience :-)

3,553
547
3,553
59

Top Related Projects

BRVAH:Powerful and flexible RecyclerAdapter

RecyclerView extension library which provides advanced features. (ex. Google's Inbox app like swiping, Play Music app like drag and drop sorting)

The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...

Android library providing simple way to control divider items (ItemDecoration) of RecyclerView

Quick Overview

The FlexibleAdapter is a powerful and flexible RecyclerView Adapter library for Android that simplifies the process of creating and managing complex RecyclerView-based user interfaces. It provides a wide range of features and customization options, making it a versatile choice for developers working on Android applications.

Pros

  • Flexibility: The library offers a highly customizable and extensible architecture, allowing developers to easily adapt it to their specific needs.
  • Performance: The FlexibleAdapter is designed with performance in mind, providing efficient data management and smooth scrolling experiences.
  • Ease of Use: The library abstracts away many of the boilerplate tasks associated with RecyclerView Adapters, making it easier for developers to focus on their application's core functionality.
  • Rich Feature Set: The FlexibleAdapter includes a wide range of features, such as header/footer support, multi-selection, animations, and more, out of the box.

Cons

  • Learning Curve: The library's flexibility and feature-richness can come with a steeper learning curve for developers who are new to the project.
  • Dependency Management: The FlexibleAdapter relies on several external libraries, which may increase the overall project's dependency footprint.
  • Potential Performance Issues: While the library is designed for performance, complex or heavily nested RecyclerView configurations may still require careful optimization.
  • Limited Documentation: The project's documentation, while generally good, could be improved in certain areas to better guide new users.

Code Examples

Example 1: Creating a Simple Adapter

val adapter = FlexibleAdapter(items)
adapter.addListener(object : OnItemClickListener {
    override fun onItemClick(view: View, position: Int): Boolean {
        // Handle item click event
        return true
    }
})

This code creates a new FlexibleAdapter instance and attaches an OnItemClickListener to handle item click events.

Example 2: Adding Header and Footer

val adapter = FlexibleAdapter(items)
adapter.addHeaderView(headerView)
adapter.addFooterView(footerView)

This code adds a header and footer view to the FlexibleAdapter instance.

Example 3: Enabling Multi-Selection

val adapter = FlexibleAdapter(items, SelectableAdapter(true))
adapter.mode = SelectableAdapter.Mode.MULTI

This code creates a FlexibleAdapter instance with multi-selection mode enabled, using the SelectableAdapter feature.

Example 4: Animating Item Changes

val adapter = FlexibleAdapter(items)
adapter.setAnimationOnScrolling(true)
adapter.setAnimationOnReverseScrolling(true)

This code enables item animation effects when the RecyclerView is scrolled forward and backward.

Getting Started

To get started with the FlexibleAdapter, follow these steps:

  1. Add the library to your project's dependencies:
dependencies {
    implementation 'eu.davidea:flexible-adapter:5.1.0'
    implementation 'eu.davidea:flexible-adapter-ui:1.0.0'
}
  1. Create a new FlexibleAdapter instance and set it as the adapter for your RecyclerView:
val adapter = FlexibleAdapter(items)
recyclerView.adapter = adapter
  1. Implement your custom FlexibleViewHolder and FlexibleItem classes to represent the data in your RecyclerView:
class MyViewHolder(view: View) : FlexibleViewHolder(view) {
    // Bind your view here
}

class MyItem(val title: String) : AbstractFlexibleItem<MyViewHolder>() {
    // Implement required methods
}
  1. Add your items to the adapter and notify the adapter of any changes:
adapter.updateDataSet(myItems)
adapter.notifyDataSetChanged()

That's the basic setup to get started with the FlexibleAdapter library. Refer to the project's documentation for more advanced usage and customization options.

Competitor Comparisons

BRVAH:Powerful and flexible RecyclerAdapter

Pros of BaseRecyclerViewAdapterHelper

  • Provides a comprehensive set of features and utilities to simplify the implementation of RecyclerView adapters.
  • Includes built-in support for multiple view types, header/footer views, and item animations.
  • Offers a flexible and extensible architecture that allows for easy customization.

Cons of BaseRecyclerViewAdapterHelper

  • The library may have a steeper learning curve compared to FlexibleAdapter, especially for developers new to the concept of RecyclerView adapters.
  • The codebase can be more complex and less intuitive for simple use cases, where FlexibleAdapter may provide a more lightweight and straightforward solution.

Code Comparison

FlexibleAdapter:

public class MyAdapter extends FlexibleAdapter<MyItem> {
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_layout, parent, false));
    }

    public static class ViewHolder extends FlexibleViewHolder {
        // ...
    }
}

BaseRecyclerViewAdapterHelper:

public class MyAdapter extends BaseQuickAdapter<MyItem, BaseViewHolder> {
    @Override
    protected void convert(BaseViewHolder helper, MyItem item) {
        // Bind data to views
    }

    @Override
    protected int getItemType(int position) {
        return 0;
    }

    @Override
    protected BaseViewHolder onCreateDefViewHolder(ViewGroup parent, int viewType) {
        return new BaseViewHolder(LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_layout, parent, false));
    }
}

RecyclerView extension library which provides advanced features. (ex. Google's Inbox app like swiping, Play Music app like drag and drop sorting)

Pros of android-advancedrecyclerview

  • Provides a wide range of advanced features for RecyclerView, including expandable items, drag and drop, and swipe-to-dismiss.
  • Offers a more comprehensive set of functionality compared to FlexibleAdapter.
  • Supports a variety of item types and layouts, making it suitable for complex UI designs.

Cons of android-advancedrecyclerview

  • Steeper learning curve due to the extensive feature set and more complex API.
  • May have a higher overhead compared to FlexibleAdapter, especially for simpler use cases.
  • Potentially less actively maintained than FlexibleAdapter, with fewer contributors.

Code Comparison

FlexibleAdapter:

FlexibleAdapter<Item> adapter = new FlexibleAdapter<>(items);
adapter.setMode(FlexibleAdapter.MODE_MULTI);
adapter.addListener(new OnItemClickListener<Item>() {
    @Override
    public void onItemClick(int position, Item item) {
        // Handle item click
    }
});

android-advancedrecyclerview:

ExpandableItemAdapter<ParentItem, ChildItem> adapter = new ExpandableItemAdapter<>();
adapter.setParentList(parentItems);
adapter.setChildList(parentPosition, childItems);
adapter.setOnItemClickListener(new ExpandableItemAdapter.OnItemClickListener() {
    @Override
    public void onItemClick(int position, ExpandableItemAdapter.ItemViewHolder<?, ?> holder) {
        // Handle item click
    }
});

The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...

Pros of FastAdapter

  • Simplicity: FastAdapter provides a straightforward and easy-to-use API, making it simpler to integrate into your project compared to FlexibleAdapter.
  • Performance: FastAdapter is known for its efficient performance, with optimized rendering and smooth scrolling.
  • Extensibility: FastAdapter offers a wide range of built-in features and the ability to easily extend its functionality to suit your specific needs.

Cons of FastAdapter

  • Limited Customization: While FastAdapter is highly extensible, it may not offer the same level of customization options as FlexibleAdapter, which is designed to be more flexible.
  • Steeper Learning Curve: Compared to FlexibleAdapter, FastAdapter may have a slightly steeper learning curve, especially for developers who are new to the library.

Code Comparison

FlexibleAdapter:

FlexibleAdapter<Item> adapter = new FlexibleAdapter<>(items);
adapter.setDisplayHeadersAtStartUp(true);
adapter.setMode(FlexibleAdapter.MODE_MULTI);
adapter.setNotifyChangeOfUnfilteredItems(true);
adapter.setAnimationOnScrolling(true);

FastAdapter:

FastAdapter<Item> adapter = FastAdapter.with(items);
adapter.withSelectable(true);
adapter.withMultiSelect(true);
adapter.withSelectOnLongClick(true);
adapter.withOnClickListener((v, adapter, item, position) -> { /* handle click */ });

Android library providing simple way to control divider items (ItemDecoration) of RecyclerView

Pros of RecyclerView-FlexibleDivider

  • Provides a simple and straightforward way to add dividers between items in a RecyclerView
  • Supports various types of dividers, including horizontal, vertical, and grid
  • Allows for easy customization of divider size, color, and padding

Cons of RecyclerView-FlexibleDivider

  • Limited functionality compared to FlexibleAdapter, which offers a more comprehensive set of features
  • May not be as flexible or customizable as FlexibleAdapter in terms of item manipulation and animation

Code Comparison

FlexibleAdapter:

FlexibleAdapter<Item> adapter = new FlexibleAdapter<>(items);
adapter.setDisplayHeadersAtStartUp(true);
adapter.addScrollableHeader(new HeaderItem("Header"));
adapter.addScrollableFooter(new FooterItem("Footer"));

RecyclerView-FlexibleDivider:

RecyclerView.ItemDecoration divider = new HorizontalDividerItemDecoration.Builder(context)
    .color(Color.GRAY)
    .size(2)
    .build();
recyclerView.addItemDecoration(divider);

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Android Arsenal Download API Licence Methods and Size

FlexibleAdapter

  • v5.1.0 built on 2018.09.30 with AndroidX
  • If you come from previous versions, update your code following the Wiki page Migrations.
  • Please read also issues and releases.

One Adapter many Apps

:mega: When initially Android:registered: team introduced the RecyclerView widget, we had to implement a custom Adapter in several applications, again and again to provide the items for our views.
We didn't know how to add selection and to combine all the use cases in the same Adapter. Since I created this library, it has become easy to configure multiple views and now, nobody wants to use a ListView anymore.

The idea behind is to regroup multiple features in a unique library, without the need to customize and import several third libraries not compatible among them.

The FlexibleAdapter helps developers to simplify this process without worrying too much about the Adapter anymore. It's easy to use, it has predefined logic for different situations and prevents common mistakes.
This library is configurable and it guides the developers to create a better user experience and now, even more with the new features.

Features in main library

  • Simple, Single & Multi selection mode.
  • Mapping multi-view types with Item interfaces.
  • Predefined ViewHolders with (child) click listeners and others callbacks.
  • Async Updates with optional DiffUtil for small lists.
  • Async Filter with spannable text (:eyeglasses:); Result list is animated; With optional original list; Works with sub items; Multi filter.
  • High performance filter and updates for medium and big lists.
  • Headers and Sections with sticky behaviour fully clickable and collapsible, elevation, transparency and automatic linkage on item move!
  • Scrollable Headers and Footers items that lay respectively at the top and at the bottom of the main items.
  • Expandable items with Selection Coherence and multi-level expansion.
  • Drag&Drop and Swipe-To-Dismiss with Leave-Behind pattern and with Selection Coherence.
  • Innovative bottom and top EndlessScroll (No OnScrollListener).
  • Customizable FastScroller with several features.
  • Customizable Scrolling Animations based on adapter position and beyond.
  • Customizable Animations when adding and removing items.
  • LayoutUtils for orientation, span count and visible items calculation.
  • Support for any thirds LayoutManagers.
  • Easy runtime position calculation for adding/moving items in sections.
  • Custom Tags for multiple adapter instances that ease our debug.
  • Comprehensive Wiki pages and JavaDoc documentation.

UI extension library :eyeglasses:

  • Faster setup selection with ActionModeHelper.
  • Faster setup for item restoration with UndoHelper; Works with expandable and swiped items too!
  • Basic empty view handling with EmptyViewHelper.
  • Advanced item decoration (customizable dividers, sections gap and item offsets).
  • 3 layout managers that support smooth scrolling.
  • FlexibleUtils for text highlighting, accent color fetching, API versions.
  • DrawableUtils for dynamic backgrounds with ripple effect (No XML).

Others experimental extension libraries

Setup

build.gradle

repositories {
    jcenter()
}
dependencies {
    // Using JCenter
    implementation 'eu.davidea:flexible-adapter:5.1.0'
    implementation 'eu.davidea:flexible-adapter-ui:1.0.0'
    implementation 'eu.davidea:flexible-adapter-livedata:1.0.0-b3'
    // From 1.0.0-b3, library is compiled with data binding v2
    implementation 'eu.davidea:flexible-adapter-databinding:1.0.0'
}

Stay Updated

Flexible AdapterUILive DataData Binding
5.1.0
1.0.0
1.0.0-b3
1.0.0

Wiki!

I strongly recommend to read the Wiki pages, where you can find a comprehensive Tutorial.

Pull requests / Issues / Improvement requests

Feel free to contribute and ask!
Active discussions:

Under the hood

Some simple features have been implemented, thanks to some Blogs (see at the bottom of the page), merged and methods have been improved for speed and scalability.

  • At lower level there is SelectableAdapter class. It provides selection features and it's able to maintain the state after the rotation: you just need to call the onSave/onRestore methods from the Activity!
  • At middle level, the AnimatorAdapter class has been added to give some animation at startup and when user scrolls.
  • At front level, the core class FlexibleAdapter. It holds and handles the main list, performs actions on all different types of item paying attention at the adding and removal of the items, as well as the new concept of "selection coherence".
  • Useful extensions and helpers have been added during the time to simplify the development.
  • Item interfaces and predefined ViewHolders complete the whole library giving more actions to the items and configuration options to developers.

Showcase of the demo App

You can download the latest demo App from the latest release page OR run it with the emulator.
This Wiki page will give you a short briefing of the demo App.

Overall Adapter Animations Undo Staggered Layout

Endless Instagram Expandables Multi Selection & SC

Drag & Drop swipe-to-dismiss1 swipe-to-dismiss2 ViewPager

Async Filter Search Filter Search Sections

Change Log

Latest release

v5.1.0 - 2018.09.30

Old releases

v5.0.6 - 2018.09.16 | v5.0.5 - 2018.06.03 | v5.0.4 - 2018.05.01 | v5.0.3 - 2018.03.23 | v5.0.2 - 2018.03.17 | v5.0.1 - 2018.03.11 | v5.0.0 - 2018.03.04

Limitations

Item half swipe cannot be implemented due to how the android.support.v7.widget.helper.ItemTouchHelper is done, also clicks on rear view are not possible, same reason. Half swipe can be done with others means, please see issues #98 and #100. See also commits of Apr 25, 2016.

Thanks

Inspired by
Special thanks goes to
  • Martin Guillon (Akylas) to have contributed at the development of the new technique for the Sticky Header.
  • Arpinca who added new features for FastScroller like autoHide and ignoreTouchesOutsideHandle and more.
Donations

This library is currently free to use and modify, if you would like to say Thank You by donating any amount, you're very welcome! Here the link to PayPal.me:

PayPal.me

Imported libraries

  • The library LollipopContactsRecyclerViewFastScroller has been imported, heavily improved and adapted to work in conjunction with AnimatorAdapter.
  • The library sticky-headers-recyclerview was initially imported, then it was removed in favor of the new technique able to manage a real View and so to handle the click events properly.
  • The item spacing technique comes from the library CommonItemDecoration and it has been improved with new features.

Apps that use this Adapter

It will be a pleasure to add your App here, once it is published.

Module.org | Neuronizer | Nextcloud Talk | Socio - Shake and Connect! | Shibagram | BNVR Client

License

FlexibleAdapter & Extensions

Copyright 2015-2018 Davide Steduto, Davidea Solutions Sprl

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.

FastScroller

Copyright 2016-2017 AndroidDeveloperLB, Davide Steduto & Arpinca

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.