시리즈 상세 추가

This commit is contained in:
Yu Sung
2024-04-30 14:58:06 +09:00
parent 101b04b6a9
commit 93110eff8c
14 changed files with 913 additions and 1 deletions

View File

@@ -0,0 +1,24 @@
//
// GetSeriesContentListResponse.swift
// SodaLive
//
// Created by klaus on 4/29/24.
//
import Foundation
struct GetSeriesContentListResponse: Decodable {
let totalCount: Int
let items: [GetSeriesContentListItem]
}
struct GetSeriesContentListItem: Decodable {
let contentId: Int
let title: String
let coverImage: String
let releaseDate: String
let duration: String
let price: Int
let isRented: Bool
let isOwned: Bool
}

View File

@@ -0,0 +1,37 @@
//
// GetSeriesDetailResponse.swift
// SodaLive
//
// Created by klaus on 4/29/24.
//
import Foundation
struct GetSeriesDetailResponse: Decodable {
let seriesId: Int
let title: String
let coverImage: String
let introduction: String
let genre: String
let isAdult: Bool
let writer: String?
let studio: String?
let publishedDate: String
let creator: GetSeriesDetailCreator
let rentalMinPrice: Int
let rentalMaxPrice: Int
let rentalPeriod: Int
let minPrice: Int
let maxPrice: Int
let keywordList: [String]
let publishedDaysOfWeek: String
let contentList: [GetSeriesContentListItem]
let contentCount: Int
}
struct GetSeriesDetailCreator: Decodable {
let creatorId: Int
let nickname: String
let profileImage: String
let isFollow: Bool
}

View File

@@ -0,0 +1,106 @@
//
// SeriesDetailHomeView.swift
// SodaLive
//
// Created by klaus on 4/29/24.
//
import SwiftUI
struct SeriesDetailHomeView: View {
let title: String
let seriesId: Int
let contentCount: Int
let contentList: [GetSeriesContentListItem]
var body: some View {
VStack(spacing: 0) {
HStack(spacing: 0) {
Text("전체회차 듣기")
.font(.custom(Font.bold.rawValue, size: 16))
.foregroundColor(Color.button)
Text(" (\(contentCount))")
.font(.custom(Font.light.rawValue, size: 16))
.foregroundColor(Color.button)
}
.frame(maxWidth: .infinity)
.padding(.vertical, 13.3)
.background(Color.bg)
.cornerRadius(5.3)
.overlay(
RoundedRectangle(cornerRadius: 5.3)
.stroke()
.foregroundColor(Color.button)
)
.padding(.top, 16)
.onTapGesture {}
VStack(spacing: 8) {
ForEach(0..<contentList.count, id: \.self) {
let item = contentList[$0]
SeriesContentListItemView(item: item)
.contentShape(Rectangle())
.onTapGesture {
AppState.shared
.setAppStep(step: .contentDetail(contentId: item.contentId))
}
}
}
.padding(.top, 16)
}
.padding(.horizontal, 13.3)
}
}
#Preview {
SeriesDetailHomeView(
title: "변호사 우영우",
seriesId: 0,
contentCount: 10,
contentList: [
GetSeriesContentListItem(
contentId: 1,
title: "[무료] 두근두근 연애 연구부 EP1",
coverImage: "https://test-cf.sodalive.net/profile/default-profile.png",
releaseDate: "",
duration: "00:14:59",
price: 0,
isRented: false,
isOwned: false
),
GetSeriesContentListItem(
contentId: 2,
title: "두근두근 연애 연구부 EP2",
coverImage: "https://test-cf.sodalive.net/profile/default-profile.png",
releaseDate: "",
duration: "00:14:59",
price: 100,
isRented: false,
isOwned: false
),
GetSeriesContentListItem(
contentId: 3,
title: "두근두근 연애 연구부 EP3",
coverImage: "https://test-cf.sodalive.net/profile/default-profile.png",
releaseDate: "",
duration: "00:14:59",
price: 100,
isRented: true,
isOwned: false
),
GetSeriesContentListItem(
contentId: 4,
title: "두근두근 연애 연구부 EP4",
coverImage: "https://test-cf.sodalive.net/profile/default-profile.png",
releaseDate: "",
duration: "00:14:59",
price: 100,
isRented: false,
isOwned: true
)
]
)
}

View File

