diff --git a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj index 513a368f..84b46861 100644 --- a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj +++ b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj @@ -34,6 +34,7 @@ CE17F0382961BF8B00E1DED0 /* FontLiterals.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE17F0372961BF8B00E1DED0 /* FontLiterals.swift */; }; CE29D582296402B500F47542 /* CourseDrawingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE29D581296402B500F47542 /* CourseDrawingVC.swift */; }; CE29D584296416D800F47542 /* caculateStatusBarHeight.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE29D583296416D800F47542 /* caculateStatusBarHeight.swift */; }; + CE40BB1C2967E4910030ABCA /* RunningWaitingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE40BB1B2967E4910030ABCA /* RunningWaitingVC.swift */; }; CE4545C9295D7AF4003201E1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE4545C8295D7AF4003201E1 /* AppDelegate.swift */; }; CE4545CB295D7AF4003201E1 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE4545CA295D7AF4003201E1 /* SceneDelegate.swift */; }; CE4545CD295D7AF4003201E1 /* TaBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE4545CC295D7AF4003201E1 /* TaBarController.swift */; }; @@ -144,6 +145,7 @@ CE17F0372961BF8B00E1DED0 /* FontLiterals.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FontLiterals.swift; sourceTree = ""; }; CE29D581296402B500F47542 /* CourseDrawingVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseDrawingVC.swift; sourceTree = ""; }; CE29D583296416D800F47542 /* caculateStatusBarHeight.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = caculateStatusBarHeight.swift; sourceTree = ""; }; + CE40BB1B2967E4910030ABCA /* RunningWaitingVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunningWaitingVC.swift; sourceTree = ""; }; CE4545C5295D7AF4003201E1 /* Runnect-iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Runnect-iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; CE4545C8295D7AF4003201E1 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; CE4545CA295D7AF4003201E1 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; @@ -347,6 +349,7 @@ CEB8416F2963360800BF8080 /* CountDownVC.swift */, CE14676F296568DC00DCEA1B /* RunTrackingVC.swift */, CE14677B2965C1B100DCEA1B /* RunningRecordVC.swift */, + CE40BB1B2967E4910030ABCA /* RunningWaitingVC.swift */, ); path = VC; sourceTree = ""; @@ -1019,6 +1022,7 @@ CE6655F0295D891B00C64E12 /* UITextView+.swift in Sources */, CEC2A6922962BE2900160BF7 /* DepartureSearchVC.swift in Sources */, CE6655EE295D88E600C64E12 /* UITextField+.swift in Sources */, + CE40BB1C2967E4910030ABCA /* RunningWaitingVC.swift in Sources */, CE6B63D6296731F9003F900F /* ScrapCourseListView.swift in Sources */, DA20D841296696C300F1581F /* MapCollectionViewCell.swift in Sources */, CE6655F8295D90CF00C64E12 /* adjusted+.swift in Sources */, diff --git a/Runnect-iOS/Runnect-iOS/Presentation/CourseStorage/VC/CourseStorageVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/CourseStorage/VC/CourseStorageVC.swift index a46da683..4664066d 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/CourseStorage/VC/CourseStorageVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/CourseStorage/VC/CourseStorageVC.swift @@ -39,13 +39,27 @@ final class CourseStorageVC: UIViewController { extension CourseStorageVC { private func bindUI() { - privateCourseListView.courseDrawButtonTapped.sink { + privateCourseListView.courseDrawButtonTapped.sink { [weak self] in + guard let self = self else { return } self.tabBarController?.selectedIndex = 0 }.store(in: cancelBag) - scrapCourseListView.scrapButtonTapped.sink { + scrapCourseListView.scrapButtonTapped.sink { [weak self] in + guard let self = self else { return } self.tabBarController?.selectedIndex = 2 }.store(in: cancelBag) + + privateCourseListView.cellDidTapped.sink { [weak self] index in + guard let self = self else { return } + let runningWaitingVC = RunningWaitingVC() + runningWaitingVC.hidesBottomBarWhenPushed = true + self.navigationController?.pushViewController(runningWaitingVC, animated: true) + }.store(in: cancelBag) + + scrapCourseListView.cellDidTapped.sink { [weak self] index in + guard let self = self else { return } + print(index) + }.store(in: cancelBag) } } diff --git a/Runnect-iOS/Runnect-iOS/Presentation/CourseStorage/Views/CourseListView/PrivateCourseListView.swift b/Runnect-iOS/Runnect-iOS/Presentation/CourseStorage/Views/CourseListView/PrivateCourseListView.swift index 9f5069c4..c3448020 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/CourseStorage/Views/CourseListView/PrivateCourseListView.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/CourseStorage/Views/CourseListView/PrivateCourseListView.swift @@ -13,6 +13,7 @@ final class PrivateCourseListView: UIView { // MARK: - Properties var courseDrawButtonTapped = PassthroughSubject() + var cellDidTapped = PassthroughSubject() final let collectionViewInset = UIEdgeInsets(top: 28, left: 16, bottom: 28, right: 16) final let itemSpacing: CGFloat = 10 @@ -126,6 +127,10 @@ extension PrivateCourseListView: UICollectionViewDelegateFlowLayout { func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { return self.lineSpacing } + + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + cellDidTapped.send(indexPath.item) + } } // MARK: - Section Heading diff --git a/Runnect-iOS/Runnect-iOS/Presentation/CourseStorage/Views/CourseListView/ScrapCourseListView.swift b/Runnect-iOS/Runnect-iOS/Presentation/CourseStorage/Views/CourseListView/ScrapCourseListView.swift index ce744c2c..5f44b7dc 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/CourseStorage/Views/CourseListView/ScrapCourseListView.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/CourseStorage/Views/CourseListView/ScrapCourseListView.swift @@ -13,6 +13,7 @@ final class ScrapCourseListView: UIView { // MARK: - Properties var scrapButtonTapped = PassthroughSubject() + var cellDidTapped = PassthroughSubject() final let collectionViewInset = UIEdgeInsets(top: 28, left: 16, bottom: 28, right: 16) final let itemSpacing: CGFloat = 10 @@ -126,6 +127,10 @@ extension ScrapCourseListView: UICollectionViewDelegateFlowLayout { func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { return self.lineSpacing } + + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + self.cellDidTapped.send(indexPath.item) + } } // MARK: - Section Heading diff --git a/Runnect-iOS/Runnect-iOS/Presentation/Running/VC/CountDownVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/Running/VC/CountDownVC.swift index cf4515aa..a0b258be 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/Running/VC/CountDownVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/Running/VC/CountDownVC.swift @@ -60,7 +60,7 @@ extension CountDownVC { self.animateTimeLabel() } else { let runTrackingVC = RunTrackingVC() - runTrackingVC.makePath(locations: self.locations, distance: self.distance ?? "0:0") + runTrackingVC.makePath(locations: self.locations, distance: self.distance ?? "0.0") runTrackingVC.pathImage = self.pathImage self.navigationController?.pushViewController(runTrackingVC, animated: true) diff --git a/Runnect-iOS/Runnect-iOS/Presentation/Running/VC/RunTrackingVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/Running/VC/RunTrackingVC.swift index 2b30ea27..762faf89 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/Running/VC/RunTrackingVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/Running/VC/RunTrackingVC.swift @@ -180,8 +180,9 @@ extension RunTrackingVC { private func pushToRunningRecordVC() { guard let pathImage = pathImage else { return } guard let distance = Float(self.distance) else { return } - let averagePaceSeconds = Int(Float(self.totalTime) / distance) - let formatedAveragePace = "\(averagePaceSeconds / 60)'\(averagePaceSeconds % 60)''" + let averagePaceSeconds = round(Float(self.totalTime) / distance) + let averagePaceSecondsInt = Int(averagePaceSeconds) + let formatedAveragePace = "\(averagePaceSecondsInt / 60)'\(averagePaceSecondsInt % 60)''" let runningRecordVC = RunningRecordVC() runningRecordVC.setData(distance: self.distance, diff --git a/Runnect-iOS/Runnect-iOS/Presentation/Running/VC/RunningWaitingVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/Running/VC/RunningWaitingVC.swift new file mode 100644 index 00000000..474e8f1e --- /dev/null +++ b/Runnect-iOS/Runnect-iOS/Presentation/Running/VC/RunningWaitingVC.swift @@ -0,0 +1,139 @@ +// +// RunningWaitingVC.swift +// Runnect-iOS +// +// Created by sejin on 2023/01/06. +// + +import UIKit + +final class RunningWaitingVC: UIViewController { + + // MARK: - UI Components + + private lazy var naviBar = CustomNavigationBar(self, type: .titleWithLeftButton) + + private let mapView = RNMapView() + + private let distanceLabel = UILabel().then { + $0.font = .h1 + $0.textColor = .g1 + $0.text = "0.0" + } + + private let kilometerLabel = UILabel().then { + $0.font = .b4 + $0.textColor = .g2 + $0.text = "km" + } + + private lazy var distanceStackView = UIStackView( + arrangedSubviews: [distanceLabel, kilometerLabel] + ).then { + $0.spacing = 3 + $0.alignment = .bottom + } + + private let distanceContainerView = UIView().then { + $0.backgroundColor = .w1 + $0.layer.cornerRadius = 22 + } + + private let startButton = CustomButton(title: "μ‹œμž‘ν•˜κΈ°") + + // MARK: - View Life Cycle + + override func viewDidLoad() { + super.viewDidLoad() + self.setUI() + self.setLayout() + self.setAddTarget() + } + + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + self.showHiddenViews(withDuration: 0.7) + } +} + +// MARK: - Methods + +extension RunningWaitingVC { + private func setAddTarget() { + self.startButton.addTarget(self, action: #selector(startButtonDidTap), for: .touchUpInside) + } +} + +// MARK: - @objc Function + +extension RunningWaitingVC { + @objc private func startButtonDidTap() { + if self.distanceLabel.text == "0.0" { + return + } + + let countDownVC = CountDownVC() + countDownVC.setData(locations: self.mapView.getMarkersLatLng(), + distance: self.distanceLabel.text, + pathImage: UIImage()) + self.navigationController?.pushViewController(countDownVC, animated: true) + } +} + +// MARK: - UI & Layout + +extension RunningWaitingVC { + private func setUI() { + self.view.backgroundColor = .w1 + self.distanceContainerView.layer.applyShadow(alpha: 0.2, x: 2, y: 4, blur: 9) + self.naviBar.backgroundColor = .clear + } + + private func setLayout() { + view.addSubviews(naviBar, + mapView, + distanceContainerView, + startButton) + + naviBar.snp.makeConstraints { make in + make.top.leading.trailing.equalTo(view.safeAreaLayoutGuide) + make.height.equalTo(48) + } + + view.bringSubviewToFront(naviBar) + + mapView.snp.makeConstraints { make in + make.edges.equalToSuperview() + } + + distanceContainerView.snp.makeConstraints { make in + make.width.equalTo(96) + make.height.equalTo(44) + make.leading.equalTo(view.safeAreaLayoutGuide).inset(16) + make.top.equalTo(view.snp.bottom) + } + + distanceContainerView.addSubviews(distanceStackView) + + distanceStackView.snp.makeConstraints { make in + make.center.equalToSuperview() + } + + startButton.snp.makeConstraints { make in + make.leading.trailing.equalTo(view.safeAreaLayoutGuide).inset(16) + make.height.equalTo(44) + make.top.equalTo(view.snp.bottom).offset(34) + } + } + + private func showHiddenViews(withDuration: TimeInterval = 0) { + [distanceContainerView, startButton].forEach { subView in + view.bringSubviewToFront(subView) + } + + UIView.animate(withDuration: withDuration) { + self.distanceContainerView.transform = CGAffineTransform(translationX: 0, y: -151) + self.startButton.transform = CGAffineTransform(translationX: 0, y: -112) + } + } +}