feat(content): 추천 오디오 탭을 추가한다
This commit is contained in:
@@ -2998,6 +2998,57 @@ If you block this user, the following features will be restricted.
|
||||
}
|
||||
}
|
||||
|
||||
enum MainContentRecommendation {
|
||||
static var tabTitle: String {
|
||||
pick(ko: "추천", en: "Recommended", ja: "おすすめ")
|
||||
}
|
||||
|
||||
static var emptyStateMessage: String {
|
||||
pick(
|
||||
ko: "추천 오디오가 아직 없어요.",
|
||||
en: "No recommended audio yet.",
|
||||
ja: "おすすめオーディオはまだありません。"
|
||||
)
|
||||
}
|
||||
|
||||
static var loadFailedMessage: String {
|
||||
pick(
|
||||
ko: "추천 오디오를 불러오지 못했습니다.\n잠시 후 다시 시도해 주세요.",
|
||||
en: "Unable to load recommended audio.\nPlease try again later.",
|
||||
ja: "おすすめオーディオを読み込めませんでした。\nしばらくしてからもう一度お試しください。"
|
||||
)
|
||||
}
|
||||
|
||||
static var latestAudioSectionTitle: String {
|
||||
pick(ko: "새로 올라온 오디오", en: "Latest audio", ja: "新着オーディオ")
|
||||
}
|
||||
|
||||
static var newAndHotSectionTitle: String {
|
||||
pick(ko: "New&Hot", en: "New&Hot", ja: "New&Hot")
|
||||
}
|
||||
|
||||
static var voiceOnOnlySectionTitle: String {
|
||||
pick(ko: "오직 보이스온에서만!", en: "Only on VoiceOn!", ja: "VoiceOnだけで!")
|
||||
}
|
||||
|
||||
static var freeAudioSectionTitle: String {
|
||||
pick(ko: "무료 오디오", en: "Free audio", ja: "無料オーディオ")
|
||||
}
|
||||
|
||||
static var pointAudioSectionTitle: String {
|
||||
pick(ko: "포인트 오디오", en: "Point audio", ja: "ポイントオーディオ")
|
||||
}
|
||||
|
||||
static var mostCommentedAudioSectionTitle: String {
|
||||
pick(ko: "최근 댓글이 많은 오디오", en: "Most commented audio", ja: "最近コメントが多いオーディオ")
|
||||
}
|
||||
|
||||
static var recommendedAudioSectionTitle: String {
|
||||
pick(ko: "추천 오디오", en: "Recommended audio", ja: "おすすめオーディオ")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
enum Home {
|
||||
static var liveNowSectionTitle: String {
|
||||
pick(ko: "지금 라이브중", en: "Live now", ja: "ライブ配信中")
|
||||
|
||||
@@ -0,0 +1,364 @@
|
||||
import SwiftUI
|
||||
|
||||
struct AudioContentListRowItem: Identifiable {
|
||||
let id: Int
|
||||
let title: String
|
||||
let subtitle: String?
|
||||
let imageUrl: String?
|
||||
let price: Int
|
||||
let isAdult: Bool
|
||||
let isPointAvailable: Bool
|
||||
let isFirstContent: Bool
|
||||
let isOriginalSeries: Bool
|
||||
let isOwned: Bool
|
||||
let isRented: Bool
|
||||
}
|
||||
|
||||
extension AudioContentListRowItem {
|
||||
init(audioContent: CreatorChannelAudioContentResponse, subtitle: String?) {
|
||||
self.init(
|
||||
id: audioContent.audioContentId,
|
||||
title: audioContent.title,
|
||||
subtitle: subtitle,
|
||||
imageUrl: audioContent.imageUrl,
|
||||
price: audioContent.price,
|
||||
isAdult: audioContent.isAdult,
|
||||
isPointAvailable: audioContent.isPointAvailable,
|
||||
isFirstContent: audioContent.isFirstContent,
|
||||
isOriginalSeries: audioContent.isOriginalSeries == true,
|
||||
isOwned: audioContent.isOwned,
|
||||
isRented: audioContent.isRented
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
enum AudioContentListRowStyle {
|
||||
case compact(width: CGFloat?, showsAdultTag: Bool = false)
|
||||
case purchaseState
|
||||
|
||||
static func compactWidth(screenWidth: CGFloat = UIScreen.main.bounds.width) -> CGFloat {
|
||||
let baselineScreenWidth: CGFloat = 402
|
||||
let baselineRowWidth: CGFloat = 346
|
||||
return baselineRowWidth * min(screenWidth, baselineScreenWidth) / baselineScreenWidth
|
||||
}
|
||||
}
|
||||
|
||||
struct AudioContentListRow: View {
|
||||
let item: AudioContentListRowItem
|
||||
let style: AudioContentListRowStyle
|
||||
let action: () -> Void
|
||||
|
||||
init(
|
||||
item: AudioContentListRowItem,
|
||||
style: AudioContentListRowStyle,
|
||||
action: @escaping () -> Void = {}
|
||||
) {
|
||||
self.item = item
|
||||
self.style = style
|
||||
self.action = action
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Button {
|
||||
action()
|
||||
} label: {
|
||||
HStack(alignment: .center, spacing: SodaSpacing.s14) {
|
||||
thumbnail
|
||||
|
||||
titleArea
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
if showsTrailingState {
|
||||
trailingState
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, horizontalPadding)
|
||||
.padding(.vertical, verticalPadding)
|
||||
.frame(width: rowWidth, alignment: .leading)
|
||||
.frame(maxWidth: maxRowWidth, alignment: .leading)
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
private var titleArea: some View {
|
||||
VStack(alignment: .leading, spacing: titleSpacing) {
|
||||
Text(item.title)
|
||||
.appFont(size: 16, weight: .bold)
|
||||
.foregroundColor(.white)
|
||||
.lineLimit(titleLineLimit)
|
||||
.truncationMode(.tail)
|
||||
|
||||
if let subtitle = item.subtitle, !subtitle.isEmpty {
|
||||
Text(subtitle)
|
||||
.appFont(size: 14, weight: .medium)
|
||||
.foregroundColor(Color.gray500)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.tail)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var thumbnail: some View {
|
||||
ZStack(alignment: .topLeading) {
|
||||
DownsampledKFImage(
|
||||
url: item.imageUrl.flatMap(URL.init(string:)),
|
||||
size: CGSize(width: 88, height: 88)
|
||||
)
|
||||
.background(Color.gray800)
|
||||
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
topTagList
|
||||
|
||||
Spacer(minLength: 0)
|
||||
|
||||
bottomTagList
|
||||
}
|
||||
}
|
||||
.frame(width: 88, height: 88)
|
||||
.clipShape(RoundedRectangle(cornerRadius: SodaSpacing.s14, style: .continuous))
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var topTagList: some View {
|
||||
HStack(spacing: 0) {
|
||||
if item.isOriginalSeries {
|
||||
CreatorChannelAudioImageTag(imageName: "ic_content_tag_original")
|
||||
}
|
||||
|
||||
if item.isFirstContent {
|
||||
CreatorChannelAudioFirstTag()
|
||||
}
|
||||
|
||||
if showsAdultTag {
|
||||
Spacer()
|
||||
|
||||
if item.isAdult {
|
||||
CreatorChannelAudioAdultTag()
|
||||
.padding(.top, 6)
|
||||
.padding(.trailing, 6)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var bottomTagList: some View {
|
||||
HStack(spacing: 0) {
|
||||
if item.isPointAvailable {
|
||||
CreatorChannelAudioImageTag(imageName: "ic_content_tag_point")
|
||||
}
|
||||
|
||||
if item.price == 0 {
|
||||
CreatorChannelAudioFreeTag()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var trailingState: some View {
|
||||
if item.isOwned {
|
||||
playbackState(I18n.Content.Status.owned)
|
||||
} else if item.isRented {
|
||||
playbackState(I18n.Content.Status.rented)
|
||||
} else if item.price == 0 {
|
||||
playbackState("")
|
||||
} else {
|
||||
HStack(spacing: 2) {
|
||||
Image("ic_bar_cash")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 18, height: 18)
|
||||
|
||||
Text(item.price.comma())
|
||||
.appFont(size: 14, weight: .regular)
|
||||
.foregroundColor(.white)
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func playbackState(_ title: String) -> some View {
|
||||
VStack(spacing: SodaSpacing.s4) {
|
||||
ZStack {
|
||||
Color.white
|
||||
|
||||
Image("ic_new_player_play")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 16, height: 16)
|
||||
}
|
||||
.frame(width: 28, height: 28)
|
||||
.clipShape(Circle())
|
||||
|
||||
if !title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
||||
Text(title)
|
||||
.appFont(size: 12, weight: .medium)
|
||||
.foregroundColor(Color.gray400)
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var rowWidth: CGFloat? {
|
||||
if case let .compact(width, _) = style {
|
||||
return width
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
private var maxRowWidth: CGFloat? {
|
||||
switch style {
|
||||
case .compact:
|
||||
return nil
|
||||
case .purchaseState:
|
||||
return .infinity
|
||||
}
|
||||
}
|
||||
|
||||
private var horizontalPadding: CGFloat {
|
||||
switch style {
|
||||
case .compact:
|
||||
return 0
|
||||
case .purchaseState:
|
||||
return SodaSpacing.s20
|
||||
}
|
||||
}
|
||||
|
||||
private var verticalPadding: CGFloat {
|
||||
switch style {
|
||||
case .compact:
|
||||
return 0
|
||||
case .purchaseState:
|
||||
return SodaSpacing.s8
|
||||
}
|
||||
}
|
||||
|
||||
private var titleSpacing: CGFloat {
|
||||
switch style {
|
||||
case .compact:
|
||||
return 2
|
||||
case .purchaseState:
|
||||
return SodaSpacing.s6
|
||||
}
|
||||
}
|
||||
|
||||
private var titleLineLimit: Int {
|
||||
switch style {
|
||||
case .compact:
|
||||
return 1
|
||||
case .purchaseState:
|
||||
return 2
|
||||
}
|
||||
}
|
||||
|
||||
private var showsTrailingState: Bool {
|
||||
if case .purchaseState = style {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private var showsAdultTag: Bool {
|
||||
switch style {
|
||||
case let .compact(_, showsAdultTag):
|
||||
return showsAdultTag
|
||||
case .purchaseState:
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct CreatorChannelAudioImageTag: View {
|
||||
let imageName: String
|
||||
|
||||
var body: some View {
|
||||
Image(imageName)
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 24, height: 24)
|
||||
}
|
||||
}
|
||||
|
||||
struct CreatorChannelAudioFirstTag: View {
|
||||
var body: some View {
|
||||
ZStack {
|
||||
Color(hex: "FF34B8")
|
||||
|
||||
Image("ic_content_tag_first_star")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.padding(SodaSpacing.s4)
|
||||
}
|
||||
.frame(width: 24, height: 24)
|
||||
}
|
||||
}
|
||||
|
||||
struct CreatorChannelAudioAdultTag: View {
|
||||
var body: some View {
|
||||
ZStack {
|
||||
Color(hex: "FF4C3C")
|
||||
|
||||
Image("ic_new_shield_small")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.padding(2)
|
||||
}
|
||||
.frame(width: 18, height: 18)
|
||||
.cornerRadius(4)
|
||||
}
|
||||
}
|
||||
|
||||
struct CreatorChannelAudioFreeTag: View {
|
||||
var body: some View {
|
||||
Text("무료")
|
||||
.appFont(size: 14, weight: .semibold)
|
||||
.foregroundColor(.white)
|
||||
.lineLimit(1)
|
||||
.padding(SodaSpacing.s4)
|
||||
.frame(height: 24)
|
||||
.background(Color.soda900)
|
||||
}
|
||||
}
|
||||
|
||||
struct AudioContentListRow_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VStack(spacing: SodaSpacing.s8) {
|
||||
AudioContentListRow(
|
||||
item: AudioContentListRowItem(
|
||||
id: 1,
|
||||
title: "콘텐츠 이름이 한 줄 콘텐츠 이름이 한 줄 콘텐츠 이름이 한 줄",
|
||||
subtitle: "3:00 • 시리즈 이름",
|
||||
imageUrl: "https://picsum.photos/300/300",
|
||||
price: 0,
|
||||
isAdult: false,
|
||||
isPointAvailable: true,
|
||||
isFirstContent: true,
|
||||
isOriginalSeries: true,
|
||||
isOwned: false,
|
||||
isRented: false
|
||||
),
|
||||
style: .compact(width: 346)
|
||||
)
|
||||
|
||||
AudioContentListRow(
|
||||
item: AudioContentListRowItem(
|
||||
id: 2,
|
||||
title: "라이브 다시듣기 제목이 두 줄까지 표시됩니다",
|
||||
subtitle: "1:43:25",
|
||||
imageUrl: "https://picsum.photos/300/300",
|
||||
price: 3000,
|
||||
isAdult: true,
|
||||
isPointAvailable: true,
|
||||
isFirstContent: true,
|
||||
isOriginalSeries: true,
|
||||
isOwned: false,
|
||||
isRented: false
|
||||
),
|
||||
style: .purchaseState
|
||||
)
|
||||
}
|
||||
.background(Color.black)
|
||||
.previewLayout(.sizeThatFits)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
import SwiftUI
|
||||
|
||||
struct AudioContentThumbnailCardItem: Identifiable {
|
||||
let id: Int
|
||||
let title: String
|
||||
let subtitle: String
|
||||
let imageUrl: String?
|
||||
let price: Int
|
||||
let isAdult: Bool
|
||||
let isPointAvailable: Bool
|
||||
let isFirstContent: Bool
|
||||
let isOriginalSeries: Bool
|
||||
}
|
||||
|
||||
struct AudioContentThumbnailCard: View {
|
||||
let item: AudioContentThumbnailCardItem
|
||||
let width: CGFloat
|
||||
let titleTypography: SodaTypography
|
||||
let subtitleTypography: SodaTypography
|
||||
let labelHorizontalPadding: CGFloat
|
||||
|
||||
init(
|
||||
item: AudioContentThumbnailCardItem,
|
||||
size: AudioContentCardSize
|
||||
) {
|
||||
self.item = item
|
||||
self.width = size.width
|
||||
self.titleTypography = size.titleTypography
|
||||
self.subtitleTypography = size.subtitleTypography
|
||||
self.labelHorizontalPadding = size.labelHorizontalPadding
|
||||
}
|
||||
|
||||
init(
|
||||
item: AudioContentThumbnailCardItem,
|
||||
width: CGFloat,
|
||||
titleTypography: SodaTypography = .heading4,
|
||||
subtitleTypography: SodaTypography = .body5,
|
||||
labelHorizontalPadding: CGFloat = 0
|
||||
) {
|
||||
self.item = item
|
||||
self.width = width
|
||||
self.titleTypography = titleTypography
|
||||
self.subtitleTypography = subtitleTypography
|
||||
self.labelHorizontalPadding = labelHorizontalPadding
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: SodaSpacing.s8) {
|
||||
thumbnail
|
||||
|
||||
labelContent
|
||||
}
|
||||
.frame(width: width, alignment: .leading)
|
||||
}
|
||||
|
||||
private var thumbnail: some View {
|
||||
ZStack(alignment: .topLeading) {
|
||||
DownsampledKFImage(
|
||||
url: item.imageUrl.flatMap(URL.init(string:)),
|
||||
size: CGSize(width: width, height: width)
|
||||
)
|
||||
.background(Color.gray800)
|
||||
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
topTagRow
|
||||
|
||||
Spacer(minLength: 0)
|
||||
|
||||
bottomTagRow
|
||||
}
|
||||
}
|
||||
.frame(width: width, height: width)
|
||||
.clipShape(RoundedRectangle(cornerRadius: SodaSpacing.s14, style: .continuous))
|
||||
}
|
||||
|
||||
private var labelContent: some View {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(item.title)
|
||||
.appFont(titleTypography)
|
||||
.foregroundColor(.white)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.tail)
|
||||
|
||||
Text(item.subtitle)
|
||||
.appFont(subtitleTypography)
|
||||
.foregroundColor(Color.gray500)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.tail)
|
||||
}
|
||||
.frame(width: width - (labelHorizontalPadding * 2), alignment: .leading)
|
||||
.padding(.horizontal, labelHorizontalPadding)
|
||||
.frame(width: width, alignment: .leading)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var topTagRow: some View {
|
||||
HStack(spacing: 0) {
|
||||
if item.isOriginalSeries {
|
||||
originalTag
|
||||
}
|
||||
|
||||
if item.isFirstContent {
|
||||
firstTag
|
||||
}
|
||||
|
||||
Spacer(minLength: 0)
|
||||
|
||||
if item.isAdult {
|
||||
adultTag
|
||||
.padding(.top, SodaSpacing.s6)
|
||||
.padding(.trailing, SodaSpacing.s6)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var bottomTagRow: some View {
|
||||
HStack(spacing: 0) {
|
||||
if item.isPointAvailable {
|
||||
pointTag
|
||||
}
|
||||
|
||||
if item.price == 0 {
|
||||
freeTag
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var originalTag: some View {
|
||||
Image("ic_content_tag_original")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 24, height: 24)
|
||||
}
|
||||
|
||||
private var firstTag: some View {
|
||||
ZStack {
|
||||
Image("ic_content_tag_first_star")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 17, height: 17)
|
||||
}
|
||||
.padding(4)
|
||||
.background(Color(hex: "FF34B8"))
|
||||
}
|
||||
|
||||
private var adultTag: some View {
|
||||
ZStack {
|
||||
Color(hex: "FF4C3C")
|
||||
|
||||
Image("ic_new_shield_small")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.padding(2)
|
||||
}
|
||||
.frame(width: 18, height: 18)
|
||||
.cornerRadius(4)
|
||||
}
|
||||
|
||||
private var pointTag: some View {
|
||||
Image("ic_content_tag_point")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 24, height: 24)
|
||||
}
|
||||
|
||||
private var freeTag: some View {
|
||||
Text("무료")
|
||||
.appFont(size: 14, weight: .semibold)
|
||||
.foregroundColor(.white)
|
||||
.lineLimit(1)
|
||||
.padding(.horizontal, SodaSpacing.s4)
|
||||
.frame(height: 24)
|
||||
.background(Color.soda900)
|
||||
}
|
||||
}
|
||||
|
||||
extension AudioContentThumbnailCardItem {
|
||||
init(audioCard: AudioCardResponse) {
|
||||
self.init(
|
||||
id: audioCard.audioContentId,
|
||||
title: audioCard.title,
|
||||
subtitle: audioCard.creatorNickname,
|
||||
imageUrl: audioCard.imageUrl,
|
||||
price: audioCard.price,
|
||||
isAdult: audioCard.isAdult,
|
||||
isPointAvailable: audioCard.isPointAvailable,
|
||||
isFirstContent: audioCard.isFirstContent,
|
||||
isOriginalSeries: audioCard.isOriginalSeries
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
struct AudioContentThumbnailCard_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
HStack(alignment: .top, spacing: SodaSpacing.s14) {
|
||||
AudioContentThumbnailCard(
|
||||
item: AudioContentThumbnailCardItem(
|
||||
id: 1,
|
||||
title: "오디오 콘텐츠 제목입니다",
|
||||
subtitle: "크리에이터명",
|
||||
imageUrl: "https://picsum.photos/300/300",
|
||||
price: 0,
|
||||
isAdult: true,
|
||||
isPointAvailable: true,
|
||||
isFirstContent: true,
|
||||
isOriginalSeries: true
|
||||
),
|
||||
size: .medium
|
||||
)
|
||||
|
||||
AudioContentThumbnailCard(
|
||||
item: AudioContentThumbnailCardItem(
|
||||
id: 2,
|
||||
title: "추천 오디오",
|
||||
subtitle: "크리에이터명",
|
||||
imageUrl: "https://picsum.photos/300/300",
|
||||
price: 10,
|
||||
isAdult: false,
|
||||
isPointAvailable: false,
|
||||
isFirstContent: true,
|
||||
isOriginalSeries: true
|
||||
),
|
||||
width: 170
|
||||
)
|
||||
}
|
||||
.padding(SodaSpacing.s20)
|
||||
.background(Color.black)
|
||||
.previewLayout(.sizeThatFits)
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ struct BannerCarousel: View {
|
||||
|
||||
init(
|
||||
items: [BannerCarouselItem],
|
||||
height: CGFloat = 120,
|
||||
action: @escaping (BannerCarouselItem) -> Void = { _ in }
|
||||
) {
|
||||
self.items = Array(items.prefix(BannerCarousel.maxItemCount))
|
||||
@@ -200,6 +199,49 @@ struct BannerCarousel: View {
|
||||
}
|
||||
}
|
||||
|
||||
struct BannerCarouselSection<Item>: View {
|
||||
let items: [Item]
|
||||
let id: (Item, Int) -> String
|
||||
let imageUrl: (Item) -> String?
|
||||
let action: (Item) -> Void
|
||||
|
||||
init(
|
||||
items: [Item],
|
||||
id: @escaping (Item, Int) -> String,
|
||||
imageUrl: @escaping (Item) -> String?,
|
||||
action: @escaping (Item) -> Void
|
||||
) {
|
||||
self.items = items
|
||||
self.id = id
|
||||
self.imageUrl = imageUrl
|
||||
self.action = action
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
if !items.isEmpty {
|
||||
BannerCarousel(items: carouselItems) { carouselItem in
|
||||
guard let item = item(for: carouselItem) else { return }
|
||||
action(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var carouselItems: [BannerCarouselItem] {
|
||||
items.enumerated().map { index, item in
|
||||
BannerCarouselItem(
|
||||
id: id(item, index),
|
||||
imageUrl: imageUrl(item)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private func item(for carouselItem: BannerCarouselItem) -> Item? {
|
||||
items.enumerated().first { index, item in
|
||||
id(item, index) == carouselItem.id
|
||||
}?.element
|
||||
}
|
||||
}
|
||||
|
||||
struct BannerCarousel_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
BannerCarousel(
|
||||
|
||||
@@ -54,7 +54,13 @@ struct CreatorChannelAudioTabView: View {
|
||||
}
|
||||
|
||||
ForEach(viewModel.audioContents) { audioContent in
|
||||
CreatorChannelAudioContentListItem(audioContent: audioContent) {
|
||||
AudioContentListRow(
|
||||
item: AudioContentListRowItem(
|
||||
audioContent: audioContent,
|
||||
subtitle: audioContent.duration
|
||||
),
|
||||
style: .purchaseState
|
||||
) {
|
||||
onTapContent(audioContent.audioContentId)
|
||||
}
|
||||
.onAppear {
|
||||
|
||||
@@ -1,221 +0,0 @@
|
||||
import SwiftUI
|
||||
|
||||
struct CreatorChannelAudioContentListItem: View {
|
||||
let audioContent: CreatorChannelAudioContentResponse
|
||||
let action: () -> Void
|
||||
|
||||
init(
|
||||
audioContent: CreatorChannelAudioContentResponse,
|
||||
action: @escaping () -> Void = {}
|
||||
) {
|
||||
self.audioContent = audioContent
|
||||
self.action = action
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Button {
|
||||
action()
|
||||
} label: {
|
||||
HStack(alignment: .center, spacing: SodaSpacing.s14) {
|
||||
thumbnail
|
||||
|
||||
VStack(alignment: .leading, spacing: SodaSpacing.s6) {
|
||||
Text(audioContent.title)
|
||||
.appFont(size: 16, weight: .bold)
|
||||
.foregroundColor(.white)
|
||||
.lineLimit(2)
|
||||
.truncationMode(.tail)
|
||||
|
||||
if let duration = audioContent.duration, !duration.isEmpty {
|
||||
Text(duration)
|
||||
.appFont(size: 14, weight: .medium)
|
||||
.foregroundColor(Color.gray500)
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
trailingState
|
||||
}
|
||||
.padding(.horizontal, SodaSpacing.s20)
|
||||
.padding(.vertical, SodaSpacing.s8)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
private var thumbnail: some View {
|
||||
ZStack(alignment: .topLeading) {
|
||||
DownsampledKFImage(
|
||||
url: audioContent.imageUrl.flatMap(URL.init(string:)),
|
||||
size: CGSize(width: 88, height: 88)
|
||||
)
|
||||
.background(Color.gray800)
|
||||
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
topTagList
|
||||
|
||||
Spacer(minLength: 0)
|
||||
|
||||
bottomTagList
|
||||
}
|
||||
}
|
||||
.frame(width: 88, height: 88)
|
||||
.clipShape(RoundedRectangle(cornerRadius: SodaSpacing.s14, style: .continuous))
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var topTagList: some View {
|
||||
HStack(spacing: 0) {
|
||||
if audioContent.isOriginalSeries == true {
|
||||
CreatorChannelAudioImageTag(imageName: "ic_content_tag_original")
|
||||
}
|
||||
|
||||
if audioContent.isFirstContent {
|
||||
CreatorChannelAudioFirstTag()
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
if audioContent.isAdult {
|
||||
CreatorChannelAudioAdultTag()
|
||||
.padding(.top, 6)
|
||||
.padding(.trailing, 6)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var bottomTagList: some View {
|
||||
HStack(spacing: 0) {
|
||||
if audioContent.isPointAvailable {
|
||||
CreatorChannelAudioImageTag(imageName: "ic_content_tag_point")
|
||||
}
|
||||
|
||||
if audioContent.price == 0 {
|
||||
CreatorChannelAudioFreeTag()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var trailingState: some View {
|
||||
if audioContent.isOwned {
|
||||
playbackState(I18n.Content.Status.owned)
|
||||
} else if audioContent.isRented {
|
||||
playbackState(I18n.Content.Status.rented)
|
||||
} else if audioContent.price == 0 {
|
||||
playbackState("")
|
||||
} else {
|
||||
HStack(spacing: 2) {
|
||||
Image("ic_bar_cash")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 18, height: 18)
|
||||
|
||||
Text(audioContent.price.comma())
|
||||
.appFont(size: 14, weight: .regular)
|
||||
.foregroundColor(.white)
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func playbackState(_ title: String) -> some View {
|
||||
VStack(spacing: SodaSpacing.s4) {
|
||||
ZStack {
|
||||
Color.white
|
||||
|
||||
Image("ic_new_player_play")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 16, height: 16)
|
||||
}
|
||||
.frame(width: 28, height: 28)
|
||||
.clipShape(Circle())
|
||||
|
||||
if !title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
||||
Text(title)
|
||||
.appFont(size: 12, weight: .medium)
|
||||
.foregroundColor(Color.gray400)
|
||||
.lineLimit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct CreatorChannelAudioContentListItem_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
VStack(spacing: SodaSpacing.s8) {
|
||||
CreatorChannelAudioContentListItem(
|
||||
audioContent: CreatorChannelAudioContentResponse(
|
||||
audioContentId: 1,
|
||||
title: "라이브 다시듣기 제목이 두 줄까지 표시됩니다",
|
||||
duration: "1:43:25",
|
||||
imageUrl: "https://picsum.photos/300/300",
|
||||
price: 10,
|
||||
isAdult: true,
|
||||
isPointAvailable: true,
|
||||
isFirstContent: true,
|
||||
seriesName: nil,
|
||||
isOriginalSeries: true,
|
||||
isOwned: true,
|
||||
isRented: false
|
||||
)
|
||||
)
|
||||
|
||||
CreatorChannelAudioContentListItem(
|
||||
audioContent: CreatorChannelAudioContentResponse(
|
||||
audioContentId: 1,
|
||||
title: "라이브 다시듣기 제목이 두 줄까지 표시됩니다",
|
||||
duration: "1:43:25",
|
||||
imageUrl: "https://picsum.photos/300/300",
|
||||
price: 10,
|
||||
isAdult: true,
|
||||
isPointAvailable: true,
|
||||
isFirstContent: true,
|
||||
seriesName: nil,
|
||||
isOriginalSeries: true,
|
||||
isOwned: false,
|
||||
isRented: true
|
||||
)
|
||||
)
|
||||
|
||||
CreatorChannelAudioContentListItem(
|
||||
audioContent: CreatorChannelAudioContentResponse(
|
||||
audioContentId: 1,
|
||||
title: "라이브 다시듣기 제목이 두 줄까지 표시됩니다",
|
||||
duration: "1:43:25",
|
||||
imageUrl: "https://picsum.photos/300/300",
|
||||
price: 3000,
|
||||
isAdult: true,
|
||||
isPointAvailable: true,
|
||||
isFirstContent: true,
|
||||
seriesName: nil,
|
||||
isOriginalSeries: true,
|
||||
isOwned: false,
|
||||
isRented: false
|
||||
)
|
||||
)
|
||||
|
||||
CreatorChannelAudioContentListItem(
|
||||
audioContent: CreatorChannelAudioContentResponse(
|
||||
audioContentId: 1,
|
||||
title: "라이브 다시듣기 제목이 두 줄까지 표시됩니다",
|
||||
duration: "1:43:25",
|
||||
imageUrl: "https://picsum.photos/300/300",
|
||||
price: 0,
|
||||
isAdult: true,
|
||||
isPointAvailable: true,
|
||||
isFirstContent: true,
|
||||
seriesName: nil,
|
||||
isOriginalSeries: true,
|
||||
isOwned: false,
|
||||
isRented: false
|
||||
)
|
||||
)
|
||||
}
|
||||
.background(Color.black)
|
||||
.previewLayout(.sizeThatFits)
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,10 @@ struct CreatorChannelAudioSection: View {
|
||||
private let homeVisibleCount = 9
|
||||
private let itemsPerColumn = 3
|
||||
|
||||
private var rowWidth: CGFloat {
|
||||
AudioContentListRowStyle.compactWidth()
|
||||
}
|
||||
|
||||
init(
|
||||
audioContents: [CreatorChannelAudioContentResponse],
|
||||
onSelectTab: @escaping (CreatorChannelTab) -> Void,
|
||||
@@ -30,7 +34,13 @@ struct CreatorChannelAudioSection: View {
|
||||
ForEach(audioContentColumns.indices, id: \.self) { index in
|
||||
VStack(alignment: .leading, spacing: SodaSpacing.s8) {
|
||||
ForEach(audioContentColumns[index]) { audioContent in
|
||||
CreatorChannelHomeAudioContentListItem(audioContent: audioContent) {
|
||||
AudioContentListRow(
|
||||
item: AudioContentListRowItem(
|
||||
audioContent: audioContent,
|
||||
subtitle: subtitle(for: audioContent)
|
||||
),
|
||||
style: .compact(width: rowWidth)
|
||||
) {
|
||||
onTapContent(audioContent.audioContentId)
|
||||
}
|
||||
}
|
||||
@@ -54,6 +64,17 @@ struct CreatorChannelAudioSection: View {
|
||||
Array(visibleAudioContents[index..<min(index + itemsPerColumn, visibleAudioContents.count)])
|
||||
}
|
||||
}
|
||||
|
||||
private func subtitle(for audioContent: CreatorChannelAudioContentResponse) -> String? {
|
||||
let subtitle = [audioContent.duration, audioContent.seriesName]
|
||||
.compactMap { value in
|
||||
guard let value, !value.isEmpty else { return nil }
|
||||
return value
|
||||
}
|
||||
.joined(separator: " • ")
|
||||
|
||||
return subtitle.isEmpty ? nil : subtitle
|
||||
}
|
||||
}
|
||||
|
||||
struct CreatorChannelAudioSection_Previews: PreviewProvider {
|
||||
|
||||
@@ -1,172 +0,0 @@
|
||||
import SwiftUI
|
||||
|
||||
struct CreatorChannelHomeAudioContentListItem: View {
|
||||
let audioContent: CreatorChannelAudioContentResponse
|
||||
let action: () -> Void
|
||||
|
||||
init(
|
||||
audioContent: CreatorChannelAudioContentResponse,
|
||||
action: @escaping () -> Void = {}
|
||||
) {
|
||||
self.audioContent = audioContent
|
||||
self.action = action
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Button(action: action) {
|
||||
HStack(alignment: .center, spacing: SodaSpacing.s14) {
|
||||
thumbnail
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(audioContent.title)
|
||||
.appFont(size: 16, weight: .bold)
|
||||
.foregroundColor(.white)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.tail)
|
||||
|
||||
if !subtitle.isEmpty {
|
||||
Text(subtitle)
|
||||
.appFont(size: 14, weight: .medium)
|
||||
.foregroundColor(Color.gray500)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.tail)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
.frame(width: 346, alignment: .leading)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
private var subtitle: String {
|
||||
[audioContent.duration, audioContent.seriesName]
|
||||
.compactMap { value in
|
||||
guard let value, !value.isEmpty else { return nil }
|
||||
return value
|
||||
}
|
||||
.joined(separator: " • ")
|
||||
}
|
||||
|
||||
private var thumbnail: some View {
|
||||
ZStack(alignment: .topLeading) {
|
||||
DownsampledKFImage(
|
||||
url: audioContent.imageUrl.flatMap(URL.init(string:)),
|
||||
size: CGSize(width: 88, height: 88)
|
||||
)
|
||||
.background(Color.gray800)
|
||||
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
topTagList
|
||||
|
||||
Spacer(minLength: 0)
|
||||
|
||||
bottomTagList
|
||||
}
|
||||
}
|
||||
.frame(width: 88, height: 88)
|
||||
.clipShape(RoundedRectangle(cornerRadius: SodaSpacing.s14, style: .continuous))
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var topTagList: some View {
|
||||
HStack(spacing: 0) {
|
||||
if audioContent.isOriginalSeries == true {
|
||||
CreatorChannelAudioImageTag(imageName: "ic_content_tag_original")
|
||||
}
|
||||
|
||||
if audioContent.isFirstContent {
|
||||
CreatorChannelAudioFirstTag()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var bottomTagList: some View {
|
||||
HStack(spacing: 0) {
|
||||
if audioContent.isPointAvailable {
|
||||
CreatorChannelAudioImageTag(imageName: "ic_content_tag_point")
|
||||
}
|
||||
|
||||
if audioContent.price == 0 {
|
||||
CreatorChannelAudioFreeTag()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct CreatorChannelAudioImageTag: View {
|
||||
let imageName: String
|
||||
|
||||
var body: some View {
|
||||
Image(imageName)
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 24, height: 24)
|
||||
}
|
||||
}
|
||||
|
||||
struct CreatorChannelAudioFirstTag: View {
|
||||
var body: some View {
|
||||
ZStack {
|
||||
Color(hex: "FF34B8")
|
||||
|
||||
Image("ic_content_tag_first_star")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.padding(SodaSpacing.s4)
|
||||
}
|
||||
.frame(width: 24, height: 24)
|
||||
}
|
||||
}
|
||||
|
||||
struct CreatorChannelAudioAdultTag: View {
|
||||
var body: some View {
|
||||
ZStack {
|
||||
Color(hex: "FF4C3C")
|
||||
|
||||
Image("ic_new_shield_small")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.padding(2)
|
||||
}
|
||||
.frame(width: 18, height: 18)
|
||||
.cornerRadius(4)
|
||||
}
|
||||
}
|
||||
|
||||
struct CreatorChannelAudioFreeTag: View {
|
||||
var body: some View {
|
||||
Text("무료")
|
||||
.appFont(size: 14, weight: .semibold)
|
||||
.foregroundColor(.white)
|
||||
.lineLimit(1)
|
||||
.padding(SodaSpacing.s4)
|
||||
.frame(height: 24)
|
||||
.background(Color.soda900)
|
||||
}
|
||||
}
|
||||
|
||||
struct CreatorChannelHomeAudioContentListItem_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
CreatorChannelHomeAudioContentListItem(
|
||||
audioContent: CreatorChannelAudioContentResponse(
|
||||
audioContentId: 1,
|
||||
title: "콘텐츠 이름이 한 줄 콘텐츠 이름이 한 줄 콘텐츠 이름이 한 줄",
|
||||
duration: "3:00",
|
||||
imageUrl: "https://picsum.photos/300/300",
|
||||
price: 0,
|
||||
isAdult: false,
|
||||
isPointAvailable: true,
|
||||
isFirstContent: true,
|
||||
seriesName: "시리즈 이름",
|
||||
isOriginalSeries: true,
|
||||
isOwned: false,
|
||||
isRented: false
|
||||
)
|
||||
)
|
||||
.padding(SodaSpacing.s14)
|
||||
.background(Color.black)
|
||||
.previewLayout(.sizeThatFits)
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,13 @@ struct CreatorChannelLiveTabView: View {
|
||||
.padding(.bottom, SodaSpacing.s12)
|
||||
|
||||
ForEach(viewModel.liveReplayContents) { audioContent in
|
||||
CreatorChannelAudioContentListItem(audioContent: audioContent) {
|
||||
AudioContentListRow(
|
||||
item: AudioContentListRowItem(
|
||||
audioContent: audioContent,
|
||||
subtitle: audioContent.duration
|
||||
),
|
||||
style: .purchaseState
|
||||
) {
|
||||
onTapContent(audioContent.audioContentId)
|
||||
}
|
||||
.onAppear {
|
||||
|
||||
12
SodaLive/Sources/V2/Main/Content/MainContentTab.swift
Normal file
12
SodaLive/Sources/V2/Main/Content/MainContentTab.swift
Normal file
@@ -0,0 +1,12 @@
|
||||
import Foundation
|
||||
|
||||
enum MainContentTab: CaseIterable, Hashable {
|
||||
case recommendation
|
||||
|
||||
var title: String {
|
||||
switch self {
|
||||
case .recommendation:
|
||||
return I18n.MainContentRecommendation.tabTitle
|
||||
}
|
||||
}
|
||||
}
|
||||
64
SodaLive/Sources/V2/Main/Content/MainContentView.swift
Normal file
64
SodaLive/Sources/V2/Main/Content/MainContentView.swift
Normal file
@@ -0,0 +1,64 @@
|
||||
import SwiftUI
|
||||
|
||||
struct MainContentView: View {
|
||||
let onTapCanCharge: () -> Void
|
||||
let onTapSearch: () -> Void
|
||||
let onTapNotificationList: () -> Void
|
||||
let onTapContent: (Int) -> Void
|
||||
let onTapBanner: (AudioBannerResponse) -> Void
|
||||
let onTapSeries: (Int) -> Void
|
||||
|
||||
@State private var selectedTab: MainContentTab = .recommendation
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
HomeTitleBar {
|
||||
HStack(spacing: SodaSpacing.s14) {
|
||||
Image("ic_bar_cash")
|
||||
.onTapGesture { onTapCanCharge() }
|
||||
|
||||
Image("ic_bar_search")
|
||||
.onTapGesture { onTapSearch() }
|
||||
|
||||
Image("ic_bar_bell")
|
||||
.onTapGesture { onTapNotificationList() }
|
||||
}
|
||||
}
|
||||
|
||||
TextTabBar(
|
||||
items: MainContentTab.allCases,
|
||||
selectedItem: $selectedTab,
|
||||
title: { $0.title }
|
||||
)
|
||||
|
||||
tabContent
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
}
|
||||
.background(Color.black.ignoresSafeArea())
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private var tabContent: some View {
|
||||
switch selectedTab {
|
||||
case .recommendation:
|
||||
MainContentRecommendationView(
|
||||
onTapContent: onTapContent,
|
||||
onTapBanner: onTapBanner,
|
||||
onTapSeries: onTapSeries
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct MainContentView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
MainContentView(
|
||||
onTapCanCharge: {},
|
||||
onTapSearch: {},
|
||||
onTapNotificationList: {},
|
||||
onTapContent: { _ in },
|
||||
onTapBanner: { _ in },
|
||||
onTapSeries: { _ in }
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import SwiftUI
|
||||
|
||||
struct MainContentAudioBannerSection: View {
|
||||
let items: [AudioBannerResponse]
|
||||
let onTapBanner: (AudioBannerResponse) -> Void
|
||||
|
||||
var body: some View {
|
||||
BannerCarouselSection(
|
||||
items: items,
|
||||
id: fallbackId,
|
||||
imageUrl: { $0.imageUrl },
|
||||
action: onTapBanner
|
||||
)
|
||||
}
|
||||
|
||||
private func fallbackId(for item: AudioBannerResponse, index: Int) -> String {
|
||||
if let eventItem = item.eventItem {
|
||||
return "content-banner-\(index)-event-\(eventItem.id)"
|
||||
}
|
||||
|
||||
if let creatorId = item.creatorId {
|
||||
return "content-banner-\(index)-creator-\(creatorId)"
|
||||
}
|
||||
|
||||
if let seriesId = item.seriesId {
|
||||
return "content-banner-\(index)-series-\(seriesId)"
|
||||
}
|
||||
|
||||
if let link = item.link, !link.isEmpty {
|
||||
return "content-banner-\(index)-link-\(link)"
|
||||
}
|
||||
|
||||
return "content-banner-\(index)-image-\(item.imageUrl)"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import SwiftUI
|
||||
|
||||
struct MainContentAudioEmptyStateView: View {
|
||||
let message: String
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: SodaSpacing.s12) {
|
||||
Image(systemName: "waveform")
|
||||
.font(.system(size: 32, weight: .semibold))
|
||||
.foregroundColor(Color.gray600)
|
||||
|
||||
Text(message)
|
||||
.appFont(.body1)
|
||||
.foregroundColor(Color.gray400)
|
||||
.multilineTextAlignment(.center)
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.padding(SodaSpacing.s20)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import SwiftUI
|
||||
|
||||
struct MainContentAudioHorizontalCardSection: View {
|
||||
let title: String
|
||||
let items: [AudioCardResponse]
|
||||
let onTapContent: (Int) -> Void
|
||||
|
||||
var body: some View {
|
||||
if !items.isEmpty {
|
||||
VStack(alignment: .leading, spacing: SodaSpacing.s12) {
|
||||
SectionTitle(title: title)
|
||||
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
HStack(alignment: .top, spacing: SodaSpacing.s14) {
|
||||
ForEach(items) { item in
|
||||
Button {
|
||||
onTapContent(item.audioContentId)
|
||||
} label: {
|
||||
AudioContentThumbnailCard(
|
||||
item: AudioContentThumbnailCardItem(audioCard: item),
|
||||
size: .medium
|
||||
)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, SodaSpacing.s20)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import SwiftUI
|
||||
|
||||
struct MainContentAudioListCarouselSection: View {
|
||||
let title: String
|
||||
let items: [AudioCardResponse]
|
||||
let onTapContent: (Int) -> Void
|
||||
|
||||
private var chunks: [[AudioCardResponse]] {
|
||||
stride(from: 0, to: items.count, by: 3).map {
|
||||
Array(items[$0..<min($0 + 3, items.count)])
|
||||
}
|
||||
}
|
||||
|
||||
private var rowWidth: CGFloat {
|
||||
AudioContentListRowStyle.compactWidth()
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
if !items.isEmpty {
|
||||
VStack(alignment: .leading, spacing: SodaSpacing.s12) {
|
||||
SectionTitle(title: title)
|
||||
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
HStack(alignment: .top, spacing: SodaSpacing.s14) {
|
||||
ForEach(Array(chunks.enumerated()), id: \.offset) { _, chunk in
|
||||
VStack(spacing: SodaSpacing.s12) {
|
||||
ForEach(chunk) { item in
|
||||
AudioContentListRow(
|
||||
item: rowItem(from: item),
|
||||
style: .compact(width: rowWidth, showsAdultTag: true)
|
||||
) {
|
||||
onTapContent(item.audioContentId)
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(width: rowWidth)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, SodaSpacing.s20)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func rowItem(from item: AudioCardResponse) -> AudioContentListRowItem {
|
||||
AudioContentListRowItem(
|
||||
id: item.audioContentId,
|
||||
title: item.title,
|
||||
subtitle: item.creatorNickname,
|
||||
imageUrl: item.imageUrl,
|
||||
price: item.price,
|
||||
isAdult: item.isAdult,
|
||||
isPointAvailable: item.isPointAvailable,
|
||||
isFirstContent: item.isFirstContent,
|
||||
isOriginalSeries: item.isOriginalSeries,
|
||||
isOwned: false,
|
||||
isRented: false
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import SwiftUI
|
||||
|
||||
struct MainContentMostCommentedAudioSection: View {
|
||||
let title: String
|
||||
let items: [CommentedAudioResponse]
|
||||
let onTapContent: (Int) -> Void
|
||||
|
||||
private let thumbnailSize: CGFloat = 88
|
||||
|
||||
private var cardWidth: CGFloat {
|
||||
UIScreen.main.bounds.width - (SodaSpacing.s14 * 2)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
if !items.isEmpty {
|
||||
VStack(alignment: .leading, spacing: SodaSpacing.s14) {
|
||||
SectionTitle(title: title)
|
||||
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
HStack(alignment: .top, spacing: SodaSpacing.s4) {
|
||||
ForEach(items) { item in
|
||||
card(item)
|
||||
}
|
||||
}
|
||||
.padding(.leading, SodaSpacing.s14)
|
||||
.padding(.trailing, SodaSpacing.s20)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func card(_ item: CommentedAudioResponse) -> some View {
|
||||
Button {
|
||||
onTapContent(item.audioContentId)
|
||||
} label: {
|
||||
VStack(alignment: .leading, spacing: SodaSpacing.s14) {
|
||||
audioSummary(item)
|
||||
|
||||
commentPreview(item)
|
||||
}
|
||||
.padding(SodaSpacing.s14)
|
||||
.frame(width: cardWidth, alignment: .leading)
|
||||
.background(Color.gray900)
|
||||
.clipShape(RoundedRectangle(cornerRadius: SodaSpacing.s14, style: .continuous))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
private func audioSummary(_ item: CommentedAudioResponse) -> some View {
|
||||
HStack(alignment: .center, spacing: SodaSpacing.s14) {
|
||||
DownsampledKFImage(
|
||||
url: URL(string: item.imageUrl),
|
||||
size: CGSize(width: thumbnailSize, height: thumbnailSize)
|
||||
)
|
||||
.background(Color.gray800)
|
||||
.clipShape(RoundedRectangle(cornerRadius: SodaSpacing.s14, style: .continuous))
|
||||
|
||||
Text(item.title)
|
||||
.appFont(size: 16, weight: .bold)
|
||||
.foregroundColor(.white)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.tail)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}
|
||||
|
||||
private func commentPreview(_ item: CommentedAudioResponse) -> some View {
|
||||
HStack(alignment: .center, spacing: SodaSpacing.s14) {
|
||||
DownsampledKFImage(
|
||||
url: URL(string: item.latestCommentWriterProfileImageUrl),
|
||||
size: CGSize(width: 28, height: 28)
|
||||
)
|
||||
.background(Color.gray700)
|
||||
.clipShape(Circle())
|
||||
|
||||
Text(item.latestComment)
|
||||
.appFont(size: 14, weight: .regular)
|
||||
.foregroundColor(.white)
|
||||
.lineLimit(2)
|
||||
.truncationMode(.tail)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
Image(systemName: "chevron.down")
|
||||
.font(.system(size: 12, weight: .medium))
|
||||
.foregroundColor(.white)
|
||||
.frame(width: 18, height: 18)
|
||||
}
|
||||
.padding(SodaSpacing.s12)
|
||||
.background(Color.gray800)
|
||||
.clipShape(RoundedRectangle(cornerRadius: SodaSpacing.s14, style: .continuous))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import SwiftUI
|
||||
|
||||
struct MainContentRecommendedAudioGridSection: View {
|
||||
let title: String
|
||||
let items: [AudioCardResponse]
|
||||
let onTapContent: (Int) -> Void
|
||||
|
||||
private let columns = [
|
||||
GridItem(.flexible(), spacing: SodaSpacing.s14),
|
||||
GridItem(.flexible(), spacing: SodaSpacing.s14)
|
||||
]
|
||||
|
||||
var body: some View {
|
||||
if !items.isEmpty {
|
||||
VStack(alignment: .leading, spacing: SodaSpacing.s12) {
|
||||
SectionTitle(title: title)
|
||||
|
||||
LazyVGrid(columns: columns, alignment: .leading, spacing: SodaSpacing.s20) {
|
||||
ForEach(items) { item in
|
||||
Button {
|
||||
onTapContent(item.audioContentId)
|
||||
} label: {
|
||||
GeometryReader { proxy in
|
||||
let width = proxy.size.width
|
||||
|
||||
AudioContentThumbnailCard(
|
||||
item: AudioContentThumbnailCardItem(audioCard: item),
|
||||
width: width
|
||||
)
|
||||
}
|
||||
.aspectRatio(0.78, contentMode: .fit)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, SodaSpacing.s20)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import SwiftUI
|
||||
|
||||
struct MainContentVoiceOnOnlySection: View {
|
||||
let title: String
|
||||
let items: [OriginalSeriesResponse]
|
||||
let onTapSeries: (Int) -> Void
|
||||
|
||||
var body: some View {
|
||||
if !items.isEmpty {
|
||||
VStack(alignment: .leading, spacing: SodaSpacing.s12) {
|
||||
SectionTitle(title: title)
|
||||
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
HStack(alignment: .top, spacing: SodaSpacing.s14) {
|
||||
ForEach(items) { item in
|
||||
Button {
|
||||
onTapSeries(item.seriesId)
|
||||
} label: {
|
||||
ZStack(alignment: .topLeading) {
|
||||
DownsampledKFImage(
|
||||
url: URL(string: item.coverImageUrl),
|
||||
size: CGSize(width: 122, height: 172)
|
||||
)
|
||||
.background(Color.gray800)
|
||||
|
||||
originalTag
|
||||
}
|
||||
.frame(width: 122, height: 172)
|
||||
.clipShape(RoundedRectangle(cornerRadius: SodaSpacing.s14, style: .continuous))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, SodaSpacing.s20)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var originalTag: some View {
|
||||
HStack(spacing: SodaSpacing.s4) {
|
||||
Image("ic_series_original")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 14, height: 14)
|
||||
|
||||
Image("img_new_only")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(height: 14)
|
||||
}
|
||||
.padding(.horizontal, SodaSpacing.s8)
|
||||
.padding(.vertical, 5)
|
||||
.background(Color.gray900)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
import SwiftUI
|
||||
|
||||
struct MainContentRecommendationView: View {
|
||||
let onTapContent: (Int) -> Void
|
||||
let onTapBanner: (AudioBannerResponse) -> Void
|
||||
let onTapSeries: (Int) -> Void
|
||||
|
||||
@StateObject private var viewModel = MainContentRecommendationViewModel()
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
Color.black
|
||||
.ignoresSafeArea()
|
||||
|
||||
if viewModel.isLoading && viewModel.recommendations == nil {
|
||||
ProgressView()
|
||||
.progressViewStyle(CircularProgressViewStyle(tint: .white))
|
||||
} else if viewModel.shouldShowEmptyState {
|
||||
MainContentAudioEmptyStateView(message: viewModel.emptyStateMessage)
|
||||
} else {
|
||||
ScrollView(showsIndicators: false) {
|
||||
VStack(alignment: .leading, spacing: SodaSpacing.s24) {
|
||||
if let recommendations = viewModel.recommendations {
|
||||
MainContentAudioBannerSection(
|
||||
items: recommendations.banners,
|
||||
onTapBanner: onTapBanner
|
||||
)
|
||||
|
||||
MainContentAudioHorizontalCardSection(
|
||||
title: I18n.MainContentRecommendation.latestAudioSectionTitle,
|
||||
items: recommendations.latestAudios,
|
||||
onTapContent: onTapContent
|
||||
)
|
||||
|
||||
MainContentAudioListCarouselSection(
|
||||
title: I18n.MainContentRecommendation.newAndHotSectionTitle,
|
||||
items: recommendations.newAndHotAudios,
|
||||
onTapContent: onTapContent
|
||||
)
|
||||
|
||||
MainContentVoiceOnOnlySection(
|
||||
title: I18n.MainContentRecommendation.voiceOnOnlySectionTitle,
|
||||
items: recommendations.originalSeries,
|
||||
onTapSeries: onTapSeries
|
||||
)
|
||||
|
||||
MainContentAudioHorizontalCardSection(
|
||||
title: I18n.MainContentRecommendation.freeAudioSectionTitle,
|
||||
items: recommendations.freeAudios,
|
||||
onTapContent: onTapContent
|
||||
)
|
||||
|
||||
MainContentAudioHorizontalCardSection(
|
||||
title: I18n.MainContentRecommendation.pointAudioSectionTitle,
|
||||
items: recommendations.pointAudios,
|
||||
onTapContent: onTapContent
|
||||
)
|
||||
|
||||
MainContentMostCommentedAudioSection(
|
||||
title: I18n.MainContentRecommendation.mostCommentedAudioSectionTitle,
|
||||
items: recommendations.mostCommentedAudios,
|
||||
onTapContent: onTapContent
|
||||
)
|
||||
|
||||
MainContentRecommendedAudioGridSection(
|
||||
title: I18n.MainContentRecommendation.recommendedAudioSectionTitle,
|
||||
items: recommendations.recommendedAudios,
|
||||
onTapContent: onTapContent
|
||||
)
|
||||
}
|
||||
}
|
||||
.padding(.vertical, SodaSpacing.s20)
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
if !viewModel.hasLoaded {
|
||||
viewModel.fetchRecommendations()
|
||||
}
|
||||
}
|
||||
.sodaToast(
|
||||
isPresented: $viewModel.isShowPopup,
|
||||
message: viewModel.errorMessage,
|
||||
autohideIn: 2
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import Foundation
|
||||
import Combine
|
||||
|
||||
final class MainContentRecommendationViewModel: ObservableObject {
|
||||
private let repository = MainContentRecommendationRepository()
|
||||
private var subscription = Set<AnyCancellable>()
|
||||
|
||||
@Published var isLoading = false
|
||||
@Published var isShowPopup = false
|
||||
@Published var errorMessage = ""
|
||||
@Published var recommendations: AudioRecommendationsResponse?
|
||||
@Published var hasLoaded = false
|
||||
|
||||
var emptyStateMessage: String {
|
||||
if !errorMessage.isEmpty {
|
||||
return errorMessage
|
||||
}
|
||||
|
||||
return I18n.MainContentRecommendation.emptyStateMessage
|
||||
}
|
||||
|
||||
var shouldShowEmptyState: Bool {
|
||||
hasLoaded && !isLoading && (recommendations?.isEmpty ?? true)
|
||||
}
|
||||
|
||||
func fetchRecommendations() {
|
||||
guard !isLoading else { return }
|
||||
|
||||
isLoading = true
|
||||
|
||||
repository.getAudioRecommendations()
|
||||
.sink { [weak self] result in
|
||||
guard let self else { return }
|
||||
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
self.errorMessage = I18n.MainContentRecommendation.loadFailedMessage
|
||||
self.isShowPopup = true
|
||||
self.isLoading = false
|
||||
self.hasLoaded = true
|
||||
}
|
||||
} receiveValue: { [weak self] response in
|
||||
guard let self else { return }
|
||||
|
||||
let responseData = response.data
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponse<AudioRecommendationsResponse>.self, from: responseData)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
self.errorMessage = ""
|
||||
self.recommendations = data
|
||||
} else {
|
||||
self.errorMessage = decoded.message ?? I18n.MainContentRecommendation.loadFailedMessage
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
self.errorMessage = I18n.MainContentRecommendation.loadFailedMessage
|
||||
self.isShowPopup = true
|
||||
}
|
||||
|
||||
self.isLoading = false
|
||||
self.hasLoaded = true
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import Foundation
|
||||
|
||||
struct AudioRecommendationsResponse: Decodable {
|
||||
let banners: [AudioBannerResponse]
|
||||
let originalSeries: [OriginalSeriesResponse]
|
||||
let latestAudios: [AudioCardResponse]
|
||||
let newAndHotAudios: [AudioCardResponse]
|
||||
let freeAudios: [AudioCardResponse]
|
||||
let pointAudios: [AudioCardResponse]
|
||||
let mostCommentedAudios: [CommentedAudioResponse]
|
||||
let recommendedAudios: [AudioCardResponse]
|
||||
|
||||
var isEmpty: Bool {
|
||||
banners.isEmpty &&
|
||||
originalSeries.isEmpty &&
|
||||
latestAudios.isEmpty &&
|
||||
newAndHotAudios.isEmpty &&
|
||||
freeAudios.isEmpty &&
|
||||
pointAudios.isEmpty &&
|
||||
mostCommentedAudios.isEmpty &&
|
||||
recommendedAudios.isEmpty
|
||||
}
|
||||
}
|
||||
|
||||
struct AudioBannerResponse: Decodable, Hashable, Identifiable {
|
||||
var id: String { "\(imageUrl)-\(creatorId ?? 0)-\(seriesId ?? 0)-\(link ?? "")" }
|
||||
|
||||
let imageUrl: String
|
||||
let eventItem: EventItem?
|
||||
let creatorId: Int?
|
||||
let seriesId: Int?
|
||||
let link: String?
|
||||
}
|
||||
|
||||
struct OriginalSeriesResponse: Decodable, Hashable, Identifiable {
|
||||
var id: Int { seriesId }
|
||||
|
||||
let seriesId: Int
|
||||
let coverImageUrl: String
|
||||
}
|
||||
|
||||
struct AudioCardResponse: Decodable, Hashable, Identifiable {
|
||||
var id: Int { audioContentId }
|
||||
|
||||
let audioContentId: Int
|
||||
let title: String
|
||||
let duration: String
|
||||
let imageUrl: String
|
||||
let price: Int
|
||||
let isAdult: Bool
|
||||
let isPointAvailable: Bool
|
||||
let isFirstContent: Bool
|
||||
let isOriginalSeries: Bool
|
||||
let creatorNickname: String
|
||||
}
|
||||
|
||||
struct CommentedAudioResponse: Decodable, Hashable, Identifiable {
|
||||
var id: Int { audioContentId }
|
||||
|
||||
let audioContentId: Int
|
||||
let title: String
|
||||
let imageUrl: String
|
||||
let latestComment: String
|
||||
let latestCommentWriterProfileImageUrl: String
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import Foundation
|
||||
import Moya
|
||||
|
||||
enum MainContentRecommendationApi {
|
||||
case getAudioRecommendations
|
||||
}
|
||||
|
||||
extension MainContentRecommendationApi: TargetType {
|
||||
var baseURL: URL {
|
||||
return URL(string: BASE_URL)!
|
||||
}
|
||||
|
||||
var path: String {
|
||||
switch self {
|
||||
case .getAudioRecommendations:
|
||||
return "/api/v2/audio/recommendations"
|
||||
}
|
||||
}
|
||||
|
||||
var method: Moya.Method {
|
||||
switch self {
|
||||
case .getAudioRecommendations:
|
||||
return .get
|
||||
}
|
||||
}
|
||||
|
||||
var task: Moya.Task {
|
||||
switch self {
|
||||
case .getAudioRecommendations:
|
||||
return .requestPlain
|
||||
}
|
||||
}
|
||||
|
||||
var headers: [String: String]? {
|
||||
return ["Authorization": "Bearer \(UserDefaults.string(forKey: UserDefaultsKey.token))"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import Foundation
|
||||
import CombineMoya
|
||||
import Combine
|
||||
import Moya
|
||||
|
||||
final class MainContentRecommendationRepository {
|
||||
private let api = MoyaProvider<MainContentRecommendationApi>()
|
||||
|
||||
func getAudioRecommendations() -> AnyPublisher<Response, MoyaError> {
|
||||
return api.requestPublisher(.getAudioRecommendations)
|
||||
}
|
||||
}
|
||||
@@ -13,27 +13,12 @@ struct MainHomeBannerSection: View {
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
if !items.isEmpty {
|
||||
BannerCarousel(items: carouselItems) { item in
|
||||
guard let banner = banner(for: item) else { return }
|
||||
onTapBanner(banner)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var carouselItems: [BannerCarouselItem] {
|
||||
items.enumerated().map { index, item in
|
||||
BannerCarouselItem(
|
||||
id: fallbackId(for: item, index: index),
|
||||
imageUrl: item.imageUrl
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private func banner(for carouselItem: BannerCarouselItem) -> RecommendationBannerResponse? {
|
||||
items.enumerated().first { index, item in
|
||||
fallbackId(for: item, index: index) == carouselItem.id
|
||||
}?.element
|
||||
BannerCarouselSection(
|
||||
items: items,
|
||||
id: fallbackId,
|
||||
imageUrl: { $0.imageUrl },
|
||||
action: onTapBanner
|
||||
)
|
||||
}
|
||||
|
||||
private func fallbackId(for item: RecommendationBannerResponse, index: Int) -> String {
|
||||
|
||||
@@ -172,7 +172,14 @@ struct MainView: View {
|
||||
onTapFollowingSchedule: handleFollowingScheduleTap
|
||||
)
|
||||
case .content:
|
||||
MainPlaceholderTabView(title: MainTab.content.title)
|
||||
MainContentView(
|
||||
onTapCanCharge: handleHomeCanChargeTap,
|
||||
onTapSearch: handleHomeSearchTap,
|
||||
onTapNotificationList: handleHomeNotificationListTap,
|
||||
onTapContent: handleRecommendationContentTap,
|
||||
onTapBanner: handleContentAudioBannerTap,
|
||||
onTapSeries: handleContentOriginalSeriesTap
|
||||
)
|
||||
case .chat:
|
||||
MainPlaceholderTabView(title: MainTab.chat.title)
|
||||
case .my:
|
||||
@@ -548,10 +555,45 @@ struct MainView: View {
|
||||
openRecommendationBannerLink(item.link)
|
||||
}
|
||||
|
||||
private func handleContentAudioBannerTap(_ item: AudioBannerResponse) {
|
||||
if let eventItem = item.eventItem {
|
||||
performRecommendationDetailAction {
|
||||
appState.setAppStep(step: .eventDetail(event: eventItem))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if let creatorId = item.creatorId {
|
||||
handleRecommendationCreatorTap(creatorId: creatorId)
|
||||
return
|
||||
}
|
||||
|
||||
if let seriesId = item.seriesId {
|
||||
handleContentOriginalSeriesTap(seriesId: seriesId)
|
||||
return
|
||||
}
|
||||
|
||||
openRecommendationBannerLink(item.link)
|
||||
}
|
||||
|
||||
private func handleContentOriginalSeriesTap(seriesId: Int) {
|
||||
guard seriesId > 0 else { return }
|
||||
performRecommendationDetailAction {
|
||||
appState.setAppStep(step: .seriesDetail(seriesId: seriesId))
|
||||
}
|
||||
}
|
||||
|
||||
private func openRecommendationBannerLink(_ link: String?) {
|
||||
guard let link = link?.trimmingCharacters(in: .whitespacesAndNewlines),
|
||||
!link.isEmpty,
|
||||
let url = URL(string: link),
|
||||
!link.isEmpty else {
|
||||
return
|
||||
}
|
||||
|
||||
if AppDeepLinkHandler.handle(urlString: link) {
|
||||
return
|
||||
}
|
||||
|
||||
guard let url = URL(string: link),
|
||||
UIApplication.shared.canOpenURL(url) else {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user