diff --git a/app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/fantalk/ui/CreatorChannelFanTalkAdapter.kt b/app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/fantalk/ui/CreatorChannelFanTalkAdapter.kt new file mode 100644 index 00000000..4aa3fae4 --- /dev/null +++ b/app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/fantalk/ui/CreatorChannelFanTalkAdapter.kt @@ -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() { + + private var items: List = emptyList() + + fun submitItems(items: List) { + 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()) + } + } + } +} diff --git a/app/src/main/res/drawable/bg_creator_channel_fantalk_reply.xml b/app/src/main/res/drawable/bg_creator_channel_fantalk_reply.xml new file mode 100644 index 00000000..c410cc4e --- /dev/null +++ b/app/src/main/res/drawable/bg_creator_channel_fantalk_reply.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/layout/item_creator_channel_fantalk.xml b/app/src/main/res/layout/item_creator_channel_fantalk.xml new file mode 100644 index 00000000..ddab3bb1 --- /dev/null +++ b/app/src/main/res/layout/item_creator_channel_fantalk.xml @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +