Skip to content

Commit

Permalink
Merge pull request #379 from OMZigak/fix/#377-promise-qa
Browse files Browse the repository at this point in the history
[fix] 약속 상세 3차 QA 반영
  • Loading branch information
youz2me authored Sep 13, 2024
2 parents 7e0cb86 + 84d883d commit 48e34e0
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class ChooseMemberViewController: BaseViewController {
}

override func setupDelegate() {
rootView.memberListView.delegate = self
rootView.memberListView.dataSource = self
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ extension EditPromiseViewModel {
extension EditPromiseViewModel {
func putPromiseInfo() {
let participants = participantList?.value.filter { $0.isParticipant }.map { $0.memberID } ?? []

let request = EditPromiseRequestModel(
name: promiseName?.value ?? "",
placeName: placeName?.value ?? "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,14 @@ private extension PromiseViewController {
func setupBindings() {
viewModel.promiseInfo.bindOnMain(with: self) { owner, info in
owner.setupNavigationBarTitle(with: info?.promiseName ?? "", isBorderHidden: true)

owner.setupPromiseEditButton(isHidden: !(info?.isParticipant ?? false))

owner.promiseInfoViewController.setupContent()
owner.promiseInfoViewController.setUpTimeContent()
owner.removePromiseViewContoller.promiseNameLabel.text = info?.promiseName ?? ""

guard let isParticipant = info?.isParticipant else { return }

owner.setupPromiseEditButton(isHidden: !isParticipant)
owner.promiseInfoViewController.rootView.editButton.isHidden = !isParticipant
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ class PromiseInfoViewController: BaseViewController {

override func setupView() {
view.backgroundColor = .gray0

if let isParticipant = viewModel.promiseInfo.value?.isParticipant {
rootView.editButton.isHidden = isParticipant
}
}

override func setupDelegate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class ReadyStatusViewController: BaseViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

viewModel.fetchTardyInfo()
viewModel.fetchPromiseInfo()
viewModel.fetchMyReadyStatus()
viewModel.fetchPromiseParticipantList()
Expand Down Expand Up @@ -97,11 +98,16 @@ class ReadyStatusViewController: BaseViewController {

extension ReadyStatusViewController {
func setupBinding() {
viewModel.isPastDue.bindOnMain(with: self) { owner, flag in
guard let isParticipant = owner.viewModel.promiseInfo.value?.isParticipant else { return }

owner.rootView.readyPlanInfoView.editButton.isHidden = flag
owner.rootView.enterReadyButtonView.isUserInteractionEnabled = !flag && isParticipant
}

viewModel.promiseInfo.bindOnMain(with: self) { owner, model in
guard let isParticipant = model?.isParticipant else { return }

owner.rootView.enterReadyButtonView.isUserInteractionEnabled = isParticipant

if !isParticipant {
owner.updateReadyInfoView(flag: false)
owner.rootView.myReadyStatusProgressView.readyStartButton.setupButton("준비 시작", .none)
Expand Down Expand Up @@ -136,6 +142,11 @@ extension ReadyStatusViewController {
}

owner.updateReadyInfoView(flag: true)
owner.updateLatePopupStatus()
}

viewModel.myReadyProgressStatus.bindOnMain(with: self) { owner, status in
owner.updateLatePopupStatus()
}

viewModel.moveDuration.bind(with: self) { owner, moveTime in
Expand Down Expand Up @@ -190,6 +201,7 @@ extension ReadyStatusViewController {

viewModel.myReadyProgressStatus.bindOnMain(with: self) { owner, status in
owner.updateReadyStartButton()
owner.updateLatePopupStatus()
owner.rootView.ourReadyStatusCollectionView.reloadData()
}

Expand All @@ -202,9 +214,51 @@ extension ReadyStatusViewController {
)
}
}
}

func updateLatePopupStatus() {
let date = Calendar.current
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "HH시 mm분"
dateFormatter.locale = Locale(identifier: "ko_KR")
dateFormatter.timeZone = TimeZone(identifier: "Asia/Seoul")

guard let readyStartTime = dateFormatter.date(from: viewModel.readyStartTime.value) else { return }
guard let moveStartTime = dateFormatter.date(from: viewModel.moveStartTime.value) else { return }

let readyStartComponent = date.dateComponents([.hour, .minute], from: readyStartTime)
let moveStartComponents = date.dateComponents([.hour, .minute], from: moveStartTime)
let currentTimeComponents = date.dateComponents([.hour, .minute], from: Date())

viewModel.isLate.bindOnMain(with: self) { owner, status in
owner.updatePopUpImageView()
guard let readyStartHour = readyStartComponent.hour,
let readyStartMinute = readyStartComponent.minute,
let moveStartHour = moveStartComponents.hour,
let moveStartMinute = moveStartComponents.minute,
let currentTimeHour = currentTimeComponents.hour,
let currentTimeMinute = currentTimeComponents.minute else { return }

DispatchQueue.main.async {
if (currentTimeHour >= readyStartHour) && (currentTimeMinute > readyStartMinute) && ((currentTimeHour <= moveStartHour) && (currentTimeMinute < moveStartMinute)) {
let readyLateFlag = !(self.viewModel.myReadyProgressStatus.value == .none)

print(">> \(readyLateFlag) : \(#function)")

self.rootView.popUpImageView.isHidden = readyLateFlag
}
else if ((currentTimeHour >= moveStartHour) && (currentTimeMinute > moveStartMinute)) && self.viewModel.isPastDue.value == false {
let moveLateFlag = !(self.viewModel.myReadyProgressStatus.value == .none || self.viewModel.myReadyProgressStatus.value == .ready)

print(">>> \(moveLateFlag) : \(#function)")

self.rootView.popUpImageView.isHidden = moveLateFlag
}
else {
let arriveLateFlag = self.viewModel.isPastDue.value && !(self.viewModel.myReadyProgressStatus.value == .done)

print(">>>> \(arriveLateFlag) : \(#function)")

self.rootView.popUpImageView.isHidden = arriveLateFlag
}
}
}

Expand Down
49 changes: 0 additions & 49 deletions KkuMulKum/Source/Promise/ViewModel/PromiseViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,51 +106,6 @@ extension PromiseViewModel {
return dateFormatter.string(from: Date())
}

/// 꾸물거릴 시간이 없어요 팝업 표시를 위해 지각 여부를 판단하는 함수
func checkLate(tappedButton: TappedButton) {
fetchMyReadyStatus()
let formatter = DateFormatter()
formatter.dateFormat = "HH시 mm분"
formatter.locale = Locale(identifier: "ko_KR")
formatter.timeZone = TimeZone(identifier: "Asia/Seoul")

switch tappedButton {
case .move:
if let moveTime = formatter.date(from: moveStartTime.value) {
let calendar = Calendar.current

let moveTimeComponents = calendar.dateComponents([.hour, .minute], from: moveTime)
let currentTimeComponents = calendar.dateComponents([.hour, .minute], from: Date())

if let moveHour = moveTimeComponents.hour, let moveMinute = moveTimeComponents.minute,
let currentHour = currentTimeComponents.hour, let currentMinute = currentTimeComponents.minute {
if currentHour > moveHour || (currentHour == moveHour && currentMinute > moveMinute) {
self.isLate.value = true
} else {
self.isLate.value = false
}
}
}
case .ready:
if let readyTime = formatter.date(from: readyStartTime.value) {
let calendar = Calendar.current

let readyTimeComponents = calendar.dateComponents([.hour, .minute], from: readyTime)
let currentTimeComponents = calendar.dateComponents([.hour, .minute], from: Date())

if let readyHour = readyTimeComponents.hour, let readyMinute = readyTimeComponents.minute,
let currentHour = currentTimeComponents.hour, let currentMinute = currentTimeComponents.minute {
if currentHour > readyHour || (currentHour == readyHour && currentMinute > readyMinute) {
self.isLate.value = true
} else {
self.isLate.value = false
}
}
}
}
}


func updateMyReadyProgressStatus() {
myReadyProgressStatus.value = myReadyStatus.value?.preparationStartAt == nil ? .none
: myReadyStatus.value?.departureAt == nil ? .ready
Expand Down Expand Up @@ -280,8 +235,6 @@ extension PromiseViewModel {

myReadyProgressStatus.value = .ready

self.checkLate(tappedButton: .ready)

completion()
}
}
Expand All @@ -303,8 +256,6 @@ extension PromiseViewModel {

myReadyProgressStatus.value = .move

self.checkLate(tappedButton: .move)

completion()
}
}
Expand Down

0 comments on commit 48e34e0

Please sign in to comment.