feat(creator): FanTalk 목록 아이템을 추가한다
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
package kr.co.vividnext.sodalive.v2.creator.channel.fantalk.ui
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import coil.transform.CircleCropTransformation
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.databinding.ItemCreatorChannelFantalkBinding
|
||||
import kr.co.vividnext.sodalive.extensions.loadUrl
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.fantalk.model.CreatorChannelFanTalkReplyUiModel
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.fantalk.model.CreatorChannelFanTalkRightAction
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.fantalk.model.CreatorChannelFanTalkUiModel
|
||||
|
||||
class CreatorChannelFanTalkAdapter(
|
||||
private val onOwnerMoreClick: (View, CreatorChannelFanTalkUiModel) -> Unit = { _, _ -> },
|
||||
private val onReportClick: (CreatorChannelFanTalkUiModel) -> Unit = { }
|
||||
) : RecyclerView.Adapter<CreatorChannelFanTalkAdapter.ViewHolder>() {
|
||||
|
||||
private var items: List<CreatorChannelFanTalkUiModel> = emptyList()
|
||||
|
||||
fun submitItems(items: List<CreatorChannelFanTalkUiModel>) {
|
||||
this.items = items
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return ViewHolder(
|
||||
ItemCreatorChannelFantalkBinding.inflate(LayoutInflater.from(parent.context), parent, false),
|
||||
onOwnerMoreClick,
|
||||
onReportClick
|
||||
)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
holder.bind(items[position])
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = items.size
|
||||
|
||||
class ViewHolder(
|
||||
private val binding: ItemCreatorChannelFantalkBinding,
|
||||
private val onOwnerMoreClick: (View, CreatorChannelFanTalkUiModel) -> Unit,
|
||||
private val onReportClick: (CreatorChannelFanTalkUiModel) -> Unit
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun bind(item: CreatorChannelFanTalkUiModel) = with(binding) {
|
||||
ivCreatorChannelFantalkProfile.loadProfile(item.writerProfileImageUrl)
|
||||
tvCreatorChannelFantalkNickname.text = item.writerNickname
|
||||
tvCreatorChannelFantalkTime.text = item.createdAtText
|
||||
tvCreatorChannelFantalkContent.text = item.content
|
||||
bindRightAction(item)
|
||||
bindReply(item.reply)
|
||||
}
|
||||
|
||||
private fun ItemCreatorChannelFantalkBinding.bindRightAction(item: CreatorChannelFanTalkUiModel) {
|
||||
when (item.rightAction) {
|
||||
CreatorChannelFanTalkRightAction.Report -> {
|
||||
tvCreatorChannelFantalkReport.isVisible = true
|
||||
tvCreatorChannelFantalkReport.setOnClickListener { onReportClick(item) }
|
||||
ivCreatorChannelFantalkMore.isVisible = false
|
||||
ivCreatorChannelFantalkMore.setOnClickListener(null)
|
||||
}
|
||||
is CreatorChannelFanTalkRightAction.OwnerMore -> {
|
||||
tvCreatorChannelFantalkReport.isVisible = false
|
||||
tvCreatorChannelFantalkReport.setOnClickListener(null)
|
||||
ivCreatorChannelFantalkMore.isVisible = true
|
||||
ivCreatorChannelFantalkMore.setOnClickListener { onOwnerMoreClick(it, item) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun ItemCreatorChannelFantalkBinding.bindReply(reply: CreatorChannelFanTalkReplyUiModel?) {
|
||||
val hasReply = reply != null
|
||||
viewCreatorChannelFantalkReplyConnector.isVisible = hasReply
|
||||
layoutCreatorChannelFantalkReply.isVisible = hasReply
|
||||
if (reply == null) return
|
||||
|
||||
ivCreatorChannelFantalkReplyProfile.loadProfile(reply.writerProfileImageUrl)
|
||||
tvCreatorChannelFantalkReplyNickname.text = reply.writerNickname
|
||||
tvCreatorChannelFantalkReplyTime.text = reply.createdAtText
|
||||
tvCreatorChannelFantalkReplyContent.text = reply.content
|
||||
}
|
||||
|
||||
private fun android.widget.ImageView.loadProfile(url: String) {
|
||||
loadUrl(url) {
|
||||
crossfade(true)
|
||||
placeholder(R.drawable.ic_placeholder_profile)
|
||||
error(R.drawable.ic_placeholder_profile)
|
||||
transformations(CircleCropTransformation())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user