RcvListDiffUtilCallBack

class RcvListDiffUtilCallBack<ITEM>(itemsTheSame: (oldItem: ITEM, newItem: ITEM) -> Boolean, contentsTheSame: (oldItem: ITEM, newItem: ITEM) -> Boolean, changePayload: (oldItem: ITEM, newItem: ITEM) -> Any?? = null) : DiffUtil.ItemCallback<ITEM>

DiffUtil.ItemCallback implementation for RecyclerView ListAdapter.
Provides lambda-based item comparison for efficient list updates.

RecyclerView ListAdapter를 위한 DiffUtil.ItemCallback 구현체입니다.
효율적인 리스트 업데이트를 위한 람다 기반 아이템 비교를 제공합니다.

Features:

  • Lambda-based flexible item comparison

  • Support for identity and content comparison

  • Optional payload generation for partial updates

  • Generic type support for any item type

    기능:

  • 람다 기반 유연한 아이템 비교

  • 동일성 및 내용 비교 지원

  • 부분 업데이트를 위한 선택적 payload 생성

  • 모든 아이템 타입에 대한 제네릭 타입 지원

Usage example:

val diffUtil = RcvListDiffUtilCallBack<User>(
itemsTheSame = { old, new -> old.id == new.id },
contentsTheSame = { old, new -> old == new },
changePayload = { old, new ->
if (old.name != new.name) "name" else null
}
)

Parameters

ITEM

The type of items to compare.

비교할 아이템의 타입.

itemsTheSame

Lambda to check if two items represent the same entity (e.g., ID comparison).

두 아이템이 같은 항목인지 확인하는 람다 (예: ID 비교).

contentsTheSame

Lambda to check if two items have the same content.

두 아이템의 내용이 같은지 확인하는 람다.

changePayload

Lambda to generate payload for partial updates when items are the same but contents differ (nullable).

아이템이 같지만 내용이 다를 때 부분 업데이트용 payload를 생성하는 람다 (null 가능).

See also

BaseRcvListAdapter

For the ListAdapter that uses this DiffUtil callback.

이 DiffUtil 콜백을 사용하는 ListAdapter는 BaseRcvListAdapter를 참조하세요.

Constructors

Link copied to clipboard
constructor(itemsTheSame: (oldItem: ITEM, newItem: ITEM) -> Boolean, contentsTheSame: (oldItem: ITEM, newItem: ITEM) -> Boolean, changePayload: (oldItem: ITEM, newItem: ITEM) -> Any?? = null)

Functions

Link copied to clipboard
open override fun areContentsTheSame(oldItem: ITEM & Any, newItem: ITEM & Any): Boolean

Checks if two items have the same content.
Called only when areItemsTheSame returns true.

두 아이템의 내용이 같은지 확인합니다.
areItemsTheSame이 true를 반환할 때만 호출됩니다.

Link copied to clipboard
open override fun areItemsTheSame(oldItem: ITEM & Any, newItem: ITEM & Any): Boolean

Checks if two items represent the same entity.
Used to determine if an item was moved or changed.

두 아이템이 같은 항목을 나타내는지 확인합니다.
아이템이 이동되었는지 또는 변경되었는지 판단하는 데 사용됩니다.

Link copied to clipboard
open override fun getChangePayload(oldItem: ITEM & Any, newItem: ITEM & Any): Any?

Returns payload for partial update when items are the same but contents differ.
Called only when areItemsTheSame returns true and areContentsTheSame returns false.

아이템이 같지만 내용이 다를 때 부분 업데이트용 payload를 반환합니다.
areItemsTheSame이 true를 반환하고 areContentsTheSame이 false를 반환할 때만 호출됩니다.