From d1b5ab31aafb978ce2eda69a718abbfa6220b6dc Mon Sep 17 00:00:00 2001 From: Yu Sung Date: Sat, 23 Sep 2023 00:08:23 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BD=98=ED=85=90=EC=B8=A0=20=EC=97=85?= =?UTF-8?q?=EB=A1=9C=EB=93=9C=20-=20=EB=AF=B8=EB=A6=AC=20=EB=93=A3?= =?UTF-8?q?=EA=B8=B0=20=EC=8B=9C=EA=B0=84=20=EC=84=A4=EC=A0=95=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Content/Create/ContentCreateView.swift | 49 +++++++++++++++ .../Create/ContentCreateViewModel.swift | 63 ++++++++++++++++++- .../Create/CreateAudioContentRequest.swift | 2 + 3 files changed, 113 insertions(+), 1 deletion(-) diff --git a/SodaLive/Sources/Content/Create/ContentCreateView.swift b/SodaLive/Sources/Content/Create/ContentCreateView.swift index 1e34034..f201e67 100644 --- a/SodaLive/Sources/Content/Create/ContentCreateView.swift +++ b/SodaLive/Sources/Content/Create/ContentCreateView.swift @@ -321,6 +321,55 @@ struct ContentCreateView: View { .padding(.top, 26.7) .padding(.horizontal, 13.3) + VStack(spacing: 13.3) { + Text("미리듣기 시간 설정") + .font(.custom(Font.bold.rawValue, size: 16.7)) + .foregroundColor(Color(hex: "eeeeee")) + .frame(maxWidth: .infinity, alignment: .leading) + + HStack(spacing: 13.3) { + VStack(spacing: 5.3) { + Text("시작 시간") + .font(.custom(Font.medium.rawValue, size: 13.3)) + .foregroundColor(Color(hex: "d2d2d2")) + .frame(maxWidth: .infinity, alignment: .leading) + + TextField("00:00:00", text: $viewModel.previewStartTime) + .autocapitalization(.none) + .disableAutocorrection(true) + .font(.custom(Font.bold.rawValue, size: 14.6)) + .foregroundColor(Color(hex: "777777")) + .padding(.vertical, 16.7) + .padding(.horizontal, 13.3) + .background(Color(hex: "222222")) + .cornerRadius(6.7) + .keyboardType(.default) + .multilineTextAlignment(.center) + } + + VStack(spacing: 5.3) { + Text("종료 시간") + .font(.custom(Font.medium.rawValue, size: 13.3)) + .foregroundColor(Color(hex: "d2d2d2")) + .frame(maxWidth: .infinity, alignment: .leading) + + TextField("00:00:30", text: $viewModel.previewEndTime) + .autocapitalization(.none) + .disableAutocorrection(true) + .font(.custom(Font.bold.rawValue, size: 14.6)) + .foregroundColor(Color(hex: "777777")) + .padding(.vertical, 16.7) + .padding(.horizontal, 13.3) + .background(Color(hex: "222222")) + .cornerRadius(6.7) + .keyboardType(.default) + .multilineTextAlignment(.center) + } + } + } + .padding(.top, 26.7) + .padding(.horizontal, 13.3) + VStack(spacing: 0) { HStack(alignment: .top, spacing: 0) { Text("등록") diff --git a/SodaLive/Sources/Content/Create/ContentCreateViewModel.swift b/SodaLive/Sources/Content/Create/ContentCreateViewModel.swift index 2f11e08..f043e06 100644 --- a/SodaLive/Sources/Content/Create/ContentCreateViewModel.swift +++ b/SodaLive/Sources/Content/Create/ContentCreateViewModel.swift @@ -58,6 +58,9 @@ final class ContentCreateViewModel: ObservableObject { } } + @Published var previewStartTime: String = "" + @Published var previewEndTime: String = "" + var placeholder = "내용을 입력하세요" func uploadAudioContent() { @@ -71,7 +74,9 @@ final class ContentCreateViewModel: ObservableObject { price: price, themeId: theme!.id, isAdult: isAdult, - isCommentAvailable: isAvailableComment + isCommentAvailable: isAvailableComment, + previewStartTime: previewStartTime, + previewEndTime: previewEndTime ) var multipartData = [MultipartFormData]() @@ -211,6 +216,62 @@ final class ContentCreateViewModel: ObservableObject { return false } + if previewStartTime.count > 0 && previewEndTime.count > 0 { + let startTimeArray = previewStartTime.split(separator: ":") + if startTimeArray.count != 3 { + errorMessage = "미리 듣기 시간 형식은 00:30:00 과 같아야 합니다" + isShowPopup = true + return false + } + + for time in startTimeArray { + if time.count != 2 { + errorMessage = "미리 듣기 시간 형식은 00:30:00 과 같아야 합니다" + isShowPopup = true + return false + } + } + + let endTimeArray = previewStartTime.split(separator: ":") + if endTimeArray.count != 3 { + errorMessage = "미리 듣기 시간 형식은 00:30:00 과 같아야 합니다" + isShowPopup = true + return false + } + + for time in endTimeArray { + if time.count != 2 { + errorMessage = "미리 듣기 시간 형식은 00:30:00 과 같아야 합니다" + isShowPopup = true + return false + } + } + + let timeDifference = timeDifference(startTime: previewStartTime, endTime: previewEndTime) + if timeDifference < 30.0 { + errorMessage = "미리 듣기의 최소 시간은 30초 입니다" + isShowPopup = true + return false + } + } else { + if previewStartTime.count > 0 || previewEndTime.count > 0 { + errorMessage = "미리 듣기 시작 시간과 종료 시간 둘 다 입력을 하거나 둘 다 입력 하지 않아야 합니다." + isShowPopup = true + return false + } + } + return true } + + private func timeDifference(startTime: String, endTime: String) -> Double { + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "HH:mm:ss" + + if let date1 = dateFormatter.date(from: startTime), let date2 = dateFormatter.date(from: endTime) { + return date2.timeIntervalSince(date1) + } + + return 0 + } } diff --git a/SodaLive/Sources/Content/Create/CreateAudioContentRequest.swift b/SodaLive/Sources/Content/Create/CreateAudioContentRequest.swift index 98bc462..458b18c 100644 --- a/SodaLive/Sources/Content/Create/CreateAudioContentRequest.swift +++ b/SodaLive/Sources/Content/Create/CreateAudioContentRequest.swift @@ -15,4 +15,6 @@ struct CreateAudioContentRequest: Encodable { let themeId: Int let isAdult: Bool let isCommentAvailable: Bool + let previewStartTime: String + let previewEndTime: String }