2024-03-29 00:10:55 -06:00
|
|
|
package com.isolaatti.search.presentation
|
|
|
|
|
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
|
import android.view.ViewGroup
|
|
|
|
|
import androidx.recyclerview.widget.DiffUtil
|
|
|
|
|
import androidx.recyclerview.widget.ListAdapter
|
|
|
|
|
import androidx.recyclerview.widget.RecyclerView.ViewHolder
|
|
|
|
|
import coil.load
|
|
|
|
|
import com.isolaatti.R
|
|
|
|
|
import com.isolaatti.databinding.UsersCarouselItemBinding
|
2024-04-28 01:09:50 -06:00
|
|
|
import com.isolaatti.profile.domain.entity.ProfileListItem
|
2024-03-29 00:10:55 -06:00
|
|
|
import com.isolaatti.search.data.ProfileSearchDto
|
|
|
|
|
import com.isolaatti.utils.UrlGen
|
|
|
|
|
|
|
|
|
|
class UserCarouselAdapter(
|
|
|
|
|
private val onProfileClick: (profileId: Int) -> Unit = {}
|
2024-04-28 01:09:50 -06:00
|
|
|
) : ListAdapter<ProfileListItem, UserCarouselAdapter.UserCarouselItemViewHolder>(itemCallback) {
|
2024-03-29 00:10:55 -06:00
|
|
|
|
|
|
|
|
companion object {
|
2024-04-28 01:09:50 -06:00
|
|
|
val itemCallback = object: DiffUtil.ItemCallback<ProfileListItem>() {
|
2024-03-29 00:10:55 -06:00
|
|
|
override fun areItemsTheSame(
|
2024-04-28 01:09:50 -06:00
|
|
|
oldItem: ProfileListItem,
|
|
|
|
|
newItem: ProfileListItem
|
2024-03-29 00:10:55 -06:00
|
|
|
): Boolean {
|
|
|
|
|
return oldItem.id == newItem.id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun areContentsTheSame(
|
2024-04-28 01:09:50 -06:00
|
|
|
oldItem: ProfileListItem,
|
|
|
|
|
newItem: ProfileListItem
|
2024-03-29 00:10:55 -06:00
|
|
|
): Boolean {
|
|
|
|
|
return oldItem == newItem
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inner class UserCarouselItemViewHolder(val usersCarouselItemBinding: UsersCarouselItemBinding) : ViewHolder(usersCarouselItemBinding.root)
|
|
|
|
|
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): UserCarouselItemViewHolder {
|
|
|
|
|
return UserCarouselItemViewHolder(UsersCarouselItemBinding.inflate(LayoutInflater.from(parent.context), parent, false))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: UserCarouselItemViewHolder, position: Int) {
|
|
|
|
|
val user = getItem(position)
|
|
|
|
|
|
|
|
|
|
holder.usersCarouselItemBinding.userCarouselName.text = user.name
|
2024-04-28 01:09:50 -06:00
|
|
|
if(user.profileImageId != null) {
|
|
|
|
|
holder.usersCarouselItemBinding.userCarouselImageView.load(UrlGen.imageUrl(user.profileImageId))
|
2024-03-29 00:10:55 -06:00
|
|
|
} else {
|
|
|
|
|
holder.usersCarouselItemBinding.userCarouselImageView.load(R.drawable.avatar)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
holder.usersCarouselItemBinding.userCarouselCard.setOnClickListener { onProfileClick(user.id) }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|