test(creator): 채널 홈 매퍼 검증을 보강한다

This commit is contained in:
2026-06-15 13:21:28 +09:00
parent 11fd892310
commit a20655badb
3 changed files with 86 additions and 15 deletions

View File

@@ -1,7 +1,10 @@
package kr.co.vividnext.sodalive.v2.creator.channel.model
import androidx.annotation.DrawableRes
import kr.co.vividnext.sodalive.R
import kr.co.vividnext.sodalive.v2.creator.channel.data.CreatorChannelHomeResponse
import kr.co.vividnext.sodalive.v2.creator.channel.data.CreatorChannelSnsResponse
import java.net.URI
fun CreatorChannelHomeResponse.toUiContent(): CreatorChannelHomeUiState.Content {
val sections = buildList {
@@ -9,7 +12,9 @@ fun CreatorChannelHomeResponse.toUiContent(): CreatorChannelHomeUiState.Content
latestAudioContent?.let { add(CreatorChannelHomeSection.LatestAudioContent(it)) }
channelDonations.takeIf { it.isNotEmpty() }?.let { add(CreatorChannelHomeSection.Donations(it)) }
notices.takeIf { it.isNotEmpty() }?.let { add(CreatorChannelHomeSection.Notices(it)) }
schedules.takeIf { it.isNotEmpty() }?.let { add(CreatorChannelHomeSection.Schedules(it)) }
schedules.sortedBy { it.scheduledAtUtc }.take(MAX_SCHEDULE_ITEM_COUNT)
.takeIf { it.isNotEmpty() }
?.let { add(CreatorChannelHomeSection.Schedules(it)) }
audioContents.takeIf { it.isNotEmpty() }?.let { add(CreatorChannelHomeSection.AudioContents(it)) }
series.takeIf { it.isNotEmpty() }?.let { add(CreatorChannelHomeSection.Series(it)) }
communities.takeIf { it.isNotEmpty() }?.let { add(CreatorChannelHomeSection.Communities(it)) }
@@ -37,13 +42,24 @@ fun CreatorChannelHomeResponse.toUiContent(): CreatorChannelHomeUiState.Content
}
private fun CreatorChannelSnsResponse.toUiItems(): List<CreatorChannelSnsUiItem> = buildList {
instagramUrl.toSnsItem("Instagram")?.let(::add)
fancimmUrl.toSnsItem("Fancimm")?.let(::add)
xUrl.toSnsItem("X")?.let(::add)
youtubeUrl.toSnsItem("YouTube")?.let(::add)
kakaoOpenChatUrl.toSnsItem("Kakao Open Chat")?.let(::add)
instagramUrl.toSnsItem(R.drawable.ic_sns_instagram, "Instagram")?.let(::add)
youtubeUrl.toSnsItem(R.drawable.ic_sns_youtube, "YouTube")?.let(::add)
xUrl.toSnsItem(R.drawable.ic_sns_x, "X")?.let(::add)
kakaoOpenChatUrl.toSnsItem(R.drawable.ic_sns_kakao, "Kakao Open Chat")?.let(::add)
fancimmUrl.toSnsItem(R.drawable.ic_sns_fancimm, "Fancimm")?.let(::add)
}
private fun String.toSnsItem(label: String): CreatorChannelSnsUiItem? = takeIf { it.isNotBlank() }?.let {
CreatorChannelSnsUiItem(label = label, url = it)
private fun String.toSnsItem(
@DrawableRes iconResId: Int,
label: String
): CreatorChannelSnsUiItem? = trim().takeIf(::isValidCreatorChannelSnsUrl)?.let {
CreatorChannelSnsUiItem(iconResId = iconResId, label = label, url = it)
}
internal fun isValidCreatorChannelSnsUrl(url: String): Boolean {
val uri = runCatching { URI(url) }.getOrNull() ?: return false
val scheme = uri.scheme?.lowercase() ?: return false
return scheme in setOf("http", "https") && !uri.host.isNullOrBlank()
}
private const val MAX_SCHEDULE_ITEM_COUNT = 3

View File

@@ -173,4 +173,5 @@
<color name="gray_700">#494949</color>
<color name="gray_800">#343434</color>
<color name="gray_900">#202020</color>
<color name="creator_channel_donation_cyan">#00EAFF</color>
</resources>