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
|
||||
@@ -119,7 +119,7 @@ class CreatorChannelLiveFragmentLayoutTest {
|
||||
val item = inflateView(R.layout.item_creator_channel_audio_content)
|
||||
val itemLayout = projectFile("app/src/main/res/layout/item_creator_channel_audio_content.xml").readText()
|
||||
val adapter = projectFile(
|
||||
"app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/live/ui/CreatorChannelLiveReplayAdapter.kt"
|
||||
"app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/ui/CreatorChannelAudioContentAdapter.kt"
|
||||
).readText()
|
||||
val thumbnail = requireNotNull(item.findViewById<View>(R.id.layout_creator_channel_audio_content_thumbnail))
|
||||
|
||||
@@ -195,7 +195,7 @@ class CreatorChannelLiveFragmentLayoutTest {
|
||||
"app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/live/CreatorChannelLiveFragment.kt"
|
||||
).readText()
|
||||
val adapter = projectFile(
|
||||
"app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/live/ui/CreatorChannelLiveReplayAdapter.kt"
|
||||
"app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/ui/CreatorChannelAudioContentAdapter.kt"
|
||||
).readText()
|
||||
val layout = projectFile("app/src/main/res/layout/fragment_creator_channel_live.xml").readText()
|
||||
val eagerLoadOnViewCreated = """
|
||||
@@ -250,22 +250,23 @@ class CreatorChannelLiveFragmentLayoutTest {
|
||||
).readText()
|
||||
val fragmentLayout = projectFile("app/src/main/res/layout/fragment_creator_channel_live.xml").readText()
|
||||
|
||||
assertTrue(activityLayout.contains("android:id=\"@+id/layout_creator_channel_live_owner_cta\""))
|
||||
assertTrue(activityLayout.contains("android:id=\"@+id/layout_creator_channel_owner_cta\""))
|
||||
assertTrue(activityLayout.contains("android:layout_height=\"100dp\""))
|
||||
assertTrue(activityLayout.contains("android:background=\"@color/black\""))
|
||||
assertTrue(activityLayout.contains("android:id=\"@+id/btn_creator_channel_live_owner_cta\""))
|
||||
assertTrue(activityLayout.contains("android:id=\"@+id/btn_creator_channel_owner_cta\""))
|
||||
assertTrue(activityLayout.contains("android:layout_marginHorizontal=\"@dimen/spacing_14\""))
|
||||
assertTrue(activityLayout.contains("android:layout_marginTop=\"@dimen/spacing_14\""))
|
||||
assertTrue(activityLayout.contains("@drawable/bg_creator_channel_owner_fab"))
|
||||
assertTrue(activityLayout.contains("@drawable/ic_new_create_live"))
|
||||
assertTrue(activityLayout.contains("@string/creator_channel_live_start_button"))
|
||||
assertTrue(activity.contains("setupLiveOwnerCtaInsets()"))
|
||||
assertTrue(activity.contains("updateLiveOwnerCtaVisibility()"))
|
||||
assertTrue(activity.contains("binding.viewPager.currentItem == CreatorChannelTab.Live.ordinal"))
|
||||
assertTrue(activity.contains("binding.layoutCreatorChannelLiveOwnerCta.isVisible = shouldShowLiveOwnerCta"))
|
||||
assertTrue(activity.contains("setupOwnerCtaInsets()"))
|
||||
assertTrue(activity.contains("updateOwnerCtaVisibility()"))
|
||||
assertTrue(activity.contains("CreatorChannelTab.Live.ordinal -> CreatorChannelTab.Live"))
|
||||
assertTrue(activity.contains("CreatorChannelTab.Audio.ordinal -> CreatorChannelTab.Audio"))
|
||||
assertTrue(activity.contains("binding.layoutCreatorChannelOwnerCta.isVisible = shouldShowOwnerCta"))
|
||||
assertTrue(
|
||||
activity.contains(
|
||||
"findLiveFragment()?.onCreatorChannelLiveOwnerCtaVisibilityChanged(shouldShowLiveOwnerCta)"
|
||||
"findLiveFragment()?.onCreatorChannelLiveOwnerCtaVisibilityChanged(ownerCtaTab == CreatorChannelTab.Live)"
|
||||
)
|
||||
)
|
||||
assertTrue(fragment.contains("fun onCreatorChannelLiveOwnerCtaVisibilityChanged(isVisible: Boolean)"))
|
||||
@@ -273,10 +274,10 @@ class CreatorChannelLiveFragmentLayoutTest {
|
||||
assertTrue(fragment.contains("LIVE_OWNER_CTA_LIST_BOTTOM_PADDING_DP.dpToPx().toInt()"))
|
||||
assertTrue(fragment.contains("DEFAULT_LIST_BOTTOM_PADDING_DP.dpToPx().toInt()"))
|
||||
assertTrue(fragment.contains("rvCreatorChannelLiveReplays.updatePadding(bottom = bottomPadding)"))
|
||||
assertTrue(activity.contains("binding.btnCreatorChannelLiveOwnerCta.setOnClickListener"))
|
||||
assertTrue(activity.contains("binding.btnCreatorChannelOwnerCta.setOnClickListener"))
|
||||
assertTrue(activity.contains("onOwnerFabLiveClicked()"))
|
||||
assertFalse(fragmentLayout.contains("android:id=\"@+id/layout_creator_channel_live_owner_cta\""))
|
||||
assertFalse(fragment.contains("layoutCreatorChannelLiveOwnerCta"))
|
||||
assertFalse(fragmentLayout.contains("android:id=\"@+id/layout_creator_channel_owner_cta\""))
|
||||
assertFalse(fragment.contains("layoutCreatorChannelOwnerCta"))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -3,7 +3,7 @@ package kr.co.vividnext.sodalive.v2.creator.channel.live
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.v2.common.data.ContentSort
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.data.CreatorChannelAudioContentResponse
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.live.model.CreatorChannelLiveReplayStatus
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.model.CreatorChannelAudioContentStatus
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.live.model.toReplayUiModel
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.model.toLabelResId
|
||||
import kr.co.vividnext.sodalive.v2.widget.AudioContentTag
|
||||
@@ -18,14 +18,14 @@ class CreatorChannelLiveMapperTest {
|
||||
fun `소장과 대여가 동시에 true이면 소장중 상태를 우선 매핑한다`() {
|
||||
val item = audioContent(isOwned = true, isRented = true).toReplayUiModel()
|
||||
|
||||
assertEquals(CreatorChannelLiveReplayStatus.Owned, item.status)
|
||||
assertEquals(CreatorChannelAudioContentStatus.Owned, item.status)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `무료 콘텐츠는 무료 tag와 play CTA 상태로 매핑한다`() {
|
||||
val item = audioContent(price = 0).toReplayUiModel()
|
||||
|
||||
assertEquals(CreatorChannelLiveReplayStatus.Play, item.status)
|
||||
assertEquals(CreatorChannelAudioContentStatus.Play, item.status)
|
||||
assertTrue(AudioContentTag.Free in item.tags)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user