@@ -0,0 +1,165 @@
//
// SeriesDetailIntroductionView.swift
// SodaLive
//
// Created by klaus on 4/29/24.
//
import SwiftUI
import TagLayoutView
struct SeriesDetailIntroductionView: View {
let width: CGFloat
let seriesDetail: GetSeriesDetailResponse
var body: some View {
VStack(alignment: .leading, spacing: 16) {
Text("키워드")
.font(.custom(Font.bold.rawValue, size: 14.7))
.foregroundColor(Color.grayee)
.padding(.top, 16)
.padding(.horizontal, 13.3)
TagLayoutView(
seriesDetail.keywordList,
tagFont: UIFont(name: Font.medium.rawValue, size: 12)!,
padding: 5.3,
parentWidth: width
) {
SeriesKeywordChipView(keyword: $0)
}
.padding(.horizontal, 13.3)
Rectangle()
.frame(height: 6.7)
.foregroundColor(Color.gray22)
VStack(alignment: .leading, spacing: 13.3) {
Text("작품소개")
.font(.custom(Font.bold.rawValue, size: 14.7))
.foregroundColor(Color.grayee)
Text(seriesDetail.introduction)
.font(.custom(Font.medium.rawValue, size: 14.7))
.foregroundColor(Color.gray77)
.lineSpacing(4)
}
.padding(.horizontal, 13.3)
Rectangle()
.frame(height: 6.7)
.foregroundColor(Color.gray22)
VStack(alignment: .leading, spacing: 16) {
Text("상세정보")
.font(.custom(Font.bold.rawValue, size: 14.7))
.foregroundColor(Color.grayee)
HStack(spacing: 30) {
VStack(alignment: .leading, spacing: 13.3) {
Text("장르")
.font(.custom(Font.medium.rawValue, size: 14.7))
.foregroundColor(Color.gray77)
Text("연령제한")
.font(.custom(Font.medium.rawValue, size: 14.7))
.foregroundColor(Color.gray77)
if let _ = seriesDetail.writer {
Text("작가")
.font(.custom(Font.medium.rawValue, size: 14.7))
.foregroundColor(Color.gray77)
}
if let _ = seriesDetail.studio {
Text("제작사")
.font(.custom(Font.medium.rawValue, size: 14.7))
.foregroundColor(Color.gray77)
}
Text("연재")
.font(.custom(Font.medium.rawValue, size: 14.7))
.foregroundColor(Color.gray77)
Text("출시일")
.font(.custom(Font.medium.rawValue, size: 14.7))
.foregroundColor(Color.gray77)
}
VStack(alignment: .leading, spacing: 13.3) {
Text(seriesDetail.genre)
.font(.custom(Font.medium.rawValue, size: 14.7))
.foregroundColor(Color.white)
Text(seriesDetail.isAdult ? "19세 이상" : "전체연령가")
.font(.custom(Font.medium.rawValue, size: 14.7))
.foregroundColor(Color.white)
if let writer = seriesDetail.writer {
Text(writer)
.font(.custom(Font.medium.rawValue, size: 14.7))
.foregroundColor(Color.white)
}
if let studio = seriesDetail.studio {
Text(studio)
.font(.custom(Font.medium.rawValue, size: 14.7))
.foregroundColor(Color.white)
}
Text(seriesDetail.publishedDaysOfWeek == "랜덤" ? seriesDetail.publishedDaysOfWeek : "\(seriesDetail.publishedDaysOfWeek)요일")
.font(.custom(Font.medium.rawValue, size: 14.7))
.foregroundColor(Color.white)
Text(seriesDetail.publishedDate)
.font(.custom(Font.medium.rawValue, size: 14.7))
.foregroundColor(Color.white)
}
}
}
.padding(.horizontal, 13.3)
VStack(alignment: .leading, spacing: 13.3) {
Text("가격")
.font(.custom(Font.bold.rawValue, size: 14.7))
.foregroundColor(Color.grayee)
HStack(spacing: 30) {
VStack(alignment: .leading, spacing: 13.3) {
Text("대여")
.font(.custom(Font.medium.rawValue, size: 14.7))
.foregroundColor(Color.gray77)
Text("소장")
.font(.custom(Font.medium.rawValue, size: 14.7))
.foregroundColor(Color.gray77)
}
VStack(alignment: .leading, spacing: 13.3) {
Text("\(calculatePriceInfo(seriesDetail.rentalMinPrice, seriesDetail.rentalMaxPrice)) (15일)")
.font(.custom(Font.medium.rawValue, size: 14.7))
.foregroundColor(Color.button)
Text("\(calculatePriceInfo(seriesDetail.minPrice, seriesDetail.maxPrice))")
.font(.custom(Font.medium.rawValue, size: 14.7))
.foregroundColor(Color.button)
}
}
}
.padding(.horizontal, 13.3)
}
}
func calculatePriceInfo(_ minPrice: Int, _ maxPrice: Int) -> String {
if minPrice == maxPrice {
if maxPrice == 0 {
return "무료"
} else {
return "\(maxPrice)"
}
} else {
return "\(minPrice == 0 ? "무료" : "\(minPrice)") ~ \(maxPrice)"
}
}
}

