{"id":13789823,"url":"https://github.com/ibrahimyilmaz/kiel","last_synced_at":"2025-05-12T07:31:06.210Z","repository":{"id":43484394,"uuid":"283586115","full_name":"ibrahimyilmaz/kiel","owner":"ibrahimyilmaz","description":"(Published to MavenCentral) Kotlin way of building RecyclerView Adapter 🧩. You do not have to write RecyclerView Adapters again and again and suffer from handling of different view types. Kiel will help you.","archived":false,"fork":false,"pushed_at":"2021-05-04T20:32:00.000Z","size":323,"stargazers_count":371,"open_issues_count":6,"forks_count":31,"subscribers_count":9,"default_branch":"develop","last_synced_at":"2024-11-18T04:34:53.862Z","etag":null,"topics":["android-library","kiel","kotlin","kotlin-android","recyclerview","recyclerview-adapter","viewholder","visitor-pattern"],"latest_commit_sha":null,"homepage":"","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/ibrahimyilmaz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-29T19:34:03.000Z","updated_at":"2024-10-28T09:53:47.000Z","dependencies_parsed_at":"2022-09-21T15:51:33.263Z","dependency_job_id":null,"html_url":"https://github.com/ibrahimyilmaz/kiel","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/ibrahimyilmaz%2Fkiel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibrahimyilmaz%2Fkiel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibrahimyilmaz%2Fkiel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibrahimyilmaz%2Fkiel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ibrahimyilmaz","download_url":"https://codeload.github.com/ibrahimyilmaz/kiel/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253695064,"owners_count":21948807,"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-library","kiel","kotlin","kotlin-android","recyclerview","recyclerview-adapter","viewholder","visitor-pattern"],"created_at":"2024-08-03T22:00:33.543Z","updated_at":"2025-05-12T07:31:05.741Z","avatar_url":"https://github.com/ibrahimyilmaz.png","language":"Kotlin","funding_links":[],"categories":["Index","Index `(light-weight pages)`"],"sub_categories":[],"readme":"![build](https://github.com/ibrahimyilmaz/kiel/workflows/build/badge.svg)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.ibrahimyilmaz/kiel/badge.svg?style=plastic)](https://maven-badges.herokuapp.com/maven-central/io.github.ibrahimyilmaz/kiel)\n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Kiel-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/8140)\n[![GitHub license](https://img.shields.io/github/license/ibrahimyilmaz/kiel)](https://github.com/ibrahimyilmaz/kiel/blob/develop/LICENSE)\n[![GitHub issues](https://img.shields.io/github/issues/ibrahimyilmaz/kiel)](https://github.com/ibrahimyilmaz/kiel/issues)\n[![GitHub stars](https://img.shields.io/github/stars/ibrahimyilmaz/kiel)](https://github.com/ibrahimyilmaz/kiel/stargazers)\n## Kiel\n\nKiel is a `RecyclerView.Adapter` with a minimalistic and convenient Kotlin DSL which provides utility on top of Android's normal `RecyclerView.Adapter`.\n\n\u003cimg alt=\"kiel_icon\" src=\"art/kiel_icon.svg\" width=\"250\"\u003e\n\nMost of the time:\n- We found ourselves repeating same boilerplate code for `RecyclerView.Adapter`.\n- We have difficulty in handling `RecyclerView.Adapter` when there are many `viewTypes`.\n\nBut now, Kiel may help us to get rid of these problems. You may read the detailed story in\n[this](https://medium.com/swlh/build-better-and-clean-recyclerview-adapter-with-kiel-a129882c1e1) blog post.\n\n## Usage:\n\n#### Basic Usage:\n\n##### adapterOf\n```kt\n val recyclerViewAdapter = adapterOf\u003cText\u003e {\n                register(\n                    layoutResource = R.layout.adapter_message_text_item,\n                    viewHolder = ::TextMessageViewHolder,\n                    onViewHolderCreated = { vh-\u003e\n                       //you may handle your on click listener\n                       vh.itemView.setOnClickListener {\n\n                       }\n                    },\n                    onBindViewHolder = { vh, _, it -\u003e\n                        vh.messageText.text = it.text\n                        vh.sentAt.text = it.sentAt\n                    }\n                )\n     }\n\n recyclerView.adapter = recyclerViewAdapter\n ```\n\n##### pagingDataAdapterOf\n```kt\n val pagingDataAdapterOf = pagingDataAdapterOf\u003cText\u003e {\n                register(\n                    layoutResource = R.layout.adapter_message_text_item,\n                    viewHolder = ::TextMessageViewHolder,\n                    onViewHolderCreated = { vh-\u003e\n                       //you may handle your on click listener\n                       vh.itemView.setOnClickListener {\n\n                       }\n                    },\n                    onBindViewHolder = { vh, _, it -\u003e\n                        vh.messageText.text = it.text\n                        vh.sentAt.text = it.sentAt\n                    }\n                )\n     }\n\n recyclerView.adapter = recyclerViewAdapter\n ```\n\n\n#### Different View Types:\n\nYou may register different `ViewHolder`s to your adapters.\n\n```kt\n              register(\n                    layoutResource = R.layout.adapter_message_text_item,\n                    viewHolder = ::TextMessageViewHolder,\n                    onBindViewHolder = { vh, _, it -\u003e\n                        vh.messageText.text = it.text\n                        vh.sentAt.text = it.sentAt\n                    }\n                )\n\n                register(\n                    layoutResource = R.layout.adapter_message_image_item,\n                    viewHolder = ::ImageMessageViewHolder,\n                    onBindViewHolder = { vh, _, item -\u003e\n                        vh.messageText.text = item.text\n                        vh.sentAt.text = item.sentAt\n\n                        Glide.with(vh.messageImage)\n                            .load(item.imageUrl)\n                            .into(vh.messageImage)\n                    }\n                )\n```\n#### Handling Events:\n\nAs `ViewHolder` instance is accessible in:\n- `onViewHolderCreated`\n- `onBindViewHolder`\n- `onBindViewHolderWithPayload`\n\n\nYou can handle the events in the same way how you did it before.\n```kt\n val recyclerViewAdapter = adapterOf\u003cText\u003e {\n                register(\n                    layoutResource = R.layout.adapter_message_text_it,\n                    viewHolder = ::TextMessageViewHolder,\n                    onViewHolderCreated = { vh-\u003e\n                       vh.itemView.setOnClickListener {\n\n                       }\n                       vh.messageText.addTextChangedListener{text -\u003e\n\n                       }\n                    },\n                    onBindViewHolder = { vh, _, it -\u003e\n                        vh.messageText.text = it.text\n                        vh.sentAt.text = it.sentAt\n                    }\n                )\n }\n\nrecyclerView.adapter = recyclerViewAdapter\n```\n#### View Binding:\n\nAs `ViewHolder` instance is accessible in:\n- `onViewHolderCreated`\n- `onBindViewHolder`\n- `onBindViewHolderWithPayload`\n\nYou may define your ViewBinding in your ViewHolder class and you can easily reach it:\n\n```kt\n\nclass TextMessageViewHolder(view: View) : RecyclerViewHolder\u003cText\u003e(view) {\n    val binding = AdapterTextItemBinding.bind(view)\n}\n\nval recyclerViewAdapter = adapterOf\u003cText\u003e {\n                register(\n                    layoutResource = R.layout.adapter_message_text_it,\n                    viewHolder = ::TextMessageViewHolder,\n                    onViewHolderCreated = { vh-\u003e\n                       vh.binding.\n                    },\n                    onBindViewHolder = { vh, _, it -\u003e\n                       vh.binding.messageText.text = it.text\n                       vh.binding.sentAt.text = it.sentAt\n                    }\n                )\n }\n```\n\n#### DiffUtil:\n\n```kt\nval recyclerViewAdapter = adapterOf\u003cMessageViewState\u003e {\n                diff(\n                    areContentsTheSame = { old, new -\u003e old == new },\n                    areItemsTheSame = { old, new -\u003e old.message.id == new.message.id },\n                    getChangePayload = { oldItem, newItem -\u003e\n                        val diffBundle = Bundle()\n\n                        if (oldItem.selectionState != newItem.selectionState) {\n                            diffBundle.putParcelable(\n                                TextMessageViewHolder.KEY_SELECTION,\n                                newItem.selectionState\n                            )\n                        }\n\n                        if (diffBundle.isEmpty) null else diffBundle\n                    }\n                )\n                register (\n                    layoutResource = R.layout.adapter_message_text_item,\n                    viewHolder = ::TextMessageViewHolder,\n                    onBindViewHolder = { vh, _, it -\u003e\n                        vh.messageText.text = it.message.text\n                        vh.sentAt.text = it.message.sentAt\n                    }\n                )\n\n```\nDownload\n--------\n\n```groovy\nimplementation 'io.github.ibrahimyilmaz:kiel:latestVersion'\n```\n\nlatestVersion = `1.2.1`\n\nLicense\n-------\n```\nCopyright 2020 Ibrahim Yilmaz\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%2Fibrahimyilmaz%2Fkiel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fibrahimyilmaz%2Fkiel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibrahimyilmaz%2Fkiel/lists"}