fix(creator): 오디오 탭 theme 선택 정규화를 보정한다
This commit is contained in:
@@ -10,7 +10,13 @@ import kr.co.vividnext.sodalive.common.ApiResponse
|
||||
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||
import kr.co.vividnext.sodalive.v2.common.data.ContentSort
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.audio.data.CreatorChannelAudioTabResponse
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.data.CreatorChannelAudioContentResponse
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.audio.model.CreatorChannelAudioContentUiModel
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.audio.model.CreatorChannelAudioRateUiModel
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.audio.model.CreatorChannelAudioThemeUiModel
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.audio.model.effectiveSelectedThemeId
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.audio.model.toAudioContentUiModels
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.audio.model.toRateUiModel
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.audio.model.toThemeUiModels
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.data.CreatorChannelRepository
|
||||
|
||||
class CreatorChannelAudioViewModel(
|
||||
@@ -74,7 +80,7 @@ class CreatorChannelAudioViewModel(
|
||||
val current = _audioStateLiveData.value as? CreatorChannelAudioUiState.Content ?: content
|
||||
if (response.success && data != null) {
|
||||
_audioStateLiveData.value = current.copy(
|
||||
audioContents = current.audioContents + data.displayableAudioContents(),
|
||||
audioContents = current.audioContents + data.audioContents.toAudioContentUiModels(),
|
||||
page = data.page,
|
||||
size = data.size,
|
||||
hasNext = data.hasNext,
|
||||
@@ -102,7 +108,8 @@ class CreatorChannelAudioViewModel(
|
||||
requestAudio(page = FIRST_PAGE, sort = sort, themeId = themeId, generation = generation) { response ->
|
||||
val data = response.data
|
||||
if (response.success && data != null) {
|
||||
val audioContents = data.displayableAudioContents()
|
||||
selectedThemeId = data.effectiveSelectedThemeId()
|
||||
val audioContents = data.audioContents.toAudioContentUiModels()
|
||||
_audioStateLiveData.value = if (audioContents.isEmpty() || data.audioContentCount == 0) {
|
||||
CreatorChannelAudioUiState.Empty
|
||||
} else {
|
||||
@@ -153,18 +160,15 @@ class CreatorChannelAudioViewModel(
|
||||
)
|
||||
}
|
||||
|
||||
private fun CreatorChannelAudioTabResponse.displayableAudioContents(): List<CreatorChannelAudioContentResponse> =
|
||||
audioContents.filter { it.duration != null }
|
||||
|
||||
private fun CreatorChannelAudioTabResponse.toContentState(
|
||||
audioContents: List<CreatorChannelAudioContentResponse>,
|
||||
audioContents: List<CreatorChannelAudioContentUiModel>,
|
||||
isLoadingMore: Boolean = false
|
||||
) = CreatorChannelAudioUiState.Content(
|
||||
audioContentCount = audioContentCount,
|
||||
themes = toThemeUiModels(),
|
||||
selectedSort = sort,
|
||||
selectedThemeId = themeId,
|
||||
rate = toRateUiModel(),
|
||||
selectedThemeId = effectiveSelectedThemeId(),
|
||||
rate = toRateUiModel(isOwner),
|
||||
audioContents = audioContents,
|
||||
page = page,
|
||||
size = size,
|
||||
@@ -172,33 +176,11 @@ class CreatorChannelAudioViewModel(
|
||||
isLoadingMore = isLoadingMore
|
||||
)
|
||||
|
||||
private fun CreatorChannelAudioTabResponse.toThemeUiModels(): List<CreatorChannelAudioThemeUiModel> =
|
||||
listOf(CreatorChannelAudioThemeUiModel(themeId = null, title = ALL_THEME_TITLE, isSelected = themeId == null)) +
|
||||
themes.map { theme ->
|
||||
CreatorChannelAudioThemeUiModel(
|
||||
themeId = theme.themeId,
|
||||
title = theme.themeName,
|
||||
isSelected = theme.themeId == themeId
|
||||
)
|
||||
}
|
||||
|
||||
private fun CreatorChannelAudioTabResponse.toRateUiModel(): CreatorChannelAudioRateUiModel? =
|
||||
if (!isOwner && themeId == null) {
|
||||
CreatorChannelAudioRateUiModel(
|
||||
ratePercent = purchasedAudioContentRate,
|
||||
purchasedCount = purchasedAudioContentCount,
|
||||
paidCount = paidAudioContentCount
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
private fun authToken(): String = "Bearer ${SharedPreferenceManager.token}"
|
||||
|
||||
companion object {
|
||||
val DEFAULT_PAGE_SIZE = 20
|
||||
private const val FIRST_PAGE = 0
|
||||
private const val ALL_THEME_TITLE = "전체"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +194,7 @@ sealed interface CreatorChannelAudioUiState {
|
||||
val selectedSort: ContentSort,
|
||||
val selectedThemeId: Long?,
|
||||
val rate: CreatorChannelAudioRateUiModel?,
|
||||
val audioContents: List<CreatorChannelAudioContentResponse>,
|
||||
val audioContents: List<CreatorChannelAudioContentUiModel>,
|
||||
val page: Int,
|
||||
val size: Int,
|
||||
val hasNext: Boolean,
|
||||
@@ -220,15 +202,3 @@ sealed interface CreatorChannelAudioUiState {
|
||||
val paginationErrorMessage: String? = null
|
||||
) : CreatorChannelAudioUiState
|
||||
}
|
||||
|
||||
data class CreatorChannelAudioThemeUiModel(
|
||||
val themeId: Long?,
|
||||
val title: String,
|
||||
val isSelected: Boolean
|
||||
)
|
||||
|
||||
data class CreatorChannelAudioRateUiModel(
|
||||
val ratePercent: Double,
|
||||
val purchasedCount: Int,
|
||||
val paidCount: Int
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user