{"id":15374111,"url":"https://github.com/mrmike/diffutil-sample","last_synced_at":"2025-08-20T14:32:26.464Z","repository":{"id":141916897,"uuid":"66019427","full_name":"mrmike/DiffUtil-sample","owner":"mrmike","description":"Android sample app in Kotlin showing usage of DiffUtil class.","archived":false,"fork":false,"pushed_at":"2020-10-01T05:58:46.000Z","size":2468,"stargazers_count":210,"open_issues_count":1,"forks_count":41,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-12-10T02:11:00.901Z","etag":null,"topics":["android","android-sample","android-support","demo","diffutil","diffutil-sample","kotlin"],"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/mrmike.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}},"created_at":"2016-08-18T18:01:33.000Z","updated_at":"2024-12-09T06:08:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"5d9ed18e-572d-4512-bd6b-e6ddd40f7ef8","html_url":"https://github.com/mrmike/DiffUtil-sample","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/mrmike%2FDiffUtil-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrmike%2FDiffUtil-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrmike%2FDiffUtil-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrmike%2FDiffUtil-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrmike","download_url":"https://codeload.github.com/mrmike/DiffUtil-sample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230431103,"owners_count":18224655,"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-sample","android-support","demo","diffutil","diffutil-sample","kotlin"],"created_at":"2024-10-01T13:57:17.719Z","updated_at":"2024-12-19T12:11:17.855Z","avatar_url":"https://github.com/mrmike.png","language":"Kotlin","readme":"# DiffUtil Android Sample - Kotlin\nExample of usage [DiffUtil](https://developer.android.com/reference/android/support/v7/util/DiffUtil.html) utility class added originally in Support Library 24.2.0.\n\n## Demo\n![Demo](https://github.com/mrmike/DiffUtil-sample/blob/master/raw/diffutil-sample-320.gif?raw=true)\n\n## Implementation\n[*calculateDiff*](https://developer.android.com/reference/android/support/v7/util/DiffUtil.html#calculateDiff(android.support.v7.util.DiffUtil.Callback)) method from DiffUtill class requires [DiffUtil.Callback](https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback.html) object as parameter.\n\n### DiffUtil callback - [ActorDiffCallback.kt](https://github.com/mrmike/DiffUtil-sample/blob/master/app/src/main/java/com/moczul/diffutilsample/ActorDiffCallback.kt)\n\nImplements 4 methods:\n* **getOldListSize** - returns size of the old list\n* **getNewListSize** - returns size of the new list\n* **areItemsTheSame** - returns true if two items are the same, e.g. have the same ids \n* **areContentsTheSame** - returns true if displayed content was not changed. In our case we only display actor's name so we're detecing name's change.\n\n### Applying diff result - [ActorAdapter.swap()](https://github.com/mrmike/DiffUtil-sample/blob/master/app/src/main/java/com/moczul/diffutilsample/ActorAdapter.kt#L31)\n\nDiffResult can be applied to adapter by calling **`diffResult.dispatchUpdatesTo(adapter)`**.\n\n```\n    fun swap(actors: List\u003cActor\u003e) {\n            val diffCallback = ActorDiffCallback(this.actors, actors)\n            val diffResult = DiffUtil.calculateDiff(diffCallback)\n\n            this.actors.clear()\n            this.actors.addAll(actors)\n            diffResult.dispatchUpdatesTo(this)\n    }\n```\n\n## Resources\n* [DiffUtil @ developer.android.com](https://developer.android.com/reference/android/support/v7/util/DiffUtil.html)\n* [\"DiffUtil is a must!\" @ Medium](https://medium.com/@nullthemall/diffutil-is-a-must-797502bc1149#.sejum95wh)\n* [\"Diffing Larger Changes\" @ Codepath](http://guides.codepath.com/android/using-the-recyclerview#diffing-larger-changes)\n\n## License\n\n    Copyright 2016 Michał Moczulski\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","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrmike%2Fdiffutil-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrmike%2Fdiffutil-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrmike%2Fdiffutil-sample/lists"}