{"id":17688730,"url":"https://github.com/boybeak/delegateadapter","last_synced_at":"2025-05-08T20:38:21.324Z","repository":{"id":87642750,"uuid":"76766613","full_name":"boybeak/DelegateAdapter","owner":"boybeak","description":"An advanced RecyclerView's Adapter.There is no need to custom an Adapter if you use this library. This library binds layout file, data and ViewHolder with Annotation.","archived":false,"fork":false,"pushed_at":"2020-07-29T19:15:27.000Z","size":14200,"stargazers_count":37,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-31T18:03:59.579Z","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/boybeak.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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-18T06:22:51.000Z","updated_at":"2020-07-29T19:15:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"3bee7cec-d056-40af-b45e-332dd5090cca","html_url":"https://github.com/boybeak/DelegateAdapter","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boybeak%2FDelegateAdapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boybeak%2FDelegateAdapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boybeak%2FDelegateAdapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/boybeak%2FDelegateAdapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/boybeak","download_url":"https://codeload.github.com/boybeak/DelegateAdapter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253146866,"owners_count":21861480,"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-10-24T11:45:17.621Z","updated_at":"2025-05-08T20:38:21.246Z","avatar_url":"https://github.com/boybeak.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"[ ![DelegateAdapter](https://api.bintray.com/packages/boybeak/nulldreams/adapter/images/download.svg) ](https://bintray.com/boybeak/nulldreams/adapter/_latestVersion)\n[ ![DelegateAdapter-Extension](https://api.bintray.com/packages/boybeak/nulldreams/adapter-extension/images/download.svg) ](https://bintray.com/boybeak/nulldreams/adapter-extension/_latestVersion)\n\n# ~~DelegateAdapter~~ \n\u003e Do not use this library ever. Try the more advanced one - [**AnyAdapter**](https://github.com/boybeak/AnyAdapter)\n\n\nThis is an advanced RecyclerView's Adapter library. With this library, writing custom adapter class is not necessary in most conditions. Using DelegateAdapter can satisfy most of what you need.\n\nThe most amazing thing is binding multi types data and ViewHolder with Injections.\n\n[Wiki](https://github.com/boybeak/DelegateAdapter/wiki)\n\n[中文Readme入口](https://github.com/boybeak/DelegateAdapter/blob/master/README_CN.md)\n\n[Selector](https://github.com/boybeak/DelegateAdapter/tree/master/selector)\n\n# Download\n\nGrab via Gradle:\n\n```groovy\ncompile 'com.github.boybeak:adapter:3.1.5'\ncompile 'com.github.boybeak:adapter-extension:2.2.6' //Optional\n```\n\n# What's new in version 3.x.x\n\n1. Reconstruct the library.\n2. Add extension library.\n\n\nYou can read a full [release note](https://github.com/boybeak/DelegateAdapter/blob/master/ReleaseNote.md).\n\n# Usage\n\n[Typical Usage](https://github.com/boybeak/DelegateAdapter/wiki/3.-Typical-Usage)\n\n[Advanced Usage](https://github.com/boybeak/DelegateAdapter/wiki/4.-Advanced-Usage)\n\n\n\n## Adapter\n\nThe most important class is [DelegateAdapter](https://github.com/boybeak/DelegateAdapter/blob/master/adapter/src/main/java/com/nulldreams/adapter/DelegateAdapter.java). With this adapter class, there's no need to make a your own custom adapter class.\n\n```java\nDelegateAdapter adapter = new DelegateAdapter (ActivityContext);\nRecyclerView rv = ...;\n//setLayoutManager etc;\nrv.setAdapter(adapter);\n```\n\n### Add data\n\nadapter add data like below:\n\n```java\nUserLayoutImpl userLayoutImpl = ...;\nUserDelegateImpl userDelegateImple = ...;\n\nUser user = ...;\nUserDelegate userDelegate = new UserDelegate (user);\nUserAnnotationDeleagate annoDelegate = new UserAnnotationDelegate (user);\n//create these User data or decode by gson from json\nadapter.add (userLayoutImpl);\nadapter.add (userDelegateImple);\nadapter.add (userDelegate);\nadapter.add (annoDelegate);\n//Don't forget notifyDataSetChanged();\nadapter.notifyDataSetChanged();\n```\n\nor you can add User model collection directly with a [DelegateParser](https://github.com/boybeak/DelegateAdapter/blob/master/adapter/src/main/java/com/nulldreams/adapter/DelegateParser.java).\n\n```java\nList\u003cUser\u003e userList = ...;//make this data your self, generally from json array\nmAdapter.addAll(userList, new DelegateParser\u003cUser\u003e() {\n    @Override\n    public LayoutImpl parse(DelegateAdapter adapter, User data) {\n      \treturn new UserDelegate(data); //return a LayoutImpl or its sub class\n    }\n});\n```\n\n### Query Data\n\nQuery data with conditions\n\n```java\n//query count\nint count = adapter.selector(UserDelegate.class)\n                .where(Path.with(UserDelegate.class, Integer.class).methodWith(\"getSource\").methodWith(\"getName\").methodWith(\"length\"), Operator.OPERATOR_GT, 4)\n                .count();\n\n//query names of users\nList\u003cString\u003e names = adapter.selector(UserDelegate.class)\n                .where(Path.with(UserDelegate.class, Integer.class).methodWith(\"getSource\").methodWith(\"getName\").methodWith(\"length\"), Operator.OPERATOR_GT, 4)\n                .extractAll(Path.with(UserDelegate.class, String.class).methodWith(\"getSource\").methodWith(\"getName\"));\n```\n\n\n\n## ViewHolder\n\nall your ViewHolder classes should extend [AbsViewHolder](https://github.com/boybeak/DelegateAdapter/blob/master/adapter/src/main/java/com/nulldreams/adapter/AbsViewHolder.java) class.\n\n```java\npublic class UserHolder extends AbsViewHolder\u003cUserDelegate\u003e {\n\n    private ImageView avatar;\n    private TextView nameTv, descTv;\n\n    public UserHolder(View itemView) {\n        super(itemView);\n        avatar = (ImageView)findViewById(R.id.avatar);\n        nameTv = (TextView)findViewById(R.id.name);\n        descTv = (TextView)findViewById(R.id.desc);\n    }\n\n    @Override\n    public void onBindView(Context context, UserDelegate userDelegate, int position, DelegateAdapter adapter) {\n        User user = userDelegate.getSource();\n        avatar.setImageResource(user.getAvatar());\n        nameTv.setText(user.getName() + \" - \" + getClass().getSimpleName());\n        descTv.setText(user.getDescription());\n    }\n}\n```\n\nIn this ViewHolder class you can bind data, bind event etc.\n\n## DelegateParser, DelegateListParser\n\nA serious of code snippets show you usage.\n\n```java\n/*DelegateParser*/\nUser[] users = ...; //Make your data yourself.\nadapter.addAll (users, new DelegateParser\u003cUser\u003e() {\n    @Override\n    public LayoutImpl parse(DelegateAdapter adapter, User data) {\n      \treturn new UserDelegate(data); //return a LayoutImpl or its sub class\n    }\n});\n```\n\n```java\n/*DelegateListParser*/\nUser[] users = ...; //Make your data yourself.\nadapter.addAll (users, new DelegateListParser () {\n    public List\u003cLayoutImpl\u003e parse (DelegateAdapter adapter, User data) {\n\t\tList\u003cLayoutImpl\u003e list = new ArrayList\u003cLayoutImpl\u003e();\n      \tlist.add (new UserHeaderDelegate(\"I'm a good teacher\"));\n      \tlist.add (new UserDelegate (data));\n      \tif (data.isGood()) {\n        \tlist.add(new UserFooterDelegate (\"I am really a good teacher!\"));\n      \t}\n      \treturn list;\n    }\n});\n```\n\n\n\n## DataChange\n\n[**DelegateAdapter** ](https://github.com/boybeak/DelegateAdapter/blob/master/adapter/src/main/java/com/nulldreams/adapter/DelegateAdapter.java) returns a [DataChange](https://github.com/boybeak/DelegateAdapter/blob/master/adapter/src/main/java/com/nulldreams/adapter/DataChange.java) instance after add, addAll and remove actions. You can call autoNotify directly.\n\n```java\nmAdapter.add(new TextDelegate(\"The Beatles\")).autoNotify();\n```\n\n```java\nmAdapter.remove(4).autoNotify();\n```\n\n```java\nmAdapter.addAll(Data.getTwitterList(v), new DelegateParser\u003cTwitter\u003e() {\n                    @Override\n                    public DelegateImpl parse(DelegateAdapter adapter, Twitter data) {\n                        return new TwitterDelegate(data);\n                    }\n                }).autoNotify();\n```\n\n## Item swap and delete\n\n```java\nmRv = (RecyclerView)findViewById(R.id.main_rv);\n\nmAdapter = new TouchableAdapter(this);\nmRv.setAdapter(mAdapter);\n\nItemTouchHelper helper = new ItemTouchHelper(new SimpleItemTouchHelperCallback(mAdapter,\n                ItemTouchHelper.UP|ItemTouchHelper.DOWN, ItemTouchHelper.END));\nhelper.attachToRecyclerView(mRv);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboybeak%2Fdelegateadapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboybeak%2Fdelegateadapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboybeak%2Fdelegateadapter/lists"}