:page_with_curl: [Android Library] Giving powers to RecyclerView

Overview

Android library that provides most common functions around recycler-view like Swipe to dismiss, Drag and Drop, Divider in the ui, events for when item selected and when not selected, on-click listener for items.

Built with ❤︎ by Nishant Srivastava and contributors


Note: Development for pre-androidx version of this library has stopped. If you are looking for pre-androidx version, then checkout this branch. Library is compatible with AndroidX version only.

Integration

RecyclerViewHelper is available in the Jcenter, so getting it as simple as adding it as a dependency

def recyclerViewVersion="{latest version}"
// Required
implementation "androidx.recyclerview:recyclerview:${recyclerViewVersion}"

// RecyclerViewHelper
implementation "com.github.nisrulz:recyclerviewhelper:x${recyclerViewVersion}"

where {latest version} corresponds to published version in Download without the prepended x. This is done to distinguish between library using andoirdx vs pre-androidx.

Usage Example:

def recyclerViewVersion="1.1.0"
// Required
implementation "androidx.recyclerview:recyclerview:${recyclerViewVersion}"

// RecyclerViewHelper
implementation "com.github.nisrulz:recyclerviewhelper:x${recyclerViewVersion}"

NOTE : The version here corresponds to the version of recyclerview dependency.

Make sure that the google's maven repo is declared in your projects build.gradle file as below
allprojects {
  repositories {
    google()
    jcenter()
  }
}

Usage

  • Implement the RHVAdapter in your recycler view adapter and RHVViewHolder in your ItemViewHolder
    public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ItemViewHolder> implements RVHAdapter {
    
         ...
    
        @Override
        public boolean onItemMove(int fromPosition, int toPosition) {
            swap(fromPosition, toPosition);
            return false;
        }
    
        @Override
        public void onItemDismiss(int position, int direction) {
            remove(position);
        }
    
        public class ItemViewHolder extends RecyclerView.ViewHolder implements RVHViewHolder {
            ...
               
            @Override
            public void onItemSelected(int actionstate) {
                System.out.println("Item is selected");
            }
    
            @Override
            public void onItemClear() {
                System.out.println("Item is unselected");
    
            }
        }
    
        // Helper functions you might want to implement to make changes in the list as an event is fired
        private void remove(int position) {
            dataList.remove(position);
            notifyItemRemoved(position);
        }
    
        private void swap(int firstPosition, int secondPosition) {
            Collections.swap(dataList, firstPosition, secondPosition);
            notifyItemMoved(firstPosition, secondPosition);
        }
    }
  • Then implement your recycler view
   public class MainActivity extends AppCompatActivity {
   
   
       RecyclerView myrecyclerview;
       ArrayList<String> data;
       MyAdapter adapter;
   
       @Override
       protected void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.activity_main);
   
           myrecyclerview = (RecyclerView) findViewById(R.id.rv_fruits);
   
           data = new ArrayList<>();
           data.add("Apple");
           ...
           data.add("Fig");
   
           // Setup your adapter
           adapter = new MyAdapter(data);
           // Setup 
           myrecyclerview.hasFixedSize();
           myrecyclerview.setLayoutManager(new LinearLayoutManager(this));
           myrecyclerview.setAdapter(adapter);
   
   
           // Setup onItemTouchHandler to enable drag and drop , swipe left or right
           ItemTouchHelper.Callback callback = new RVHItemTouchHelperCallback(adapter, true, true,
                   true);
           ItemTouchHelper helper = new ItemTouchHelper(callback);
           helper.attachToRecyclerView(myrecyclerview);
   
           // Set the divider in the recyclerview
           myrecyclerview.addItemDecoration(new RVHItemDividerDecoration(this, LinearLayoutManager.VERTICAL));
   
           // Set On Click Listener
           myrecyclerview.addOnItemTouchListener(new RVHItemClickListener(this, new RVHItemClickListener.OnItemClickListener() {
               @Override
               public void onItemClick(View view, int position) {
                   String value = "Clicked Item " + data.get(position) + " at " + position;
   
                   Log.d("TAG", value);
                   Toast.makeText(MainActivity.this, value, Toast.LENGTH_SHORT).show();
               }
           }));
   
       }
   }

