diff --git a/MEME/MEME.xcodeproj/project.pbxproj b/MEME/MEME.xcodeproj/project.pbxproj index 791abd1..c78cac7 100644 --- a/MEME/MEME.xcodeproj/project.pbxproj +++ b/MEME/MEME.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ 09275E822B518D150033EF34 /* ArtistHomeViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 09275E812B518D150033EF34 /* ArtistHomeViewController.xib */; }; 09275E892B528A610033EF34 /* ArtistReservationStatusTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09275E872B528A610033EF34 /* ArtistReservationStatusTableViewCell.swift */; }; 09275E8A2B528A610033EF34 /* ArtistReservationStatusTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 09275E882B528A610033EF34 /* ArtistReservationStatusTableViewCell.xib */; }; + 0936EDDA2C57FAD300212AF0 /* PortfolioImageCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0936EDD92C57FAD300212AF0 /* PortfolioImageCollectionViewCell.swift */; }; 094884C72B584B7000C233E0 /* ArtistMakeupTagCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 094884C52B584B7000C233E0 /* ArtistMakeupTagCollectionViewCell.swift */; }; 094884C82B584B7000C233E0 /* ArtistMakeupTagCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 094884C62B584B7000C233E0 /* ArtistMakeupTagCollectionViewCell.xib */; }; 094884CB2B584B8F00C233E0 /* ArtistPortfolioCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 094884C92B584B8F00C233E0 /* ArtistPortfolioCollectionViewCell.swift */; }; @@ -349,6 +350,7 @@ 09275E812B518D150033EF34 /* ArtistHomeViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ArtistHomeViewController.xib; sourceTree = ""; }; 09275E872B528A610033EF34 /* ArtistReservationStatusTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArtistReservationStatusTableViewCell.swift; sourceTree = ""; }; 09275E882B528A610033EF34 /* ArtistReservationStatusTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ArtistReservationStatusTableViewCell.xib; sourceTree = ""; }; + 0936EDD92C57FAD300212AF0 /* PortfolioImageCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PortfolioImageCollectionViewCell.swift; sourceTree = ""; }; 094884C52B584B7000C233E0 /* ArtistMakeupTagCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArtistMakeupTagCollectionViewCell.swift; sourceTree = ""; }; 094884C62B584B7000C233E0 /* ArtistMakeupTagCollectionViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ArtistMakeupTagCollectionViewCell.xib; sourceTree = ""; }; 094884C92B584B8F00C233E0 /* ArtistPortfolioCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArtistPortfolioCollectionViewCell.swift; sourceTree = ""; }; @@ -776,6 +778,7 @@ isa = PBXGroup; children = ( 0957424F2B66153E0011B580 /* ArtistPortfolioEditingViewController.swift */, + 0936EDD92C57FAD300212AF0 /* PortfolioImageCollectionViewCell.swift */, 095742502B66153E0011B580 /* ArtistPortfolioEditingViewController.xib */, ); path = ArtistPortfolioEditingView; @@ -2411,6 +2414,7 @@ 31EA86F42BBFEC39003BCBF7 /* MoyaAsyncError.swift in Sources */, CC2F3AC22B54361100508DA5 /* MyPageInfoViewController.swift in Sources */, 2DA2080B2B7AFC36006EB9B9 /* ModelSearchResultViewController.swift in Sources */, + 0936EDDA2C57FAD300212AF0 /* PortfolioImageCollectionViewCell.swift in Sources */, 316239672B80DE9B002D9E2F /* BasicResponseDTO.swift in Sources */, 31B4137E2B6D29C500535BB1 /* BusinessIDVerificationAPI.swift in Sources */, 31F6F8482B52C7B800EC621D /* NavigationBarView.swift in Sources */, diff --git a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.swift b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.swift index f07b247..175d079 100644 --- a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.swift +++ b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.swift @@ -6,20 +6,13 @@ // import UIKit +import PhotosUI -class ArtistPortfolioEditingViewController: UIViewController, UINavigationControllerDelegate { - //MARK: - UI Properties - @IBOutlet private weak var makeupCategoryCollectionView: UICollectionView! - @IBOutlet private weak var imagePickerStackView: UIStackView! - - @IBOutlet private weak var firstImgView: UIImageView! - @IBOutlet private weak var secondImgView: UIImageView! - @IBOutlet private weak var thirdImgView: UIImageView! - - @IBOutlet private weak var firstDeleteButton: UIButton! - @IBOutlet private weak var secondDeleteButton: UIButton! - @IBOutlet private weak var thirdDeleteButton: UIButton! +class ArtistPortfolioEditingViewController: UIViewController { + // MARK: - UI Properties + @IBOutlet private weak var portfolioImageCollectionView: UICollectionView! + @IBOutlet private weak var makeupCategoryCollectionView: UICollectionView! @IBOutlet private weak var makeupNameTextField: UITextField! @IBOutlet private weak var priceTextField: UITextField! @IBOutlet private weak var infoTextView: UITextView! @@ -37,34 +30,30 @@ class ArtistPortfolioEditingViewController: UIViewController, UINavigationContro return button }() - //MARK: - init + // MARK: - Properties + let portfolioId: Int + private var portfolioDetailData: PortfolioData! + private var isBlock = false + private var selectedCategory: PortfolioCategories? + private var portfolioImage = [UIImage(), UIImage(), UIImage()] + private var configuration = PHPickerConfiguration() + private var imageCount = 0 + private var selectedImageIndexPath = 0 + + // MARK: - Initialization init(receivedData: Int) { self.portfolioId = receivedData super.init(nibName: nil, bundle: nil) } + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } - //MARK: - Properties - let portfolioId: Int - private var portfolioDetailData: PortfolioData! - private var isBlock : Bool = false - private var selectedCategory: PortfolioCategories? - - private var buttonAt: Int = 0 - private var imgCnt: Int = 0 - private var isEdit: Bool = portfolioIdx == -1 ? false : true - private lazy var imgViewUrlList: [String] = [] - private var portfolioImageData: [ImageData]? - private lazy var imgViewList: [UIImageView] = { - return [self.firstImgView, self.secondImgView, self.thirdImgView] - }() - - //MARK: - ViewController 생명 주기 + // MARK: - View Lifecycle override func viewDidLoad() { super.viewDidLoad() - if isEdit { + if portfolioId == -1 { getPortfolioDetail() } configureSubviews() @@ -72,10 +61,11 @@ class ArtistPortfolioEditingViewController: UIViewController, UINavigationContro collectionViewConfigure() setUI() setupDismissKeyboardOnTapGesture() + imagePickerConfigure() } - //MARK: - setUI() - private func setUI(){ + // MARK: - UI Setup + private func setUI() { makeupCategoryCollectionView.backgroundColor = .white infoTextView.backgroundColor = .white self.tabBarController?.tabBar.isHidden = true @@ -83,252 +73,161 @@ class ArtistPortfolioEditingViewController: UIViewController, UINavigationContro infoTextView.layer.cornerRadius = 10 infoTextView.layer.borderWidth = 1 infoTextView.layer.borderColor = UIColor.gray200.cgColor - firstImgView.layer.cornerRadius = 5 - secondImgView.layer.cornerRadius = 5 - thirdImgView.layer.cornerRadius = 5 - - - [firstDeleteButton, secondDeleteButton, thirdDeleteButton].forEach { button in - button?.layer.cornerRadius = 5 - button?.layer.maskedCorners = .layerMaxXMinYCorner - button?.layer.masksToBounds = true - } priceTextField.keyboardType = .numberPad - if !isEdit { + + if portfolioId != -1 { artistProfileEditingInfoBar.setTitle("수정하기", for: .normal) self.navigationItem.title = "포트폴리오 수정" navigationItem.rightBarButtonItem = UIBarButtonItem(image: .icTrash.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(trashButtonDidTap)) - }else { - self.navigationItem.title = "포트폴리오 추가" + } else { + self.navigationItem.title = "포트폴리오 추가" artistProfileEditingInfoBar.setTitle("추가하기", for: .normal) } - deleteButtonAppear() } - //MARK: - collectionViewConfigure() - private func collectionViewConfigure(){ + // MARK: - CollectionView Configuration + private func collectionViewConfigure() { makeupCategoryCollectionView.delegate = self makeupCategoryCollectionView.dataSource = self makeupCategoryCollectionView.register(UINib(nibName: ArtistMakeupTagCollectionViewCell.className, bundle: nil), forCellWithReuseIdentifier: ArtistMakeupTagCollectionViewCell.className) + portfolioImageCollectionView.delegate = self + portfolioImageCollectionView.dataSource = self + portfolioImageCollectionView.register(PortfolioImageCollectionViewCell.self, forCellWithReuseIdentifier: PortfolioImageCollectionViewCell.className) } - //MARK: - codebase UI config + // MARK: - UI Configuration private func configureSubviews() { view.addSubview(artistProfileEditingInfoBar) } - //MARK: - codebase UI constraints private func makeConstraints() { - artistProfileEditingInfoBar.snp.makeConstraints {make in - make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom).offset(0) + artistProfileEditingInfoBar.snp.makeConstraints { make in + make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom) make.leading.equalTo(view.snp.leading).offset(24) make.trailing.equalTo(view.snp.trailing).offset(-24) make.height.equalTo(49) } } - //MARK: - deleteButtonAppear() - private func deleteButtonAppear() { - if self.imgCnt==3 { - firstDeleteButton.isHidden = false - secondDeleteButton.isHidden = false - thirdDeleteButton.isHidden = false - }else if self.imgCnt==2 { - firstDeleteButton.isHidden = true - secondDeleteButton.isHidden = false - thirdDeleteButton.isHidden = false - }else if self.imgCnt==1 { - firstDeleteButton.isHidden = true - secondDeleteButton.isHidden = false - thirdDeleteButton.isHidden = true - }else { - firstDeleteButton.isHidden = true - secondDeleteButton.isHidden = true - thirdDeleteButton.isHidden = true - } + private func imagePickerConfigure() { + configuration.selectionLimit = 1 + configuration.filter = .images } - //MARK: - @IBAction + + // MARK: - Actions @IBAction func backButtonDidTap(_ sender: UIButton) { let okAction = UIAlertAction(title: "예", style: .default) { [weak self] _ in self?.navigationController?.popViewController(animated: true) } - let noAction = UIAlertAction(title: "아니오", style: .cancel, handler: nil) + let noAction = UIAlertAction(title: "아니오", style: .cancel) - var title = "" - var message = "" + let title = portfolioId == -1 ? "포트폴리오 수정하기" : "포트폴리오 등록하기" + let message = portfolioId == -1 ? "\n포트폴리오 수정을 취소하시겠습니까?" : "\n포트폴리오 등록을 취소하시겠습니까?" - if isEdit { - title = "포트폴리오 수정하기" - message = "\n포트폴리오 수정을 취소하시겠습니까?" - } else { - title = "포트폴리오 등록하기" - message = "\n포트폴리오 등록을 취소하시겠습니까?" - } - - let alert = UIAlertController( - title: title, - message: message, - preferredStyle: .alert - ) - - // HIG에 따라 Cancel이 왼쪽 + let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) alert.addAction(okAction) alert.addAction(noAction) - present(alert, animated: true, completion: nil) + present(alert, animated: true) } @objc func editButtonDidTap(_ sender: UIButton) { - let okCreateAction = UIAlertAction(title: "예", style: .default) { [weak self] _ in - self?.createPortfolio(completion: { result in - self?.navigationController?.popViewController(animated: true) - }) - } - let okEditAction = UIAlertAction(title: "예", style: .default) { [weak self] _ in - self?.editPortfolio(completion: { result in - self?.navigationController?.popViewController(animated: true) - }) - } - - let noAction = UIAlertAction(title: "아니오", style: .cancel, handler: nil) - - var title = "" - var message = "" + let title = portfolioId == -1 ? "포트폴리오 수정하기" : "포트폴리오 등록하기" + let message = portfolioId == -1 ? "\n포트폴리오를 수정하시겠습니까?" : "\n포트폴리오를 등록하시겠습니까?" - if isEdit { - title = "포트폴리오 수정하기" - message = "\n포트폴리오를 수정하시겠습니까?" - } else { - title = "포트폴리오 등록하기" - message = "\n포트폴리오를 등록하시겠습니까?" + let okAction = UIAlertAction(title: "예", style: .default) { [weak self] _ in + // TODO: 포트폴리오 수정/등록 } + let noAction = UIAlertAction(title: "아니오", style: .cancel) let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) - - // HIG에 따라 Cancel이 왼쪽 - if isEdit{ - alert.addAction(okEditAction) - }else { - alert.addAction(okCreateAction) - } + alert.addAction(okAction) alert.addAction(noAction) - present(alert, animated: true, completion: nil) + present(alert, animated: true) } + @IBAction func trashButtonDidTap(_ sender: UIButton) { - let alert = UIAlertController(title: "포트폴리오 삭제하기", message: "\n포트폴리오를 삭제하시겠습니까?", preferredStyle: .alert) let okAction = UIAlertAction(title: "예", style: .default) { [weak self] _ in - self?.isBlock=true - self?.editPortfolio(completion: { result in - self?.navigationController?.popViewController(animated: true) - }) + self?.isBlock = true + // TODO: 포트폴리오 삭제 } - let noAction = UIAlertAction( - title: "아니오", - style: .cancel, - handler : nil - ) - // HIG에 따라 Cancel이 왼쪽 + let noAction = UIAlertAction(title: "아니오", style: .cancel) + alert.addAction(okAction) alert.addAction(noAction) - present(alert, animated: true, completion: nil) - } - @IBAction func pick(_ sender: UIButton) { - // 이미지 피커 컨트롤러 생성 - buttonAt = sender.tag - let picker = UIImagePickerController() - picker.sourceType = .photoLibrary // 이미지 소스로 사진 라이브러리 선택 - picker.allowsEditing = true // 이미지 편집 기능 On - // 델리게이트 지정 - picker.delegate = self - // 이미지 피커 컨트롤러 실행 - self.present(picker, animated: false) - } - @IBAction func deleteImg(_ sender: UIButton) { - buttonAt = sender.tag - if buttonAt==0 { - imgViewList[0].image = .icPicture - }else if buttonAt==1 { - if imgCnt==1 { - imgViewList[buttonAt].image = nil - imgViewList[0].image = .icPicture - imgViewUrlList[0] = "string" - }else if imgCnt==2 { - imgViewList[buttonAt].image = imgViewList[buttonAt+1].image - imgViewList[buttonAt+1].image = nil - imgViewList[0].image = .icPicture - }else { - imgViewList[buttonAt].image = imgViewList[buttonAt-1].image - imgViewList[0].image = .icPicture - } - }else{ - if imgCnt==3 { - imgViewList[buttonAt].image = imgViewList[buttonAt-1].image - imgViewList[buttonAt-1].image = imgViewList[buttonAt-2].image - imgViewList[0].image = .icPicture - }else { - imgViewList[buttonAt].image = nil - } - } - imgCnt-=1 - deleteButtonAppear() + present(alert, animated: true) } - } -//MARK: - UICollectionViewDataSource -extension ArtistPortfolioEditingViewController : UICollectionViewDataSource { +// MARK: - UICollectionViewDataSource +extension ArtistPortfolioEditingViewController: UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return portfolioCategories.count + if collectionView == makeupCategoryCollectionView { + return portfolioCategories.count + } else { + return imageCount == 3 ? 3 : imageCount + 1 + } } + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ArtistMakeupTagCollectionViewCell.className, for: indexPath) as? ArtistMakeupTagCollectionViewCell else { return UICollectionViewCell() } - let tagName = portfolioCategories[indexPath.row].korName - cell.makeupTagLabel.text = tagName - - if let selectedCategory = selectedCategory { - if selectedCategory == portfolioCategories[indexPath.row] { + if collectionView == makeupCategoryCollectionView { + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ArtistMakeupTagCollectionViewCell.className, for: indexPath) as? ArtistMakeupTagCollectionViewCell else { return UICollectionViewCell() } + let tagName = portfolioCategories[indexPath.row].korName + cell.makeupTagLabel.text = tagName + + if let selectedCategory = selectedCategory, selectedCategory == portfolioCategories[indexPath.row] { cell.selected() } else { + cell.deSelected() } + return cell } else { + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PortfolioImageCollectionViewCell.className, for: indexPath) as? PortfolioImageCollectionViewCell else { return UICollectionViewCell() } + cell.hideDeleteButton(imageCount != 3 && indexPath.row == 0) + cell.configure(image: imageCount == 3 ? portfolioImage[imageCount - 1 - indexPath.row] : (indexPath.row != 0 ? portfolioImage[imageCount - indexPath.row] : UIImage(named: "portfolio_image") ?? UIImage())) + cell.delegate = self + return cell } - return cell } } -//MARK: - UICollectionViewDelegate -extension ArtistPortfolioEditingViewController : UICollectionViewDelegate { +// MARK: - UICollectionViewDelegate +extension ArtistPortfolioEditingViewController: UICollectionViewDelegate { func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - // 선택된 indexPath에 대한 셀을 가져오기 - if let selectedCell = collectionView.cellForItem(at: indexPath) as? ArtistMakeupTagCollectionViewCell { - // 선택된 셀에 대한 작업 수행 - selectedCell.selected() - selectedCategory = portfolioCategories[indexPath.row] - } - - // 나머지 indexPath에 대한 셀을 가져와서 작업 수행 - for visibleIndexPath in collectionView.indexPathsForVisibleItems { - if visibleIndexPath != indexPath, - let deselectedCell = collectionView.cellForItem(at: visibleIndexPath) as? ArtistMakeupTagCollectionViewCell { - // 선택되지 않은 셀에 대한 작업 수행 - deselectedCell.deSelected() + if collectionView == makeupCategoryCollectionView { + if let selectedCell = collectionView.cellForItem(at: indexPath) as? ArtistMakeupTagCollectionViewCell { + selectedCell.selected() + selectedCategory = portfolioCategories[indexPath.row] + } + + for visibleIndexPath in collectionView.indexPathsForVisibleItems { + if visibleIndexPath != indexPath, let deselectedCell = collectionView.cellForItem(at: visibleIndexPath) as? ArtistMakeupTagCollectionViewCell { + deselectedCell.deSelected() + } } + } else { + selectedImageIndexPath = indexPath.row + let picker = PHPickerViewController(configuration: configuration) + picker.delegate = self + self.present(picker, animated: true) + portfolioImageCollectionView.reloadData() } } } -//MARK: - UICollectionViewDelegateFlowLayout +// MARK: - UICollectionViewDelegateFlowLayout extension ArtistPortfolioEditingViewController: UICollectionViewDelegateFlowLayout { func collectionView( _ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath ) -> CGSize { + if collectionView == makeupCategoryCollectionView { var width = 97 switch indexPath.row { case 3: @@ -341,147 +240,44 @@ extension ArtistPortfolioEditingViewController: UICollectionViewDelegateFlowLayo break } return CGSize(width: width, height: 27) + } else { + return CGSize(width: 80, height: 82) + } } + func collectionView( _ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int ) -> CGFloat { - return CGFloat(7) + return 7 } + func collectionView( _ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int ) -> CGFloat { - return CGFloat(15) + return 15 } } -// MARK: - UIImagePickerControllerDelegate -extension ArtistPortfolioEditingViewController : UIImagePickerControllerDelegate{ - func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { - // 이미지 피커 컨트롤러 창 닫기 - self.dismiss(animated: false) { () in - // 알림 창 호출 - let alert = UIAlertController( - title: "", - message: "이미지 선택이 취소되었습니다.", - preferredStyle: .alert - ) - alert.addAction(UIAlertAction( - title: "확인", - style: .cancel - )) - self.present(alert, animated: false) - } - } - // 이미지 피커에서 이미지를 선택했을 때 호출되는 메소드 - func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { - // 이미지 피커 컨트롤러 창 닫기 - picker.dismiss(animated: false) { () in - let img = info[UIImagePickerController.InfoKey.editedImage] as? UIImage - self.imgViewList[1].image = img - self.imgCnt += 1 - self.deleteButtonAppear() - - } - } -} - -//MARK: - API 호출 +// MARK: - API Calls extension ArtistPortfolioEditingViewController { private func getPortfolioDetail() { - let getPortfolio = PortfolioManager.shared - self.infoTextViewPlaceHolderLabel.isHidden = true - getPortfolio.getPortfolioDetail(userId: modelID, portfolioId: portfolioId) { result in - switch result { - case .success(let response): - if let url = URL(string: response.data!.portfolioImgDtoList![0].portfolioImgSrc) { - URLSession.shared.dataTask( - with: url) { - data, response, error in - DispatchQueue.main.async { - if let data = data, error == nil { - self.imgCnt = 1 - self.deleteButtonAppear() - self.secondImgView.image = UIImage(data: data) - } else { - self.secondImgView.image = nil - } - } - }.resume() - self.portfolioImageData = response.data?.portfolioImgDtoList - } else { - self.firstImgView.image = nil - } - self.portfolioDetailData = response.data - self.selectedCategory = PortfolioCategories(rawValue: response.data!.category) - self.makeupCategoryCollectionView.reloadData() - self.makeupNameTextField.text = response.data?.makeupName - self.priceTextField.text = String(response.data!.price) - self.infoTextView.text = response.data?.info - case .failure(let error): - print(error) - } - } + // TODO: 포트폴리오 세부조회 API } - private func createPortfolio(completion: @escaping (Bool) -> Void) { - let createPortfolio = PortfolioManager.shared - createPortfolio.createPortfolio( - artistId: artistID, - category: selectedCategory!, - makeup_name: makeupNameTextField.text!, - price: Int(priceTextField.text!)!, - info: infoTextView.text!, - portfolio_img_src: imgViewUrlList - ) { result in - switch result { - case .success(let data): - print(data.message) - completion(true) - case .failure(let error): - print(error.localizedDescription) - completion(false) - } - } + private func createPortfolio() { + // TODO: 포트폴리오 추가 API } - private func editPortfolio(completion: @escaping (Bool) -> Void) { - FirebaseStorageManager.uploadImage(image: imgViewList[0].image!) { [self] url in - guard - let url = url, - let aritstId = KeyChainManager.read(forkey: .memberId) as? Int - else { return } // 성공적으로 업로드 했으면 url이 nil 값이 아님 - portfolioImageData?[0].portfolioImgSrc = url.absoluteString - portfolioImageData?[0].delete = false - let editPortfolio = PortfolioManager.shared - editPortfolio.editPortfolio( - artistId: aritstId, - portfolioId: portfolioId, - category: selectedCategory!, - makeup_name: makeupNameTextField.text!, - price: Int(priceTextField.text!)!, - info: infoTextView.text, - isBlock: isBlock, - portfolio_img_src: portfolioImageData! - ) { result in - switch result { - case .success(let response): - print("성공" + response.message) - completion(true) - case .failure(let error): - print("수정 실패" + error.localizedDescription) - completion(false) - } - } - } + private func editPortfolio() { + // TODO: 포트폴리오 수정 API } - } -// MARK: - keyboard tabGesture +// MARK: - Keyboard Handling extension ArtistPortfolioEditingViewController { func setupDismissKeyboardOnTapGesture() { let tapGesture = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)) @@ -494,14 +290,58 @@ extension ArtistPortfolioEditingViewController { } } -// MARK: - textView PlaceHolder +// MARK: - UITextViewDelegate extension ArtistPortfolioEditingViewController: UITextViewDelegate { func textViewDidChange(_ textView: UITextView) { - if let text = textView.text, !text.isEmpty { - self.infoTextViewPlaceHolderLabel.isHidden = true - } else { - self.infoTextViewPlaceHolderLabel.isHidden = false + infoTextViewPlaceHolderLabel.isHidden = !textView.text.isEmpty + } +} + +// MARK: - PortfolioImageCollectionViewCellDelegate +extension ArtistPortfolioEditingViewController: PortfolioImageCollectionViewCellDelegate { + func deleteButtonTapped(_ cell: PortfolioImageCollectionViewCell) { + guard let indexPath = portfolioImageCollectionView.indexPath(for: cell) else { return } + portfolioImage[2 - indexPath.row] = UIImage() + moveEmptyImagesToEnd() + imageCount -= 1 + if imageCount == 2 { + let temp = portfolioImage[0] + portfolioImage[0] = portfolioImage[1] + portfolioImage[1] = temp + } + portfolioImageCollectionView.reloadData() + } + + private func moveEmptyImagesToEnd() { + portfolioImage.sort { (first, second) -> Bool in + if first == UIImage() && second == UIImage() { return false } + if first == UIImage() { return false } + if second == UIImage() { return true } + return true } } } +// MARK: - PHPickerViewControllerDelegate +extension ArtistPortfolioEditingViewController: PHPickerViewControllerDelegate { + func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) { + picker.dismiss(animated: true) + let itemProvider = results.first?.itemProvider + if let itemProvider = itemProvider, itemProvider.canLoadObject(ofClass: UIImage.self) { + itemProvider.loadObject(ofClass: UIImage.self) { [weak self] image, error in + DispatchQueue.main.async { + guard let self = self, let selectedImage = image as? UIImage else { return } + if self.imageCount == 3 { + self.portfolioImage[2 - self.selectedImageIndexPath] = selectedImage + } else { + self.portfolioImage[self.imageCount - self.selectedImageIndexPath] = selectedImage + if self.selectedImageIndexPath == 0 { + self.imageCount += 1 + } + } + self.portfolioImageCollectionView.reloadData() + } + } + } + } +} diff --git a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.xib b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.xib index ba48146..1b2c738 100644 --- a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.xib +++ b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/ArtistPortfolioEditingViewController.xib @@ -17,18 +17,12 @@ - - - + - - - - @@ -50,71 +44,51 @@ - + + + + - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -126,91 +100,8 @@ - - - - - - - - - - - - + @@ -220,50 +111,54 @@ + + + + + + + + + + + + + - - - + - - - - - + - + - - - - + @@ -292,13 +187,14 @@ - - + + + diff --git a/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/PortfolioImageCollectionViewCell.swift b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/PortfolioImageCollectionViewCell.swift new file mode 100644 index 0000000..a57949b --- /dev/null +++ b/MEME/MEME/Artist/ArtistPortfolio/ArtistPortfolioEditingView/PortfolioImageCollectionViewCell.swift @@ -0,0 +1,57 @@ +import UIKit +import SnapKit + +protocol PortfolioImageCollectionViewCellDelegate: AnyObject { + func deleteButtonTapped(_ cell: PortfolioImageCollectionViewCell) +} + +class PortfolioImageCollectionViewCell: UICollectionViewCell { + private lazy var deleteButton: UIButton = { + let button = UIButton() + button.setImage(.icDelete, for: .normal) + button.addTarget(self, action: #selector(deleteButtonTapped), for: .touchUpInside) + return button + }() + + private lazy var portfolioImageView: UIImageView = { + let imageView = UIImageView(image: UIImage(named: "portfolio_image")) + imageView.contentMode = .scaleAspectFill + return imageView + }() + + weak var delegate: PortfolioImageCollectionViewCellDelegate? + + override init(frame: CGRect) { + super.init(frame: frame) + contentView.addSubview(portfolioImageView) + contentView.addSubview(deleteButton) + makeConstraints() + contentView.layer.cornerRadius = 5 + contentView.layer.masksToBounds = true + } + + private func makeConstraints(){ + portfolioImageView.snp.makeConstraints { make in + make.edges.equalToSuperview() + } + deleteButton.snp.makeConstraints { make in + make.trailing.top.equalToSuperview() + make.height.width.equalTo(18) + } + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + @objc func deleteButtonTapped(_ sender: UIButton) { + delegate?.deleteButtonTapped(self) + } + + func configure(image: UIImage) { + portfolioImageView.image = image + } + func hideDeleteButton(_ option: Bool) { + deleteButton.isHidden = option + } +} diff --git a/MEME/MEME/Assets.xcassets/ArtistHome/portfolio_image.imageset/Contents.json b/MEME/MEME/Assets.xcassets/ArtistHome/portfolio_image.imageset/Contents.json new file mode 100644 index 0000000..bd486aa --- /dev/null +++ b/MEME/MEME/Assets.xcassets/ArtistHome/portfolio_image.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images" : [ + { + "filename" : "portfolio_image.svg", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MEME/MEME/Assets.xcassets/ArtistHome/portfolio_image.imageset/portfolio_image.svg b/MEME/MEME/Assets.xcassets/ArtistHome/portfolio_image.imageset/portfolio_image.svg new file mode 100644 index 0000000..e4b8c9f --- /dev/null +++ b/MEME/MEME/Assets.xcassets/ArtistHome/portfolio_image.imageset/portfolio_image.svg @@ -0,0 +1,6 @@ + + + + + +