Skip to content

Commit

Permalink
[Feat] #70 - 목표산책시간 업데이트 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
0inn committed Feb 8, 2023
1 parent 684eff9 commit 3942180
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 35 deletions.
29 changes: 14 additions & 15 deletions FootprintIOS/FootprintIOS/Sources/View/Alert/CustomAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CustomAlertView: BaseView {
$0.textColor = FootprintIOSAsset.Colors.blackM.color
}

private lazy var customView = UIView.init()
lazy var selectGoalWalkTimeView = SelectGoalWalkTimeView.init()

private let lineView = UIView().then {
$0.backgroundColor = FootprintIOSAsset.Colors.white3.color
Expand Down Expand Up @@ -72,28 +72,25 @@ class CustomAlertView: BaseView {

titleLabel.text = type.title
rightButton.setTitle(type.buttonTitle, for: .normal)

switch customViewType {
case .selectGoalWalkTime:
customView = SelectGoalWalkTimeView.init()
case .none:
return
}
}

override func setupHierarchy() {
super.setupHierarchy()

addSubview(backgroundView)
backgroundView.addSubviews([titleLabel, customView, lineView, buttonStackView])
backgroundView.addSubviews([titleLabel, lineView, buttonStackView])

if customViewType == .selectGoalWalkTime {
backgroundView.addSubview(selectGoalWalkTimeView)
}
}

override func setupLayout() {
super.setupLayout()

backgroundView.snp.makeConstraints {
$0.width.equalTo(326)
$0.height.equalTo(259)
$0.width.equalTo(327)
$0.height.equalTo(230)
$0.center.equalToSuperview()
}

Expand All @@ -102,10 +99,12 @@ class CustomAlertView: BaseView {
$0.centerX.equalTo(backgroundView)
}

customView.snp.makeConstraints {
$0.top.equalTo(titleLabel.snp.bottom).offset(10)
$0.leading.trailing.equalTo(backgroundView)
$0.height.equalTo(150)
if customViewType == .selectGoalWalkTime {
selectGoalWalkTimeView.snp.makeConstraints {
$0.top.equalTo(titleLabel.snp.bottom).offset(10)
$0.leading.trailing.equalTo(backgroundView)
$0.height.equalTo(130)
}
}

buttonStackView.snp.makeConstraints {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import UIKit

import RxSwift

class SelectGoalWalkTimeView: BaseView {

enum Time: Int {
Expand All @@ -20,6 +22,9 @@ class SelectGoalWalkTimeView: BaseView {
private var hours: [String] = []
private var minutes: [String] = []

var selectedHour = BehaviorSubject<String>(value: "0시간")
var selectedMinute = BehaviorSubject<String>(value: "0분")

// MARK: - UI Components

let pickerView = UIPickerView()
Expand Down Expand Up @@ -91,9 +96,9 @@ extension SelectGoalWalkTimeView: UIPickerViewDelegate {
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
switch component {
case Time.hour.rawValue:
print(hours[row])
selectedHour.onNext(hours[row])
case Time.minute.rawValue:
print(minutes[row])
selectedMinute.onNext(minutes[row])
default:
break
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import UIKit

import ReactorKit
import RxSwift
import Then

enum AlertType {
Expand Down Expand Up @@ -96,6 +97,9 @@ class AlertViewController: NavigationBarViewController, View {
private let customViewType: AlertType.Custom?
typealias Reactor = AlertReactor
var alertAction: (() -> Void)?
var selectTimeAction: ((String) -> Void)?

private lazy var selectedTime: String = ""

// MARK: - UI Components

Expand Down Expand Up @@ -196,15 +200,27 @@ class AlertViewController: NavigationBarViewController, View {
})
.disposed(by: disposeBag)

if customViewType == .selectGoalWalkTime {
Observable.combineLatest(
customAlertView.selectGoalWalkTimeView.selectedHour,
customAlertView.selectGoalWalkTimeView.selectedMinute
).bind { [weak self] (hour, minute) in
self?.selectedTime = "\(hour) \(minute)"
}
.disposed(by: disposeBag)
}

customAlertView.rightButton.rx.tap
.withUnretained(self)
.asDriver(onErrorDriveWith: .empty())
.drive(onNext: { owner, _ in
owner.alertAction?()
if owner.customViewType == .selectGoalWalkTime {
owner.selectTimeAction?(owner.selectedTime)
}
owner.dismiss(animated: true)
})
.disposed(by: disposeBag)

reactor.state
.map(\.isDismiss)
.bind { [weak self] _ in
Expand All @@ -215,11 +231,15 @@ class AlertViewController: NavigationBarViewController, View {
}

extension UIViewController {
func makeAlert(type: AlertType, customViewType: AlertType.Custom? = nil, alertAction: (() -> Void)? = nil) {
func makeAlert(type: AlertType,
customViewType: AlertType.Custom? = nil,
alertAction: (() -> Void)? = nil,
selectTimeAction: ((String) -> Void)? = nil) {
let alertVC = AlertViewController(type: type, customViewType: customViewType, reactor: .init())
alertVC.modalTransitionStyle = .crossDissolve
alertVC.modalPresentationStyle = .overCurrentContext
alertVC.alertAction = alertAction
alertVC.selectTimeAction = selectTimeAction
self.present(alertVC, animated: true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,23 @@ extension LoginReactor {
if let error = error {
print(error)
} else {
guard let userEmail = user?.kakaoAccount?.email else { return observable.onNext(.doKakaoLogin(false)) }
guard let userEmail = user?.kakaoAccount?.email,
let userId = user?.id,
let userName = user?.properties?["nickname"]
else { return observable.onNext(.doKakaoLogin(false)) }

self?.keychainService.updateTokens(accessToken: token.accessToken, refreshToken: token.refreshToken)

self?.loginService.login(userId: String(userId), userName: userName, userEmail: userEmail, providerType: .kakao)

self?.loginService.event
.subscribe(onNext: { event in
switch event {
case let .login(data):
self?.keychainService.updateJWTId(id: data.jwtID)
}
})

observable.onNext(.doKakaoLogin(true))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,23 @@ final class GoalEditNextMonthViewController: NavigationBarViewController, View {
.bind(to: reactor.action)
.disposed(by: disposeBag)

goalView.walkSelectView.rx.tapGesture()
goalView.goalWalkSelectView.rx.tapGesture()
.when(.recognized)
.withUnretained(self)
.bind { owner, _ in
let reactor = reactor.reactorForWalk()
let walkBottomSheet = WalkBottomSheetViewController(reactor: reactor)
owner.present(walkBottomSheet, animated: true)
let reactor = reactor.reactorForGoalWalk()
let goalWalkBottomSheet = GoalWalkBottomSheetViewController(reactor: reactor)
owner.present(goalWalkBottomSheet, animated: true)
}
.disposed(by: disposeBag)

goalView.goalWalkSelectView.rx.tapGesture()
goalView.walkSelectView.rx.tapGesture()
.when(.recognized)
.withUnretained(self)
.bind { owner, _ in
let reactor = reactor.reactorForGoalWalk()
let goalWalkBottomSheet = GoalWalkBottomSheetViewController(reactor: reactor)
owner.present(goalWalkBottomSheet, animated: true)
let reactor = reactor.reactorForWalk()
let walkBottomSheet = WalkBottomSheetViewController(reactor: reactor)
owner.present(walkBottomSheet, animated: true)
}
.disposed(by: disposeBag)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,11 @@ class GoalViewController: BaseViewController, View {
bottomButton.rx.tap
.withUnretained(self)
.map { owner, _ -> GoalRequestDTO in
let info = GoalRequestDTO(dayIdx: reactor.currentState.isSelectedButtons.enumerated().filter { $0.1 }.map { $0.0 + 1 },
walkGoalTime: owner.goalView.getWalkIndex(type: .goalTime),
walkTimeSlot: owner.goalView.getWalkIndex(type: .time))
let info = GoalRequestDTO(
dayIdx: reactor.currentState.isSelectedButtons
.enumerated().filter { $0.1 }.map { $0.0 + 1 },
walkGoalTime: owner.goalView.getWalkIndex(type: .goalTime),
walkTimeSlot: owner.goalView.getWalkIndex(type: .time))

return info
}
Expand Down Expand Up @@ -202,15 +204,17 @@ class GoalViewController: BaseViewController, View {
.flatMap { owner, _ in
let selectGoalWalkTime: PublishSubject<String> = .init()

owner.makeAlert(type: .custom(value: .selectGoalWalkTime), customViewType: .selectGoalWalkTime, alertAction: {

owner.makeAlert(type: .custom(value: .selectGoalWalkTime),
customViewType: .selectGoalWalkTime,
selectTimeAction: { time in
selectGoalWalkTime.onNext(time)
})

return selectGoalWalkTime
}
.withUnretained(self)
.bind { (owner, goalWalkTime) in
print("!! alert !!")
owner.goalView.goalWalkSelectView.update(text: goalWalkTime)
}
.disposed(by: disposeBag)

Expand Down

0 comments on commit 3942180

Please sign in to comment.