From 51306d13bcf9c33e208abe72ec4cb10956cb1644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Junnos=20=EF=A3=BF?= Date: Thu, 11 Jan 2024 10:14:31 +0900 Subject: [PATCH] =?UTF-8?q?:bug:=20=EC=97=AC=EC=A0=95=20=EA=B8=B0=EB=A1=9D?= =?UTF-8?q?=20=EC=A4=91=20=EC=8A=A4=ED=8C=9F=20=ED=9B=84=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=EC=9D=B4=20=EC=A7=80?= =?UTF-8?q?=EB=8F=84=20=EC=83=81=EC=97=90=20=EC=B6=94=EA=B0=80=EB=90=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Home/Presentation/HomeViewController.swift | 10 +++++++--- .../RecordJourneyButtonStackView.swift | 4 ++-- .../MapViewController+EventListener.swift | 15 +++++++++++++++ .../Common/MapViewController.swift | 8 ++------ .../Coordinator/SpotNavigationDelegate.swift | 6 +++--- .../Presentation/SaveSpotViewController.swift | 4 ++-- .../Spot/Presentation/SaveSpotViewModel.swift | 4 ++-- .../MusicSpot.xcodeproj/project.pbxproj | 4 ++++ .../Coordinator/HomeCoordinator.swift | 18 ++++++++++++++++++ .../SpotCoordinatorFinishDelegate.swift | 16 ++++++++++++++++ .../Coordinator/SpotCoordinator.swift | 8 +++++--- 11 files changed, 76 insertions(+), 21 deletions(-) create mode 100644 iOS/MusicSpot/MusicSpot/Coordinator/Protocol/SpotCoordinatorFinishDelegate.swift diff --git a/iOS/Features/Home/Sources/Home/Presentation/HomeViewController.swift b/iOS/Features/Home/Sources/Home/Presentation/HomeViewController.swift index 1bf3e11..31851ca 100644 --- a/iOS/Features/Home/Sources/Home/Presentation/HomeViewController.swift +++ b/iOS/Features/Home/Sources/Home/Presentation/HomeViewController.swift @@ -209,6 +209,10 @@ public final class HomeViewController: HomeBottomSheetViewController { }) } + public func spotDidAdded(_ spot: Spot, photoData: Data) { + self.contentViewController.spotDidAdded(spot, photoData: photoData) + } + } // MARK: - Buttons @@ -240,13 +244,13 @@ extension HomeViewController: RecordJourneyButtonViewDelegate { self.viewModel.trigger(.refreshButtonDidTap(visibleCoordinates: coordinates)) } - public func backButtonDidTap(_ button: MSRectButton) { + func backButtonDidTap(_ button: MSRectButton) { guard self.viewModel.state.isRecording.value == true else { return } self.viewModel.trigger(.backButtonDidTap) } - public func spotButtonDidTap(_ button: MSRectButton) { + func spotButtonDidTap(_ button: MSRectButton) { guard self.viewModel.state.isRecording.value == true else { return } guard let currentUserCoordiante = self.contentViewController.currentUserCoordinate else { @@ -256,7 +260,7 @@ extension HomeViewController: RecordJourneyButtonViewDelegate { self.navigationDelegate?.navigateToSpot(spotCoordinate: currentUserCoordiante) } - public func nextButtonDidTap(_ button: MSRectButton) { + func nextButtonDidTap(_ button: MSRectButton) { guard self.viewModel.state.isRecording.value == true else { return } guard let currentUserCoordiante = self.contentViewController.currentUserCoordinate else { diff --git a/iOS/Features/Home/Sources/Home/Presentation/RecordJourneyButtonStackView.swift b/iOS/Features/Home/Sources/Home/Presentation/RecordJourneyButtonStackView.swift index 765418f..bb084da 100644 --- a/iOS/Features/Home/Sources/Home/Presentation/RecordJourneyButtonStackView.swift +++ b/iOS/Features/Home/Sources/Home/Presentation/RecordJourneyButtonStackView.swift @@ -10,7 +10,7 @@ import UIKit import MSDesignSystem import MSUIKit -public protocol RecordJourneyButtonViewDelegate: AnyObject { +internal protocol RecordJourneyButtonViewDelegate: AnyObject { func backButtonDidTap(_ button: MSRectButton) func spotButtonDidTap(_ button: MSRectButton) @@ -64,7 +64,7 @@ public final class RecordJourneyButtonStackView: UIView { // MARK: - Properties - public var delegate: RecordJourneyButtonViewDelegate? + internal var delegate: RecordJourneyButtonViewDelegate? // MARK: - Initializer diff --git a/iOS/Features/Home/Sources/NavigateMap/Presentation/Common/MapViewController+EventListener.swift b/iOS/Features/Home/Sources/NavigateMap/Presentation/Common/MapViewController+EventListener.swift index c4fa331..b2b19e8 100644 --- a/iOS/Features/Home/Sources/NavigateMap/Presentation/Common/MapViewController+EventListener.swift +++ b/iOS/Features/Home/Sources/NavigateMap/Presentation/Common/MapViewController+EventListener.swift @@ -92,3 +92,18 @@ extension MapViewController { } } + +// MARK: - Spot + +extension MapViewController { + + public func spotDidAdded(_ spot: Spot, photoData: Data) { + let coordinate = CLLocationCoordinate2D(latitude: spot.coordinate.latitude, + longitude: spot.coordinate.longitude) + + self.addAnnotation(title: spot.timestamp.description, + coordinate: coordinate, + photoData: photoData) + } + +} diff --git a/iOS/Features/Home/Sources/NavigateMap/Presentation/Common/MapViewController.swift b/iOS/Features/Home/Sources/NavigateMap/Presentation/Common/MapViewController.swift index 327ab4a..5791986 100644 --- a/iOS/Features/Home/Sources/NavigateMap/Presentation/Common/MapViewController.swift +++ b/iOS/Features/Home/Sources/NavigateMap/Presentation/Common/MapViewController.swift @@ -214,12 +214,8 @@ public final class MapViewController: UIViewController { } } - private func addAnnotation(title: String, - coordinate: CLLocationCoordinate2D, - photoData: Data) { - let annotation = SpotAnnotation(title: title, - coordinate: coordinate, - photoData: photoData) + func addAnnotation(title: String, coordinate: CLLocationCoordinate2D, photoData: Data) { + let annotation = SpotAnnotation(title: title, coordinate: coordinate, photoData: photoData) self.mapView.addAnnotation(annotation) } diff --git a/iOS/Features/Spot/Sources/Spot/Presentation/Coordinator/SpotNavigationDelegate.swift b/iOS/Features/Spot/Sources/Spot/Presentation/Coordinator/SpotNavigationDelegate.swift index d84f269..82b568b 100644 --- a/iOS/Features/Spot/Sources/Spot/Presentation/Coordinator/SpotNavigationDelegate.swift +++ b/iOS/Features/Spot/Sources/Spot/Presentation/Coordinator/SpotNavigationDelegate.swift @@ -14,14 +14,14 @@ public protocol SpotNavigationDelegate: AnyObject { func presentPhotoLibrary(from viewController: UIViewController) func presentSaveSpot(using image: UIImage, coordinate: Coordinate) func dismissToSpot() - func popToHome(spot: Spot?) + func popToHome(with spot: Spot?, photoData: Data?) } extension SpotNavigationDelegate { - public func popToHome(spot: Spot? = nil) { - self.popToHome(spot: nil) + public func popToHome(with spot: Spot? = nil, photoData: Data? = nil) { + self.popToHome(with: nil, photoData: nil) } } diff --git a/iOS/Features/Spot/Sources/Spot/Presentation/SaveSpotViewController.swift b/iOS/Features/Spot/Sources/Spot/Presentation/SaveSpotViewController.swift index f6a882e..6ef1d47 100644 --- a/iOS/Features/Spot/Sources/Spot/Presentation/SaveSpotViewController.swift +++ b/iOS/Features/Spot/Sources/Spot/Presentation/SaveSpotViewController.swift @@ -116,8 +116,8 @@ public final class SaveSpotViewController: UIViewController { private func bind() { self.viewModel.state.uploadedSpot .receive(on: DispatchQueue.main) - .sink { [weak self] spot in - self?.navigationDelegate?.popToHome(spot: spot) + .sink { [weak self] spot, photoData in + self?.navigationDelegate?.popToHome(with: spot, photoData: photoData) } .store(in: &self.cancellables) } diff --git a/iOS/Features/Spot/Sources/Spot/Presentation/SaveSpotViewModel.swift b/iOS/Features/Spot/Sources/Spot/Presentation/SaveSpotViewModel.swift index 6db1c41..73c534b 100644 --- a/iOS/Features/Spot/Sources/Spot/Presentation/SaveSpotViewModel.swift +++ b/iOS/Features/Spot/Sources/Spot/Presentation/SaveSpotViewModel.swift @@ -20,7 +20,7 @@ public final class SaveSpotViewModel { public struct State { // Passthrough - public var uploadedSpot = PassthroughSubject() + public var uploadedSpot = PassthroughSubject<(Spot, Data), Never>() } // MARK: - Properties @@ -66,7 +66,7 @@ internal extension SaveSpotViewModel { let result = await self.spotRepository.upload(spot: spot) switch result { case .success(let spot): - self.state.uploadedSpot.send(spot) + self.state.uploadedSpot.send((spot, data)) MSLogger.make(category: .network).debug("성공적으로 업로드되었습니다: \(spot)") case .failure(let error): MSLogger.make(category: .network).error("\(error): 업로드에 실패하였습니다.") diff --git a/iOS/MusicSpot/MusicSpot.xcodeproj/project.pbxproj b/iOS/MusicSpot/MusicSpot.xcodeproj/project.pbxproj index 7daa0d7..e81d46b 100644 --- a/iOS/MusicSpot/MusicSpot.xcodeproj/project.pbxproj +++ b/iOS/MusicSpot/MusicSpot.xcodeproj/project.pbxproj @@ -26,6 +26,7 @@ DD92FEB52B35EE0700A672F5 /* Spot in Frameworks */ = {isa = PBXBuildFile; productRef = DD92FEB42B35EE0700A672F5 /* Spot */; }; DD92FEB82B35EE5500A672F5 /* MSUIKit in Frameworks */ = {isa = PBXBuildFile; productRef = DD92FEB72B35EE5500A672F5 /* MSUIKit */; }; DD92FEBA2B35EEAF00A672F5 /* SaveJourney in Frameworks */ = {isa = PBXBuildFile; productRef = DD92FEB92B35EEAF00A672F5 /* SaveJourney */; }; + DDB3B9F22B4F6DF60024C6BF /* SpotCoordinatorFinishDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDB3B9F12B4F6DF60024C6BF /* SpotCoordinatorFinishDelegate.swift */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -58,6 +59,7 @@ DD73F8662B024C4B00EE9BF2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; DD73F86D2B024CA000EE9BF2 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/LaunchScreen.strings; sourceTree = ""; }; DDB22F742B433EC300F83D84 /* CoordinatorFinishDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoordinatorFinishDelegate.swift; sourceTree = ""; }; + DDB3B9F12B4F6DF60024C6BF /* SpotCoordinatorFinishDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpotCoordinatorFinishDelegate.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -97,6 +99,7 @@ children = ( 08CBF8772B18468E007D3797 /* Coordinator.swift */, DDB22F742B433EC300F83D84 /* CoordinatorFinishDelegate.swift */, + DDB3B9F12B4F6DF60024C6BF /* SpotCoordinatorFinishDelegate.swift */, ); path = Protocol; sourceTree = ""; @@ -227,6 +230,7 @@ 08CBF87F2B18468E007D3797 /* Coordinator.swift in Sources */, 08CBF87D2B18468E007D3797 /* SpotCoordinator.swift in Sources */, 08CBF87E2B18468E007D3797 /* SaveJourneyFlowCoordinator.swift in Sources */, + DDB3B9F22B4F6DF60024C6BF /* SpotCoordinatorFinishDelegate.swift in Sources */, 08CBF87A2B18468E007D3797 /* RewindJourneyCoordinator.swift in Sources */, DD73F8592B024C4900EE9BF2 /* AppDelegate.swift in Sources */, 08CBF87B2B18468E007D3797 /* HomeCoordinator.swift in Sources */, diff --git a/iOS/MusicSpot/MusicSpot/Coordinator/HomeCoordinator.swift b/iOS/MusicSpot/MusicSpot/Coordinator/HomeCoordinator.swift index bc68236..db854d0 100644 --- a/iOS/MusicSpot/MusicSpot/Coordinator/HomeCoordinator.swift +++ b/iOS/MusicSpot/MusicSpot/Coordinator/HomeCoordinator.swift @@ -77,6 +77,23 @@ extension HomeCoordinator: CoordinatorFinishDelegate { } +// MARK: - Finish Delegate: Spot + +extension HomeCoordinator: SpotCoordinatorFinishDelegate { + + func shouldFinish(childCoordinator: Coordinator, with spot: Spot?, photoData: Data?) { + guard let homeViewController = self.rootViewController as? HomeViewController else { return } + + if let spot = spot, let photoData = photoData { + homeViewController.spotDidAdded(spot, photoData: photoData) + } + + self.shouldFinish(childCoordinator: childCoordinator) + } + +} + + // MARK: - Home Navigation extension HomeCoordinator: HomeNavigationDelegate { @@ -84,6 +101,7 @@ extension HomeCoordinator: HomeNavigationDelegate { func navigateToSpot(spotCoordinate coordinate: Coordinate) { let spotCoordinator = SpotCoordinator(navigationController: self.navigationController) spotCoordinator.finishDelegate = self + spotCoordinator.spotFinishDelegate = self self.childCoordinators.append(spotCoordinator) spotCoordinator.start(spotCoordinate: coordinate) } diff --git a/iOS/MusicSpot/MusicSpot/Coordinator/Protocol/SpotCoordinatorFinishDelegate.swift b/iOS/MusicSpot/MusicSpot/Coordinator/Protocol/SpotCoordinatorFinishDelegate.swift new file mode 100644 index 0000000..73d2b70 --- /dev/null +++ b/iOS/MusicSpot/MusicSpot/Coordinator/Protocol/SpotCoordinatorFinishDelegate.swift @@ -0,0 +1,16 @@ +// +// SpotCoordinatorFinishDelegate.swift +// MusicSpot +// +// Created by 이창준 on 2024.01.11. +// + +import Foundation + +import MSDomain + +protocol SpotCoordinatorFinishDelegate: AnyObject { + + func shouldFinish(childCoordinator: Coordinator, with spot: Spot?, photoData: Data?) + +} diff --git a/iOS/MusicSpot/MusicSpot/Coordinator/SpotCoordinator.swift b/iOS/MusicSpot/MusicSpot/Coordinator/SpotCoordinator.swift index 84eb1fa..41b400d 100644 --- a/iOS/MusicSpot/MusicSpot/Coordinator/SpotCoordinator.swift +++ b/iOS/MusicSpot/MusicSpot/Coordinator/SpotCoordinator.swift @@ -20,6 +20,7 @@ final class SpotCoordinator: Coordinator { var childCoordinators: [Coordinator] = [] weak var finishDelegate: CoordinatorFinishDelegate? + weak var spotFinishDelegate: SpotCoordinatorFinishDelegate? // MARK: - Initializer @@ -82,13 +83,14 @@ extension SpotCoordinator: SpotNavigationDelegate { spotSaveViewController.dismiss(animated: true) } - func popToHome(spot: Spot?) { + func popToHome(with spot: Spot?, photoData: Data?) { if let presentedViewController = self.navigationController.presentedViewController { presentedViewController.dismiss(animated: true) { [weak self] in - self?.finish() + guard let self = self else { return } + self.spotFinishDelegate?.shouldFinish(childCoordinator: self, with: spot, photoData: photoData) } } else { - self.finish() + self.spotFinishDelegate?.shouldFinish(childCoordinator: self, with: spot, photoData: photoData) } }