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 3942180 commit 126f467
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import UIKit

import RxSwift
import RxRelay

class SelectGoalWalkTimeView: BaseView {

Expand All @@ -22,8 +23,8 @@ class SelectGoalWalkTimeView: BaseView {
private var hours: [String] = []
private var minutes: [String] = []

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

// MARK: - UI Components

Expand Down Expand Up @@ -53,8 +54,14 @@ class SelectGoalWalkTimeView: BaseView {
}
}

override func layoutSubviews() {
super.layoutSubviews()

pickerView.selectRow(1, inComponent: 1, animated: true)
}

private func setupPickerView() {
for hour in Array(0...23) {
for hour in Array(0...4) {
hours.append("\(hour)시간")
}

Expand Down Expand Up @@ -82,32 +89,30 @@ extension SelectGoalWalkTimeView: UIPickerViewDataSource {
}

extension SelectGoalWalkTimeView: UIPickerViewDelegate {
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
switch component {
case Time.hour.rawValue:
return hours[row]
case Time.minute.rawValue:
return minutes[row]
default:
return ""
}
}

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

switch component {
case Time.hour.rawValue:
selectedHour.onNext(hours[row])
selectedHour.accept(hours[row])
case Time.minute.rawValue:
selectedMinute.onNext(minutes[row])
selectedMinute.accept(minutes[row])
default:
break
}

if selectedHour.value == hours[0] {
pickerView.selectRow(1, inComponent: 1, animated: true)
}
}

func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
return 40
}

func pickerView(_ pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat {
return 90
}

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {

let label = UILabel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import UIKit

class GoalView: BaseView {

// MARK: - Properties

var walkTimes: [Int] = [15, 30, 60, 90, 0]

// MARK: - UI Components

lazy var dayButtons: [UIButton] = []
Expand Down Expand Up @@ -120,11 +116,25 @@ class GoalView: BaseView {
func getWalkIndex(type: UserInfoSelectBarType) -> Int {
switch type {
case .goalTime:
for (index, walkType) in InfoTexts.goalWalkTexts.enumerated() {
if walkType == goalWalkSelectView.selectLabel.text {
return walkTimes[safe: index] ?? 0
}
let time = goalWalkSelectView.selectLabel.text ?? ""
var goalTime: Int

if !time.contains("시간") {
goalTime = time.split(separator: "").map { Int($0) ?? 0 }.first ?? 0
} else if !time.contains("") {
goalTime = (time.split(separator: "시간").map { Int($0) ?? 0 }.first ?? 0) * 60
} else {
let hourMinute = time.split(separator: " ")
let hour = (hourMinute[0].split(separator: "시간").map { Int($0) ?? 0 }.first ?? 0) * 60
let minute = hourMinute[1].split(separator: "").map { Int($0) ?? 0 }.first ?? 0
goalTime = hour + minute
}

if time == "0분" {
goalTime = 10
}

return goalTime
case .time:
for (index, walkType) in InfoTexts.walkTexts.enumerated() {
if walkType == walkSelectView.selectLabel.text {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,12 @@ class AlertViewController: NavigationBarViewController, View {
customAlertView.selectGoalWalkTimeView.selectedHour,
customAlertView.selectGoalWalkTimeView.selectedMinute
).bind { [weak self] (hour, minute) in
self?.selectedTime = "\(hour) \(minute)"
let time = hour.contains("0") ? "\(minute)" :
(minute == "0분") ? "\(hour)" : "\(hour) \(minute)"

if time == "0분" {
self?.selectedTime = "10분"
}
}
.disposed(by: disposeBag)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,18 @@ class GoalReactor: Reactor {
case .updateDayButton(let day):
newState.isSelectedButtons[day] = !newState.isSelectedButtons[day]
newState.isEnabledDoneButton[0] = newState.isSelectedButtons.filter { $0 }.count > 0
newState.isPresentGoalWalkSelectView = false
case .updateWalk(let walk):
newState.walk = walk
newState.isEnabledDoneButton[1] = true
newState.isPresentGoalWalkSelectView = false
case .updateGoalWalk(let goalWalk):
newState.goalWalk = goalWalk
newState.isEnabledDoneButton[2] = true
newState.isPresentGoalWalkSelectView = false
case .showGoalWalkAlertView:
newState.isPresentGoalWalkSelectView = true
newState.isEnabledDoneButton[2] = true
}

return newState
Expand Down

0 comments on commit 126f467

Please sign in to comment.