Created
July 4, 2021 15:10
-
-
Save ziginsider/4d320ea659d18213909743e3fab9ef93 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StopwatchAdapter: ListAdapter<Stopwatch, StopwatchViewHolder>(itemComparator) { | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): StopwatchViewHolder { | |
val layoutInflater = LayoutInflater.from(parent.context) | |
val binding = StopwatchItemBinding.inflate(layoutInflater, parent, false) | |
return StopwatchViewHolder(binding) | |
} | |
override fun onBindViewHolder(holder: StopwatchViewHolder, position: Int) { | |
holder.bind(getItem(position)) | |
} | |
private companion object { | |
private val itemComparator = object : DiffUtil.ItemCallback<Stopwatch>() { | |
override fun areItemsTheSame(oldItem: Stopwatch, newItem: Stopwatch): Boolean { | |
return oldItem.id == newItem.id | |
} | |
override fun areContentsTheSame(oldItem: Stopwatch, newItem: Stopwatch): Boolean { | |
return oldItem.currentMs == newItem.currentMs && | |
oldItem.isStarted == newItem.isStarted | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment