feat(creator): 시리즈 탭 UI를 구현한다

This commit is contained in:
2026-06-20 04:50:30 +09:00
parent 7ea06fda2f
commit 92cea6d3ee
5 changed files with 717 additions and 0 deletions

View File

@@ -0,0 +1,182 @@
package kr.co.vividnext.sodalive.v2.creator.channel.series
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import kr.co.vividnext.sodalive.R
import kr.co.vividnext.sodalive.base.BaseFragment
import kr.co.vividnext.sodalive.databinding.FragmentCreatorChannelSeriesBinding
import kr.co.vividnext.sodalive.extensions.moneyFormat
import kr.co.vividnext.sodalive.v2.creator.channel.model.toLabelResId
import kr.co.vividnext.sodalive.v2.creator.channel.series.ui.CreatorChannelSeriesAdapter
import kr.co.vividnext.sodalive.v2.creator.channel.ui.CreatorChannelSortPopup
import org.koin.androidx.viewmodel.ext.android.viewModel
class CreatorChannelSeriesFragment : BaseFragment<FragmentCreatorChannelSeriesBinding>(
FragmentCreatorChannelSeriesBinding::inflate
) {
private val viewModel: CreatorChannelSeriesViewModel by viewModel()
private val seriesAdapter = CreatorChannelSeriesAdapter { seriesId ->
host.onCreatorChannelSeriesClicked(seriesId)
}
private var sortPopup: CreatorChannelSortPopup? = null
private var currentContentState: CreatorChannelSeriesUiState.Content? = null
private var lastContentLayoutKey: CreatorChannelSeriesContentLayoutKey? = null
private val creatorId: Long by lazy { arguments?.getLong(ARG_CREATOR_ID) ?: 0L }
private val host: Host
get() = requireActivity() as Host
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
bindLoading()
setupSeriesList()
setupClickListeners()
observeViewModel()
}
override fun onDestroyView() {
sortPopup?.dismiss()
sortPopup = null
currentContentState = null
lastContentLayoutKey = null
binding.rvCreatorChannelSeries.adapter = null
super.onDestroyView()
}
private fun setupSeriesList() = with(binding.rvCreatorChannelSeries) {
layoutManager = LinearLayoutManager(requireContext())
adapter = seriesAdapter
}
private fun setupClickListeners() = with(binding) {
ivCreatorChannelSeriesSort.setImageResource(R.drawable.ic_new_sort)
layoutCreatorChannelSeriesSortButton.setOnClickListener {
currentContentState?.let { state -> showSortPopup(state) }
}
btnCreatorChannelSeriesRetry.setOnClickListener {
viewModel.retrySeries()
}
}
private fun observeViewModel() {
viewModel.seriesStateLiveData.observe(viewLifecycleOwner) { state ->
when (state) {
CreatorChannelSeriesUiState.Loading -> bindLoading()
CreatorChannelSeriesUiState.Empty -> bindEmpty()
is CreatorChannelSeriesUiState.Error -> bindError(state)
is CreatorChannelSeriesUiState.Content -> bindContent(state)
}
}
}
fun onCreatorChannelSeriesTabSelected() {
if (creatorId > 0L) {
viewModel.loadSeries(creatorId, isOwner = host.isCreatorChannelOwner())
}
}
fun onCreatorChannelSeriesScrolledToBottom() {
viewModel.loadMore()
}
@Suppress("UNUSED_PARAMETER")
fun onCreatorChannelSeriesViewportHeightChanged(minHeight: Int) = Unit
private fun bindLoading() = with(binding) {
currentContentState = null
lastContentLayoutKey = null
layoutCreatorChannelSeriesSortBar.isVisible = false
rvCreatorChannelSeries.isVisible = false
layoutCreatorChannelSeriesEmpty.isVisible = false
tvCreatorChannelSeriesErrorMessage.isVisible = false
btnCreatorChannelSeriesRetry.isVisible = false
}
private fun bindEmpty() = with(binding) {
currentContentState = null
lastContentLayoutKey = null
layoutCreatorChannelSeriesSortBar.isVisible = false
rvCreatorChannelSeries.isVisible = false
layoutCreatorChannelSeriesEmpty.isVisible = true
tvCreatorChannelSeriesErrorMessage.isVisible = false
btnCreatorChannelSeriesRetry.isVisible = false
host.onCreatorChannelSeriesContentChanged()
}
private fun bindError(state: CreatorChannelSeriesUiState.Error) = with(binding) {
currentContentState = null
lastContentLayoutKey = null
layoutCreatorChannelSeriesSortBar.isVisible = false
rvCreatorChannelSeries.isVisible = false
layoutCreatorChannelSeriesEmpty.isVisible = false
tvCreatorChannelSeriesErrorMessage.isVisible = true
tvCreatorChannelSeriesErrorMessage.text = state.message ?: getString(R.string.creator_channel_series_error_message)
btnCreatorChannelSeriesRetry.isVisible = true
host.onCreatorChannelSeriesContentChanged()
}
private fun bindContent(state: CreatorChannelSeriesUiState.Content) = with(binding) {
currentContentState = state
layoutCreatorChannelSeriesSortBar.isVisible = true
tvCreatorChannelSeriesTotalCount.text = state.seriesCount.moneyFormat()
tvCreatorChannelSeriesSortLabel.setText(state.selectedSort.toLabelResId())
rvCreatorChannelSeries.isVisible = true
seriesAdapter.submitItems(state.series)
layoutCreatorChannelSeriesEmpty.isVisible = false
tvCreatorChannelSeriesErrorMessage.isVisible = false
btnCreatorChannelSeriesRetry.isVisible = false
notifyContentChangedIfLayoutChanged(state)
state.paginationErrorMessage?.let {
Toast.makeText(requireContext(), it, Toast.LENGTH_SHORT).show()
viewModel.consumePaginationErrorMessage()
}
}
private fun notifyContentChangedIfLayoutChanged(state: CreatorChannelSeriesUiState.Content) {
val contentLayoutKey = state.toContentLayoutKey()
if (contentLayoutKey == lastContentLayoutKey) return
lastContentLayoutKey = contentLayoutKey
host.onCreatorChannelSeriesContentChanged()
}
private fun showSortPopup(state: CreatorChannelSeriesUiState.Content) {
sortPopup?.dismiss()
sortPopup = CreatorChannelSortPopup(
anchor = binding.layoutCreatorChannelSeriesSortButton,
selectedSort = state.selectedSort,
onSortSelected = { sort -> viewModel.changeSort(sort) }
).also { it.show() }
}
interface Host {
fun isCreatorChannelOwner(): Boolean
fun onCreatorChannelSeriesClicked(seriesId: Long)
fun onCreatorChannelSeriesContentChanged()
}
companion object {
private const val ARG_CREATOR_ID: String = "arg_creator_id"
fun newInstance(creatorId: Long): CreatorChannelSeriesFragment {
return CreatorChannelSeriesFragment().apply {
arguments = Bundle().apply { putLong(ARG_CREATOR_ID, creatorId) }
}
}
}
}
private data class CreatorChannelSeriesContentLayoutKey(
val seriesCount: Int,
val seriesIds: List<Long>
)
private fun CreatorChannelSeriesUiState.Content.toContentLayoutKey(): CreatorChannelSeriesContentLayoutKey {
return CreatorChannelSeriesContentLayoutKey(
seriesCount = seriesCount,
seriesIds = series.map { it.seriesId }
)
}

