From d763cf32c47b1d0e9e6ba846f918221d8110bf21 Mon Sep 17 00:00:00 2001 From: cirtuare Date: Mon, 20 Jan 2025 18:55:42 +0900 Subject: [PATCH] =?UTF-8?q?[Refactor]=20=EC=A2=8C=ED=91=9C=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20VM=EC=9C=BC=EB=A1=9C=20=EC=9D=B4=EB=8F=99=20(#70)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../View/LocalMapViewController.swift | 62 ++++++++++++++----- .../LocalVerificationViewController.swift | 41 ++++++------ 2 files changed, 69 insertions(+), 34 deletions(-) diff --git a/ACON-iOS/ACON-iOS/Presentation/LocalVerification/View/LocalMapViewController.swift b/ACON-iOS/ACON-iOS/Presentation/LocalVerification/View/LocalMapViewController.swift index 848aa64..c34bedc 100644 --- a/ACON-iOS/ACON-iOS/Presentation/LocalVerification/View/LocalMapViewController.swift +++ b/ACON-iOS/ACON-iOS/Presentation/LocalVerification/View/LocalMapViewController.swift @@ -19,31 +19,36 @@ class LocalMapViewController: BaseNavViewController { private var viewBlurEffect: UIVisualEffectView = UIVisualEffectView() - private let coordinate: CLLocationCoordinate2D + private var localArea: String = "" - // MARK: - LifeCycle + private let localVerificationViewModel: LocalVerificationViewModel - override func viewDidLoad() { - super.viewDidLoad() - - self.setXButton() - addTarget() - } - init(coordinate: CLLocationCoordinate2D) { - self.coordinate = coordinate + // MARK: - LifeCycle + + init(viewModel: LocalVerificationViewModel) { + self.localVerificationViewModel = viewModel super.init(nibName: nil, bundle: nil) } - + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } + override func viewDidLoad() { + super.viewDidLoad() + + addTarget() + bindViewModel() + } + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(false) self.tabBarController?.tabBar.isHidden = true - moveCameraToLocation(latitude: coordinate.latitude, longitude: coordinate.longitude) + print(localVerificationViewModel.userCoordinate) + moveCameraToLocation(latitude: localVerificationViewModel.userCoordinate?.latitude ?? 0, + longitude: localVerificationViewModel.userCoordinate?.longitude ?? 0) } override func setHierarchy() { @@ -62,7 +67,7 @@ class LocalMapViewController: BaseNavViewController { override func setStyle() { super.setStyle() - + self.setXButton() self.setSecondTitleLabelStyle(title: StringLiterals.LocalVerification.locateOnMap) } @@ -75,14 +80,42 @@ class LocalMapViewController: BaseNavViewController { } + +// MARK: - bindViewModel + +private extension LocalMapViewController { + + func bindViewModel() { + self.localVerificationViewModel.onSuccessPostLocalArea.bind { [weak self] onSuccess in + guard let onSuccess, let data = self?.localVerificationViewModel.localArea.value else { return } + if onSuccess { + self?.localArea = data + self?.presentVerificationFinsishedVC() + } + } + } +} + + // MARK: - @objc functions private extension LocalMapViewController { @objc func finishVerificationButtonTapped() { - let vc = LocalVerificationFinishedViewController() + self.localVerificationViewModel.postLocalArea() + } + +} + + +// MARK: - @objc functions + +private extension LocalMapViewController { + + func presentVerificationFinsishedVC() { + let vc = LocalVerificationFinishedViewController(localArea: self.localArea) vc.dismissCompletion = { [weak self] in self?.removeBlurView() } @@ -94,7 +127,6 @@ private extension LocalMapViewController { } - // MARK: - Map Functions extension LocalMapViewController { diff --git a/ACON-iOS/ACON-iOS/Presentation/LocalVerification/View/LocalVerificationViewController.swift b/ACON-iOS/ACON-iOS/Presentation/LocalVerification/View/LocalVerificationViewController.swift index e3c2614..29a535c 100644 --- a/ACON-iOS/ACON-iOS/Presentation/LocalVerification/View/LocalVerificationViewController.swift +++ b/ACON-iOS/ACON-iOS/Presentation/LocalVerification/View/LocalVerificationViewController.swift @@ -6,7 +6,6 @@ // import UIKit -import CoreLocation import SnapKit import Then @@ -17,7 +16,7 @@ class LocalVerificationViewController: BaseNavViewController { private let localVerificationView = LocalVerificationView() - private var userCoordinate: CLLocationCoordinate2D? + private let localVerificationViewModel = LocalVerificationViewModel() // MARK: - LifeCycle @@ -26,11 +25,7 @@ class LocalVerificationViewController: BaseNavViewController { self.setXButton() addTarget() - ACLocationManager.shared.addDelegate(self) - } - - deinit { - ACLocationManager.shared.removeDelegate(self) + bindViewModel() } override func viewWillAppear(_ animated: Bool) { @@ -70,6 +65,22 @@ class LocalVerificationViewController: BaseNavViewController { } + +// MARK: - bindViewModel + +private extension LocalVerificationViewController { + + func bindViewModel() { + self.localVerificationViewModel.isLocationChecked.bind { [weak self] isChecked in + guard let isChecked else { return } + if isChecked { + self?.pushToLocalMapVC() + } + } + } + +} + // MARK: - @objc functions @@ -86,26 +97,18 @@ private extension LocalVerificationViewController { @objc func nextButtonTapped() { - ACLocationManager.shared.checkUserDeviceLocationServiceAuthorization() + localVerificationViewModel.checkLocation() } } -extension LocalVerificationViewController: ACLocationManagerDelegate { - - func locationManager(_ manager: ACLocationManager, didUpdateLocation coordinate: CLLocationCoordinate2D) { - print("성공 - 위도: \(coordinate.latitude), 경도: \(coordinate.longitude)") - self.userCoordinate = coordinate - pushToLocalMapVC() - } - -} + +// MARK: - Navigation Logic extension LocalVerificationViewController { func pushToLocalMapVC() { - guard let coordinate = userCoordinate else { return } - let vc = LocalMapViewController(coordinate: coordinate) + let vc = LocalMapViewController(viewModel: localVerificationViewModel) navigationController?.pushViewController(vc, animated: false) }