refactor(creator): 라이브 replay adapter를 공통화한다
This commit is contained in:
@@ -13,7 +13,7 @@ import kr.co.vividnext.sodalive.extensions.dpToPx
|
||||
import kr.co.vividnext.sodalive.extensions.moneyFormat
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.data.CreatorChannelLiveResponse
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.live.model.toReplayUiModel
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.live.ui.CreatorChannelLiveReplayAdapter
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.ui.CreatorChannelAudioContentAdapter
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.model.toLabelResId
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.ui.formatCreatorChannelLiveDateTime
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.ui.CreatorChannelSortPopup
|
||||
@@ -24,7 +24,7 @@ class CreatorChannelLiveFragment : BaseFragment<FragmentCreatorChannelLiveBindin
|
||||
) {
|
||||
|
||||
private val viewModel: CreatorChannelLiveViewModel by viewModel()
|
||||
private val replayAdapter = CreatorChannelLiveReplayAdapter { item ->
|
||||
private val replayAdapter = CreatorChannelAudioContentAdapter { item ->
|
||||
host.onCreatorChannelLiveReplayClicked(item.audioContentId)
|
||||
}
|
||||
private var lastContentLayoutKey: CreatorChannelLiveContentLayoutKey? = null
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package kr.co.vividnext.sodalive.v2.creator.channel.live.model
|
||||
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.data.CreatorChannelAudioContentResponse
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.model.CreatorChannelAudioContentStatus
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.model.CreatorChannelAudioContentUiModel
|
||||
import kr.co.vividnext.sodalive.v2.widget.AudioContentTag
|
||||
|
||||
fun CreatorChannelAudioContentResponse.toReplayUiModel(): CreatorChannelLiveReplayUiModel =
|
||||
CreatorChannelLiveReplayUiModel(
|
||||
fun CreatorChannelAudioContentResponse.toReplayUiModel(): CreatorChannelAudioContentUiModel =
|
||||
CreatorChannelAudioContentUiModel(
|
||||
audioContentId = audioContentId,
|
||||
title = title,
|
||||
secondaryText = duration,
|
||||
@@ -22,9 +24,9 @@ private fun CreatorChannelAudioContentResponse.toAudioContentTags(): Set<AudioCo
|
||||
if (price == 0) add(AudioContentTag.Free)
|
||||
}
|
||||
|
||||
private fun CreatorChannelAudioContentResponse.toReplayStatus(): CreatorChannelLiveReplayStatus = when {
|
||||
isOwned -> CreatorChannelLiveReplayStatus.Owned
|
||||
isRented -> CreatorChannelLiveReplayStatus.Rented
|
||||
price == 0 -> CreatorChannelLiveReplayStatus.Play
|
||||
else -> CreatorChannelLiveReplayStatus.Price(price)
|
||||
private fun CreatorChannelAudioContentResponse.toReplayStatus(): CreatorChannelAudioContentStatus = when {
|
||||
isOwned -> CreatorChannelAudioContentStatus.Owned
|
||||
isRented -> CreatorChannelAudioContentStatus.Rented
|
||||
price == 0 -> CreatorChannelAudioContentStatus.Play
|
||||
else -> CreatorChannelAudioContentStatus.Price(price)
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package kr.co.vividnext.sodalive.v2.creator.channel.live.model
|
||||
|
||||
import kr.co.vividnext.sodalive.v2.widget.AudioContentTag
|
||||
|
||||
data class CreatorChannelLiveReplayUiModel(
|
||||
val audioContentId: Long,
|
||||
val title: String,
|
||||
val secondaryText: String?,
|
||||
val imageUrl: String?,
|
||||
val price: Int,
|
||||
val showAdultBadge: Boolean,
|
||||
val tags: Set<AudioContentTag>,
|
||||
val status: CreatorChannelLiveReplayStatus
|
||||
)
|
||||
|
||||
sealed interface CreatorChannelLiveReplayStatus {
|
||||
data object Play : CreatorChannelLiveReplayStatus
|
||||
data object Owned : CreatorChannelLiveReplayStatus
|
||||
data object Rented : CreatorChannelLiveReplayStatus
|
||||
data class Price(val price: Int) : CreatorChannelLiveReplayStatus
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package kr.co.vividnext.sodalive.v2.creator.channel.live.ui
|
||||
package kr.co.vividnext.sodalive.v2.creator.channel.ui
|
||||
|
||||
import android.graphics.Outline
|
||||
import android.view.LayoutInflater
|
||||
@@ -11,17 +11,17 @@ import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.databinding.ItemCreatorChannelAudioContentBinding
|
||||
import kr.co.vividnext.sodalive.extensions.loadUrl
|
||||
import kr.co.vividnext.sodalive.extensions.moneyFormat
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.live.model.CreatorChannelLiveReplayStatus
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.live.model.CreatorChannelLiveReplayUiModel
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.model.CreatorChannelAudioContentStatus
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.model.CreatorChannelAudioContentUiModel
|
||||
import kr.co.vividnext.sodalive.v2.widget.AudioContentTag
|
||||
|
||||
class CreatorChannelLiveReplayAdapter(
|
||||
private val onReplayClick: (CreatorChannelLiveReplayUiModel) -> Unit = {}
|
||||
) : RecyclerView.Adapter<CreatorChannelLiveReplayAdapter.ViewHolder>() {
|
||||
class CreatorChannelAudioContentAdapter(
|
||||
private val onAudioContentClick: (CreatorChannelAudioContentUiModel) -> Unit = {}
|
||||
) : RecyclerView.Adapter<CreatorChannelAudioContentAdapter.ViewHolder>() {
|
||||
|
||||
private var items: List<CreatorChannelLiveReplayUiModel> = emptyList()
|
||||
private var items: List<CreatorChannelAudioContentUiModel> = emptyList()
|
||||
|
||||
fun submitItems(items: List<CreatorChannelLiveReplayUiModel>) {
|
||||
fun submitItems(items: List<CreatorChannelAudioContentUiModel>) {
|
||||
this.items = items
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
@@ -29,7 +29,7 @@ class CreatorChannelLiveReplayAdapter(
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return ViewHolder(
|
||||
ItemCreatorChannelAudioContentBinding.inflate(LayoutInflater.from(parent.context), parent, false),
|
||||
onReplayClick
|
||||
onAudioContentClick
|
||||
)
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class CreatorChannelLiveReplayAdapter(
|
||||
|
||||
class ViewHolder(
|
||||
private val binding: ItemCreatorChannelAudioContentBinding,
|
||||
private val onReplayClick: (CreatorChannelLiveReplayUiModel) -> Unit
|
||||
private val onAudioContentClick: (CreatorChannelAudioContentUiModel) -> Unit
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
init {
|
||||
@@ -59,7 +59,7 @@ class CreatorChannelLiveReplayAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
fun bind(item: CreatorChannelLiveReplayUiModel) = with(binding) {
|
||||
fun bind(item: CreatorChannelAudioContentUiModel) = with(binding) {
|
||||
ivCreatorChannelAudioContentThumbnail.loadUrl(item.imageUrl)
|
||||
tvCreatorChannelAudioContentTitle.text = item.title
|
||||
tvCreatorChannelAudioContentSecondaryText.text = item.secondaryText.orEmpty()
|
||||
@@ -71,24 +71,24 @@ class CreatorChannelLiveReplayAdapter(
|
||||
bindTag(ivCreatorChannelAudioContentPointTag, AudioContentTag.Point, item.tags)
|
||||
tvCreatorChannelAudioContentFreeTag.isVisible = AudioContentTag.Free in item.tags
|
||||
bindStatus(item.status)
|
||||
root.setOnClickListener { onReplayClick(item) }
|
||||
root.setOnClickListener { onAudioContentClick(item) }
|
||||
}
|
||||
|
||||
private fun bindTag(view: View, tag: AudioContentTag, tags: Set<AudioContentTag>) {
|
||||
view.isVisible = tag in tags
|
||||
}
|
||||
|
||||
private fun bindStatus(status: CreatorChannelLiveReplayStatus) = with(binding) {
|
||||
private fun bindStatus(status: CreatorChannelAudioContentStatus) = with(binding) {
|
||||
ivCreatorChannelAudioContentPlay.setImageResource(R.drawable.ic_new_player_play)
|
||||
when (status) {
|
||||
CreatorChannelLiveReplayStatus.Play -> {
|
||||
CreatorChannelAudioContentStatus.Play -> {
|
||||
ivCreatorChannelAudioContentPlay.isVisible = true
|
||||
ivCreatorChannelAudioContentCan.isVisible = false
|
||||
layoutCreatorChannelAudioContentActionText.isVisible = false
|
||||
}
|
||||
CreatorChannelLiveReplayStatus.Owned -> bindTextStatus(R.string.audio_content_badge_owned)
|
||||
CreatorChannelLiveReplayStatus.Rented -> bindTextStatus(R.string.audio_content_badge_rented)
|
||||
is CreatorChannelLiveReplayStatus.Price -> {
|
||||
CreatorChannelAudioContentStatus.Owned -> bindTextStatus(R.string.audio_content_badge_owned)
|
||||
CreatorChannelAudioContentStatus.Rented -> bindTextStatus(R.string.audio_content_badge_rented)
|
||||
is CreatorChannelAudioContentStatus.Price -> {
|
||||
ivCreatorChannelAudioContentPlay.isVisible = false
|
||||
layoutCreatorChannelAudioContentActionText.isVisible = true
|
||||
ivCreatorChannelAudioContentCan.isVisible = true
|
||||
Reference in New Issue
Block a user