{"id":22378214,"url":"https://github.com/aminography/primeadapter","last_synced_at":"2025-07-31T00:30:58.002Z","repository":{"id":45909023,"uuid":"149086698","full_name":"aminography/PrimeAdapter","owner":"aminography","description":"PrimeAdapter makes working with RecyclerView easier.","archived":false,"fork":false,"pushed_at":"2019-12-20T11:54:22.000Z","size":4129,"stargazers_count":54,"open_issues_count":0,"forks_count":8,"subscribers_count":7,"default_branch":"master","last_synced_at":"2023-04-25T11:49:26.616Z","etag":null,"topics":["adapter","android","annotations","builder","kotlin","recyclerview","recyclerview-adapter"],"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/aminography.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-17T07:33:59.000Z","updated_at":"2022-09-02T09:53:14.000Z","dependencies_parsed_at":"2022-09-10T14:11:44.750Z","dependency_job_id":null,"html_url":"https://github.com/aminography/PrimeAdapter","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminography%2FPrimeAdapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminography%2FPrimeAdapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminography%2FPrimeAdapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminography%2FPrimeAdapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aminography","download_url":"https://codeload.github.com/aminography/PrimeAdapter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228198803,"owners_count":17883776,"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":["adapter","android","annotations","builder","kotlin","recyclerview","recyclerview-adapter"],"created_at":"2024-12-04T22:18:05.783Z","updated_at":"2024-12-04T22:18:06.442Z","avatar_url":"https://github.com/aminography.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `PrimeAdapter` :zap:\n[![Android Arsenal]( https://img.shields.io/badge/Android%20Arsenal-PrimeAdapter-brightgreen.svg?style=flat )]( https://android-arsenal.com/details/1/7178)\n[![API](https://img.shields.io/badge/API-11%2B-ffaa00.svg?style=flat)](https://android-arsenal.com/api?level=11)\n[![Download](https://api.bintray.com/packages/aminography/maven/PrimeAdapter/images/download.svg) ](https://bintray.com/aminography/maven/PrimeAdapter/_latestVersion)\n\u003c!-- [![Open-Source](https://badges.frapsoft.com/os/v2/open-source.svg?v=103)](https://github.com/aminography/PrimeAdapter) --\u003e\n  \n**`PrimeAdapter`** makes working with `RecyclerView` easier by separating required code in a few simple and well-structured classes.\nIt brings simplicity when you have multiple view types in a `RecyclerView`.\nBy using annotation processing, it generates unique view types automatically to make the code more clear.\nYou can use **`PrimeAdapter`** in both [Kotlin](https://github.com/aminography/PrimeAdapter/tree/master/sample-app) and [Java](https://github.com/aminography/PrimeAdapter/tree/master/java-sample-app) Android projects as the sample apps are written.\n  \n![](static/prime_logo.png)\n  \n| Custom Divider | Draggability | Expandability | \n| --- | --- | --- | \n![Example](https://media.giphy.com/media/mzhpG2SByqHtrSLCZ8/giphy.gif) | ![Example](https://media.giphy.com/media/64amX8wGab3BY8czuS/giphy.gif) | ![Example](https://media.giphy.com/media/TamHIVOnBDk1m1vdUd/giphy.gif) | \n\n\u003cbr/\u003e\n\nDownload\n--------\nAdd the following lines to your `build.gradle` file:\n```gradle\napply plugin: 'kotlin-android'\napply plugin: 'kotlin-android-extensions'\napply plugin: 'kotlin-kapt'\n  \nrepositories {\n    jcenter()\n}\n  \ndependencies {\n    implementation 'com.aminography:primeadapter:1.0.14'\n    compileOnly 'com.aminography:primeadapter-annotation:1.0.14'\n    kapt 'com.aminography:primeadapter-processor:1.0.14'\n}\n```\n\n* If you write code in Java, you should also add kotlin dependency too:\n```gradle\ndependencies {\n    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.50'\n}\n```\n\n\u003cbr/\u003e \n\nHow to use `PrimeAdapter`?\n--------\n  \nYou should create both **data holder** and **view holder** classes for each type of view that you want to show in `RecyclerView`.\n\n\u003cbr/\u003e\n\n**1.** It's necessary to add [`@DataHolder`](https://github.com/aminography/PrimeAdapter) annotation above all data holder classes which inherits from `PrimeDataHolder`:\n\n```kotlin\n@DataHolder\ndata class ActorDataHolder(\n        val name: String\n) : PrimeDataHolder()\n```\n \n**2.** Each view holder class should inherit from `PrimeViewHolder` and specify related data holder as a type parameter like following:\n\n```kotlin\nclass ActorViewHolder(\n        delegate: PrimeDelegate\n) : PrimeViewHolder\u003cActorDataHolder\u003e(delegate, R.layout.list_item) {\n  \n    override fun bindDataToView(dataHolder: ActorDataHolder) {\n        with(itemView) {\n            nameTextView.text = dataHolder.name\n        }\n    }\n}\n```\n  \n**3.** Your custom adapter class must inherit from **`PrimeAdapter`** that decides to make view holder instance based on data holder type.\nFollow this pattern:\n\n```kotlin\nclass ActorAdapter : PrimeAdapter() {\n  \n    override fun makeViewHolder(dataHolderClass: Class\u003c*\u003e?): PrimeViewHolder\u003c*\u003e? {\n        return when (dataHolderClass) {\n            ActorDataHolder::class.java -\u003e ActorViewHolder(this)\n            else -\u003e null\n        }\n    }\n}\n```\n\n**4.** Finally, you can instantiate your custom adapter using **`PrimeAdapter`** builder mechanism.\n\n```kotlin\noverride fun onCreate(savedInstanceState: Bundle?) {\n    super.onCreate(savedInstanceState)\n    setContentView(R.layout.activity_main)\n      \n    val adapter = PrimeAdapter.with(recyclerView)\n                    .setLayoutManager(LinearLayoutManager(activity))\n                    .set()\n                    .build(ActorAdapter::class.java)\n      \n    val dataList = mutableListOf\u003cPrimeDataHolder\u003e()\n    dataList.add(ActorDataHolder(\"Tom Hanks\"))\n    dataList.add(ActorDataHolder(\"Morgan Freeman\"))\n    dataList.add(ActorDataHolder(\"Robert De Niro\"))\n    adapter.replaceDataList(dataList)\n}\n```\n\n\u003cbr/\u003e\n\nExtra Features\n--------\n\n### Handling Item Clicks\n**`PrimeAdapter`** helps you handle `RecyclerView` items click events,\nsimply by `setItemClickListener()` with an `OnRecyclerViewItemClickListener` argument when you're building an adapter instance or later:\n\n```kotlin\nval onRecyclerViewItemClickListener = object: OnRecyclerViewItemClickListener{\n    override fun onItemClick(primeDataHolder: PrimeDataHolder) {\n        // do something\n    }\n    override fun onItemLongClick(primeDataHolder: PrimeDataHolder) {\n        // do something\n    }\n}\n\n// In builder pattern:\nval adapter = PrimeAdapter.with(recyclerView)\n                ...\n                .setItemClickListener(onRecyclerViewItemClickListener)\n                ...\n                .build(ActorAdapter::class.java)\n                \n// or after adapter instantiation:\nadapter.setItemClickListener(onRecyclerViewItemClickListener)\n```\n\n\u003cbr/\u003e\n\n### Draggability\n**`PrimeAdapter`** helps you make the `RecyclerView` items draggable.\nIt would be activated/deactivated by calling `setDraggable(true)`/`setDraggable(false)` on a builder or an adapter instance.\nOptionally, you can get notified about item movements by calling `setItemDragListener()` and passing an `OnRecyclerViewItemDragListener` instance to it.\n\n```kotlin\nadapter.setDraggable(true)\nadapter.setItemDragListener(object: OnRecyclerViewItemDragListener{\n    override fun onItemMoved(fromPosition: Int, toPosition: Int) {\n        // do something\n    }\n})\n```\nIt is necessary to introduce a view as handle of dragging in view holders which are going to be draggable: \n\n```kotlin\nclass ActorViewHolder(\n        delegate: PrimeDelegate\n) : PrimeViewHolder\u003cActorDataHolder\u003e(delegate, R.layout.list_item) {\n  \n    init {\n        setDragHandle(itemView)\n    }\n    ...\n}\n```\n\n\u003cbr/\u003e\n\n### Expandability\nAnother feature of **`PrimeAdapter`** is making the implementation of `RecyclerView` items expansion easier.\nCalling the `setExpandable(true)`/`setExpandable(false)` on a builder or on adapter instance changes its activation.\n\n```kotlin\nadapter.setExpandable(true)\n```\n\nTo see how to implement it, please check the [related example code][2].\n\n\u003cbr/\u003e\n\n### Custom Skippable Divider\nShowing custom divider lines is a good feature that **`PrimeAdapter`** provides.\nCalling the `setDivider()` on a builder or on adapter instance leads to show default divider line between items.\nIt's possible to pass it a custom `Drawable` instance or simply a color to change the divider looking.\nAlso we can set inset for divider drawables in pixels.\n\n```kotlin\n//----- default divider:\nadapter.setDivider()\n  \n//----- divider with custom drawable:\nadapter.setDivider(ContextCompat.getDrawable(context, R.drawable.divider))\n  \n//----- divider with custom color:\nadapter.setDivider(Color.RED)\n  \n//----- divider with custom color and custom inset:\nadapter.setDivider(Color.RED, insetLeft = 16, insetRight = 16)\n  \n//----- deactivate dividers:\nadapter.setDivider(null)\n```\nBy default dividers are shown for all items except the last one.\nIt's easy to skip some items divider by setting `hasDivider` property to `false` on their data holder instances.\n\n```kotlin\nadapter.getItem(position).hasDivider = false\nadapter.notifyDataSetChanged()\n```\n\n\u003cbr/\u003e\n\nProGuard\n--------\nIf you want to create a release version of your app, you need to include the following lines in the app level proguard file: \n```pro\n-keep class com.aminography.primeadapter.ViewTypeManager { *; }\n-keepclassmembers class ** {\n    @com.aminography.primeadapter.annotation.DataHolder *;\n}\n```\n\n\u003cbr/\u003e\n\nLicense\n--------\n```\nCopyright 2018 Mohammad Amin Hassani.\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\n[1]: https://github.com/aminography/PrimeAdapter/wiki\n[2]: https://github.com/aminography/PrimeAdapter/blob/master/sample-app/src/main/java/com/aminography/primeadapter/sample/view/viewholder/InstalledAppListViewHolder.kt\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faminography%2Fprimeadapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faminography%2Fprimeadapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faminography%2Fprimeadapter/lists"}