{"id":13537730,"url":"https://github.com/StanKocken/EfficientAdapter","last_synced_at":"2025-04-02T04:31:23.938Z","repository":{"id":22068312,"uuid":"25397479","full_name":"StanKocken/EfficientAdapter","owner":"StanKocken","description":"Create a new adapter for a RecyclerView or ViewPager is now much easier.","archived":false,"fork":false,"pushed_at":"2019-09-03T16:44:54.000Z","size":198,"stargazers_count":420,"open_issues_count":2,"forks_count":40,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-11-03T02:33:09.384Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StanKocken.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-18T13:04:10.000Z","updated_at":"2024-08-22T13:49:28.000Z","dependencies_parsed_at":"2022-08-20T19:40:52.821Z","dependency_job_id":null,"html_url":"https://github.com/StanKocken/EfficientAdapter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StanKocken%2FEfficientAdapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StanKocken%2FEfficientAdapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StanKocken%2FEfficientAdapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StanKocken%2FEfficientAdapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StanKocken","download_url":"https://codeload.github.com/StanKocken/EfficientAdapter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246757252,"owners_count":20828864,"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","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":[],"created_at":"2024-08-01T09:01:02.917Z","updated_at":"2025-04-02T04:31:18.925Z","avatar_url":"https://github.com/StanKocken.png","language":"Java","funding_links":[],"categories":["Java","Libs"],"sub_categories":["\u003cA NAME=\"Adapter\"\u003e\u003c/A\u003eAdapter"],"readme":"# Efficient Adapter for Android\n\nCreate a new adapter for a [RecyclerView](https://developer.android.com/jetpack/androidx/releases/recyclerview) or [ViewPager](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/ViewPager) is now much easier.\n\n## Overview\n\nCreate a list of elements into a [RecyclerView](https://developer.android.com/jetpack/androidx/releases/recyclerview) or [ViewPager](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/ViewPager) is not that easy for a beginner, and repetitive for others. The goal of this library is to simplify that for you.\n\n## How does it work?\n\nCreate a class ViewHolder (`BookViewHolder` for example). The method `updateView` will be call with the object, when an update of your view is require:\n\n    public class BookViewHolder extends EfficientViewHolder\u003cBook\u003e {\n        public BookViewHolder(View itemView) {  super(itemView); }\n\n        @Override\n        protected void updateView(Context context, Book object) {\n            TextView textView = findViewByIdEfficient(R.id.title_textview);\n            textView.setText(object.getTitle());\n\t\t\t// or just\n\t\t\tsetText(R.id.title_textview, object.getTitle());\n        }\n    }\n\nGive this ViewHolder class to the constructor of the adapter (SimpleAdapter) of your [RecyclerView](https://developer.android.com/jetpack/androidx/releases/recyclerview), with the resource id of your item view and the list of objects:\n\n    EfficientRecyclerAdapter\u003cPlane\u003e adapter = new EfficientRecyclerAdapter\u003cPlane\u003e(R.layout.item_book, BookViewHolder.class, listOfBooks);\n    recyclerView.setAdapter(adapter);\n\nAnd that's it!\n\nIt's also working with a [ViewPager](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/ViewPager):\n\n    EfficientPagerAdapter\u003cPlane\u003e adapter = new EfficientPagerAdapter\u003cPlane\u003e(R.layout.item_book, BookViewHolder.class, listOfBooks);\n    viewPager.setAdapter(adapter);\n\n## Other features\n\n### Heterogenous list\nFor a list of different kind of objects, layout, viewholder…\n\n    EfficientRecyclerAdapter adapter = new EfficientRecyclerAdapter(generateListObjects()) {\n        @Override\n        public int getItemViewType(int position) {\n            if (get(position) instanceof Plane) {\n                return VIEW_TYPE_PLANE;\n            } else {\n                return VIEW_TYPE_BOOK;\n            }\n        }\n\n        @Override\n        public Class\u003c? extends EfficientViewHolder\u003e getViewHolderClass(int viewType) {\n            switch (viewType) {\n                case VIEW_TYPE_BOOK:\n                    return BookViewHolder.class;\n                case VIEW_TYPE_PLANE:\n                    return PlaneViewHolder.class;\n                default:\n                    return null;\n            }\n        }\n\n        @Override\n        public int getLayoutResId(int viewType) {\n            switch (viewType) {\n                case VIEW_TYPE_BOOK:\n                    return R.layout.item_book;\n                case VIEW_TYPE_PLANE:\n                    return R.layout.item_plane;\n                default:\n                    return 0;\n            }\n        }\n    };\n\n### Efficient findViewById()\n\nBecause `findViewById(int)` is CPU-consuming (this is why we use the ViewHolder pattern), this library use a `findViewByIdEfficient(int id)` into the ViewHolder class.\n\nYou can use it like a `findViewById(int id)` but the view return will be cached to be returned into the next call.\n\nYour view id should be unique into your view hierarchy, but sometimes is not that easy (with an include for example). It's now easier to find a subview by specify the parent of this subview with `findViewByIdEfficient(int parentId, int id)` to say \"the view with this id into the parent with this id\".\n\n\n### Let the element be clickable\n\nYour ViewHolder class can override the method `isClickable()` to tell is this element is clickable or not.\n\nBy default, the view is clickable if you have a listener on your adapter.\n\n## Proguard\n\nThis library includes the proguard configuration file.\nIf you want to add it manually:\n\n    -keepclassmembers public class * extends com.skocken.efficientadapter.lib.viewholder.EfficientViewHolder {\n        public \u003cinit\u003e(...);\n    }\n\n## Gradle\n\n    dependencies {\n        compile 'com.skocken:efficientadapter:2.4.0'\n    }\n\n## Android Support library\n\nIf you are still using the deprecated Android Support Library (instead of AndroidX), please use the dependency 2.3.X instead.\n\n## License\n\n* [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0.html)\n\n## Contributing\n\nPlease fork this repository and contribute back using\n[pull requests](https://github.com/StanKocken/EfficientAdapter/pulls).\n\nAny contributions, large or small, major features, bug fixes, additional\nlanguage translations, unit/integration tests are welcomed and appreciated\nbut will be thoroughly reviewed and discussed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FStanKocken%2FEfficientAdapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FStanKocken%2FEfficientAdapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FStanKocken%2FEfficientAdapter/lists"}