diff --git a/KkuMulKum/Source/Promise/EditPromise/ViewController/ChooseMemberViewController.swift b/KkuMulKum/Source/Promise/EditPromise/ViewController/ChooseMemberViewController.swift index 2b6d0d5e..d5c78267 100644 --- a/KkuMulKum/Source/Promise/EditPromise/ViewController/ChooseMemberViewController.swift +++ b/KkuMulKum/Source/Promise/EditPromise/ViewController/ChooseMemberViewController.swift @@ -66,6 +66,7 @@ class ChooseMemberViewController: BaseViewController { } override func setupDelegate() { + rootView.memberListView.delegate = self rootView.memberListView.dataSource = self } } diff --git a/KkuMulKum/Source/Promise/EditPromise/ViewModel/EditPromiseViewModel.swift b/KkuMulKum/Source/Promise/EditPromise/ViewModel/EditPromiseViewModel.swift index 2c78b758..268dc7a4 100644 --- a/KkuMulKum/Source/Promise/EditPromise/ViewModel/EditPromiseViewModel.swift +++ b/KkuMulKum/Source/Promise/EditPromise/ViewModel/EditPromiseViewModel.swift @@ -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 ?? "", diff --git a/KkuMulKum/Source/Promise/PagePromise/ViewController/PromiseViewController.swift b/KkuMulKum/Source/Promise/PagePromise/ViewController/PromiseViewController.swift index cb888c15..4d53e4ee 100644 --- a/KkuMulKum/Source/Promise/PagePromise/ViewController/PromiseViewController.swift +++ b/KkuMulKum/Source/Promise/PagePromise/ViewController/PromiseViewController.swift @@ -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 } } diff --git a/KkuMulKum/Source/Promise/PromiseInfo/ViewController/PromiseInfoViewController.swift b/KkuMulKum/Source/Promise/PromiseInfo/ViewController/PromiseInfoViewController.swift index 55f1dcae..44da0ec1 100644 --- a/KkuMulKum/Source/Promise/PromiseInfo/ViewController/PromiseInfoViewController.swift +++ b/KkuMulKum/Source/Promise/PromiseInfo/ViewController/PromiseInfoViewController.swift @@ -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() { diff --git a/KkuMulKum/Source/Promise/ReadyStatus/ViewController/ReadyStatusViewController.swift b/KkuMulKum/Source/Promise/ReadyStatus/ViewController/ReadyStatusViewController.swift index 6f0b9e8c..65661298 100644 --- a/KkuMulKum/Source/Promise/ReadyStatus/ViewController/ReadyStatusViewController.swift +++ b/KkuMulKum/Source/Promise/ReadyStatus/ViewController/ReadyStatusViewController.swift @@ -45,6 +45,7 @@ class ReadyStatusViewController: BaseViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) + viewModel.fetchTardyInfo() viewModel.fetchPromiseInfo() viewModel.fetchMyReadyStatus() viewModel.fetchPromiseParticipantList() @@ -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) @@ -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 @@ -190,6 +201,7 @@ extension ReadyStatusViewController { viewModel.myReadyProgressStatus.bindOnMain(with: self) { owner, status in owner.updateReadyStartButton() + owner.updateLatePopupStatus() owner.rootView.ourReadyStatusCollectionView.reloadData() } @@ -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 + } } } diff --git a/KkuMulKum/Source/Promise/ViewModel/PromiseViewModel.swift b/KkuMulKum/Source/Promise/ViewModel/PromiseViewModel.swift index 3d79fa08..01e824e8 100644 --- a/KkuMulKum/Source/Promise/ViewModel/PromiseViewModel.swift +++ b/KkuMulKum/Source/Promise/ViewModel/PromiseViewModel.swift @@ -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 @@ -280,8 +235,6 @@ extension PromiseViewModel { myReadyProgressStatus.value = .ready - self.checkLate(tappedButton: .ready) - completion() } } @@ -303,8 +256,6 @@ extension PromiseViewModel { myReadyProgressStatus.value = .move - self.checkLate(tappedButton: .move) - completion() } }