diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordDetailVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordDetailVC.swift index 7030b17d..53c9057b 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordDetailVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordDetailVC.swift @@ -10,21 +10,22 @@ import UIKit import SnapKit import Then import Moya +import DropDown final class ActivityRecordDetailVC: UIViewController { // MARK: - Properties private let recordProvider = Providers.recordProvider - + private var recordId: Int? - + private let courseTitleMaxLength = 20 - + // MARK: - UI Components private lazy var navibar = CustomNavigationBar(self, type: .titleWithLeftButton) - + private let moreButton = UIButton(type: .system).then { $0.setImage(ImageLiterals.icMore, for: .normal) $0.tintColor = .g1 @@ -42,8 +43,8 @@ final class ActivityRecordDetailVC: UIViewController { $0.font = .h4 } - private let courseTitleTextField = UITextField().then { - $0.resignFirstResponder() + private lazy var courseTitleTextField = UITextField().then { + $0.attributedPlaceholder = NSAttributedString( string: "글 제목", attributes: [.font: UIFont.h4, .foregroundColor: UIColor.g3] @@ -51,6 +52,7 @@ final class ActivityRecordDetailVC: UIViewController { $0.font = .h4 $0.textColor = .g1 $0.addLeftPadding(width: 2) + $0.addTarget(self, action: #selector(textFieldTextDidChange), for: .editingChanged) } private let recordDateInfoView = CourseDetailInfoView(title: "날짜", description: String()) @@ -70,7 +72,7 @@ final class ActivityRecordDetailVC: UIViewController { private lazy var recordDistanceLabel = SetInfoLayout.makeGreySmailTitleLabel().then { $0.text = "거리" } - + private lazy var recordRunningTimeLabel = SetInfoLayout.makeGreySmailTitleLabel().then { $0.text = "이동 시간" } @@ -78,7 +80,7 @@ final class ActivityRecordDetailVC: UIViewController { private lazy var recordAveragePaceLabel = SetInfoLayout.makeGreySmailTitleLabel().then { $0.text = "평균 페이스" } - + private lazy var recordDistanceValueLabel = SetInfoLayout.makeBlackTitleLabel() private lazy var recordRunningTimeValueLabel = SetInfoLayout.makeBlackTitleLabel() @@ -125,25 +127,35 @@ final class ActivityRecordDetailVC: UIViewController { extension ActivityRecordDetailVC { @objc func moreButtonDidTap() { - let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) - let editAction = UIAlertAction(title: "수정하기", style: .default, handler: {(_: UIAlertAction!) in - // 수정 모드일 때 - self.setEditMode() - }) - let deleteAlertVC = RNAlertVC(description: "러닝 기록을 정말로 삭제하시겠어요?").setButtonTitle("취소", "삭제하기") - deleteAlertVC.modalPresentationStyle = .overFullScreen - let deleteAlertAction = UIAlertAction(title: "삭제하기", style: .destructive, handler: {(_: UIAlertAction!) in - self.present(deleteAlertVC, animated: false, completion: nil)}) - deleteAlertVC.rightButtonTapAction = { [weak self] in - deleteAlertVC.dismiss(animated: false) - self?.deleteRecord() + let hideLastCellSeparatorBoxSize = 79 + let items = ["수정하기", "삭제하기"] + let imageArray: [UIImage] = [ImageLiterals.icModify, ImageLiterals.icRemove] + + let menu = DropDown().then { + $0.anchorView = moreButton + $0.backgroundColor = .w1 + $0.bottomOffset = CGPoint(x: -136, y: moreButton.bounds.height - 10) + $0.width = 170 + $0.cellHeight = 40 + $0.cornerRadius = 12 + $0.dismissMode = .onTap + $0.separatorColor = UIColor(hex: "#EBEBEB") + $0.dataSource = items + $0.textFont = .b3 + } + + menu.customCellConfiguration = { (index: Index, _: String, cell: DropDownCell) -> Void in + let lastDividerLineRemove = UIView(frame: CGRect(origin: CGPoint(x: 0, y: hideLastCellSeparatorBoxSize), size: CGSize(width: 170, height: 10))) + lastDividerLineRemove.backgroundColor = .white + cell.separatorInset = .zero + cell.dropDownImage.image = imageArray[index] + cell.addSubview(lastDividerLineRemove) } - let cancelAction = UIAlertAction(title: "닫기", style: .cancel, handler: nil) + dropDownTouchAction(menu: menu) - [ editAction, deleteAlertAction, cancelAction ].forEach { alertController.addAction($0) } - present(alertController, animated: true, completion: nil) + menu.show() } @objc private func textFieldTextDidChange() { @@ -166,30 +178,28 @@ extension ActivityRecordDetailVC { } } - @objc private func keyboardWillShow(_ notification: Notification) { - guard let userInfo = notification.userInfo, - let keyboardFrame = userInfo[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { - return + @objc private func keyboardWillShow(_ sender: Notification) { // 키보드의 높이만큼 화면을 올려줍니다. + if let keyboardFrame: NSValue = sender.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue { + let keyboardRectangle = keyboardFrame.cgRectValue + let keyboardHeight = keyboardRectangle.height + self.view.frame.origin.y -= keyboardHeight } - - let contentInset = UIEdgeInsets( - top: 0.0, - left: 0.0, - bottom: keyboardFrame.size.height, - right: 0.0) - middleScorollView.contentInset = contentInset - middleScorollView.scrollIndicatorInsets = contentInset } - @objc private func keyboardWillHide() { - let contentInset = UIEdgeInsets.zero - middleScorollView.contentInset = contentInset - middleScorollView.scrollIndicatorInsets = contentInset + @objc private func keyboardWillHide(_ sender: Notification) { // 키보드의 높이만큼 화면을 내려줍니다. + if let keyboardFrame: NSValue = sender.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue { + let keyboardRectangle = keyboardFrame.cgRectValue + let keyboardHeight = keyboardRectangle.height + self.view.frame.origin.y += keyboardHeight + } } @objc private func finishEditButtonDidTap() { editRecordTitle() + // 키보드가 올라와 있다면 내려가는 코드 추가 + view.endEditing(true) + // 수정이 완료되면 팝업 뜨지 않음 self.navibar.resetLeftButtonAction({ [weak self] in self?.navigationController?.popViewController(animated: true) @@ -202,6 +212,7 @@ extension ActivityRecordDetailVC { make.leading.trailing.equalTo(view.safeAreaLayoutGuide) make.bottom.equalTo(view.safeAreaLayoutGuide) } + } @objc private func presentToQuitEditAlertVC() { @@ -245,7 +256,6 @@ extension ActivityRecordDetailVC { private func setAddTarget() { self.moreButton.addTarget(self, action: #selector(moreButtonDidTap), for: .touchUpInside) - self.courseTitleTextField.addTarget(self, action: #selector(textFieldTextDidChange), for: .editingChanged) self.finishEditButton.addTarget(self, action: #selector(finishEditButtonDidTap), for: .touchUpInside) } @@ -307,8 +317,11 @@ extension ActivityRecordDetailVC { extension ActivityRecordDetailVC: UITextFieldDelegate { func textFieldShouldReturn(_ textField: UITextField) -> Bool { + textField.resignFirstResponder() if textField == self.courseTitleTextField { - self.finishEditButtonDidTap() + if finishEditButton.isEnabled == true { + self.finishEditButtonDidTap() + } } return true } @@ -419,7 +432,7 @@ extension ActivityRecordDetailVC { private func setEditMode() { self.navibar.isHidden = false // true - + mapImageView.snp.remakeConstraints { make in make.top.equalToSuperview() make.leading.trailing.equalTo(view.safeAreaLayoutGuide) @@ -431,13 +444,13 @@ extension ActivityRecordDetailVC { self.courseTitleTextField.text = self.courseTitleLabel.text middleScorollView.addSubview(courseTitleTextField) - + courseTitleTextField.snp.makeConstraints { make in make.top.equalTo(mapImageView.snp.bottom).offset(27) make.leading.trailing.equalToSuperview().inset(16) make.height.equalTo(35) } - + self.finishEditButton.isHidden = false firstHorizontalDivideLine.snp.remakeConstraints { make in @@ -461,9 +474,9 @@ extension ActivityRecordDetailVC { make.top.equalTo(secondHorizontalDivideLine.snp.bottom).offset(22) make.centerX.equalToSuperview() } - + middleScorollView.addSubview(finishEditButton) - + finishEditButton.snp.makeConstraints { make in make.bottom.equalToSuperview().inset(30) make.leading.trailing.equalTo(view.safeAreaLayoutGuide).inset(16) @@ -518,6 +531,7 @@ extension ActivityRecordDetailVC { if 200..<300 ~= status { print("제목 수정 성공") self.showToast(message: "제목 수정이 완료되었어요") + self.finishEditButton.isEnabled = false } if status >= 400 { print("400 error") @@ -530,3 +544,34 @@ extension ActivityRecordDetailVC { } } } +// MARK: - DropDown + +extension ActivityRecordDetailVC { + private func dropDownTouchAction(menu: DropDown) { + + DropDown.appearance().textColor = .g1 + DropDown.appearance().selectionBackgroundColor = .w1 + DropDown.appearance().shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.2) + DropDown.appearance().shadowOpacity = 1 + DropDown.appearance().shadowRadius = 10 + + menu.selectionAction = { [unowned self] (_, item) in + menu.clearSelection() + + switch item { + case "수정하기": + self.setEditMode() + case "삭제하기": + let deleteAlertVC = RNAlertVC(description: "러닝 기록을 정말로 삭제하시겠어요?").setButtonTitle("취소", "삭제하기") + deleteAlertVC.modalPresentationStyle = .overFullScreen + deleteAlertVC.rightButtonTapAction = { + deleteAlertVC.dismiss(animated: false) + self.deleteRecord() + } + self.present(deleteAlertVC, animated: false) + default: + self.showToast(message: "없는 명령어 입니다.") + } + } + } +}