diff --git a/NotToDo/NotToDo/Presentation/AddMissionScene/Views/AddMissionView.swift b/NotToDo/NotToDo/Presentation/AddMissionScene/Views/AddMissionView.swift index a886085..33e4ebb 100644 --- a/NotToDo/NotToDo/Presentation/AddMissionScene/Views/AddMissionView.swift +++ b/NotToDo/NotToDo/Presentation/AddMissionScene/Views/AddMissionView.swift @@ -353,10 +353,5 @@ extension AddMissionView { unavailableAddBehaviorButton.isHidden = false addBehaviorButton.isHidden = true } - -// if missionText.text!.count > 0 && goalTextField.text!.count > 0 { -// addMissionButton.isUserInteractionEnabled = true -// addMissionButton.backgroundColor = .nottodoBlack -// } } } diff --git a/NotToDo/NotToDo/Presentation/AddSituationScene/ViewControllers/AddSituationViewController.swift b/NotToDo/NotToDo/Presentation/AddSituationScene/ViewControllers/AddSituationViewController.swift index 47d24f9..e0c1074 100644 --- a/NotToDo/NotToDo/Presentation/AddSituationScene/ViewControllers/AddSituationViewController.swift +++ b/NotToDo/NotToDo/Presentation/AddSituationScene/ViewControllers/AddSituationViewController.swift @@ -30,7 +30,6 @@ final class AddSituationViewController: UIViewController { super.viewDidLoad() hideKeyboardWhenTappedAround() setAddTarget() - requestAddSituationAPI() } override func loadView() { @@ -38,6 +37,11 @@ final class AddSituationViewController: UIViewController { addSituationView = AddSituationView() view = addSituationView } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + requestAddSituationAPI() + } } extension AddSituationViewController { @@ -46,7 +50,7 @@ extension AddSituationViewController { addSituationView.navigationBarView.successButton.addTarget(self, action: #selector(popToAddMissionController), for: .touchUpInside) } - private func requestAddSituationAPI() { + func requestAddSituationAPI() { AddSituationAPI.shared.getAddSituation { [weak self] response in guard self != nil else { return } guard let response = response else { return } @@ -57,8 +61,6 @@ extension AddSituationViewController { self?.addSituationView.recommendList = data.recommends self?.addSituationView.recentList = data.recents self?.addSituationView.addSituationCollectionView.reloadData() - - dump(response) } } diff --git a/NotToDo/NotToDo/Presentation/MissionHistoryScene/ViewControllers/MissionHistoryViewController.swift b/NotToDo/NotToDo/Presentation/MissionHistoryScene/ViewControllers/MissionHistoryViewController.swift index 95b7876..59d7d30 100644 --- a/NotToDo/NotToDo/Presentation/MissionHistoryScene/ViewControllers/MissionHistoryViewController.swift +++ b/NotToDo/NotToDo/Presentation/MissionHistoryScene/ViewControllers/MissionHistoryViewController.swift @@ -14,6 +14,8 @@ final class MissionHistoryViewController: UIViewController { var missionHistoryResponse: MissionHistoryResponse? var historyList: [MissionHistoryModel] = [] weak var delegate: MissionHistoryViewDelegate? + let historyInset: UIEdgeInsets = UIEdgeInsets(top: 15.adjusted, left: 20.adjusted, bottom: 15.adjusted, right: 20.adjusted) + let cellHeight: CGFloat = 49.adjusted // MARK: - UI Components @@ -26,6 +28,7 @@ final class MissionHistoryViewController: UIViewController { hideKeyboardWhenTappedAround() setAddTarget() requestMissionHistoryAPI() + setDelegate() } override func loadView() { @@ -36,6 +39,11 @@ final class MissionHistoryViewController: UIViewController { } extension MissionHistoryViewController { + private func setDelegate() { + missionHistoryView.missionHistoryCollectionView.delegate = self + missionHistoryView.missionHistoryCollectionView.dataSource = self + } + private func setAddTarget() { missionHistoryView.backButton.addTarget(self, action: #selector(popToAddMissionViewController), for: .touchUpInside) } @@ -55,7 +63,48 @@ extension MissionHistoryViewController { } @objc private func popToAddMissionViewController() { + sendData() + } + + private func sendData() { delegate?.sendMissionHistoryData(data: missionHistoryView.inputTextField.text ?? "") self.navigationController?.popViewController(animated: true) } } + +extension MissionHistoryViewController: UICollectionViewDelegateFlowLayout { + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, + sizeForItemAt indexPath: IndexPath) -> CGSize { + return CGSize(width: Numbers.width, height: cellHeight) + } + + func collectionView(_collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, + insetForSectionAt section: Int) -> UIEdgeInsets { + return historyInset + } +} + +extension MissionHistoryViewController: UICollectionViewDelegate { + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + missionHistoryView.changedText = historyList[indexPath.row].title + missionHistoryView.inputTextField.text = historyList[indexPath.row].title + sendData() + self.navigationController?.popViewController(animated: true) + } +} + +extension MissionHistoryViewController: UICollectionViewDataSource { + + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + return historyList.count + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + guard let cell = collectionView.dequeueReusableCell( + withReuseIdentifier: MissionHistoryCollectionViewCell.identifier, for: indexPath) + as? MissionHistoryCollectionViewCell else { return UICollectionViewCell() } + cell.configure(model: historyList[indexPath.row]) + cell.setBorder(indexPath) + return cell + } +} diff --git a/NotToDo/NotToDo/Presentation/MissionHistoryScene/Views/MissionHistoryView.swift b/NotToDo/NotToDo/Presentation/MissionHistoryScene/Views/MissionHistoryView.swift index 242c199..5bb5701 100644 --- a/NotToDo/NotToDo/Presentation/MissionHistoryScene/Views/MissionHistoryView.swift +++ b/NotToDo/NotToDo/Presentation/MissionHistoryScene/Views/MissionHistoryView.swift @@ -21,6 +21,8 @@ class MissionHistoryView: UIView { var missionHistoryResponse: MissionHistoryResponse? var historyList: [MissionHistoryModel] = [] weak var delegate: MissionHistoryViewDelegate? + let historyInset: UIEdgeInsets = UIEdgeInsets(top: 15.adjusted, left: 20.adjusted, bottom: 15.adjusted, right: 20.adjusted) + let cellHeight: CGFloat = 49.adjusted // MARK: - UI Components @@ -30,9 +32,6 @@ class MissionHistoryView: UIView { private var missionHistoryLabel = UILabel() lazy var missionHistoryCollectionView = UICollectionView(frame: .zero, collectionViewLayout: layout()) - let historyInset: UIEdgeInsets = UIEdgeInsets(top: 15.adjusted, left: 20.adjusted, bottom: 15.adjusted, right: 20.adjusted) - let cellHeight: CGFloat = 49.adjusted - let width: CGFloat = UIScreen.main.bounds.width var changedText: String? @@ -89,8 +88,6 @@ extension MissionHistoryView { missionHistoryCollectionView.do { $0.isScrollEnabled = true $0.collectionViewLayout = layout() - $0.delegate = self - $0.dataSource = self } } @@ -152,7 +149,7 @@ extension MissionHistoryView { private func calculateCellHeight() -> CGFloat { let count = CGFloat(historyList.count) - return count * cellHeight + (count-1) * historyInset.top + historyInset.bottom + return count * self.cellHeight + (count-1) * self.historyInset.top + self.historyInset.bottom } private func register() { @@ -160,38 +157,3 @@ extension MissionHistoryView { forCellWithReuseIdentifier: MissionHistoryCollectionViewCell.identifier) } } - -extension MissionHistoryView: UICollectionViewDataSource { - - func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return historyList.count - } - - func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - guard let cell = collectionView.dequeueReusableCell( - withReuseIdentifier: MissionHistoryCollectionViewCell.identifier, for: indexPath) - as? MissionHistoryCollectionViewCell else { return UICollectionViewCell() } - cell.configure(model: historyList[indexPath.row]) - cell.setBorder(indexPath) - return cell - } -} - -extension MissionHistoryView: UICollectionViewDelegateFlowLayout { - func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, - sizeForItemAt indexPath: IndexPath) -> CGSize { - return CGSize(width: width, height: cellHeight) - } - - func collectionView(_collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, - insetForSectionAt section: Int) -> UIEdgeInsets { - return historyInset - } -} - -extension MissionHistoryView: UICollectionViewDelegate { - func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - changedText = historyList[indexPath.row].title - inputTextField.text = historyList[indexPath.row].title - } -}