Skip to content

Commit

Permalink
[Feat] #70 - 목표 산책 시간 직접설정 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
0inn committed Feb 5, 2023
1 parent 74a2d06 commit 43596f4
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 15 deletions.
7 changes: 7 additions & 0 deletions FootprintIOS/FootprintIOS/Sources/Service/InfoService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -28,6 +29,7 @@ protocol InfoServiceType {
func updateBirth(to birth: String) -> Observable<String>
func updateWalk(to walk: String) -> Observable<String>
func updateGoalWalk(to goalWalk: String) -> Observable<String>
func showGoalWalkAlertView() -> Observable<Void>
}

class InfoService: NetworkService, InfoServiceType {
Expand Down Expand Up @@ -108,6 +110,11 @@ class InfoService: NetworkService, InfoServiceType {
return .just(walk)
}

func showGoalWalkAlertView() -> Observable<Void> {
event.onNext(.showGoalWalkAlertView)
return .just(Void())
}

func updateGoalWalk(to goalWalk: String) -> Observable<String> {
event.onNext(.updateGoalWalk(content: goalWalk))
return .just(goalWalk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -34,8 +36,8 @@ class GoalWalkBottomSheetReactor: Reactor {

func mutate(action: Action) -> Observable<Mutation> {
switch action {
case .tapGoalWalkTime(let goalWalk):
return service.updateGoalWalk(to: goalWalk).map { _ in .dismiss }
case .tapGoalWalkTime(let goalWalkTime):
return goalWalkTimeMutation(goalWalkTime)
}
}

Expand All @@ -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<Mutation> {
if goalWalkTime == "직접 설정" {
return .just(.selectGoalWalkTime)
} else {
return service.updateGoalWalk(to: goalWalkTime).map { _ in .dismiss }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ class GoalReactor: Reactor {
case updateDayButton(Int)
case updateWalk(String)
case updateGoalWalk(String)
case showGoalWalkAlertView
}

struct State {
var isSelectedButtons: [Bool] = [false, false, false, false, false, false, false]
var walk: String?
var goalWalk: String?
var isEnabledDoneButton: [Bool] = [false, false, false]
var isPresentGoalWalkSelectView: Bool = false
}

var initialState: State
Expand Down Expand Up @@ -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()
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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<String> = .init()

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

})

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

Expand Down

0 comments on commit 43596f4

Please sign in to comment.