View File

@@ -0,0 +1,195 @@
//
// SeriesDetailView.swift
// SodaLive
//
// Created by klaus on 4/29/24.
//
import SwiftUI
import Kingfisher
struct SeriesDetailView: View {
@ObservedObject var viewModel = SeriesDetailViewModel()
let seriesId: Int
var body: some View {
BaseView(isLoading: $viewModel.isLoading) {
ZStack(alignment: .top) {
Color.gray11.ignoresSafeArea()
if let seriesDetail = viewModel.seriesDetail {
KFImage(URL(string: seriesDetail.coverImage))
.resizable()
.scaledToFit()
.frame(maxWidth: .infinity)
.blur(radius: 25)
ScrollView(.vertical, showsIndicators: false) {
VStack(spacing: 0) {
HStack(spacing: 0) {
Image("ic_back")
.resizable()
.frame(width: 20, height: 20)
.onTapGesture { AppState.shared.back() }
Spacer()
}
.padding(.horizontal, 13.3)
.frame(height: 50)
ZStack {
Rectangle()
.frame(width: screenSize().width, height: 94)
.foregroundColor(Color.gray11)
.cornerRadius(21.3, corners: [.topLeft, .topRight])
.padding(.top, 94)
KFImage(URL(string: seriesDetail.coverImage))
.resizable()
.scaledToFit()
.cornerRadius(5)
.frame(width: 133.3, height: 188)
}
VStack(alignment: .leading, spacing: 0) {
Text(seriesDetail.title)
.font(.custom(Font.bold.rawValue, size: 18.3))
.foregroundColor(Color.grayee)
.padding(.horizontal, 13.3)
.padding(.top, 24)
HStack(spacing: 5.3) {
Text(seriesDetail.genre)
.font(.custom(Font.medium.rawValue, size: 12))
.foregroundColor(Color(hex: "3bac6a"))
.padding(.horizontal, 5.3)
.padding(.vertical, 3.3)
.background(Color(hex: "28312b"))
.cornerRadius(2.6)
if seriesDetail.isAdult {
Text("19세")
.font(.custom(Font.medium.rawValue, size: 12))
.foregroundColor(Color(hex: "f1291c"))
.padding(.horizontal, 5.3)
.padding(.vertical, 3.3)
.background(Color(hex: "312827"))
.cornerRadius(2.6)
} else {
Text("전체연령가")
.font(.custom(Font.medium.rawValue, size: 12))
.foregroundColor(Color(hex: "d2d2d2"))
.padding(.horizontal, 5.3)
.padding(.vertical, 3.3)
.background(Color(hex: "222222"))
.cornerRadius(2.6)
}
Text(seriesDetail.publishedDaysOfWeek)
.font(.custom(Font.medium.rawValue, size: 12))
.foregroundColor(Color(hex: "909090"))
}
.padding(.top, 8)
.padding(.horizontal, 13.3)
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 5.3) {
ForEach(0..<seriesDetail.keywordList.count, id: \.self) {
SeriesKeywordChipView(keyword: seriesDetail.keywordList[$0])
}
}
}
.padding(.top, 16)
.padding(.horizontal, 13.3)
HStack(spacing: 5.3) {
KFImage(URL(string: seriesDetail.creator.profileImage))
.resizable()
.scaledToFit()
.clipShape(Circle())
.frame(width: 26.7, height: 26.7)
Text(seriesDetail.creator.nickname)
.font(.custom(Font.medium.rawValue, size: 12))
.foregroundColor(Color(hex: "909090"))
Spacer()
if seriesDetail.creator.creatorId != UserDefaults.int(forKey: .userId) {
Image(viewModel.isFollow ? "btn_following_big" : "btn_follow_big")
.onTapGesture {
if viewModel.isFollow {
viewModel.unFollow(seriesDetail.creator.creatorId)
} else {
viewModel.follow(seriesDetail.creator.creatorId)
}
}
}
}
.padding(.top, 16)
.padding(.horizontal, 13.3)
HStack(spacing: 0) {
SeriesDetailTabView(
title: "",
width: screenSize().width / 2,
isSelected: viewModel.currentTab == .home
) {
if viewModel.currentTab != .home {
viewModel.currentTab = .home
}
}
SeriesDetailTabView(
title: "작품소개",
width: screenSize().width / 2,
isSelected: viewModel.currentTab == .introduction
) {
if viewModel.currentTab != .introduction {
viewModel.currentTab = .introduction
}
}
}
.padding(.top, 16)
Rectangle()
.foregroundColor(Color.gray90.opacity(0.5))
.frame(height: 1)
.frame(maxWidth: .infinity)
switch(viewModel.currentTab) {
case .introduction:
SeriesDetailIntroductionView(
width: screenSize().width - 26.7,
seriesDetail: seriesDetail
)
default:
SeriesDetailHomeView(
title: seriesDetail.title,
seriesId: seriesDetail.seriesId,
contentCount: seriesDetail.contentCount,
contentList: seriesDetail.contentList
)
}
}
.padding(.bottom, 10)
.background(Color.gray11)
}
}
}
}
}
.onAppear {
viewModel.seriesId = seriesId
viewModel.getSeriesDetail()
}
}
}
#Preview {
SeriesDetailView(seriesId: 0)
}

