Skip to content

Commit

Permalink
feat: 거리기록 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
guesswb committed Jul 6, 2023
1 parent 82804cf commit cdcf77e
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 117 deletions.
6 changes: 3 additions & 3 deletions RunningCrew/Sources/Manager/LocationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class LocationManager: NSObject {

private let locationManager = CLLocationManager()

var currentCoordinate: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 37.554763, longitude: 126.97092)
var currentCoordinate: BehaviorRelay<CLLocationCoordinate2D> = BehaviorRelay<CLLocationCoordinate2D>(value: CLLocationCoordinate2D(latitude: 37.554763, longitude: 126.97092))
var address: BehaviorRelay<String> = BehaviorRelay<String>(value: "현 위치를 찾을 수 없습니다.")
var isNeedLocationAuthorization: BehaviorRelay<Bool> = BehaviorRelay<Bool>(value: false)

Expand All @@ -35,7 +35,7 @@ extension LocationManager {

private func reverseGeocode() {
Task {
let location = CLLocation(latitude: currentCoordinate.latitude, longitude: currentCoordinate.longitude)
let location = CLLocation(latitude: currentCoordinate.value.latitude, longitude: currentCoordinate.value.longitude)
let geocoder = CLGeocoder()
let locale = Locale(identifier: "Ko-kr")
let placemarks = try await geocoder.reverseGeocodeLocation(location, preferredLocale: locale)
Expand All @@ -54,7 +54,7 @@ extension LocationManager {
extension LocationManager: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let coordinate = manager.location?.coordinate else { return }
currentCoordinate = coordinate
currentCoordinate.accept(coordinate)
reverseGeocode()
self.locationManager.stopUpdatingLocation()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ extension RecordRunningCoordinator: RunningStartViewControllerDelegate {
self.navigationController.pushViewController(goalSettingVC, animated: false)
}

func showRecordView() {
let recordVC = RecordViewController(viewModel: RecordViewModel())
func showRecordView(goalType: GoalType, goal: String) {
let recordVC = RecordViewController(viewModel: RecordViewModel(goalType: goalType, goal: goal))
recordVC.modalPresentationStyle = .fullScreen
self.navigationController.present(recordVC, animated: false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,15 @@ class RecordViewController: BaseViewController {
@IBOutlet weak var completeButton: UIButton!
@IBOutlet weak var completeButtonContainerView: UIView!
@IBOutlet weak var runningTimerLabel: UILabel!
@IBOutlet weak var runningDistanceLabel: UILabel!
private var completeButtonRingLayer: CAShapeLayer?

//MARK: - Properties
private var timer: Timer?
private var readyTimerNum = 5
var viewModel: RecordViewModel?
private var readyTimer = Observable<Int>.timer(.seconds(1), period: .seconds(1), scheduler: MainScheduler.instance)
private var viewModel: RecordViewModel

override func viewDidLoad() {
super.viewDidLoad()
runningMeasuringView.isHidden = true
setControlButtonCornerRadius()
startReadyTimer()
setCompleteButton()
setCompleteButtonRing()
bind()
override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}

//MARK: - Initalizer
Expand All @@ -46,92 +40,18 @@ class RecordViewController: BaseViewController {

//MARK: - deinit
deinit {
timer?.invalidate()
timer = nil
viewModel?.deinitViewModel()
viewModel.deinitViewModel()
print("deinit record viewcontroller")
}


//MARK: - Ready Time Method
private func startReadyTimer() {
self.timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(readyTimerCallBack), userInfo: nil, repeats: true)
}

@objc func readyTimerCallBack() {
readyTimerNum -= 1
if readyTimerNum == 0 {
timer?.invalidate()
timer = nil
hiddenTimerLabel()
runningMeasuringView.isHidden = false
viewModel?.startTimer()
}
readyTimerLabel.text = String(readyTimerNum)
override func viewDidLoad() {
super.viewDidLoad()
}

//MARK: - Set UI Constraint
private func setControlButtonCornerRadius() {
override func setView() {
pauseAndPlayButton.layer.cornerRadius = pauseAndPlayButton.frame.height / 2

completeButton.layer.cornerRadius = completeButton.frame.height / 2
}

private func hiddenTimerLabel() {
readyDiscussionLabel.isHidden = true
readyTimerLabel.isHidden = true
}

override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}

//MARK: - Action Method

@IBAction func tapPauseOrPlayButton(_ sender: Any) {
guard let viewModel = viewModel else { return }
if viewModel.isRunning {
pauseAndPlayButton.setImage(UIImage(systemName: "play.fill"), for: .normal)
viewModel.stopTimer()
} else {
pauseAndPlayButton.setImage(UIImage(systemName: "pause.fill"), for: .normal)
viewModel.startTimer()
}
}

func setCompleteButton() {
completeButton.addTarget(self, action: #selector(completeButtonTouchDown), for: .touchDown)
completeButton.addTarget(self, action: #selector(completeButtonTouchUp), for: .touchUpInside)
}

@objc func completeButtonTouchDown() {
if timer == nil {
timer = Timer.scheduledTimer(withTimeInterval: 2.0, repeats: false, block: {[weak self] timer in
let vc = SaveRecordRunningViewController()
vc.modalPresentationStyle = .fullScreen
self?.present(vc, animated: true)
})
}
let animation = CABasicAnimation(keyPath: "strokeEnd")
animation.toValue = 1
animation.duration = 2
animation.isRemovedOnCompletion = false
animation.fillMode = .forwards
completeButtonRingLayer?.add(animation, forKey: "animation")
}

@objc func completeButtonTouchUp() {
completeButtonRingLayer?.removeAllAnimations()
timer?.invalidate()
timer = nil
showToastMessage()
}

func showToastMessage() {
print("show toast message ")
}

func setCompleteButtonRing() {

let trackLayer = CAShapeLayer()
trackLayer.frame = completeButton.bounds
completeButtonRingLayer = CAShapeLayer()
Expand All @@ -144,12 +64,68 @@ class RecordViewController: BaseViewController {
completeButtonRingLayer.strokeEnd = 0
}

func showToastMessage() {
print("show toast message ")
}

//MARK: - bind
private func bind() {
viewModel?.timerText.asDriver()
.drive(runningTimerLabel.rx
.text)
override func bind() {
let input = RecordViewModel.Input(pauseAndPlayButtonDidTap: pauseAndPlayButton.rx.tap.asObservable())

let output = viewModel.transform(input: input)

output.isRunning
.bind { isRunning in
if isRunning {
self.pauseAndPlayButton.setImage(UIImage(systemName: "play.fill"), for: .normal)
} else {
self.pauseAndPlayButton.setImage(UIImage(systemName: "pause.fill"), for: .normal)
}
}
.disposed(by: disposeBag)

output.timerText
.drive(runningTimerLabel.rx.text)
.disposed(by: disposeBag)

output.runningDistance
.drive(runningDistanceLabel.rx.text)
.disposed(by: disposeBag)


readyTimer.take(5)
.subscribe(onNext: { value in
self.readyTimerLabel.text = String(4-value)
}, onDisposed: {
self.readyDiscussionLabel.isHidden = true
self.readyTimerLabel.isHidden = true
self.runningMeasuringView.isHidden = false
self.viewModel.startTimer()
})
.disposed(by: disposeBag)

completeButton.rx.controlEvent(.touchDown)
.bind {
Timer.scheduledTimer(withTimeInterval: 2.0, repeats: false, block: {[weak self] timer in
let vc = SaveRecordRunningViewController()
vc.modalPresentationStyle = .fullScreen
self?.present(vc, animated: true)
})

let animation = CABasicAnimation(keyPath: "strokeEnd")
animation.toValue = 1
animation.duration = 2
animation.isRemovedOnCompletion = false
animation.fillMode = .forwards
self.completeButtonRingLayer?.add(animation, forKey: "animation")
}
.disposed(by: disposeBag)

completeButton.rx.controlEvent(.touchUpInside)
.bind {
self.completeButtonRingLayer?.removeAllAnimations()
self.showToastMessage()
}
.disposed(by: disposeBag)
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="21507" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_12" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21505"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21679"/>
<capability name="Image references" minToolsVersion="12.0"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
Expand All @@ -26,6 +26,7 @@
<outlet property="pauseAndPlayButton" destination="2HC-tE-siq" id="g3W-g3-7qh"/>
<outlet property="readyDiscussionLabel" destination="vay-W8-NzT" id="KL6-dD-In9"/>
<outlet property="readyTimerLabel" destination="E9f-6d-nuA" id="D3R-It-96z"/>
<outlet property="runningDistanceLabel" destination="0Uq-dW-nRt" id="KUD-Px-1XB"/>
<outlet property="runningMeasuringView" destination="WQ8-ny-CUm" id="YEz-1y-d8Y"/>
<outlet property="runningTimerLabel" destination="pf3-vx-iVb" id="1cT-P6-8qe"/>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
Expand All @@ -36,7 +37,7 @@
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="WQ8-ny-CUm">
<view hidden="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="WQ8-ny-CUm">
<rect key="frame" x="0.0" y="59" width="393" height="759"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" spacing="50" translatesAutoresizingMaskIntoConstraints="NO" id="mLZ-bP-uxG">
Expand Down Expand Up @@ -149,9 +150,6 @@
<imageReference key="image" image="pause.fill" catalog="system" symbolScale="default"/>
<preferredSymbolConfiguration key="preferredSymbolConfigurationForImage" configurationType="pointSize" pointSize="44"/>
</buttonConfiguration>
<connections>
<action selector="tapPauseOrPlayButton:" destination="-1" eventType="touchUpInside" id="vAU-HD-Ef1"/>
</connections>
</button>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="hoV-vj-Ho7">
<rect key="frame" x="145" y="0.0" width="90" height="90"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import RxGesture

protocol RunningStartViewControllerDelegate: AnyObject {
func showGoalSettingView(viewModel: RunningStartViewModel)
func showRecordView()
func showRecordView(goalType: GoalType, goal: String)
}

class RunningStartViewController: BaseViewController {
Expand Down Expand Up @@ -133,7 +133,8 @@ class RunningStartViewController: BaseViewController {
.disposed(by: disposeBag)

startButton.rx.tap
.bind { self.delegate?.showRecordView() }
.bind { self.delegate?.showRecordView(goalType: self.viewModel.goalType.value,
goal: self.goalSettingStackView.goalSettingLabelStackView.destinationLabel.text ?? "") }
.disposed(by: disposeBag)
}
}
Loading

0 comments on commit cdcf77e

Please sign in to comment.