View File

@@ -0,0 +1,110 @@
package kr.co.vividnext.sodalive.v2.creator.channel.series.ui
import android.graphics.Outline
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewOutlineProvider
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import kr.co.vividnext.sodalive.R
import kr.co.vividnext.sodalive.databinding.ItemCreatorChannelSeriesBinding
import kr.co.vividnext.sodalive.extensions.loadUrl
import kr.co.vividnext.sodalive.extensions.moneyFormat
import kr.co.vividnext.sodalive.v2.creator.channel.series.model.CreatorChannelSeriesItemUiModel
import kr.co.vividnext.sodalive.v2.creator.channel.series.model.CreatorChannelSeriesSubtitleUiModel
class CreatorChannelSeriesAdapter(
private val onSeriesClicked: (Long) -> Unit = {}
) : RecyclerView.Adapter<CreatorChannelSeriesAdapter.ViewHolder>() {
private var items: List<CreatorChannelSeriesItemUiModel> = emptyList()
fun submitItems(items: List<CreatorChannelSeriesItemUiModel>) {
this.items = items
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(
ItemCreatorChannelSeriesBinding.inflate(LayoutInflater.from(parent.context), parent, false),
onSeriesClicked
)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(items[position])
}
override fun getItemCount(): Int = items.size
class ViewHolder(
private val binding: ItemCreatorChannelSeriesBinding,
private val onSeriesClicked: (Long) -> Unit
) : RecyclerView.ViewHolder(binding.root) {
init {
binding.layoutCreatorChannelSeriesThumbnail.clipToOutline = true
binding.layoutCreatorChannelSeriesThumbnail.outlineProvider = object : ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline) {
outline.setRoundRect(
0,
0,
view.width,
view.height,
view.resources.getDimension(R.dimen.radius_14)
)
}
}
}
fun bind(item: CreatorChannelSeriesItemUiModel) = with(binding) {
ivCreatorChannelSeriesThumbnail.loadUrl(item.coverImageUrl)
layoutCreatorChannelSeriesOriginalTag.isVisible = item.showOriginalTag
ivCreatorChannelSeriesAdultBadge.isVisible = item.showAdultBadge
tvCreatorChannelSeriesTitle.text = item.title
tvCreatorChannelSeriesSubtitle.text = formatSubtitle(item.subtitle)
bindProgress(item)
root.setOnClickListener { onSeriesClicked(item.seriesId) }
}
private fun formatSubtitle(subtitle: CreatorChannelSeriesSubtitleUiModel): String {
return listOfNotNull(
subtitle.publishedDaysOfWeek,
binding.root.context.getString(
R.string.creator_channel_series_subtitle_content_count,
subtitle.contentCount.moneyFormat()
),
binding.root.context.getString(
if (subtitle.isProceeding) {
R.string.creator_channel_series_status_proceeding
} else {
R.string.creator_channel_series_status_completed
}
)
).joinToString(BULLET_SEPARATOR)
}
private fun bindProgress(item: CreatorChannelSeriesItemUiModel) = with(binding) {
val progress = item.progress
layoutCreatorChannelSeriesProgress.isVisible = progress != null
if (progress == null) return@with
tvCreatorChannelSeriesProgressCount.text = root.context.getString(
R.string.creator_channel_series_progress_count,
progress.purchasedCount.moneyFormat(),
progress.paidCount.moneyFormat()
)
tvCreatorChannelSeriesProgressPercent.text = root.context.getString(
R.string.creator_channel_series_progress_percent,
progress.ratePercent.toInt().moneyFormat()
)
viewCreatorChannelSeriesProgressFill.pivotX = 0f
viewCreatorChannelSeriesProgressFill.scaleX = progress.progressScale
}
}
companion object {
private const val BULLET_SEPARATOR = ""
}
}