Skip to content

Commit

Permalink
[Merge] 'develop' into feature/DO-NOTTO-DO#84
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongdung-eo committed Jan 13, 2023
2 parents b3c5c53 + f55e220 commit 04fb956
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ final class AddSituationViewController: UIViewController {
super.viewDidLoad()
hideKeyboardWhenTappedAround()
setAddTarget()
requestAddSituationAPI()
}

override func loadView() {
super.loadView()
addSituationView = AddSituationView()
view = addSituationView
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
requestAddSituationAPI()
}
}

extension AddSituationViewController {
Expand All @@ -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 }
Expand All @@ -57,8 +61,6 @@ extension AddSituationViewController {
self?.addSituationView.recommendList = data.recommends
self?.addSituationView.recentList = data.recents
self?.addSituationView.addSituationCollectionView.reloadData()

dump(response)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -26,6 +28,7 @@ final class MissionHistoryViewController: UIViewController {
hideKeyboardWhenTappedAround()
setAddTarget()
requestMissionHistoryAPI()
setDelegate()
}

override func loadView() {
Expand All @@ -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)
}
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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?

Expand Down Expand Up @@ -89,8 +88,6 @@ extension MissionHistoryView {
missionHistoryCollectionView.do {
$0.isScrollEnabled = true
$0.collectionViewLayout = layout()
$0.delegate = self
$0.dataSource = self
}
}

Expand Down Expand Up @@ -152,46 +149,11 @@ 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() {
missionHistoryCollectionView.register(MissionHistoryCollectionViewCell.self,
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
}
}

0 comments on commit 04fb956

Please sign in to comment.