Demo

Walkthrough

Pull Requests

I welcome and encourage all pull requests. It usually will take me within 24-48 hours to respond to any issue or request. Here are some basic rules to follow to ensure timely addition of your request:

  1. Match coding style (braces, spacing, etc.) This is best achieved using CMD+Option+L (Reformat code) on Mac (not sure for Windows) with Android Studio defaults. This project uses a modified version of Grandcentrix's code style, so please use the same when editing this project.
  2. If its a feature, bugfix, or anything please only change code to what you specify.
  3. Please keep PR titles easy to read and descriptive of changes, this will make them easier to merge :)
  4. Pull requests must be made against develop branch. Any other branch (unless specified by the maintainers) will get rejected.
  5. Check for existing issues first, before filing an issue.
  6. Have fun!

License

Licensed under the Apache License, Version 2.0, click here for the full license.

Author & support

This project was created by Nishant Srivastava but hopefully developed and maintained by many others. See the the list of contributors here.

Special Credits to Paul Burke and his article which got me thinking

This library contains a modified version of his implementations of ItemTouchHelper.


If you appreciate my work, consider buying me a cup of to keep me recharged 🤘 [PayPal]

Comments
  • Can not build project from console

    Can not build project from console

    I've got the following error during gradlew build:

    Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain
    

    It looks like gradle wrapper jar file was missed in "gradle/wrapper".

    opened by vbauer 3
  • Cannot get property 'GROUP' on extra properties extension as it does not exist

    Cannot get property 'GROUP' on extra properties extension as it does not exist

    Thanks for library.

    While cloning repository and sync project, I am getting below gradle sync failed message here:

    Cannot get property 'GROUP' on extra properties extension as it does not exist

    opened by pranaypatel512 2
  • Swipe to dismiss doesn't remove the card permanently

    Swipe to dismiss doesn't remove the card permanently

    I am using your swipe to dismiss feature and it removes the card and even deletes the object from the list but messes up with the animation.

    If I delete the card there is just a big grey space where it was and if I scroll down and then back up again the old card is still there where the gray space was but it is deleted from the actual list.

    searchList.remove(position); notifyItemRemoved(position);

    Thats my code on item dismiss

    opened by kiaanpillay 2
  • Implement canDropOver to control where an item can be dropped

    Implement canDropOver to control where an item can be dropped

    
    @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder source, RecyclerView.ViewHolder target) {
            if (source.getItemViewType() != target.getItemViewType()) {
                return false;
            }
    
            // Notify the adapter of the move
            mAdapter.onItemMove(source.getAdapterPosition(), target.getAdapterPosition());
            return true;
        }
    

    If source and target item types are not the same you don't want to move the item. ItemTouchHelper.Callback docs recommends to override canDropOver(RecyclerView, ViewHolder, ViewHolder) to control where a view can be dropped.

    opened by ISatya 1
  • Migrate to Maven Central

    Migrate to Maven Central

    JFrog just announced that they'll be shutting down JCenter: https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/

    Key dates are:

    February 28th: No more submissions will be accepted to Bintray, JCenter May 1st: Bintray, JCenter services will no longer be available

    Hence need to migrate to another maven repository like Maven central.

    opened by nisrulz 0
  • 📖 Guest Book 🙇🏻‍♂️

    📖 Guest Book 🙇🏻‍♂️

    This "issue" serves as a guest book. You're welcome to write nice things about this project, share how it's helped you out, or name drop companies using it.

    Idea came from this tweet.

    opened by nisrulz 0
  • Could not get unknown property 'GROUP' for object of type org.gradle.api.internal.plugins.DefaultExtraPropertiesExtension.

    Could not get unknown property 'GROUP' for object of type org.gradle.api.internal.plugins.DefaultExtraPropertiesExtension.

    Do you want to request a feature or report a bug? Report a bug What is the current behavior?

    If the current behavior is a bug, please provide the steps to reproduce.

    I cloned the project from github, but I am unable to build it. It always gives error "Could not get unknown property 'GROUP' for object of type org.gradle.api.internal.plugins.DefaultExtraPropertiesExtension."

    Any logs, error output, bugreport etc?

    What is the expected behavior? The code should build Any other comments?

    What versions of software are you using?

    • Device Information:

    • Android Version:

    • Configuration Information:

    • Misc:

    opened by maheshwariaanchal 2
  • Refreshing gives IndexOutOfBoundsException

    Refreshing gives IndexOutOfBoundsException

    BUG

    What is the current behavior? When I refresh my recyclerview and then try to swipe to dismiss an item, I get an IndexOutOfBoundsException. If the current behavior is a bug, please provide the steps to reproduce.

    I just to a refresh and then try to swipe to dismiss an item.

    Any logs, error output, bugreport etc?

    adapter = RVHAdapter(context, listOfFiles)
    recyclerView.swapAdapter(adapter, true)
    val callback = RVHItemTouchHelperCallback(adapter, false, true, true)
    val helper = ItemTouchHelper(callback)
    helper.attachToRecyclerView(recyclerView)
    

    What is the expected behavior? No IndexOutOfBoundsException Any other comments?

    What versions of software are you using?

    • Device Information: Google Pixel 2

    • Android Version: Android 9: Pie

    • Configuration Information:

    • Misc: Logcat: java.lang.IndexOutOfBoundsException: Index: 4, Size: 0 at java.util.ArrayList.get(ArrayList.java:437) at com.example.ViewVideosActivity$VideoAdapter$onItemDismiss$1.invoke(ViewVideosActivity.kt:295) at com.example.ViewVideosActivity$VideoAdapter$onItemDismiss$1.invoke(ViewVideosActivity.kt:260) at org.jetbrains.anko.AsyncKt.runOnUiThread(Async.kt:34) at com.example.ViewVideosActivity$VideoAdapter.onItemDismiss(ViewVideosActivity.kt:291)

    opened by jakepurple13 4
  • i have two recyclerview in a activity. For one list working perfectly and other one failed.

    i have two recyclerview in a activity. For one list working perfectly and other one failed.

    Hi I have implemented the lib for two different list view in single activity. One working fine without any issue. For another one, the onMove function didn't call while onDrag.

    Can you please explain why if you faced already this issue? Is it possible to use two list in single activity with ItemTouchHelper?

    opened by tkharishankar 2
