Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,15 +43,16 @@ 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]
)
$0.font = .h4
$0.textColor = .g1
$0.addLeftPadding(width: 2)
$0.addTarget(self, action: #selector(textFieldTextDidChange), for: .editingChanged)
Comment on lines +46 to +55
Copy link
Collaborator Author

@thingineeer thingineeer Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

소진

새로운거 개발하는 와중에도 리팩토링 하는 모습 .. 진짜 본받겠습니다 😉

텍스트 필드의 텍스트(TextField.text)를 눌러야 .editingChanged 가 되는데.. 왜 텍스트 필드를 누르면 안 될까요..?
-> 근데 이건 무슨 상황인지 잘 파악이 안되는데 다시 설명해주실 수 있나요 ㅜㅜ

@513sojin

마이페이지 -> 러닝 기록 보시면 수정하기 누르고 제목을 수정하는 과정에서,
텍스트 필드를 누르면 안 되고.. 텍스트 필드의 텍스트를 눌러야만 수정하기가 되더라고요..?
merge 전에도 똑같아서 생각나실때 보셔도 좋을 것 같아요!

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

흠 가서 해봤는데 왜 text 부분 눌러야지만 수정되는지 모르겠네요 ,, 딱히 의도가 있을거 같지는 않은데 ㅠ

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

흑흑.. 배포 전에 꼭 수정 ‼️‼️‼️‼️‼️‼️‼️‼️‼️

}

private let recordDateInfoView = CourseDetailInfoView(title: "날짜", description: String())
Expand All @@ -70,15 +72,15 @@ final class ActivityRecordDetailVC: UIViewController {
private lazy var recordDistanceLabel = SetInfoLayout.makeGreySmailTitleLabel().then {
$0.text = "거리"
}

private lazy var recordRunningTimeLabel = SetInfoLayout.makeGreySmailTitleLabel().then {
$0.text = "이동 시간"
}

private lazy var recordAveragePaceLabel = SetInfoLayout.makeGreySmailTitleLabel().then {
$0.text = "평균 페이스"
}

private lazy var recordDistanceValueLabel = SetInfoLayout.makeBlackTitleLabel()

private lazy var recordRunningTimeValueLabel = SetInfoLayout.makeBlackTitleLabel()
Expand Down Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

더 나은 코드를 향해 항상 수정하는 모습 너무 보기 좋아요 👍🏻


[ editAction, deleteAlertAction, cancelAction ].forEach { alertController.addAction($0) }
present(alertController, animated: true, completion: nil)
menu.show()
}

@objc private func textFieldTextDidChange() {
Expand All @@ -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)
Expand All @@ -202,6 +212,7 @@ extension ActivityRecordDetailVC {
make.leading.trailing.equalTo(view.safeAreaLayoutGuide)
make.bottom.equalTo(view.safeAreaLayoutGuide)
}

}

@objc private func presentToQuitEditAlertVC() {
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finishEditButton.isEnabled == true
이 코드는 수정을 한 상태를 표현하였기 때문에, 텍스트가 수정되었을 때만 return 키보드를 눌러야 작동이 되게 짰습니다.

self.finishEditButtonDidTap()
}
}
return true
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -518,6 +531,7 @@ extension ActivityRecordDetailVC {
if 200..<300 ~= status {
print("제목 수정 성공")
self.showToast(message: "제목 수정이 완료되었어요")
self.finishEditButton.isEnabled = false
}
if status >= 400 {
print("400 error")
Expand All @@ -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: "없는 명령어 입니다.")
}
}
}
}