diff --git a/FootprintIOS/FootprintIOS/Sources/View/Alert/CustomAlertView.swift b/FootprintIOS/FootprintIOS/Sources/View/Alert/CustomAlertView.swift index b344535..028cd9a 100644 --- a/FootprintIOS/FootprintIOS/Sources/View/Alert/CustomAlertView.swift +++ b/FootprintIOS/FootprintIOS/Sources/View/Alert/CustomAlertView.swift @@ -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 @@ -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() } @@ -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 { diff --git a/FootprintIOS/FootprintIOS/Sources/View/Alert/CustomView/SelectGoalWalkTimeView.swift b/FootprintIOS/FootprintIOS/Sources/View/Alert/CustomView/SelectGoalWalkTimeView.swift index 972f4a4..46f6bdb 100644 --- a/FootprintIOS/FootprintIOS/Sources/View/Alert/CustomView/SelectGoalWalkTimeView.swift +++ b/FootprintIOS/FootprintIOS/Sources/View/Alert/CustomView/SelectGoalWalkTimeView.swift @@ -8,6 +8,8 @@ import UIKit +import RxSwift + class SelectGoalWalkTimeView: BaseView { enum Time: Int { @@ -20,6 +22,9 @@ class SelectGoalWalkTimeView: BaseView { private var hours: [String] = [] private var minutes: [String] = [] + var selectedHour = BehaviorSubject(value: "0시간") + var selectedMinute = BehaviorSubject(value: "0분") + // MARK: - UI Components let pickerView = UIPickerView() @@ -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 } diff --git a/FootprintIOS/FootprintIOS/Sources/ViewController/Alert/AlertViewController.swift b/FootprintIOS/FootprintIOS/Sources/ViewController/Alert/AlertViewController.swift index 2d8eb36..7b23d58 100644 --- a/FootprintIOS/FootprintIOS/Sources/ViewController/Alert/AlertViewController.swift +++ b/FootprintIOS/FootprintIOS/Sources/ViewController/Alert/AlertViewController.swift @@ -9,6 +9,7 @@ import UIKit import ReactorKit +import RxSwift import Then enum AlertType { @@ -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 @@ -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 @@ -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) } } diff --git a/FootprintIOS/FootprintIOS/Sources/ViewController/Login/LoginReactor.swift b/FootprintIOS/FootprintIOS/Sources/ViewController/Login/LoginReactor.swift index 8a97c13..dff3633 100644 --- a/FootprintIOS/FootprintIOS/Sources/ViewController/Login/LoginReactor.swift +++ b/FootprintIOS/FootprintIOS/Sources/ViewController/Login/LoginReactor.swift @@ -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)) } } diff --git a/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalEdit/NextMonth/GoalEditNextMonthViewController.swift b/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalEdit/NextMonth/GoalEditNextMonthViewController.swift index 406dee0..dd6e2ae 100644 --- a/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalEdit/NextMonth/GoalEditNextMonthViewController.swift +++ b/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalEdit/NextMonth/GoalEditNextMonthViewController.swift @@ -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) diff --git a/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalViewController.swift b/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalViewController.swift index 61bb912..6688431 100644 --- a/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalViewController.swift +++ b/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalViewController.swift @@ -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 } @@ -202,15 +204,17 @@ class GoalViewController: BaseViewController, View { .flatMap { owner, _ in let selectGoalWalkTime: PublishSubject = .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)