diff --git a/app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/donation/ui/CreatorChannelDonationAdapter.kt b/app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/donation/ui/CreatorChannelDonationAdapter.kt new file mode 100644 index 00000000..4592f920 --- /dev/null +++ b/app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/donation/ui/CreatorChannelDonationAdapter.kt @@ -0,0 +1,108 @@ +package kr.co.vividnext.sodalive.v2.creator.channel.donation.ui + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.GridLayoutManager +import androidx.recyclerview.widget.RecyclerView +import coil.transform.CircleCropTransformation +import kr.co.vividnext.sodalive.R +import kr.co.vividnext.sodalive.databinding.ItemCreatorChannelDonationBinding +import kr.co.vividnext.sodalive.databinding.ItemCreatorChannelDonationRankingBinding +import kr.co.vividnext.sodalive.extensions.loadUrl +import kr.co.vividnext.sodalive.extensions.moneyFormat +import kr.co.vividnext.sodalive.v2.creator.channel.donation.model.CreatorChannelDonationRankingUiModel +import kr.co.vividnext.sodalive.v2.creator.channel.donation.model.CreatorChannelDonationUiModel + +class CreatorChannelDonationAdapter( + private val onRankingAllClick: () -> Unit = { } +) : RecyclerView.Adapter() { + + private var items: List = emptyList() + + fun submitItems( + rankings: List, + donations: List + ) { + items = buildList { + if (rankings.isNotEmpty()) add(CreatorChannelDonationListItem.Ranking(rankings)) + donations.forEach { add(CreatorChannelDonationListItem.Donation(it)) } + } + notifyDataSetChanged() + } + + override fun getItemViewType(position: Int): Int = when (items[position]) { + is CreatorChannelDonationListItem.Ranking -> VIEW_TYPE_RANKING + is CreatorChannelDonationListItem.Donation -> VIEW_TYPE_DONATION + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { + return when (viewType) { + VIEW_TYPE_RANKING -> RankingViewHolder( + ItemCreatorChannelDonationRankingBinding.inflate(LayoutInflater.from(parent.context), parent, false), + onRankingAllClick + ) + else -> DonationViewHolder( + ItemCreatorChannelDonationBinding.inflate(LayoutInflater.from(parent.context), parent, false) + ) + } + } + + override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { + when (val item = items[position]) { + is CreatorChannelDonationListItem.Ranking -> (holder as RankingViewHolder).bind(item.rankings) + is CreatorChannelDonationListItem.Donation -> (holder as DonationViewHolder).bind(item.donation) + } + } + + override fun getItemCount(): Int = items.size + + class RankingViewHolder( + private val binding: ItemCreatorChannelDonationRankingBinding, + private val onRankingAllClick: () -> Unit + ) : RecyclerView.ViewHolder(binding.root) { + + private val rankingAdapter = CreatorChannelDonationRankingAdapter() + + init { + binding.rvCreatorChannelDonationRankingMembers.layoutManager = GridLayoutManager(itemView.context, 4) + binding.rvCreatorChannelDonationRankingMembers.adapter = rankingAdapter + binding.btnCreatorChannelDonationRankingAll.setOnClickListener { onRankingAllClick() } + } + + fun bind(rankings: List) { + rankingAdapter.submitItems(rankings) + } + } + + class DonationViewHolder( + private val binding: ItemCreatorChannelDonationBinding + ) : RecyclerView.ViewHolder(binding.root) { + + fun bind(item: CreatorChannelDonationUiModel) = with(binding) { + layoutCreatorChannelDonationHeader.setBackgroundColor(root.context.getColor(item.headerColorResId)) + ivCreatorChannelDonationProfile.loadUrl(item.profileImageUrl) { + crossfade(true) + placeholder(R.drawable.ic_placeholder_profile) + error(R.drawable.ic_placeholder_profile) + transformations(CircleCropTransformation()) + } + tvCreatorChannelDonationNickname.text = item.nickname + tvCreatorChannelDonationCreatedAt.text = item.createdAtText + tvCreatorChannelDonationCan.text = root.context.getString( + R.string.creator_channel_donation_can_format, + item.can.moneyFormat() + ) + tvCreatorChannelDonationMessage.text = item.message + } + } + + companion object { + private const val VIEW_TYPE_RANKING = 0 + private const val VIEW_TYPE_DONATION = 1 + } +} + +private sealed interface CreatorChannelDonationListItem { + data class Ranking(val rankings: List) : CreatorChannelDonationListItem + data class Donation(val donation: CreatorChannelDonationUiModel) : CreatorChannelDonationListItem +} diff --git a/app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/donation/ui/CreatorChannelDonationRankingAdapter.kt b/app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/donation/ui/CreatorChannelDonationRankingAdapter.kt new file mode 100644 index 00000000..bc5cb072 --- /dev/null +++ b/app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/donation/ui/CreatorChannelDonationRankingAdapter.kt @@ -0,0 +1,52 @@ +package kr.co.vividnext.sodalive.v2.creator.channel.donation.ui + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import coil.transform.CircleCropTransformation +import kr.co.vividnext.sodalive.R +import kr.co.vividnext.sodalive.databinding.ItemCreatorChannelDonationRankingMemberBinding +import kr.co.vividnext.sodalive.extensions.loadUrl +import kr.co.vividnext.sodalive.v2.creator.channel.donation.model.CreatorChannelDonationRankingUiModel + +class CreatorChannelDonationRankingAdapter : RecyclerView.Adapter() { + + private var items: List = emptyList() + + fun submitItems(items: List) { + this.items = items.take(MAX_VISIBLE_RANKING_COUNT) + notifyDataSetChanged() + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { + return ViewHolder( + ItemCreatorChannelDonationRankingMemberBinding.inflate(LayoutInflater.from(parent.context), parent, false) + ) + } + + override fun onBindViewHolder(holder: ViewHolder, position: Int) { + holder.bind(items[position]) + } + + override fun getItemCount(): Int = items.size + + class ViewHolder( + private val binding: ItemCreatorChannelDonationRankingMemberBinding + ) : RecyclerView.ViewHolder(binding.root) { + + fun bind(item: CreatorChannelDonationRankingUiModel) = with(binding) { + ivCreatorChannelDonationRankingProfile.loadUrl(item.profileImageUrl) { + crossfade(true) + placeholder(R.drawable.ic_placeholder_profile) + error(R.drawable.ic_placeholder_profile) + transformations(CircleCropTransformation()) + } + tvCreatorChannelDonationRankingRank.text = item.rank.toString() + tvCreatorChannelDonationRankingNickname.text = item.nickname + } + } + + companion object { + private const val MAX_VISIBLE_RANKING_COUNT = 8 + } +}