Releases(x1.1.0)
Owner
Nishant Srivastava
non-GDE Android Engineer crushing code 👨🏻‍💻
Nishant Srivastava
Renderers is an Android library created to avoid all the boilerplate needed to use a RecyclerView/ListView with adapters.

Renderers Renderers is an Android library created to avoid all the RecyclerView/Adapter boilerplate needed to create a list/grid of data in your app a

Pedro Vicente Gómez Sánchez 1.2k Nov 19, 2022
Android library to auto-play/pause videos from url in recyclerview.

AutoplayVideos Show some ❤️ and star the repo to support the project This library is created with the purpose to implement recyclerview with videos ea

Krupen Ghetiya 989 Nov 17, 2022
Android library for the adapter view (RecyclerView, ViewPager, ViewPager2)

Antonio Android library for the adapter view (RecyclerView, ViewPager, ViewPager2) Free from implementation of the adapter's boilerplate code ! Reuse

NAVER Z 106 Dec 23, 2022
An Adapter that allows a RecyclerView to be split into Sections with headers and/or footers. Each Section can have its state controlled individually.

⚠️ Archived: this repository is no longer going to be maintained. SectionedRecyclerViewAdapter An Adapter that allows a RecyclerView to be split into

Gustavo Pagani 1.7k Dec 21, 2022
Create a new adapter for a RecyclerView or ViewPager is now much easier.

