{"id":21331058,"url":"https://github.com/bobomee/databindingdemo","last_synced_at":"2025-03-16T00:41:55.117Z","repository":{"id":160854595,"uuid":"76571896","full_name":"BoBoMEe/DataBindingDemo","owner":"BoBoMEe","description":"A MultiType Recyclerview Adapter using Data Binding | 使用databinding实现适应多种type的Recyclerview adapter","archived":false,"fork":false,"pushed_at":"2017-02-23T05:46:35.000Z","size":56,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-22T13:46:50.389Z","etag":null,"topics":["databinding","mvvm-architecture","recyclerview-adapter"],"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/BoBoMEe.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-12-15T15:32:23.000Z","updated_at":"2017-02-23T04:05:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"27ff31cb-f876-49e9-8f9f-330594a07fb9","html_url":"https://github.com/BoBoMEe/DataBindingDemo","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/BoBoMEe%2FDataBindingDemo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoBoMEe%2FDataBindingDemo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoBoMEe%2FDataBindingDemo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BoBoMEe%2FDataBindingDemo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BoBoMEe","download_url":"https://codeload.github.com/BoBoMEe/DataBindingDemo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243809848,"owners_count":20351407,"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":["databinding","mvvm-architecture","recyclerview-adapter"],"created_at":"2024-11-21T22:28:47.210Z","updated_at":"2025-03-16T00:41:55.103Z","avatar_url":"https://github.com/BoBoMEe.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DataBindingDemos\n----\n\n[中文版 README](https://github.com/BoBoMEe/DataBindingDemo/blob/master/README_CN.md)\n\n## DataBinding RecyclerViewAdapter\n\nSuper simple RecyclerView adapter using Data Binding Technology, no longer need to write any adapter! You don't need to write any extra class like ViewHolder or ItemView.\n\nIt`s Based on [markzhai/DataBindingAdapter](https://github.com/markzhai/DataBindingAdapter) and [tianzhijiexian/CommonAdapter](https://github.com/tianzhijiexian/CommonAdapter)\n\nCombined with the Characteristics of the two, make `Adapter` easier to use\n\n## Get Started\n\n\n`AdapterItem`:\n\n```Java\npublic class EmployerItem implements AdapterItem\u003cEmployerViewModel\u003e {\n//...\n  @Override public int getLayoutResId() {\n    return R.layout.item_employer;// layout res\n  }\n\n  @Override public Integer getVariableId() {\n    return BR.item; // xml中的item\n  }\n\n  @Override public Decorator getDecorator() {\n    return null; // item Decorator\n  }\n\n  @Override public Map\u003cInteger, Object\u003e getBindData() {\n    Map\u003cInteger, Object\u003e map = new HashMap\u003c\u003e();\n    map.put(BR.presenter, new EmployerPresenter());\n    return map; // item \u003c-\u003e Variable\n  }\n\n  public class EmployerPresenter {//presenter\n    public void onItemClick(EmployerViewModel model) {\n      Toast.makeText(context, \"employer \" + model.name, Toast.LENGTH_SHORT).show();\n    }\n  }\n}\n```\n\n`CommonAdapter`:\n\n```Java\npublic class MainAdapter extends CommonAdapter {\n  //...\n  @NonNull @Override public AdapterItem createItem(int viewType) {\n    return adapterItem;\n  }\n\n  @Override public int getViewType(Object _o) {\n    return viewType;\n  }\n}\n```\n\n## Listener Binding\n\nAn easy way to add listener binding\n\n```java\n holder.getBinding().setVariable(key, value);\n```\nDo not have their own settings, only need to set up presenter，Such as：\n\n```java\n public class EmployerPresenter {//presenter\n    public void onItemClick(EmployerViewModel model) {\n      Toast.makeText(context, \"employer \" + model.name, Toast.LENGTH_SHORT).show();\n    }\n  }\n```\n\n## Decorator\n\nA Decorator is provided to let user implement and set ,With it we can do some extra works in onBindViewHolder\n\n```java\nAdapterItem.Decorator decorator = adapterItem.getDecorator();\n\nif (decorator != null) {\n      decorator.decorator(holder, position, getItemViewType(position));\n}\n\n//adapter\n@Override public Decorator getDecorator() {\n    return null; // return AdapterItem.Decorator\n  }\n```\n\n# Thanks\n\n- [markzhai/DataBindingAdapter](https://github.com/markzhai/DataBindingAdapter)\n- [tianzhijiexian/CommonAdapter](https://github.com/tianzhijiexian/CommonAdapter)\n\n# Links\n\n- [Android MVVM 之DataBinding,BindingAdapter及component](http://blog.csdn.net/wbwjx/article/details/53638715)\n\n# License\n\n    Copyright (C) 2016 BoBoMEe (wbwjx115@gmail.com).\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbobomee%2Fdatabindingdemo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbobomee%2Fdatabindingdemo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbobomee%2Fdatabindingdemo/lists"}