{"id":18019886,"url":"https://github.com/vpaliy/multichoicemode-recyclerview","last_synced_at":"2025-10-04T17:55:32.505Z","repository":{"id":97269505,"uuid":"79627587","full_name":"vpaliy/MultiChoiceMode-RecyclerView","owner":"vpaliy","description":"This repository provides an API for creating a multi choice mode in RecyclerView.","archived":false,"fork":false,"pushed_at":"2017-06-14T15:48:07.000Z","size":5196,"stargazers_count":20,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-04T17:55:32.212Z","etag":null,"topics":["animation","multi-choice-selection","multi-choice-toolbar","recyclerview"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vpaliy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-21T06:09:48.000Z","updated_at":"2024-05-14T08:54:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"750aa52d-072c-440d-8f8a-562cf9ce1a98","html_url":"https://github.com/vpaliy/MultiChoiceMode-RecyclerView","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vpaliy/MultiChoiceMode-RecyclerView","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpaliy%2FMultiChoiceMode-RecyclerView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpaliy%2FMultiChoiceMode-RecyclerView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpaliy%2FMultiChoiceMode-RecyclerView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpaliy%2FMultiChoiceMode-RecyclerView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vpaliy","download_url":"https://codeload.github.com/vpaliy/MultiChoiceMode-RecyclerView/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpaliy%2FMultiChoiceMode-RecyclerView/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278350987,"owners_count":25972676,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["animation","multi-choice-selection","multi-choice-toolbar","recyclerview"],"created_at":"2024-10-30T05:12:50.795Z","updated_at":"2025-10-04T17:55:32.459Z","avatar_url":"https://github.com/vpaliy.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MultiChoiceMode-RecyclerView\n\n[![API](https://img.shields.io/badge/API-11%2B-blue.svg?style=flat)](https://android-arsenal.com/api?level=11) \u003cbr\u003e\nThis repository provides an API for creating a multiple choice mode in `RecyclerView`.\n\n## A brief glance at the sample ##\n![](https://github.com/vpaliyX/MultiChoiceMode-RecyclerView/blob/master/art/ezgif.com-video-to-gif%20(5).gif)\n\n# Get on Google Play #\n\u003ca href=\"https://play.google.com/store/apps/details?id=com.vpaliy.multiplechoicerecyclerview\"\u003e\n\u003cimg src=\"https://github.com/chrisbanes/PhotoView/blob/master/art/google-play-badge-small.png\" /\u003e\n\u003c/a\u003e\n\n\n\n## How does it work? ##\n\nThe API contains three main classes:`BaseAdapter`, `MultiMode` and `StateTracker`. The last one has a package-private access, so you don't need to deal with it at all.\n\nBasically, you need to do the following steps in order to make it work:\n  \n * Get a toolbar and create a `MultiMode` instance using the builder approach:\n    ```java\n      /** You can set colors, menu to inflate and callback to use, navigation icon, logo, title and subtitle */\n      MultiMode mode=new MultiMode.Builder(actionBar,this)\n                .setMenu(R.menu.list_menu,new MultiMode.Callback() {\n                    @Override\n                    public boolean onMenuItemClick(BaseAdapter adapter, MenuItem item) {\n                        // you can use any function of the adapter in order to work with selected items\n                        return false;\n                    }\n                })\n                .setStatusBarColor(Color.MAGENTA)\n                .setBackgroundColor(Color.WHITE)\n                .setNavigationIcon(getResources().getDrawable(R.drawable.ic_clear_black_24dp))\n                .build();\n    ```\n \n * Extend the `BaseAdapter` class and initialize it using the `MultiMode` instance:\n \n    ```java\n     public class Adapter extends BaseAdapter {\n     \n         public Adapter(MultiMode mode, boolean animate){\n            super(mode,animate);\n         }\n         \n         public Adapter(MultiMode mode, boolean animate, @NonNull Bundle savedInstanceState){\n            super(mode,animate,savedInstanceState);\n         }\n         \n         //implement the rest of the important methods which RecyclerView has\n         \n         @Override\n         public void removeAt(int index){\n            //write your implementation of this method\n         }\n     }\n    ```\n * Then create a `ViewHolder` class of your adapter using a special class in `BaseAdapter` and implement the next methods:\n  \n    ```java\n    public class ViewHolder extends BaseAdapter.BaseViewHolder {\n\n        public ViewHolder(View itemView) {\n            super(itemView);\n            //bind your views here\n        }\n\n        @Override\n        public void onBindData() {\n            //install your views with the data here \n            \n            //after you have installed your data, call this method, otherwise you will not get any animation\n            determineState();\n        }\n\n        @Override\n        public void updateBackground() {\n            if(isChecked(getAdapterPosition())){\n                //if this item has been selected, set an appropriate background\n            }else{\n               //install the background of your view\n            }\n        }\n\n        @Override\n        public void enterState() {\n            super.enterState();\n            //animate your view \n        }\n\n        @Override\n        public void animatedState() {\n            //set your view to the animated state, without animation \n        }\n\n        @Override\n        public void exitState() {\n            super.exitState();\n            //create your exit animation\n        }\n\n        @Override\n        public void defaultState() {\n           //set your view to the default state\n        }\n     }\n    ```\n \u003cbr\u003e\n \n \n### Understanding of animation in the `BaseAdapter.BaseViewHolder` class ###\n \nIf you decide to animate an item upon click, you have to understand how it works. Basically, there are 4 states of the item:\u003cbr\u003e\n \n  1) `Enter` state\u003cbr\u003e\n     This state represents an animation that has to occur when an item is clicked.\n     For example, you can use this implementation of the method:\n     \n  ```java   \n       @Override\n       public void enterState() {\n          super.enterState();\n          itemView.animate()\n            .scaleX(0.85f)\n            .scaleY(0.85f)\n            .setDuration(180).start();\n       }\n  ```\n  \n  2) `Animated` state\u003cbr\u003e\n    This is a state of an item that has been animated, and doesn't need this animation again. So, the main purpose of this method is to put a view into the animated state.\u003cbr\u003e\n   ```java   \n        @Override\n        public void animatedState() {\n          itemView.setScale(0.85f);\n          itemView.setScale(0.85f);\n        }\n   ```\n   \n  3) `Exit` state\u003cbr\u003e\n     This state is responsible for animating a view in the normal state, some kind of back animation. Here is the example:\u003cbr\u003e\n   ```java   \n        @Override\n        public void exitState() {\n          super.exitState();\n          itemView.animate()\n            .scaleX(1.f)\n            .scaleY(1.f)\n            .setDuration(180).start();\n        }\n   ```\n   \n  4) `Default` state\u003cbr\u003e\n      That is a default or normal state of your item. The following method can be a representation of such state:\n      \n  ```java   \n        @Override\n        public void defaultState() {\n           if(itemView.getScale()\u003c1.f){\n              itemView.setScale(1.f);\n              itemView.setScale(1.f);\n            }\n        }\n   ```\n  \nOnce again, if you don't want to animate items, you are not obliged to implement those methods.\n\n \n### What if screen rotation occurs? ###\n  \nAs long as you have a reference to your adapter, screen rotation is not a big deal. You can easily save and restore the state of the adapter using the following code:\n \n * Save the state:\n \n   ```java\n    @Override\n    protected void onSaveInstanceState(Bundle outState) {\n        super.onSaveInstanceState(outState);\n        adapter.saveState(outState);\n    }    \n    ```\n    \n * Restore:\n    ```java   \n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        //do some stuff$\n        \n        if(savedInstanceState!=null){\n          adapter=new Adapter(mode,true,savedInstanceState);\n        }else{\n          adapter=new Adapter(mode,true);\n        }\n    }\n    ```\n  \n Also you need to keep in mind that activity can be stopped by launching another app or receiving a phone call.\n In this particular case that is not a problem as well, as long as you keep the reference to your adapter, you can restore it:\n \n   ```java   \n    @Override\n    protected void onResume() {\n        super.onResume();\n        if(adapter!=null){\n            adapter.onResume();\n        }\n    }\n   ```\n   \n\n## License ##\n\n``````\nMIT License\n\nCopyright (c) 2016 Vasyl Paliy\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n``````\n  \n  \n      \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvpaliy%2Fmultichoicemode-recyclerview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvpaliy%2Fmultichoicemode-recyclerview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvpaliy%2Fmultichoicemode-recyclerview/lists"}