feat(live): 온에어 라이브 목록 어댑터를 추가한다
This commit is contained in:
@@ -0,0 +1,68 @@
|
|||||||
|
package kr.co.vividnext.sodalive.v2.live.onair.ui
|
||||||
|
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
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.ItemHomeOnAirLiveBinding
|
||||||
|
import kr.co.vividnext.sodalive.extensions.loadUrl
|
||||||
|
import kr.co.vividnext.sodalive.v2.live.onair.model.HomeOnAirLivePriceUiModel
|
||||||
|
import kr.co.vividnext.sodalive.v2.live.onair.model.HomeOnAirLiveUiModel
|
||||||
|
|
||||||
|
class HomeOnAirLiveAdapter(
|
||||||
|
private val onClick: (HomeOnAirLiveUiModel) -> Unit
|
||||||
|
) : RecyclerView.Adapter<HomeOnAirLiveAdapter.ViewHolder>() {
|
||||||
|
private var items: List<HomeOnAirLiveUiModel> = emptyList()
|
||||||
|
|
||||||
|
fun submitItems(items: List<HomeOnAirLiveUiModel>) {
|
||||||
|
this.items = items
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
|
return ViewHolder(
|
||||||
|
ItemHomeOnAirLiveBinding.inflate(LayoutInflater.from(parent.context), parent, false),
|
||||||
|
onClick
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
|
holder.bind(items[position])
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount(): Int = items.size
|
||||||
|
|
||||||
|
class ViewHolder(
|
||||||
|
private val binding: ItemHomeOnAirLiveBinding,
|
||||||
|
private val onClick: (HomeOnAirLiveUiModel) -> Unit
|
||||||
|
) : RecyclerView.ViewHolder(binding.root) {
|
||||||
|
fun bind(item: HomeOnAirLiveUiModel) = with(binding) {
|
||||||
|
ivHomeOnAirLiveProfile.loadUrl(item.creatorProfileImage) {
|
||||||
|
crossfade(true)
|
||||||
|
placeholder(R.drawable.bg_placeholder)
|
||||||
|
transformations(CircleCropTransformation())
|
||||||
|
}
|
||||||
|
tvHomeOnAirLiveTime.text = item.liveTimeText.removePrefix("LIVE ")
|
||||||
|
tvHomeOnAirLiveTitle.text = item.title
|
||||||
|
tvHomeOnAirLiveCreator.text = item.creatorNickname
|
||||||
|
bindPrice(item.price)
|
||||||
|
root.setOnClickListener { onClick(item) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun bindPrice(price: HomeOnAirLivePriceUiModel) = with(binding) {
|
||||||
|
when (price) {
|
||||||
|
is HomeOnAirLivePriceUiModel.Paid -> {
|
||||||
|
ivHomeOnAirLiveCash.isVisible = true
|
||||||
|
tvHomeOnAirLivePrice.text = price.amountText
|
||||||
|
}
|
||||||
|
|
||||||
|
HomeOnAirLivePriceUiModel.Free -> {
|
||||||
|
ivHomeOnAirLiveCash.isVisible = false
|
||||||
|
tvHomeOnAirLivePrice.setText(R.string.screen_live_now_all_free)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user