From bf17f8b99dd6ec12c015e41a4f937eca8af3dffb Mon Sep 17 00:00:00 2001 From: klaus Date: Thu, 1 Oct 2026 21:19:32 +0900 Subject: [PATCH] =?UTF-8?q?feat(gift):=20=EC=84=A0=EB=AC=BC=ED=95=A8=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=96=B4=EB=8C=91=ED=84=B0=EB=A5=BC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sodalive/v2/gift/ui/GiftInboxAdapter.kt | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 app/src/main/java/kr/co/vividnext/sodalive/v2/gift/ui/GiftInboxAdapter.kt diff --git a/app/src/main/java/kr/co/vividnext/sodalive/v2/gift/ui/GiftInboxAdapter.kt b/app/src/main/java/kr/co/vividnext/sodalive/v2/gift/ui/GiftInboxAdapter.kt new file mode 100644 index 00000000..87490a1d --- /dev/null +++ b/app/src/main/java/kr/co/vividnext/sodalive/v2/gift/ui/GiftInboxAdapter.kt @@ -0,0 +1,120 @@ +package kr.co.vividnext.sodalive.v2.gift.ui + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.core.view.isVisible +import androidx.recyclerview.widget.DiffUtil +import androidx.recyclerview.widget.ListAdapter +import androidx.recyclerview.widget.RecyclerView +import androidx.viewbinding.ViewBinding +import coil.load +import kr.co.vividnext.sodalive.R +import kr.co.vividnext.sodalive.databinding.ItemGiftInboxAddressBannerBinding +import kr.co.vividnext.sodalive.databinding.ItemGiftInboxEmptyReceivedBinding +import kr.co.vividnext.sodalive.databinding.ItemGiftInboxFooterBinding +import kr.co.vividnext.sodalive.databinding.ItemGiftInboxNoticeBannerBinding +import kr.co.vividnext.sodalive.databinding.ItemGiftInboxReceivedBinding +import kr.co.vividnext.sodalive.databinding.ItemGiftInboxSentBinding +import kr.co.vividnext.sodalive.v2.gift.GiftInboxCardUiModel +import kr.co.vividnext.sodalive.v2.gift.GiftInboxRow +import kr.co.vividnext.sodalive.v2.gift.GiftInboxRowType + +class GiftInboxAdapter( + private val onCardClick: (GiftInboxCardUiModel) -> Unit, + private val onInquiryClick: () -> Unit, + private val onRetryClick: () -> Unit +) : ListAdapter(RowDiff) { + class Holder(val binding: ViewBinding) : RecyclerView.ViewHolder(binding.root) + + override fun getItemViewType(position: Int) = getItem(position).type.ordinal + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder { + val inflater = LayoutInflater.from(parent.context) + val binding = when (GiftInboxRowType.entries[viewType]) { + GiftInboxRowType.NOTICE -> ItemGiftInboxNoticeBannerBinding.inflate(inflater, parent, false) + GiftInboxRowType.ADDRESS -> ItemGiftInboxAddressBannerBinding.inflate(inflater, parent, false) + GiftInboxRowType.SENT -> ItemGiftInboxSentBinding.inflate(inflater, parent, false) + GiftInboxRowType.RECEIVED -> ItemGiftInboxReceivedBinding.inflate(inflater, parent, false) + GiftInboxRowType.EMPTY_RECEIVED -> ItemGiftInboxEmptyReceivedBinding.inflate(inflater, parent, false).also { + it.root.minimumHeight = parent.height - parent.paddingTop - parent.paddingBottom + } + GiftInboxRowType.INQUIRY, GiftInboxRowType.LOADING, GiftInboxRowType.RETRY -> + ItemGiftInboxFooterBinding.inflate(inflater, parent, false) + } + return Holder(binding) + } + + override fun onBindViewHolder(holder: Holder, position: Int) { + val row = getItem(position) + val binding = holder.binding + val context = binding.root.context + when (binding) { + is ItemGiftInboxNoticeBannerBinding -> { + val received = (row as GiftInboxRow.Notice).received + binding.title.setText( + if (received) R.string.gift_inbox_received_notice_title else R.string.gift_inbox_sent_notice_title + ) + binding.body.setText( + if (received) R.string.gift_inbox_received_notice_body else R.string.gift_inbox_sent_notice_body + ) + } + is ItemGiftInboxAddressBannerBinding -> { + binding.root.setOnClickListener { onCardClick((row as GiftInboxRow.Address).card) } + } + is ItemGiftInboxSentBinding -> { + val card = (row as GiftInboxRow.Card).card + binding.counterpartNickname.text = card.counterpartNickname + binding.counterpartProfileImage.load(card.counterpartProfileImageUrl ?: R.drawable.ic_placeholder_profile) { + placeholder(R.drawable.ic_placeholder_profile) + fallback(R.drawable.ic_placeholder_profile) + error(R.drawable.ic_placeholder_profile) + } + binding.status.text = card.status.resId?.let(context::getString) ?: card.status.message + binding.date.isVisible = card.createdDate.isNotEmpty() + binding.date.text = context.getString(card.dateLabelRes, card.createdDate) + binding.details.text = context.getString(R.string.gift_inbox_details, card.sizeName, card.categoryName) + binding.root.setOnClickListener { onCardClick(card) } + } + is ItemGiftInboxReceivedBinding -> { + val card = (row as GiftInboxRow.Card).card + binding.counterpartNickname.text = card.counterpartNickname + binding.counterpartProfileImage.load(card.counterpartProfileImageUrl ?: R.drawable.ic_placeholder_profile) { + placeholder(R.drawable.ic_placeholder_profile) + fallback(R.drawable.ic_placeholder_profile) + error(R.drawable.ic_placeholder_profile) + } + binding.status.text = card.status.resId?.let(context::getString) ?: card.status.message + binding.date.isVisible = card.createdDate.isNotEmpty() + binding.date.text = context.getString(card.dateLabelRes, card.createdDate) + binding.subtitle.isVisible = card.subtitleRes != null + binding.subtitle.text = card.subtitleRes?.let(context::getString) + binding.root.setOnClickListener { onCardClick(card) } + } + is ItemGiftInboxEmptyReceivedBinding -> binding.feedback.setOnClickListener { onInquiryClick() } + is ItemGiftInboxFooterBinding -> { + binding.progress.isVisible = row == GiftInboxRow.Loading + binding.action.isVisible = row != GiftInboxRow.Loading + binding.action.setText(if (row == GiftInboxRow.Retry) R.string.gift_inbox_retry else R.string.gift_inbox_inquiry) + binding.action.setOnClickListener { + if (row == GiftInboxRow.Retry) onRetryClick() else onInquiryClick() + } + } + } + } + + private object RowDiff : DiffUtil.ItemCallback() { + override fun areItemsTheSame(oldItem: GiftInboxRow, newItem: GiftInboxRow): Boolean { + if (oldItem.type != newItem.type) return false + return when { + oldItem is GiftInboxRow.Card && newItem is GiftInboxRow.Card -> + oldItem.card.applicationNo == newItem.card.applicationNo + oldItem is GiftInboxRow.Notice && newItem is GiftInboxRow.Notice -> oldItem.received == newItem.received + oldItem is GiftInboxRow.Address && newItem is GiftInboxRow.Address -> + oldItem.card.applicationNo == newItem.card.applicationNo + else -> true + } + } + + override fun areContentsTheSame(oldItem: GiftInboxRow, newItem: GiftInboxRow) = oldItem == newItem + } +}