diff --git a/FootprintIOS/FootprintIOS/Sources/Service/InfoService.swift b/FootprintIOS/FootprintIOS/Sources/Service/InfoService.swift index b2e5112..871a2fc 100644 --- a/FootprintIOS/FootprintIOS/Sources/Service/InfoService.swift +++ b/FootprintIOS/FootprintIOS/Sources/Service/InfoService.swift @@ -12,6 +12,7 @@ enum InfoEvent { case updateBirth(content: String) case updateWalk(content: String) case updateGoalWalk(content: String) + case showGoalWalkAlertView case getThisMonthGoal(GoalResponseDTO) case getNextMonthGoal(GoalResponseDTO) @@ -28,6 +29,7 @@ protocol InfoServiceType { func updateBirth(to birth: String) -> Observable func updateWalk(to walk: String) -> Observable func updateGoalWalk(to goalWalk: String) -> Observable + func showGoalWalkAlertView() -> Observable } class InfoService: NetworkService, InfoServiceType { @@ -108,6 +110,11 @@ class InfoService: NetworkService, InfoServiceType { return .just(walk) } + func showGoalWalkAlertView() -> Observable { + event.onNext(.showGoalWalkAlertView) + return .just(Void()) + } + func updateGoalWalk(to goalWalk: String) -> Observable { event.onNext(.updateGoalWalk(content: goalWalk)) return .just(goalWalk) diff --git a/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalBottomSheet/GoalWalkBottomSheet/GoalWalkBottomSheetReactor.swift b/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalBottomSheet/GoalWalkBottomSheet/GoalWalkBottomSheetReactor.swift index cda6f2d..dad0c36 100644 --- a/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalBottomSheet/GoalWalkBottomSheet/GoalWalkBottomSheetReactor.swift +++ b/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalBottomSheet/GoalWalkBottomSheet/GoalWalkBottomSheetReactor.swift @@ -15,12 +15,14 @@ class GoalWalkBottomSheetReactor: Reactor { enum Mutation { case updateGoalWalkInfo(String) + case selectGoalWalkTime case dismiss } struct State { var goalWalk: String? var goalWalkNum: Int? + var showGoalWalkTimeAlertView: Bool = false var dismiss: Bool = true } @@ -34,8 +36,8 @@ class GoalWalkBottomSheetReactor: Reactor { func mutate(action: Action) -> Observable { switch action { - case .tapGoalWalkTime(let goalWalk): - return service.updateGoalWalk(to: goalWalk).map { _ in .dismiss } + case .tapGoalWalkTime(let goalWalkTime): + return goalWalkTimeMutation(goalWalkTime) } } @@ -45,10 +47,23 @@ class GoalWalkBottomSheetReactor: Reactor { switch mutation { case .updateGoalWalkInfo(let goalWalk): newState.goalWalk = goalWalk + case .selectGoalWalkTime: + newState.showGoalWalkTimeAlertView = true case .dismiss: newState.dismiss = true + newState.showGoalWalkTimeAlertView = false } return newState } } + +extension GoalWalkBottomSheetReactor { + private func goalWalkTimeMutation(_ goalWalkTime: String) -> Observable { + if goalWalkTime == "직접 설정" { + return .just(.selectGoalWalkTime) + } else { + return service.updateGoalWalk(to: goalWalkTime).map { _ in .dismiss } + } + } +} diff --git a/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalBottomSheet/GoalWalkBottomSheet/GoalWalkBottomSheetViewController.swift b/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalBottomSheet/GoalWalkBottomSheet/GoalWalkBottomSheetViewController.swift index 1b595b1..8318e93 100644 --- a/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalBottomSheet/GoalWalkBottomSheet/GoalWalkBottomSheetViewController.swift +++ b/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalBottomSheet/GoalWalkBottomSheet/GoalWalkBottomSheetViewController.swift @@ -94,18 +94,29 @@ final class GoalWalkBottomSheetViewController: BottomSheetViewController, View { func bind(reactor: GoalWalkBottomSheetReactor) { setGoalWalkLabels() - for goalWalk in 0..<5 { + for goalWalk in texts.indices { goalWalkLabels[goalWalk].rx.tapGesture() .when(.recognized) .withUnretained(self) .map { owner, _ -> String in - return owner.texts[goalWalk] ?? "0" + return owner.texts[goalWalk] } .map { .tapGoalWalkTime($0) } .bind(to: reactor.action) .disposed(by: disposeBag) } + reactor.state + .map(\.showGoalWalkTimeAlertView) + .filter { $0 } + .withUnretained(self) + .bind { owner, _ in + owner.dismiss(animated: true) { + reactor.service.showGoalWalkAlertView() + } + } + .disposed(by: disposeBag) + reactor.state .map(\.dismiss) .withUnretained(self) diff --git a/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalReactor.swift b/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalReactor.swift index 35765af..00245d6 100644 --- a/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalReactor.swift +++ b/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalReactor.swift @@ -18,6 +18,7 @@ class GoalReactor: Reactor { case updateDayButton(Int) case updateWalk(String) case updateGoalWalk(String) + case showGoalWalkAlertView } struct State { @@ -25,6 +26,7 @@ class GoalReactor: Reactor { var walk: String? var goalWalk: String? var isEnabledDoneButton: [Bool] = [false, false, false] + var isPresentGoalWalkSelectView: Bool = false } var initialState: State @@ -53,6 +55,8 @@ class GoalReactor: Reactor { return .just(.updateWalk(walk)) case .updateGoalWalk(content: let goalWalk): return .just(.updateGoalWalk(goalWalk)) + case .showGoalWalkAlertView: + return .just(.showGoalWalkAlertView) default: return .never() } @@ -74,6 +78,9 @@ class GoalReactor: Reactor { case .updateGoalWalk(let goalWalk): newState.goalWalk = goalWalk newState.isEnabledDoneButton[2] = true + newState.isPresentGoalWalkSelectView = false + case .showGoalWalkAlertView: + newState.isPresentGoalWalkSelectView = true } return newState diff --git a/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalViewController.swift b/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalViewController.swift index 5559047..61bb912 100644 --- a/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalViewController.swift +++ b/FootprintIOS/FootprintIOS/Sources/ViewController/UserInfo/Goal/GoalViewController.swift @@ -149,23 +149,23 @@ class GoalViewController: BaseViewController, 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) @@ -179,6 +179,14 @@ class GoalViewController: BaseViewController, View { } .disposed(by: disposeBag) + reactor.state + .compactMap(\.walk) + .withUnretained(self) + .bind { owner, walk in + owner.goalView.walkSelectView.update(text: walk) + } + .disposed(by: disposeBag) + reactor.state .compactMap(\.goalWalk) .withUnretained(self) @@ -188,10 +196,21 @@ class GoalViewController: BaseViewController, View { .disposed(by: disposeBag) reactor.state - .compactMap(\.walk) + .map(\.isPresentGoalWalkSelectView) + .filter { $0 } .withUnretained(self) - .bind { owner, walk in - owner.goalView.walkSelectView.update(text: walk) + .flatMap { owner, _ in + let selectGoalWalkTime: PublishSubject = .init() + + owner.makeAlert(type: .custom(value: .selectGoalWalkTime), customViewType: .selectGoalWalkTime, alertAction: { + + }) + + return selectGoalWalkTime + } + .withUnretained(self) + .bind { (owner, goalWalkTime) in + print("!! alert !!") } .disposed(by: disposeBag)