From 0cadae99a4290b2e0ed353bbe526de04e2e4d91f Mon Sep 17 00:00:00 2001 From: kim-seonwoo Date: Fri, 19 Jan 2024 00:20:06 +0900 Subject: [PATCH] =?UTF-8?q?[Fix/#108]=20Challenge=20-=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20=EC=8B=9C=20alert=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HMH_iOS/Global/Protocols/AlertDelegate.swift | 1 + .../ViewControllers/ChallengeViewController.swift | 15 ++++++++++++--- .../Challenge/Views/ChallengeView.swift | 9 +++++++-- .../Common/CustomAlert/AlertViewController.swift | 10 +++++++++- .../Common/CustomAlert/HMHDeleteAlert.swift | 8 ++++---- 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/HMH_iOS/HMH_iOS/Global/Protocols/AlertDelegate.swift b/HMH_iOS/HMH_iOS/Global/Protocols/AlertDelegate.swift index 2dfce1f..3b89369 100644 --- a/HMH_iOS/HMH_iOS/Global/Protocols/AlertDelegate.swift +++ b/HMH_iOS/HMH_iOS/Global/Protocols/AlertDelegate.swift @@ -11,4 +11,5 @@ protocol AlertDelegate: AnyObject { func enabledButtonTapped() func alertDismissTapped() func confirmButtonTapped() + func deleteButtonTapped() } diff --git a/HMH_iOS/HMH_iOS/Presentation/Challenge/ViewControllers/ChallengeViewController.swift b/HMH_iOS/HMH_iOS/Presentation/Challenge/ViewControllers/ChallengeViewController.swift index 764302c..e38803e 100644 --- a/HMH_iOS/HMH_iOS/Presentation/Challenge/ViewControllers/ChallengeViewController.swift +++ b/HMH_iOS/HMH_iOS/Presentation/Challenge/ViewControllers/ChallengeViewController.swift @@ -11,8 +11,8 @@ import SnapKit import Then final class ChallengeViewController: UIViewController { - var isCreatedChallenge = false + var decodedIndex: Int = 0 func updateChallengeStatus(isCreatedChallenge: Bool) { self.isCreatedChallenge = isCreatedChallenge configureTabBar(isCreatedChallenge: isCreatedChallenge) @@ -27,7 +27,7 @@ final class ChallengeViewController: UIViewController { let challengeView = ChallengeView(frame: .zero, appAddButtonViewModel: BlockingApplicationModel.shared) - private var selectedIndex = IndexPath() + var selectedIndex = IndexPath() override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) @@ -79,6 +79,10 @@ final class ChallengeViewController: UIViewController { let nextViewController = CreatePeriodController() self.navigationController?.pushViewController(nextViewController, animated: false) } + + func deleteTap() { + challengeView.deleteCell() + } } @@ -93,6 +97,8 @@ extension ChallengeViewController: UICollectionViewDelegate { } func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + self.decodedIndex = indexPath.item + print(decodedIndex) if selectedIndex == [] { selectedIndex = [1,0] } @@ -102,14 +108,17 @@ extension ChallengeViewController: UICollectionViewDelegate { } if let currentSelectedCell = collectionView.cellForItem(at: indexPath) as? AppListCollectionViewCell { currentSelectedCell.isSelectedCell = true + self.selectedIndex = indexPath let alertController = AlertViewController() alertController.setAlertType(.delete) alertController.modalPresentationStyle = .overFullScreen self.present(alertController, animated: false, completion: nil) } - } } + } + + diff --git a/HMH_iOS/HMH_iOS/Presentation/Challenge/Views/ChallengeView.swift b/HMH_iOS/HMH_iOS/Presentation/Challenge/Views/ChallengeView.swift index 720557c..e4a5a57 100644 --- a/HMH_iOS/HMH_iOS/Presentation/Challenge/Views/ChallengeView.swift +++ b/HMH_iOS/HMH_iOS/Presentation/Challenge/Views/ChallengeView.swift @@ -14,14 +14,13 @@ import Then import FamilyControls final class ChallengeView: UIView { - private var appAddButtonViewModel: BlockingApplicationModel = BlockingApplicationModel.shared private var cancellables: Set = [] var isChallengeComplete: Bool = true private let goalTime: Int = 3 private var days: Int = 7 - private var appList: [AppModel] = [AppModel(appIcon: "", appName: "Instagram", appUseTime: "1시간 20분"), + var appList: [AppModel] = [AppModel(appIcon: "", appName: "Instagram", appUseTime: "1시간 20분"), AppModel(appIcon: "", appName: "Youtube", appUseTime: "1시간")] var isDeleteMode: Bool = false { didSet { @@ -95,6 +94,11 @@ final class ChallengeView: UIView { @objc private func deleteButtonTapped() { isDeleteMode.toggle() } + + func deleteCell() { + print("tap") + } + } extension ChallengeView: UICollectionViewDataSource { @@ -273,3 +277,4 @@ extension ChallengeView { return nil } } + diff --git a/HMH_iOS/HMH_iOS/Presentation/Common/CustomAlert/AlertViewController.swift b/HMH_iOS/HMH_iOS/Presentation/Common/CustomAlert/AlertViewController.swift index 44ac173..a438699 100644 --- a/HMH_iOS/HMH_iOS/Presentation/Common/CustomAlert/AlertViewController.swift +++ b/HMH_iOS/HMH_iOS/Presentation/Common/CustomAlert/AlertViewController.swift @@ -120,6 +120,13 @@ final class AlertViewController: UIViewController { } extension AlertViewController: AlertDelegate { + func deleteButtonTapped() { + let challengeController = ChallengeViewController() + challengeController.deleteTap() + dismiss(animated: false) { + (self.okAction ?? self.emptyActions)() + } + } func confirmButtonTapped() { setRootViewController(TabBarController()) } @@ -139,7 +146,7 @@ extension AlertViewController: AlertDelegate { UserManager.shared.clearAll() } } - + dismiss(animated: false) { let loginViewController = LoginViewController() if let window = UIApplication.shared.windows.first { @@ -157,3 +164,4 @@ extension AlertViewController: AlertDelegate { } } } + diff --git a/HMH_iOS/HMH_iOS/Presentation/Common/CustomAlert/HMHDeleteAlert.swift b/HMH_iOS/HMH_iOS/Presentation/Common/CustomAlert/HMHDeleteAlert.swift index 79eaab9..a0620c2 100644 --- a/HMH_iOS/HMH_iOS/Presentation/Common/CustomAlert/HMHDeleteAlert.swift +++ b/HMH_iOS/HMH_iOS/Presentation/Common/CustomAlert/HMHDeleteAlert.swift @@ -79,8 +79,8 @@ final class HMHDeleteAlert: UIView { } private func setAddTarget() { - cancelButton.addTarget(self, action: #selector(cancelButtonTapped), for: .touchUpInside) - confirmButton.addTarget(self, action: #selector(confirmButtonTapped), for: .touchUpInside) + cancelButton.addTarget(self, action: #selector(deleteButtonTapped), for: .touchUpInside) + confirmButton.addTarget(self, action: #selector(cancelButtonTapped), for: .touchUpInside) } private func configureView() { @@ -98,8 +98,8 @@ final class HMHDeleteAlert: UIView { delegate?.alertDismissTapped() } - @objc func confirmButtonTapped() { - delegate?.alertDismissTapped() + @objc func deleteButtonTapped() { + delegate?.deleteButtonTapped() } }