{"id":13428875,"url":"https://github.com/rahulchowdhury/Mystique","last_synced_at":"2025-03-16T02:30:41.732Z","repository":{"id":215760501,"uuid":"92713603","full_name":"rahulchowdhury/Mystique","owner":"rahulchowdhury","description":"💡🚀⭐️ A generalized adapter for RecyclerView on Android which makes it easy to add heterogeneous items to a list","archived":false,"fork":false,"pushed_at":"2017-06-01T13:14:48.000Z","size":181,"stargazers_count":47,"open_issues_count":0,"forks_count":8,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-27T06:39:21.590Z","etag":null,"topics":["android","android-library","gradle","kotlin","kotlin-android","kotlin-library","list","recyclerview-adapter","recyclerview-multi-type"],"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/rahulchowdhury.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":"2017-05-29T06:42:57.000Z","updated_at":"2023-08-13T11:44:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"fbacc102-536a-47f4-ab8b-b1c0b63ff5f6","html_url":"https://github.com/rahulchowdhury/Mystique","commit_stats":null,"previous_names":["rahulchowdhury/mystique"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahulchowdhury%2FMystique","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahulchowdhury%2FMystique/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahulchowdhury%2FMystique/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rahulchowdhury%2FMystique/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rahulchowdhury","download_url":"https://codeload.github.com/rahulchowdhury/Mystique/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243815605,"owners_count":20352195,"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","gradle","kotlin","kotlin-android","kotlin-library","list","recyclerview-adapter","recyclerview-multi-type"],"created_at":"2024-07-31T01:01:07.527Z","updated_at":"2025-03-16T02:30:41.713Z","avatar_url":"https://github.com/rahulchowdhury.png","language":"Kotlin","funding_links":[],"categories":["Libraries"],"sub_categories":["Android"],"readme":"[ ![Download](https://api.bintray.com/packages/rahulchowdhury/maven/mystique/images/download.svg) ](https://bintray.com/rahulchowdhury/maven/mystique/_latestVersion) [![Kotlin](https://img.shields.io/badge/Kotlin-1.1.2-green.svg)](http://kotlinlang.org/) [![API](https://img.shields.io/badge/API-19%2B-red.svg?style=flat)](https://android-arsenal.com/api?level=19) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Mystique-lightgrey.svg?style=flat)](https://android-arsenal.com/details/1/5826) [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)\n\n\u003cimg src=\"https://github.com/rahulchowdhury/Mystique/blob/master/docs/Mystique.png\" width=\"300px\" /\u003e\n\nMystique is a [Kotlin](http://kotlinlang.org/) library for Android’s `RecyclerView` which allows you to create homogeneous and heterogeneous lists effortlessly using an universal adapter. It’s `RecyclerView.Adapter` on steroids, written purely in Kotlin (_oh yeah, with extension functions too_).\n\n# Download\nYou can download this library through **jCenter** by one of the following ways,\n\n## Gradle\nAdd this line to your `build.gradle` file under the `dependencies` section along with any other library that you might use.\n\n```groovy\ndependencies {\n\tcompile 'co.upcurve.mystique:mystique:1.0'\n}\n```\n\n## Maven\nIf you prefer to use Maven, then add the following lines,\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003eco.upcurve.mystique\u003c/groupId\u003e\n  \u003cartifactId\u003emystique\u003c/artifactId\u003e\n  \u003cversion\u003e1.0\u003c/version\u003e\n  \u003ctype\u003epom\u003c/type\u003e\n\u003c/dependency\u003e\n```\n\n# Usage\nUsing this library is fairly simple. You need to create a data class which will be the model for your row data, and a presenter or item which extends `MystiqueItemPresenter`\n\n## Creating the model class\nThe model class is a regular data class which holds all the data that needs to be displayed in a single row inside the list, with however one special addition. \n\nYou need to annotate the presenter that will be used with this model class for Mystique to correctly recognize the presenter for this model class and bind both of them without any effort from your side.\n\n### NewsModel.kt\n\n```kotlin\n//Specify your presenter here in this format\n@Presenter(NewsItem::class)\ndata class NewsModel(var heading: String = \"\", \n\t\t     var desc: String = \"\",\n\t\t     var content: String = \"\")\n```\n\nPlease note, the model class needs to be `data` class for functions  like `removeItem()` to work.\n\nThat’s it, nothing more is required to add to your data class.\n\n## Creating your presenter or item class\nThe presenter or the item class is the place where you specify which layout should be inflated for the model and how to load data into the inflated view from your model according to your business logic. You can also add your custom click listeners here to handle clicks on the row or individual items in the row.\n\nConsider the following example class,\n\n### NewsItem.kt\n\n```kotlin\nclass NewsItem : MystiqueItemPresenter() {\n\n    //Declare your NewsModel object\n    lateinit private var newsModel: NewsModel\n\n    //Binding all the views in the row using ButterKnife\n    @BindView(R.id.heading_news)\n    lateinit var newsHeading: TextView\n\n    /**\n     * This is where you need to populate your data from the model\n     * to each element in the row according to your business logic\n     */\n    override fun displayView(itemView: View) {\n        ButterKnife.bind(this, itemView)\n\n        newsHeading.text = newsModel.heading\n    }\n\n    /**\n     * Return your model here for Mystic to do proper mapping\n     * while adding or deleting items from your list\n     */\n    override fun getModel() = newsModel\n\n    /**\n     * Return the layout associated with the model for Mystic\n     * to correctly inflate the proper views for each supplied\n     * model\n     */\n    override fun getLayout() = R.layout.view_item_news\n\n    /**\n     * This is where you initialize your model as supplied\n     * by Mystique through this method call\n     */\n    override fun loadModel(model: Any) {\n        newsModel = model as NewsModel\n    }\n\n    /**\n     * If you need to handle clicks on your items or\n     * items within your item, this is where you do it\n     * by adding your own custom listener (see sample)\n     */\n    override fun handleClickEvents(itemView: View) {\n\n    }\n\n    /**\n     * Initialize your custom listener in this function\n     * call, which will be called my Mystique while loading\n     * your data\n     */\n    override fun setListener(listener: Any?) {\n\n    }\n}\n```\n\nAnd, you’re all set!\n\n## Loading the models to the adapter\nThe next step is to load your models to the universal adapter, which is a breeze thanks to Mystique’s ***auto-binding*** of models to their respective presenters.\n\nOnce you have your data initialized in their appropriate model classes, declare a reference to your adapter and load the data in this fashion,\n\n```kotlin\n/**\n  * Initialize your adapter\n  */\nval adapter = MystiqueAdapter\u003cMystiqueItemPresenter\u003e()\n\n/**\n  * Set the models to the adapter for loading\n  */\nadapter.setItems(newsList.toMystifiedList())\n```\n\nHere, the extension function (_since it’s Kotlin_) converts a regular `List\u003cT\u003e` to a `MutableList\u003cMystiqueItemPresenter\u003e` by attaching all the appropriate models to their presenters behind the scenes for you.\n\nVoila! That’s all. Did you expect more?\n\n## Other functions\nMystique also defines other functions such as,\n\n### Add an item\n\n```kotlin\nfun \u003cT : MystiqueItemPresenter\u003e MystiqueAdapter\u003cT\u003e.addItem(item: T?, index: Int = mystiqueItems.size)\n```\n\n### Remove an item\n\n#### Using an index,\n\n```kotlin\nfun \u003cT : MystiqueItemPresenter\u003e MystiqueAdapter\u003cT\u003e.removeItem(index: Int = mystiqueItems.size - 1)\n```\n\n#### Using a model,\n\n```kotlin\nfun \u003cT : MystiqueItemPresenter\u003e MystiqueAdapter\u003cT\u003e.removeItem(model: Any)\n```\n\n### Add a list of items\n\n```kotlin\nfun \u003cT : MystiqueItemPresenter\u003e MystiqueAdapter\u003cT\u003e.addItems(items: List\u003cT\u003e, startPosition: Int = mystiqueItems.size)\n```\n\n### Remove a list of items\n\n```kotlin\nfun \u003cT : MystiqueItemPresenter\u003e MystiqueAdapter\u003cT\u003e.removeItems(items: List\u003cAny\u003e)\n```\n\n### Convert any object to a Mystified object\n\n```kotlin\nobject.toMystifiedItem()\n```\n\n# Sample app\nRefer to this section in this repo for a sample app using the library,\n\n[MystiqueSample](https://github.com/rahulchowdhury/Mystique/tree/master/app)\n\n# Contribution\nI have made this library as easy as possible to use, but I might have missed out some cool stuff. If you have something that you would like to add, fork the library, make your changes and please send a pull request.\n\nI would be happy to add your contribution to the library, if it improves the library.\n\n# Who made Mystique?\nWell the name of the library might be Mystique, but certainly the author is not a mystery.\n\n### Rahul Chowdhury\n\n[Blog](http://blog.rahulchowdhury.co/) | [Twitter](https://twitter.com/chowdhuryrahul) | [LinkedIn](https://www.linkedin.com/in/chowdhuryrahul/) | [Facebook](https://www.facebook.com/itsrcthegreat) | [Medium](https://medium.com/@rahulchowdhury)\n\n# License\n```\nCopyright 2017 Rahul Chowdhury\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\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frahulchowdhury%2FMystique","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frahulchowdhury%2FMystique","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frahulchowdhury%2FMystique/lists"}