Efficient Adapter for Android Create a new adapter for a RecyclerView or ViewPager is now much easier. Overview Create a list of elements into a Recyc

Stan Kocken 423 Sep 16, 2022
Rx based RecyclerView Adapter

RxRecyclerAdapter Rx based generic RecyclerView Adapter Library. How to use it? Example! Enable Databinding by adding these lines to your build.gradle

Ahmed Rizwan 193 Jun 18, 2022
This Repository simplifies working with RecyclerView Adapter

AutoAdapter This Repository simplifies working with RecyclerView Adapter Gradle: Add it in your root build.gradle at the end of repositories: allproj

George Dzotsenidze 151 Aug 15, 2021
Generic RecyclerView adapter

Generic RecyclerView Adapter. Lightweight library which simplifies creating RecyclerView adapters and illuminates writing boilerplate code. Creating a

Leonid Ustenko 77 Dec 24, 2022
Vector map library and writer - running on Android and Desktop.

Mapsforge See the integration guide and changelog. And read through how to contribute guidelines. If you have any questions or problems, don't hesitat

mapsforge 1k Jan 2, 2023
[] Easy Adapters library for Android

Deprecated Due to the growing use of the RecyclerView and the RecyclerView.Adapter provided adapter class, Easy-Adapter is now deprecated. Whilst the

ribot 425 Nov 25, 2022
This library provides GridAdapters(ListGridAdapter & CursorGridAdapter) which enable you to bind your data in grid card fashion within android.widget.ListView, Also provides many other features related to GridListView.

GridListViewAdapters This libarary enables you to implement GridView like card layout within ListView with added capabilites like Paginations, Additio

Biraj Patel 270 Nov 25, 2022
This library provides Easy Android ListView Adapters(EasyListAdapter & EasyCursorAdapter) which makes designing Multi-Row-Type ListView very simple & cleaner, It also provides many useful features for ListView.

EasyListViewAdapters Whenever you want to display custom items in listview, then only way to achieve this is to implement your own subclass of BaseAda

Biraj Patel 132 Nov 25, 2022
Open source routing engine for OpenStreetMap. Use it as Java library or server.

GraphHopper Routing Engine GraphHopper is a fast and memory efficient Java routing engine, released under Apache License 2.0. By default it uses OpenS

GraphHopper 4k Jan 7, 2023
The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...

FastAdapter The FastAdapter is here to simplify creating adapters for RecyclerViews. Don't worry about the adapter anymore. Just write the logic for h

Mike Penz 3.7k Jan 8, 2023
A library to make a mosaic with a preview of multiple images

Preview Image Collection Introduction Preview Image Collection is a library to draw a collage with a number of images like facebook preview album Inst

Agnaldo Pereira 50 Jun 13, 2022
Android - A ListView adapter with support for multiple choice modal selection

MultiChoiceAdapter MultiChoiceAdapter is an implementation of ListAdapter which adds support for modal multiple choice selection as in the native Gmai

Manuel Peinado Gallego 855 Nov 11, 2022
Adapter Kit is a set of useful adapters for Android.

Adapter Kit Adapter Kit is a set of useful adapters for Android. The kit currently includes, Instant Adapter Instant Cursor Adapter Simple Section Ada

Ragunath Jawahar 368 Nov 25, 2022
Simplify Adapter creation for your Android ListViews.

FunDapter takes the pain and hassle out of creating a new Adapter class for each ListView you have in your Android app. It is a new approach to custom

Ami Goldenberg 287 Dec 22, 2022
Generate data-view-binding adapters of android recycler view.

Items 这个库可以为 Android 的 RecyclerView 生成基于 Data-View-Binding 的 Adapter。 对比其他一些类似的开源库,它有以下的一些优势: 更好的拓展性。这个库不需要你继承特定的 Adapter 或 ViewHolder 类,你可以继承任何第三方提供的

nekocode 253 Nov 11, 2022