Skip to content

Commit

Permalink
[Refactor] 좌표 로직 VM으로 이동 (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
cirtuare committed Jan 20, 2025
1 parent b811da0 commit d763cf3
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -62,7 +67,7 @@ class LocalMapViewController: BaseNavViewController {

override func setStyle() {
super.setStyle()

self.setXButton()
self.setSecondTitleLabelStyle(title: StringLiterals.LocalVerification.locateOnMap)
}
Expand All @@ -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()
}
Expand All @@ -94,7 +127,6 @@ private extension LocalMapViewController {

}


// MARK: - Map Functions

extension LocalMapViewController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import UIKit
import CoreLocation

import SnapKit
import Then
Expand All @@ -17,7 +16,7 @@ class LocalVerificationViewController: BaseNavViewController {

private let localVerificationView = LocalVerificationView()

private var userCoordinate: CLLocationCoordinate2D?
private let localVerificationViewModel = LocalVerificationViewModel()

// MARK: - LifeCycle

Expand All @@ -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) {
Expand Down Expand Up @@ -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

Expand All @@ -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)
}

Expand Down

0 comments on commit d763cf3

Please sign in to comment.