// // ContentModifyView.swift // SodaLive // // Created by klaus on 2023/08/13. // import SwiftUI import Kingfisher struct ContentModifyView: View { let contentId: Int @StateObject var keyboardHandler = KeyboardHandler() @StateObject private var viewModel = ContentModifyViewModel() @State private var isShowPhotoPicker = false var body: some View { BaseView(isLoading: $viewModel.isLoading) { GeometryReader { proxy in ZStack { VStack(spacing: 0) { DetailNavigationBar(title: I18n.CreateContent.modifyTitle) ScrollView(.vertical, showsIndicators: false) { VStack(spacing: 0) { Text(I18n.CreateContent.thumbnail) .appFont(size: 16.7, weight: .bold) .foregroundColor(Color(hex: "eeeeee")) .frame(maxWidth: .infinity, alignment: .leading) ZStack { if let selectedImage = viewModel.coverImage { Image(uiImage: selectedImage) .resizable() .scaledToFill() .frame(width: 107, height: 107) .background(Color(hex: "3e3358")) .cornerRadius(8) .clipped() } else if let coverImageUrl = viewModel.coverImageUrl { KFImage(URL(string: coverImageUrl)) .cancelOnDisappear(true) .downsampling( size: CGSize( width: 107, height: 107 ) ) .resizable() .scaledToFill() .frame(width: 107, height: 107) .background(Color(hex: "3e3358")) .cornerRadius(8) .clipped() } else { Image("ic_logo") .resizable() .scaledToFit() .padding(13.3) .frame(width: 107, height: 107) .background(Color(hex: "3e3358")) .cornerRadius(8) } Image("ic_camera") .padding(10) .background(Color.button) .cornerRadius(30) .offset(x: 50, y: 36) } .frame(alignment: .bottomTrailing) .onTapGesture { isShowPhotoPicker = true } } .padding(.top, 13.3) .padding(.horizontal, 13.3) Rectangle() .foregroundColor(Color(hex: "232323")) .frame(height: 6.7) .padding(.top, 26.7) VStack(spacing: 0) { Text(I18n.CreateContent.titleLabel) .appFont(size: 16.7, weight: .bold) .foregroundColor(Color(hex: "eeeeee")) .frame(maxWidth: .infinity, alignment: .leading) TextField(I18n.CreateContent.titlePlaceholder, text: $viewModel.title) .autocapitalization(.none) .disableAutocorrection(true) .appFont(size: 13.3, weight: .medium) .foregroundColor(Color(hex: "eeeeee")) .padding(.vertical, 16.7) .padding(.horizontal, 13.3) .background(Color(hex: "222222")) .cornerRadius(6.7) .keyboardType(.default) .padding(.top, 13.3) HStack(spacing: 0) { Text(I18n.CreateContent.contentLabel) .appFont(size: 16.7, weight: .bold) .foregroundColor(Color(hex: "eeeeee")) Spacer() Text(I18n.CreateContent.characterCount(viewModel.detail.count)) .appFont(size: 13.3, weight: .medium) .foregroundColor(Color(hex: "ff5c49")) Text(I18n.CreateContent.max500CharactersSuffix) .appFont(size: 13.3, weight: .medium) .foregroundColor(Color(hex: "777777")) } .padding(.top, 26.7) TextViewWrapper( text: $viewModel.detail, placeholder: viewModel.placeholder, textColorHex: "eeeeee", backgroundColorHex: "222222" ) .frame(height: 184) .cornerRadius(6.7) .padding(.top, 13.3) Text(I18n.CreateContent.tagLabel) .appFont(size: 16.7, weight: .bold) .foregroundColor(Color.grayee) .frame(maxWidth: .infinity, alignment: .leading) .padding(.top, 26.7) TextField(I18n.CreateContent.tagPlaceholderExample, text: $viewModel.hashtags) .autocapitalization(.none) .disableAutocorrection(true) .appFont(size: 13.3, weight: .medium) .foregroundColor(Color.grayee) .padding(.vertical, 16.7) .padding(.horizontal, 13.3) .background(Color.gray22) .cornerRadius(6.7) .keyboardType(.default) .padding(.top, 13.3) } .padding(.top, 26.7) .padding(.horizontal, 13.3) Rectangle() .foregroundColor(Color(hex: "232323")) .frame(height: 6.7) .padding(.top, 26.7) VStack(spacing: 13.3) { Text(I18n.CreateContent.pointUsageTitle) .appFont(size: 16.7, weight: .bold) .foregroundColor(Color.grayee) .frame(maxWidth: .infinity, alignment: .leading) HStack(spacing: 13.3) { SelectButtonView(title: I18n.CreateContent.available, isChecked: viewModel.isPointAvailable) { if !viewModel.isPointAvailable { viewModel.isPointAvailable = true } } SelectButtonView(title: I18n.CreateContent.unavailable, isChecked: !viewModel.isPointAvailable) { if viewModel.isPointAvailable { viewModel.isPointAvailable = false } } } } .padding(.top, 26.7) .padding(.horizontal, 13.3) if viewModel.isAdultShowUi { VStack(spacing: 13.3) { Text(I18n.CreateContent.ageRestrictionTitle) .appFont(size: 16.7, weight: .bold) .foregroundColor(Color(hex: "eeeeee")) .frame(maxWidth: .infinity, alignment: .leading) HStack(spacing: 13.3) { SelectButtonView(title: I18n.CreateContent.allAges, isChecked: !viewModel.isAdult) { if viewModel.isAdult { viewModel.isAdult = false } } SelectButtonView(title: I18n.CreateContent.over19, isChecked: viewModel.isAdult) { if !viewModel.isAdult { viewModel.isAdult = true } } } Text(I18n.CreateContent.adultLegalNotice) .appFont(size: 13.3, weight: .medium) .foregroundColor(Color(hex: "DD4500")) .frame(maxWidth: .infinity, alignment: .leading) .padding(.top, 13.3) } .padding(.top, 26.7) .padding(.horizontal, 13.3) } VStack(spacing: 13.3) { Text(I18n.CreateContent.commentAvailabilityTitle) .appFont(size: 16.7, weight: .bold) .foregroundColor(Color(hex: "eeeeee")) .frame(maxWidth: .infinity, alignment: .leading) HStack(spacing: 13.3) { SelectButtonView(title: I18n.CreateContent.commentAllowed, isChecked: viewModel.isAvailableComment) { if !viewModel.isAvailableComment { viewModel.isAvailableComment = true } } SelectButtonView(title: I18n.CreateContent.commentNotAllowed, isChecked: !viewModel.isAvailableComment) { if viewModel.isAvailableComment { viewModel.isAvailableComment = false } } } } .padding(.top, 26.7) .padding(.horizontal, 13.3) VStack(spacing: 0) { HStack(alignment: .top, spacing: 0) { Text(I18n.CreateContent.modifyAction) .appFont(size: 18.3, weight: .bold) .foregroundColor(Color.white) .frame(height: 50) .frame(maxWidth: .infinity) .background(Color.button) .cornerRadius(10) .padding(13.3) } .frame(maxWidth: .infinity) .background(Color(hex: "222222")) .cornerRadius(16.7, corners: [.topLeft, .topRight]) .onTapGesture { hideKeyboard() viewModel.modifyAudioContent { DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { AppState.shared.back() } } } Rectangle() .foregroundColor(Color(hex: "222222")) .frame(height: keyboardHandler.keyboardHeight) .frame(maxWidth: .infinity) if proxy.safeAreaInsets.bottom > 0 { Rectangle() .foregroundColor(Color(hex: "222222")) .frame(height: 15.3) .frame(maxWidth: .infinity) } } .padding(.top, 30) } } if isShowPhotoPicker { ImagePicker( isShowing: $isShowPhotoPicker, selectedImage: $viewModel.coverImage, sourceType: .photoLibrary ) } } .onTapGesture { hideKeyboard() } .edgesIgnoringSafeArea(.bottom) .sodaToast(isPresented: $viewModel.isShowPopup, message: viewModel.errorMessage, autohideIn: 2) .onAppear { viewModel.contentId = contentId viewModel.getAudioContentDetail { DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { AppState.shared.back() } } } } } } }