You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.5 KiB
Kotlin
37 lines
1.5 KiB
Kotlin
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
package org.mozilla.fenix.library.recentlyclosed
|
|
|
|
import android.view.LayoutInflater
|
|
import android.view.ViewGroup
|
|
import androidx.recyclerview.widget.DiffUtil
|
|
import androidx.recyclerview.widget.ListAdapter
|
|
import mozilla.components.browser.state.state.ClosedTab
|
|
|
|
class RecentlyClosedAdapter(
|
|
private val interactor: RecentlyClosedFragmentInteractor
|
|
) : ListAdapter<ClosedTab, RecentlyClosedItemViewHolder>(DiffCallback) {
|
|
override fun onCreateViewHolder(
|
|
parent: ViewGroup,
|
|
viewType: Int
|
|
): RecentlyClosedItemViewHolder {
|
|
val view = LayoutInflater.from(parent.context)
|
|
.inflate(RecentlyClosedItemViewHolder.LAYOUT_ID, parent, false)
|
|
return RecentlyClosedItemViewHolder(view, interactor)
|
|
}
|
|
|
|
override fun onBindViewHolder(holder: RecentlyClosedItemViewHolder, position: Int) {
|
|
holder.bind(getItem(position))
|
|
}
|
|
|
|
private object DiffCallback : DiffUtil.ItemCallback<ClosedTab>() {
|
|
override fun areItemsTheSame(oldItem: ClosedTab, newItem: ClosedTab) =
|
|
oldItem.id == newItem.id || oldItem.title == newItem.title || oldItem.url == newItem.url
|
|
|
|
override fun areContentsTheSame(oldItem: ClosedTab, newItem: ClosedTab) =
|
|
oldItem.id == newItem.id || oldItem.title == newItem.title || oldItem.url == newItem.url
|
|
}
|
|
}
|