View File

@@ -0,0 +1,151 @@
//
// SeriesDetailViewModel.swift
// SodaLive
//
// Created by klaus on 4/29/24.
//
import Foundation
import Combine
final class SeriesDetailViewModel: ObservableObject {
private let repository = SeriesRepository()
private let userRepository = UserRepository()
private var subscription = Set<AnyCancellable>()
@Published var isLoading = false
@Published var errorMessage = ""
@Published var isShowPopup = false
@Published var isFollow: Bool = false
@Published var seriesDetail: GetSeriesDetailResponse? = nil
var seriesId: Int = 0
func getSeriesDetail() {
isLoading = true
repository
.getSeriesDetail(seriesId: seriesId)
.sink { result in
switch result {
case .finished:
DEBUG_LOG("finish")
case .failure(let error):
ERROR_LOG(error.localizedDescription)
}
} receiveValue: { [unowned self] response in
let responseData = response.data
do {
let jsonDecoder = JSONDecoder()
let decoded = try jsonDecoder.decode(ApiResponse<GetSeriesDetailResponse>.self, from: responseData)
if let data = decoded.data, decoded.success {
self.seriesDetail = data
self.isFollow = data.creator.isFollow
} else {
if let message = decoded.message {
self.errorMessage = message
} else {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
}
self.isShowPopup = true
}
} catch {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
self.isShowPopup = true
}
self.isLoading = false
}
.store(in: &subscription)
}
func follow(_ creatorId: Int) {
isLoading = true
userRepository.creatorFollow(creatorId: creatorId)
.sink { result in
switch result {
case .finished:
DEBUG_LOG("finish")
case .failure(let error):
ERROR_LOG(error.localizedDescription)
}
} receiveValue: { [unowned self] response in
self.isLoading = false
let responseData = response.data
do {
let jsonDecoder = JSONDecoder()
let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
if decoded.success {
self.isFollow = !self.isFollow
} else {
if let message = decoded.message {
self.errorMessage = message
} else {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
}
self.isShowPopup = true
}
} catch {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
self.isShowPopup = true
}
self.isLoading = false
}
.store(in: &subscription)
}
func unFollow(_ creatorId: Int) {
isLoading = true
userRepository.creatorUnFollow(creatorId: creatorId)
.sink { result in
switch result {
case .finished:
DEBUG_LOG("finish")
case .failure(let error):
ERROR_LOG(error.localizedDescription)
}
} receiveValue: { [unowned self] response in
self.isLoading = false
let responseData = response.data
do {
let jsonDecoder = JSONDecoder()
let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
if decoded.success {
self.isFollow = !self.isFollow
} else {
if let message = decoded.message {
self.errorMessage = message
} else {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
}
self.isShowPopup = true
}
} catch {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
self.isShowPopup = true
}
self.isLoading = false
}
.store(in: &subscription)
}
enum CurrentTab: String {
case home, introduction
}
@Published var currentTab: CurrentTab = .home
}