{"id":13428669,"url":"https://github.com/nitrico/LastAdapter","last_synced_at":"2025-03-16T01:32:51.779Z","repository":{"id":98666915,"uuid":"61912405","full_name":"nitrico/LastAdapter","owner":"nitrico","description":"Don't write a RecyclerView adapter again. Not even a ViewHolder!","archived":false,"fork":false,"pushed_at":"2018-08-16T12:17:19.000Z","size":225,"stargazers_count":776,"open_issues_count":12,"forks_count":71,"subscribers_count":20,"default_branch":"master","last_synced_at":"2024-10-27T05:37:12.191Z","etag":null,"topics":["android","android-library","databinding","kotlin","kotlin-android","kotlin-library","recyclerview","recyclerview-adapter","viewholder"],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","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/nitrico.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-06-24T21:05:40.000Z","updated_at":"2024-09-18T20:39:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"4bbaa384-0560-414e-8b29-7056a51e5efe","html_url":"https://github.com/nitrico/LastAdapter","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/nitrico%2FLastAdapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitrico%2FLastAdapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitrico%2FLastAdapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nitrico%2FLastAdapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nitrico","download_url":"https://codeload.github.com/nitrico/LastAdapter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243814905,"owners_count":20352037,"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":["android","android-library","databinding","kotlin","kotlin-android","kotlin-library","recyclerview","recyclerview-adapter","viewholder"],"created_at":"2024-07-31T01:01:02.544Z","updated_at":"2025-03-16T01:32:51.473Z","avatar_url":"https://github.com/nitrico.png","language":"Kotlin","funding_links":[],"categories":["Libraries","\u003ca name=\"ui\"\u003e\u003c/a\u003eUI \u003csup\u003e[Back ⇈](#contents)\u003c/sup\u003e","开源库","Kotlin"],"sub_categories":["Android","数据绑定"],"readme":"[![Download](https://api.bintray.com/packages/moreno/maven/lastadapter/images/download.svg)](https://bintray.com/moreno/maven/lastadapter/_latestVersion)\n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-LastAdapter-brightgreen.svg?style=flat)](http://android-arsenal.com/details/1/3810)\n[![License](https://img.shields.io/badge/License-Apache%202.0-orange.svg)](https://opensource.org/licenses/Apache-2.0)\n[![Gitter](https://badges.gitter.im/nitrico/LastAdapter.svg)](https://gitter.im/nitrico/LastAdapter?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge)\n\n# LastAdapter\n\n**Don't write a RecyclerView adapter again. Not even a ViewHolder!**\n\n* Based on [**Android Data Binding**](https://developer.android.com/topic/libraries/data-binding/index.html)\n* Written in [**Kotlin**](http://kotlinlang.org)\n* No need to write the adapter\n* No need to write the viewholders\n* No need to modify your model classes\n* No need to notify the adapter when data set changes\n* Supports multiple item view types\n* Optional Callbacks/Listeners\n* Very fast — no reflection\n* Super easy API\n* Tiny size: **~30 KB**\n* Minimum Android SDK: **9**\n\n\n## Setup\n\n### Gradle\n\n```gradle\n// apply plugin: 'kotlin-kapt' // this line only for Kotlin projects\n\nandroid {\n    ...\n    dataBinding.enabled true \n}\n\ndependencies {\n    compile 'com.github.nitrico.lastadapter:lastadapter:2.3.0'\n    // kapt 'com.android.databinding:compiler:GRADLE_PLUGIN_VERSION' // this line only for Kotlin projects\n}\n```\n\n\n## Usage\n\nCreate your item layouts with `\u003clayout\u003e` as root:\n\n```xml\n\u003clayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\u003e\n\n    \u003cdata\u003e\n        \u003cvariable name=\"item\" type=\"com.github.nitrico.lastadapterproject.item.Header\"/\u003e\n    \u003c/data\u003e\n    \n    \u003cTextView\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"wrap_content\"\n        android:text=\"@{item.text}\"/\u003e\n        \n\u003c/layout\u003e\n```\n\n**It is important for all the item types to have the same variable name**, in this case \"item\". \nThis name is passed to the adapter builder as BR.variableName, in this case BR.item:\n\n```java\n// Java\nnew LastAdapter(listOfItems, BR.item)\n           .map(Header.class, R.layout.item_header)\n           .map(Point.class, R.layout.item_point)\n           .into(recyclerView);\n```\n```kotlin     \n// Kotlin\nLastAdapter(listOfItems, BR.item)\n           .map\u003cHeader\u003e(R.layout.item_header)\n           .map\u003cPoint\u003e(R.layout.item_point)\n           .into(recyclerView)\n```\n\nThe list of items can be an `ObservableList` if you want to get the adapter **automatically updated** when its content changes, or a simple `List` if you don't need to use this feature.\n\n\n### LayoutHandler\n\nThe LayoutHandler interface allows you to use different layouts based on more complex criteria. Its one single method receives the item and the position and returns the layout resource id.\n\n```java\n// Java sample\nnew LastAdapter(listOfItems, BR.item)\n           .handler(handler)\n           .into(recyclerView);\n\nprivate LayoutHandler handler = new LayoutHandler() {\n    @Override public int getItemLayout(@NotNull Object item, int position) {\n        if (item instanceof Header) {\n            return (position == 0) ? R.layout.item_header_first : R.layout.item_header;\n        } else {\n            return R.layout.item_point;\n        }\n    }\n};\n```\n```kotlin\n// Kotlin sample\nLastAdapter(listOfItems, BR.item).layout { item, position -\u003e\n    when (item) {\n        is Header -\u003e if (position == 0) R.layout.item_header_first else R.layout.item_header\n        else -\u003e R.layout.item_point \n    }\n}.into(recyclerView)\n```\n\nFor further information, please take a look at [my article at Medium](https://medium.com/@miguelangelmoreno/dont-write-recyclerview-adapters-b1dbc2c683bb).\n\n### Custom fonts\n\nYou might also want to try [**FontBinder**](https://github.com/nitrico/FontBinder) to easily use custom fonts in your XML layouts.\n\n\n## Acknowledgments\n\nThanks to **Yigit Boyar** and **George Mount** for [this talk](https://realm.io/news/data-binding-android-boyar-mount/).\n\n\n## Author\n\n#### Miguel Ángel Moreno\n\nI'm open to new job positions - Contact me!\n\n|[AngelList](https://angel.co/miguelangelmoreno)|[Email](mailto:nitrico@gmail.com)|[Facebook](https://www.facebook.com/miguelangelmoreno)|[Google+](https://plus.google.com/+Miguel%C3%81ngelMorenoS) |[Linked.in](https://www.linkedin.com/in/morenomiguelangel)|[Twitter](https://twitter.com/nitrico/)\n|---|---|---|---|---|---|\n\n\n## License\n\n```txt\nCopyright 2016 Miguel Ángel Moreno\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnitrico%2FLastAdapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnitrico%2FLastAdapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnitrico%2FLastAdapter/lists"}