From ac189ea964a193ba1a00416b8a2b803385951c5b Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Tue, 14 Mar 2023 20:56:47 +0900 Subject: [PATCH 01/25] chore: update lint (#380) --- .swiftlint.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.swiftlint.yml b/.swiftlint.yml index ffd35e67..f88838ed 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -6,6 +6,7 @@ disabled_rules: - function_body_length - cyclomatic_complexity - force_cast +- type_body_length excluded: - Pods - NADA-iOS-forRelease/Sources/AppDelegate.swift From cf867f6e9821d77b7148f2c8bfe69ac157cfeccc Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Tue, 14 Mar 2023 21:06:03 +0900 Subject: [PATCH 02/25] feat: init timeLabel (#380) --- .../CardShareBottomSheetViewController.swift | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift index e5c059e8..f0510c87 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift @@ -55,6 +55,16 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { return label }() + private let nearByTimeLabel: UILabel = { + let label = UILabel() + label.font = .button02 + label.textColor = .mainColorNadaMain + label.text = "10:00" + label.sizeToFit() + + return label + }() + lazy private var nearBySwitch: UISwitch = { let nearBySwitch = UISwitch() @@ -139,7 +149,7 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { cardBackgroundView.addSubviews([nadaLogoImage, qrImage, idStackView, saveAsImageButton]) - nearByBackgroundView.addSubviews([nearByImage, nearByLabel, nearBySwitch, lottieImage]) + nearByBackgroundView.addSubviews([nearByImage, nearByLabel, nearByTimeLabel, nearBySwitch, lottieImage]) idLabel.text = cardDataModel?.cardID ?? "" @@ -156,6 +166,7 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { nearByLabel.text = isActivate ? "내 근처의 명함 ON" : "내 근처의 명함 OFF" nearByLabel.textColor = isActivate ? .mainColorNadaMain : .tertiary + nearByTimeLabel.isHidden = !isActivate nearBySwitch.setOn(isActivate, animated: false) @@ -220,7 +231,7 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { nearByLabel.centerYAnchor.constraint(equalTo: nearByBackgroundView.centerYAnchor), nearByLabel.leadingAnchor.constraint(equalTo: nearByImage.trailingAnchor) ]) - + nearBySwitch.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ nearBySwitch.centerYAnchor.constraint(equalTo: nearByBackgroundView.centerYAnchor), @@ -229,6 +240,12 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { nearBySwitch.widthAnchor.constraint(equalToConstant: 51.0) ]) + nearByTimeLabel.translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint.activate([ + nearByTimeLabel.centerYAnchor.constraint(equalTo: nearByBackgroundView.centerYAnchor), + nearByTimeLabel.trailingAnchor.constraint(equalTo: nearBySwitch.leadingAnchor, constant: -5.0) + ]) + lottieImage.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ lottieImage.centerXAnchor.constraint(equalTo: nearByImage.centerXAnchor), From 80a4ccdb911253ae063df85e4a2a87f0d307e5b3 Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Tue, 14 Mar 2023 21:15:00 +0900 Subject: [PATCH 03/25] feat: timer countdown (#380) --- .../CardShareBottomSheetViewController.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift index f0510c87..5753d761 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift @@ -18,6 +18,8 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { public var isShareable = false public var cardDataModel: Card? public var isActivate: Bool? + private weak var timer: Timer? + private var seconds = 0 private let cardBackgroundView: UIView = { let view = UIView() @@ -172,6 +174,13 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { lottieImage.isHidden = isActivate ? false : true _ = isActivate ? lottieImage.play() : lottieImage.stop() + + if isActivate { + timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(processTimer), userInfo: nil, repeats: true) + } else { + timer?.invalidate() + seconds = 0 + } } private func setupLayout() { @@ -382,4 +391,10 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { @objc func touchSwitch(_ sender: UISwitch) { setCardActivationUI(with: sender.isOn) } + + @objc + func processTimer() { + seconds += 1 + print(seconds) + } } From 365690873d41f9543c978b79a63bd9791542daa1 Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Tue, 14 Mar 2023 21:22:40 +0900 Subject: [PATCH 04/25] =?UTF-8?q?feat:=20label=20countdown=20=EB=B0=98?= =?UTF-8?q?=EC=98=81=20(#380)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .swiftlint.yml | 1 + NADA-iOS-forRelease.xcodeproj/project.pbxproj | 4 ++++ .../Resouces/Utils/calculateTime.swift | 21 +++++++++++++++++++ .../CardShareBottomSheetViewController.swift | 3 ++- 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 NADA-iOS-forRelease/Resouces/Utils/calculateTime.swift diff --git a/.swiftlint.yml b/.swiftlint.yml index f88838ed..01450ae1 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -7,6 +7,7 @@ disabled_rules: - cyclomatic_complexity - force_cast - type_body_length +- file_length excluded: - Pods - NADA-iOS-forRelease/Sources/AppDelegate.swift diff --git a/NADA-iOS-forRelease.xcodeproj/project.pbxproj b/NADA-iOS-forRelease.xcodeproj/project.pbxproj index d1234fa3..ba7061a9 100644 --- a/NADA-iOS-forRelease.xcodeproj/project.pbxproj +++ b/NADA-iOS-forRelease.xcodeproj/project.pbxproj @@ -99,6 +99,7 @@ 77A4D60429BD743600367B7C /* ModuleFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A4D60329BD743600367B7C /* ModuleFactory.swift */; }; 77A4D60629BD747300367B7C /* controllerFromStoryBoard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A4D60529BD747300367B7C /* controllerFromStoryBoard.swift */; }; 77A4D60829BD74BC00367B7C /* getClassName.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A4D60729BD74BC00367B7C /* getClassName.swift */; }; + 77A4D60A29C09D2900367B7C /* calculateTime.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A4D60929C09D2900367B7C /* calculateTime.swift */; }; 77AA68EA273E0EC4009C89B0 /* CardAddInGroupRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77AA68E9273E0EC4009C89B0 /* CardAddInGroupRequest.swift */; }; 77B4E7482990E420006098DC /* Home.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 77B4E7472990E420006098DC /* Home.storyboard */; }; 77B4E74B2990E50E006098DC /* HomeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B4E74A2990E50E006098DC /* HomeViewController.swift */; }; @@ -329,6 +330,7 @@ 77A4D60329BD743600367B7C /* ModuleFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModuleFactory.swift; sourceTree = ""; }; 77A4D60529BD747300367B7C /* controllerFromStoryBoard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = controllerFromStoryBoard.swift; sourceTree = ""; }; 77A4D60729BD74BC00367B7C /* getClassName.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = getClassName.swift; sourceTree = ""; }; + 77A4D60929C09D2900367B7C /* calculateTime.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = calculateTime.swift; sourceTree = ""; }; 77AA68E9273E0EC4009C89B0 /* CardAddInGroupRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardAddInGroupRequest.swift; sourceTree = ""; }; 77B4E7422990E00B006098DC /* Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; 77B4E7432990E015006098DC /* Beta.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Beta.xcconfig; sourceTree = ""; }; @@ -753,6 +755,7 @@ children = ( 77A4D5EA29AE20CB00367B7C /* makeVibrate.swift */, 77A4D60729BD74BC00367B7C /* getClassName.swift */, + 77A4D60929C09D2900367B7C /* calculateTime.swift */, ); path = Utils; sourceTree = ""; @@ -1636,6 +1639,7 @@ 7713E8482752E2A900724C8B /* SelectGroupBottomSheetViewController.swift in Sources */, 39007F2C27080D8200E7143E /* UIViewController+Extension.swift in Sources */, F8C83FB6272F9E380009DF0D /* UtilService.swift in Sources */, + 77A4D60A29C09D2900367B7C /* calculateTime.swift in Sources */, 3958F239270FFBBF00B100B2 /* GroupViewController.swift in Sources */, 3909242F26FA15E800236C51 /* UIView+Extension.swift in Sources */, 39523E09270184A700536900 /* CardListViewController.swift in Sources */, diff --git a/NADA-iOS-forRelease/Resouces/Utils/calculateTime.swift b/NADA-iOS-forRelease/Resouces/Utils/calculateTime.swift new file mode 100644 index 00000000..4b2fc1be --- /dev/null +++ b/NADA-iOS-forRelease/Resouces/Utils/calculateTime.swift @@ -0,0 +1,21 @@ +// +// calculateTime.swift +// NADA-iOS-forRelease +// +// Created by Yi Joon Choi on 2023/03/14. +// + +import Foundation + +func calculateTime(sec: Int) -> String { + let hour = sec / 3600 + let minute = (sec % 3600) / 60 + let second = (sec % 3600) % 60 + return "\(String(format: "%02d", hour)):\(String(format: "%02d", minute)):\(String(format: "%02d", second))" +} + +func calculateMinuteTime(sec: Int) -> String { + let minute = (sec % 3600) / 60 + let second = (sec % 3600) % 60 + return "\(String(format: "%02d", minute)):\(String(format: "%02d", second))" +} diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift index 5753d761..808427ac 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift @@ -180,6 +180,7 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { } else { timer?.invalidate() seconds = 0 + nearByTimeLabel.text = "10:00" } } @@ -395,6 +396,6 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { @objc func processTimer() { seconds += 1 - print(seconds) + nearByTimeLabel.text = calculateMinuteTime(sec: 600 - seconds) } } From c5bedd45e13a63b5b8b346e9f8af6a3b70fa4567 Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Tue, 28 Mar 2023 21:04:16 +0900 Subject: [PATCH 05/25] =?UTF-8?q?feat:=20background=EC=97=90=EC=84=9C=20fo?= =?UTF-8?q?reground=20=EA=B0=90=EC=A7=80=20(#380)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .swiftlint.yml | 1 + .../Resouces/Utils/calculateTime.swift | 9 ++++++ .../CardShareBottomSheetViewController.swift | 31 +++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/.swiftlint.yml b/.swiftlint.yml index 01450ae1..6f77d5bc 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -8,6 +8,7 @@ disabled_rules: - force_cast - type_body_length - file_length +- identifier_name excluded: - Pods - NADA-iOS-forRelease/Sources/AppDelegate.swift diff --git a/NADA-iOS-forRelease/Resouces/Utils/calculateTime.swift b/NADA-iOS-forRelease/Resouces/Utils/calculateTime.swift index 4b2fc1be..f2bb8599 100644 --- a/NADA-iOS-forRelease/Resouces/Utils/calculateTime.swift +++ b/NADA-iOS-forRelease/Resouces/Utils/calculateTime.swift @@ -19,3 +19,12 @@ func calculateMinuteTime(sec: Int) -> String { let second = (sec % 3600) % 60 return "\(String(format: "%02d", minute)):\(String(format: "%02d", second))" } + +func calculateMinuteTimeToInt(time: String) -> Int { + let components = time.split { $0 == ":" } .map { (x) -> Int in return Int(String(x))! } + + let minutes = components[0] + let seconds = components[1] + let secondsCaculated = minutes*60 + seconds + return secondsCaculated +} diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift index 808427ac..186a1260 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift @@ -20,6 +20,8 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { public var isActivate: Bool? private weak var timer: Timer? private var seconds = 0 + private var savedTime = "" + private var appDidEnterBackgroundDate: Date? private let cardBackgroundView: UIView = { let view = UIView() @@ -140,6 +142,10 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { setupUI() } + override func viewWillAppear(_ animated: Bool) { + setNotification() + } + // MARK: - @Functions private func setupUI() { @@ -184,6 +190,31 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { } } + func setNotification() { + NotificationCenter.default.addObserver(self, selector: #selector(applicationDidEnterBackground(_:)), name: UIApplication.didEnterBackgroundNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(applicationWillEnterForeground(_:)), name: UIApplication.willEnterForegroundNotification, object: nil) + } + + @objc func applicationDidEnterBackground(_ notification: NotificationCenter) { + appDidEnterBackgroundDate = Date() + savedTime = nearByTimeLabel.text ?? "00:00" + print(savedTime) + } + + @objc func applicationWillEnterForeground(_ notification: NotificationCenter) { + guard let previousDate = appDidEnterBackgroundDate else { return } + let calendar = Calendar.current + let difference = calendar.dateComponents([.second], from: previousDate, to: Date()) + let seconds = difference.second! + print(savedTime) + print(calculateMinuteTime(sec: calculateMinuteTimeToInt(time: savedTime) - seconds)) + print(seconds) + DispatchQueue.main.async { + self.nearByTimeLabel.text = calculateMinuteTime(sec: calculateMinuteTimeToInt(time: self.savedTime) - seconds) + } + print(nearByTimeLabel.text) + } + private func setupLayout() { cardBackgroundView.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ From 1af6491a972e9701cec73eab21e4aecfa062e6ac Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Wed, 29 Mar 2023 18:44:18 +0900 Subject: [PATCH 06/25] =?UTF-8?q?chore:=20=EC=95=9E=EC=97=90=20=EB=9D=84?= =?UTF-8?q?=EC=96=B4=EC=93=B0=EA=B8=B0=20=EC=88=98=EC=A0=95=20(#380)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NADA-iOS-forRelease/Resouces/Utils/makeVibrate.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NADA-iOS-forRelease/Resouces/Utils/makeVibrate.swift b/NADA-iOS-forRelease/Resouces/Utils/makeVibrate.swift index d26128e9..c7b94bf7 100644 --- a/NADA-iOS-forRelease/Resouces/Utils/makeVibrate.swift +++ b/NADA-iOS-forRelease/Resouces/Utils/makeVibrate.swift @@ -9,7 +9,7 @@ import Foundation import UIKit extension UIViewController { - public func makeVibrate(degree: UIImpactFeedbackGenerator.FeedbackStyle = .medium) { + public func makeVibrate(degree: UIImpactFeedbackGenerator.FeedbackStyle = .medium) { let generator = UIImpactFeedbackGenerator(style: degree) generator.impactOccurred() } From 6ad04e8c2d7bb367dd65be9a0d76b80aee497444 Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Wed, 29 Mar 2023 18:56:03 +0900 Subject: [PATCH 07/25] =?UTF-8?q?chore:=20import=20=EC=88=9C=EC=84=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20(#380)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewControllers/AroundMe/VC/AroundMeViewController.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift index 2bfd9871..1dc5ef02 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift @@ -5,13 +5,14 @@ // Created by Yi Joon Choi on 2023/02/28. // +import UIKit + import RxSwift import RxRelay import RxCocoa import RxGesture import SnapKit import Then -import UIKit final class AroundMeViewController: UIViewController { From 6990b7c505fb35905010e37c2a9d22595c8d1b6d Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Wed, 29 Mar 2023 19:14:20 +0900 Subject: [PATCH 08/25] =?UTF-8?q?feat:=20dividerline=20=EB=B0=98=EC=98=81?= =?UTF-8?q?=20(#380)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AroundMe/View/AroundMeCollectionViewCell.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift index 150b2bd3..5df80993 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift @@ -32,6 +32,7 @@ class AroundMeCollectionViewCell: UICollectionViewCell { } private var cardNameLabel = UILabel().then { + $0.textColor = .tertiary $0.font = .textBold02 } @@ -88,8 +89,10 @@ class AroundMeCollectionViewCell: UICollectionViewCell { make.leading.equalToSuperview().inset(20) } dividerLine.snp.makeConstraints { make in + make.centerX.equalToSuperview() + make.leading.equalToSuperview() make.bottom.equalTo(cardNameLabel.snp.top).offset(-11) - make.height.equalTo(0.5) + make.height.equalTo(1) } } } From 11ed94584caae467bbe117a1765c8cae1a458088 Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Wed, 29 Mar 2023 19:16:15 +0900 Subject: [PATCH 09/25] =?UTF-8?q?feat:=20setlayout()=20=EB=B0=98=EC=98=81?= =?UTF-8?q?=20(#380)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Views/CustomNavigationBar/CustomNavigationBar.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/NADA-iOS-forRelease/Sources/Views/CustomNavigationBar/CustomNavigationBar.swift b/NADA-iOS-forRelease/Sources/Views/CustomNavigationBar/CustomNavigationBar.swift index 072f8570..0f248605 100644 --- a/NADA-iOS-forRelease/Sources/Views/CustomNavigationBar/CustomNavigationBar.swift +++ b/NADA-iOS-forRelease/Sources/Views/CustomNavigationBar/CustomNavigationBar.swift @@ -51,6 +51,7 @@ class CustomNavigationBar: UIView { required init?(coder: NSCoder) { super.init(coder: coder) + setLayout() } // MARK: - UI & Layout From 8be6d9c9f19b646c12f1c3acb662ee34b12817b2 Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Wed, 29 Mar 2023 19:19:35 +0900 Subject: [PATCH 10/25] =?UTF-8?q?feat:=20=EA=B0=84=EA=B2=A9=20=EC=A1=B0?= =?UTF-8?q?=EC=A0=95=20(#380)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewControllers/AroundMe/VC/AroundMeViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift index 1dc5ef02..2e9a7b5c 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift @@ -38,7 +38,7 @@ final class AroundMeViewController: UIViewController { $0.textAlignment = .center } private let emptyStackView = UIStackView().then { - $0.spacing = 9 + $0.spacing = 10 $0.axis = .vertical $0.alignment = .center } From 45f1b661dca3a7e3df5f9aff101240b6ed0cb8a3 Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Sat, 1 Apr 2023 12:14:38 +0900 Subject: [PATCH 11/25] =?UTF-8?q?feat:=20rxbinding=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?(#380)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewControllers/AroundMe/VC/AroundMeViewController.swift | 4 ++-- .../Views/CustomNavigationBar/CustomNavigationBar.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift index 2e9a7b5c..131322bc 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift @@ -112,8 +112,8 @@ extension AroundMeViewController { private func bindViewModels() { let input = AroundMeViewModel.Input( - viewDidLoadEvent: self.rx.methodInvoked(#selector(UIViewController.viewWillAppear)).map { _ in }, - refreshButtonTapEvent: self.rx.methodInvoked(#selector(UIViewController.viewWillAppear)).map { _ in }) + viewDidLoadEvent: self.rx.methodInvoked(#selector(UIViewController.viewDidLoad)).map { _ in }, + refreshButtonTapEvent: self.navigationBar.rightButton.rx.tap.map { _ in }) // let output = self.viewModel.transform(from: input, disposeBag: self.disposeBag) //TODO: 서버 연결 뒤 rx binding diff --git a/NADA-iOS-forRelease/Sources/Views/CustomNavigationBar/CustomNavigationBar.swift b/NADA-iOS-forRelease/Sources/Views/CustomNavigationBar/CustomNavigationBar.swift index 0f248605..0e0bcee5 100644 --- a/NADA-iOS-forRelease/Sources/Views/CustomNavigationBar/CustomNavigationBar.swift +++ b/NADA-iOS-forRelease/Sources/Views/CustomNavigationBar/CustomNavigationBar.swift @@ -38,7 +38,7 @@ class CustomNavigationBar: UIView { private lazy var leftButton = UIButton().then { $0.addTarget(self, action: #selector(touchLeftButton(_:)), for: .touchUpInside) } - private lazy var rightButton = UIButton().then { + lazy var rightButton = UIButton().then { $0.addTarget(self, action: #selector(touchRightButton(_:)), for: .touchUpInside) } From e958dc7a4812288dbcba7d075d7cc87bbd7f8fe9 Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Sun, 2 Apr 2023 17:40:43 +0900 Subject: [PATCH 12/25] =?UTF-8?q?refactor:=20force-cast=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81=20(#380)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .swiftlint.yml | 1 - .../Sources/Factory/controllerFromStoryBoard.swift | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 6f77d5bc..b751133e 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -5,7 +5,6 @@ disabled_rules: - function_parameter_count - function_body_length - cyclomatic_complexity -- force_cast - type_body_length - file_length - identifier_name diff --git a/NADA-iOS-forRelease/Sources/Factory/controllerFromStoryBoard.swift b/NADA-iOS-forRelease/Sources/Factory/controllerFromStoryBoard.swift index 9c851992..4fbcfc0a 100644 --- a/NADA-iOS-forRelease/Sources/Factory/controllerFromStoryBoard.swift +++ b/NADA-iOS-forRelease/Sources/Factory/controllerFromStoryBoard.swift @@ -25,7 +25,8 @@ import UIKit extension UIViewController { private class func instantiateControllerInStoryboard(_ storyboard: UIStoryboard, identifier: String) -> T { - return storyboard.instantiateViewController(withIdentifier: identifier) as! T + guard let viewcontroller = storyboard.instantiateViewController(withIdentifier: identifier) as? T else { return T() } + return viewcontroller } class func controllerInStoryboard(_ storyboard: UIStoryboard, identifier: String) -> Self { From c2d463fd584dd60f3980e9295bce9133c212f21e Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Tue, 11 Apr 2023 14:56:05 +0900 Subject: [PATCH 13/25] =?UTF-8?q?refactor:=20import=20=EC=88=9C=EC=84=9C?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD=20(#380)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/ViewControllers/Home/VC/HomeViewController.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/Home/VC/HomeViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/Home/VC/HomeViewController.swift index dbd58e77..b82a87e7 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/Home/VC/HomeViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/Home/VC/HomeViewController.swift @@ -5,13 +5,14 @@ // Created by Yi Joon Choi on 2023/02/06. // +import UIKit + import RxSwift import RxRelay import RxCocoa import RxGesture import SnapKit import Then -import UIKit final class HomeViewController: UIViewController { From 27f6a427c8e9d521a188672ccc5937e3e3ccaf5f Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Mon, 24 Apr 2023 16:30:47 +0900 Subject: [PATCH 14/25] add: add Nearby API, Service (#427) --- NADA-iOS-forRelease.xcodeproj/project.pbxproj | 16 ++++++ .../NetworkService/Nearby/NearbyAPI.swift | 51 +++++++++++++++++++ .../NetworkService/Nearby/NearbyService.swift | 51 +++++++++++++++++++ .../AroundMe/VC/AroundMeViewController.swift | 36 ++++++++++++- 4 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyAPI.swift create mode 100644 NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyService.swift diff --git a/NADA-iOS-forRelease.xcodeproj/project.pbxproj b/NADA-iOS-forRelease.xcodeproj/project.pbxproj index ed0782d3..58a92f0d 100644 --- a/NADA-iOS-forRelease.xcodeproj/project.pbxproj +++ b/NADA-iOS-forRelease.xcodeproj/project.pbxproj @@ -87,6 +87,8 @@ 777FF89F27364B7B00BF69D3 /* GroupEditRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777FF89E27364B7B00BF69D3 /* GroupEditRequest.swift */; }; 77812947275F6EA3004B34F4 /* CardDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77812946275F6EA3004B34F4 /* CardDetailViewController.swift */; }; 7781294A275F6ED7004B34F4 /* CardDetail.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 77812949275F6ED7004B34F4 /* CardDetail.storyboard */; }; + 77A196C729F661DC000DEF49 /* NearbyAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A196C629F661DC000DEF49 /* NearbyAPI.swift */; }; + 77A196C929F661E3000DEF49 /* NearbyService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A196C829F661E3000DEF49 /* NearbyService.swift */; }; 77A4D5EB29AE20CB00367B7C /* makeVibrate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A4D5EA29AE20CB00367B7C /* makeVibrate.swift */; }; 77A4D5EF29AE269B00367B7C /* AroundMeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A4D5EE29AE269B00367B7C /* AroundMeViewController.swift */; }; 77A4D5F429AE291F00367B7C /* CustomNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A4D5F329AE291F00367B7C /* CustomNavigationBar.swift */; }; @@ -322,6 +324,8 @@ 777FF89E27364B7B00BF69D3 /* GroupEditRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupEditRequest.swift; sourceTree = ""; }; 77812946275F6EA3004B34F4 /* CardDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardDetailViewController.swift; sourceTree = ""; }; 77812949275F6ED7004B34F4 /* CardDetail.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = CardDetail.storyboard; sourceTree = ""; }; + 77A196C629F661DC000DEF49 /* NearbyAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NearbyAPI.swift; sourceTree = ""; }; + 77A196C829F661E3000DEF49 /* NearbyService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NearbyService.swift; sourceTree = ""; }; 77A4D5EA29AE20CB00367B7C /* makeVibrate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = makeVibrate.swift; sourceTree = ""; }; 77A4D5EE29AE269B00367B7C /* AroundMeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AroundMeViewController.swift; sourceTree = ""; }; 77A4D5F329AE291F00367B7C /* CustomNavigationBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomNavigationBar.swift; sourceTree = ""; }; @@ -763,6 +767,15 @@ path = CardDetail; sourceTree = ""; }; + 77A196C529F661C4000DEF49 /* Nearby */ = { + isa = PBXGroup; + children = ( + 77A196C629F661DC000DEF49 /* NearbyAPI.swift */, + 77A196C829F661E3000DEF49 /* NearbyService.swift */, + ); + path = Nearby; + sourceTree = ""; + }; 77A4D5E929AE20A600367B7C /* Utils */ = { isa = PBXGroup; children = ( @@ -1274,6 +1287,7 @@ F8C83FB0272F9CB10009DF0D /* Card */, F8C83FB3272F9CF30009DF0D /* Group */, F8C83FB4272F9E250009DF0D /* Util */, + 77A196C529F661C4000DEF49 /* Nearby */, F8F00C3C29DD487E00A15377 /* Update */, ); path = NetworkService; @@ -1685,6 +1699,7 @@ F8C83FCB272FA32C0009DF0D /* GroupService.swift in Sources */, F88C8DE929B8919700196A33 /* ViewModelType.swift in Sources */, F858079E2700354E00872484 /* BackgroundCollectionViewCell.swift in Sources */, + 77A196C929F661E3000DEF49 /* NearbyService.swift in Sources */, F8C83FBD272F9F430009DF0D /* GenericResponse.swift in Sources */, 77A4D5F629BC304C00367B7C /* UIStackView+Extension.swift in Sources */, F835EF6F29800F51001ABAAF /* UIApplication+Extension.swift in Sources */, @@ -1790,6 +1805,7 @@ F8915A23275728F20013D609 /* SelectMBTIBottomViewController.swift in Sources */, 393E3345275F69EE00965BBF /* SplashViewController.swift in Sources */, F8C83FB8272F9E3F0009DF0D /* UtilAPI.swift in Sources */, + 77A196C729F661DC000DEF49 /* NearbyAPI.swift in Sources */, F8FC438826C01CDD0033E151 /* SceneDelegate.swift in Sources */, 77A4D5F929BC320600367B7C /* AroundMeCollectionViewCell.swift in Sources */, 39C394D4277CD33500DBA566 /* EmptyCardListTableViewCell.swift in Sources */, diff --git a/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyAPI.swift b/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyAPI.swift new file mode 100644 index 00000000..1a39c6a7 --- /dev/null +++ b/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyAPI.swift @@ -0,0 +1,51 @@ +// +// NearbyAPI.swift +// NADA-iOS-forRelease +// +// Created by Yi Joon Choi on 2023/04/24. +// + +import Foundation +import Moya + +public final class NearbyAPI { + static let shared = NearbyAPI() + private var nearbyProvider = MoyaProvider(plugins: [MoyaLoggerPlugin()]) + + private init() { } + + func cardNearByFetch(longitde: Double, latitude: Double, completion: @escaping(NetworkResult) -> Void) { + nearbyProvider.request(.cardNearByFetch(longitude: longitde, latitude: latitude)) { result in + switch result { + case .success(let response): + let statusCode = response.statusCode + let data = response.data + + // TODO: datamodel 만들어서 바꾸기 + let networkResult = self.judgeStatus(by: statusCode, data: data, type: UpdateNote.self) + completion(networkResult) + case .failure(let err): + print(err) + } + } + } + + // MARK: - judgeStatus methods + + private func judgeStatus(by statusCode: Int, data: Data, type: T.Type) -> NetworkResult { + let decoder = JSONDecoder() + guard let decodedData = try? decoder.decode(GenericResponse.self, from: data) + else { return .pathErr } + + switch statusCode { + case 200: + return .success(decodedData.data ?? "None-Data") + case 400..<500: + return .requestErr(decodedData.message ?? "error message") + case 500: + return .serverErr + default: + return .networkFail + } + } +} diff --git a/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyService.swift b/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyService.swift new file mode 100644 index 00000000..034e5af9 --- /dev/null +++ b/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyService.swift @@ -0,0 +1,51 @@ +// +// NearbyService.swift +// NADA-iOS-forRelease +// +// Created by Yi Joon Choi on 2023/04/24. +// + +import Foundation +import Moya + +enum NearbyService { + case cardNearByFetch(longitude: Double, latitude: Double) +} + +extension NearbyService: TargetType { + var baseURL: URL { + return URL(string: Const.URL.baseURL)! + } + + var authorizationType: AuthorizationType? { + return .bearer + } + + var path: String { + switch self { + case .cardNearByFetch(let longitude, let latitude): + return "/card/nearby/point/longitude/\(longitude)/latitude/\(latitude)" + } + } + + var method: Moya.Method { + switch self { + case .cardNearByFetch: + return .get + } + } + + var task: Moya.Task { + switch self { + case .cardNearByFetch: + return .requestPlain + } + } + + var headers: [String: String]? { + switch self { + case .cardNearByFetch: + return Const.Header.bearerHeader() + } + } +} diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift index 96132ca4..f2b6d678 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift @@ -4,6 +4,7 @@ // // Created by Yi Joon Choi on 2023/02/28. // +import UIKit import RxSwift import RxRelay @@ -11,7 +12,6 @@ import RxCocoa import RxGesture import SnapKit import Then -import UIKit final class AroundMeViewController: UIViewController { @@ -158,3 +158,37 @@ extension AroundMeViewController: UICollectionViewDataSource { return cardCell } } + +// MARK: - Network +/* +extension AroundMeViewController { + func cardNearByFetchWithAPI(longitude: Double, latitude: Double) { + NearbyAPI.shared.cardNearByFetch(longitde: longitude, latitude: latitude) { response in + switch response { + case .success(let data): + if let group = data as? [Group] { + self.serverGroups = group + self.groupCollectionView.reloadData() + self.groupId = group[self.selectedRow].cardGroupId + print("✅", self.groupId) + self.cardListInGroupWithAPI(cardListInGroupRequest: CardListInGroupRequest(cardGroupId: self.groupId ?? 0, pageNo: 1, pageSize: 1)) { + if self.frontCards?.count != 0 { + self.cardsCollectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .top, animated: false) + } + self.isInfiniteScroll = true + } + } + print("groupListFetchWithAPI - success") + case .requestErr(let message): + print("groupListFetchWithAPI - requestErr: \(message)") + case .pathErr: + print("groupListFetchWithAPI - pathErr") + case .serverErr: + print("groupListFetchWithAPI - serverErr") + case .networkFail: + print("groupListFetchWithAPI - networkFail") + } + } + } +} +*/ From e6f28e629731c4fcb66eded468b93f98aa754c92 Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Mon, 24 Apr 2023 17:11:20 +0900 Subject: [PATCH 15/25] feat: add cardNearBy API (#427) --- .../AroundMe/AroundMeResponse.swift | 5 +- .../AroundMe/VC/AroundMeViewController.swift | 80 ++++++++++--------- .../View/AroundMeCollectionViewCell.swift | 9 ++- .../ViewModel/AroundMeViewModel.swift | 47 ++++------- 4 files changed, 63 insertions(+), 78 deletions(-) diff --git a/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/AroundMeResponse.swift b/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/AroundMeResponse.swift index 2ea90a86..02eff5c7 100644 --- a/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/AroundMeResponse.swift +++ b/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/AroundMeResponse.swift @@ -8,7 +8,8 @@ import Foundation struct AroundMeResponse { - let profileImage: String - let myName: String let cardName: String + let cardUuid: String + let imageUrl: String + let name: String } diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift index f2b6d678..34d739b9 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift @@ -19,6 +19,7 @@ final class AroundMeViewController: UIViewController { var viewModel: AroundMeViewModel! private let disposeBag = DisposeBag() + var cardsNearBy: [AroundMeResponse]? = [] // MARK: - UI Components @@ -103,23 +104,47 @@ extension AroundMeViewController { // MARK: - Methods private func setDelegate() { - aroundMeCollectionView.dataSource = self -// aroundMeCollectionView.delegate = self + aroundMeCollectionView.rx.setDelegate(self) + .disposed(by: disposeBag) + + aroundMeCollectionView.rx.modelSelected(AroundMeResponse.self) + .subscribe { [weak self] model in + guard let self = self else { return } + if let game = model.element { +// let playVC = self.moduleFactory.makePlayVC(.replay, type: .disableControl, matchId: game.matchID) +// self.hidesBottomBarWhenPushed = true +// self.navigationController?.pushViewController(playVC, animated: true) + print("Clicked") + } + }.disposed(by: disposeBag) } private func setRegister() { aroundMeCollectionView.register(AroundMeCollectionViewCell.self, forCellWithReuseIdentifier: AroundMeCollectionViewCell.className) } + func setData(cardList: [AroundMeResponse]) { + self.cardsNearBy = cardList + self.aroundMeCollectionView.reloadData() + } + private func bindViewModels() { let input = AroundMeViewModel.Input( - viewDidLoadEvent: self.rx.methodInvoked(#selector(UIViewController.viewWillAppear)).map { _ in }, + viewWillAppearEvent: self.rx.methodInvoked(#selector(UIViewController.viewWillAppear)).map { _ in }, refreshButtonTapEvent: self.rx.methodInvoked(#selector(UIViewController.viewWillAppear)).map { _ in }) - // let output = self.viewModel.transform(from: input, disposeBag: self.disposeBag) + let output = self.viewModel.transform(input: input) - //TODO: 서버 연결 뒤 rx binding + output.cardList + .compactMap { $0 } + .withUnretained(self) + .subscribe { owner, list in + owner.setData(cardList: list) + }.disposed(by: self.disposeBag) - aroundMeCollectionView.rx.setDelegate(self) + output.cardList + .bind(to: aroundMeCollectionView.rx.items(cellIdentifier: AroundMeCollectionViewCell.className, cellType: AroundMeCollectionViewCell.self)) { _, model, cell in + cell.setData(model) + } .disposed(by: disposeBag) } } @@ -144,51 +169,28 @@ extension AroundMeViewController: UICollectionViewDelegateFlowLayout { } } -// MARK: - UICollectionViewDataSource - -extension AroundMeViewController: UICollectionViewDataSource { - func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return 6 - } - - func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let model = viewModel.dummyList - guard let cardCell = collectionView.dequeueReusableCell(withReuseIdentifier: AroundMeCollectionViewCell.className, for: indexPath) as? AroundMeCollectionViewCell else { return UICollectionViewCell()} - cardCell.setData(model[indexPath.row]) - return cardCell - } -} - // MARK: - Network -/* + extension AroundMeViewController { func cardNearByFetchWithAPI(longitude: Double, latitude: Double) { NearbyAPI.shared.cardNearByFetch(longitde: longitude, latitude: latitude) { response in switch response { case .success(let data): - if let group = data as? [Group] { - self.serverGroups = group - self.groupCollectionView.reloadData() - self.groupId = group[self.selectedRow].cardGroupId - print("✅", self.groupId) - self.cardListInGroupWithAPI(cardListInGroupRequest: CardListInGroupRequest(cardGroupId: self.groupId ?? 0, pageNo: 1, pageSize: 1)) { - if self.frontCards?.count != 0 { - self.cardsCollectionView.scrollToItem(at: IndexPath(item: 0, section: 0), at: .top, animated: false) - } - self.isInfiniteScroll = true - } + if let cards = data as? [AroundMeResponse] { + self.cardsNearBy = cards + print(cards) + self.aroundMeCollectionView.reloadData() } - print("groupListFetchWithAPI - success") + print("cardNearByFetchWithAPI - success") case .requestErr(let message): - print("groupListFetchWithAPI - requestErr: \(message)") + print("cardNearByFetchWithAPI - requestErr: \(message)") case .pathErr: - print("groupListFetchWithAPI - pathErr") + print("cardNearByFetchWithAPI - pathErr") case .serverErr: - print("groupListFetchWithAPI - serverErr") + print("cardNearByFetchWithAPI - serverErr") case .networkFail: - print("groupListFetchWithAPI - networkFail") + print("cardNearByFetchWithAPI - networkFail") } } } } -*/ diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift index 150b2bd3..a36a10c2 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift @@ -13,6 +13,8 @@ class AroundMeCollectionViewCell: UICollectionViewCell { // MARK: - Properties + var cardUUID: String = "" + // MARK: - UI Components private let plusButton = UIButton().then { @@ -53,12 +55,11 @@ class AroundMeCollectionViewCell: UICollectionViewCell { // MARK: - Methods - //TODO: 나중에 model 나오면 재정의 public func setData(_ model: AroundMeResponse) { -// profileImageView.updateServerImage(model.profileImage) - profileImageView.image = UIImage(named: model.profileImage) - myNameLabel.text = model.myName + profileImageView.updateServerImage(model.imageUrl) + myNameLabel.text = model.name cardNameLabel.text = model.cardName + cardUUID = model.cardUuid } // MARK: - UI & Layout diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/ViewModel/AroundMeViewModel.swift b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/ViewModel/AroundMeViewModel.swift index 4222f067..bd85a67a 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/ViewModel/AroundMeViewModel.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/ViewModel/AroundMeViewModel.swift @@ -12,32 +12,13 @@ final class AroundMeViewModel: ViewModelType { // MARK: - Properties -// private let useCase: StadiumUseCase - let dummyList = [AroundMeResponse(profileImage: "imgProfileSmall", - myName: "내 이름(닉네임)", - cardName: "명함 이름"), - AroundMeResponse(profileImage: "imgProfileSmall", - myName: "내 이름(닉네임)", - cardName: "명함 이름"), - AroundMeResponse(profileImage: "imgProfileSmall", - myName: "내 이름(닉네임)", - cardName: "명함 이름"), - AroundMeResponse(profileImage: "imgProfileSmall", - myName: "내 이름(닉네임)", - cardName: "명함 이름"), - AroundMeResponse(profileImage: "imgProfileSmall", - myName: "내 이름(닉네임)", - cardName: "명함 이름"), - AroundMeResponse(profileImage: "imgProfileSmall", - myName: "내 이름(닉네임)", - cardName: "명함 이름")] - + private var cardList: [AroundMeResponse] = [] private let disposeBag = DisposeBag() // MARK: - Inputs struct Input { - let viewDidLoadEvent: Observable + let viewWillAppearEvent: Observable let refreshButtonTapEvent: Observable } @@ -58,33 +39,33 @@ final class AroundMeViewModel: ViewModelType { extension AroundMeViewModel { func transform(input: Input) -> Output { let output = Output() - self.bindOutput(output: output, disposeBag: disposeBag) +// self.bindOutput(output: output, disposeBag: disposeBag) - input.viewDidLoadEvent + input.viewWillAppearEvent .withUnretained(self) .subscribe { owner, _ in // self.useCase.getStadiumList() + // get 서버통신 + output.cardList.accept(owner.cardList) }.disposed(by: self.disposeBag) input.refreshButtonTapEvent .withUnretained(self) .subscribe { owner, _ in // self.useCase.getStadiumList() + // get 서버통신 + + output.cardList.accept(owner.cardList) }.disposed(by: self.disposeBag) return output } - private func bindOutput(output: Output, disposeBag: DisposeBag) { -// let stadiumListRelay = useCase.stadiumList -// let ingStadiumRelay = useCase.ingStadium -// -// stadiumListRelay.subscribe { model in -// output.stadiumLists.accept(model) -// }.disposed(by: self.disposeBag) +// private func bindOutput(output: Output, disposeBag: DisposeBag) { +// let cardListRelay = useCase.stadiumList // -// ingStadiumRelay.subscribe { model in -// output.ingStadium.accept(model) +// cardListRelay.subscribe { model in +// output.cardList.accept(model) // }.disposed(by: self.disposeBag) - } +// } } From f358cb3e85e32532603bed3a9184fbf83aff6ce2 Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Mon, 24 Apr 2023 17:31:55 +0900 Subject: [PATCH 16/25] =?UTF-8?q?feat:=20cardNearBy=20API=20=EC=97=B0?= =?UTF-8?q?=EA=B2=B0=20(#427)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AroundMe/AroundMeResponse.swift | 15 ++++--- .../NetworkService/Nearby/NearbyAPI.swift | 3 +- .../AroundMe/VC/AroundMeViewController.swift | 42 +++++++++++++++++++ .../View/AroundMeCollectionViewCell.swift | 4 +- .../CardShareBottomSheetViewController.swift | 1 - 5 files changed, 55 insertions(+), 10 deletions(-) diff --git a/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/AroundMeResponse.swift b/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/AroundMeResponse.swift index 02eff5c7..e50c5470 100644 --- a/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/AroundMeResponse.swift +++ b/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/AroundMeResponse.swift @@ -7,9 +7,14 @@ import Foundation -struct AroundMeResponse { - let cardName: String - let cardUuid: String - let imageUrl: String - let name: String +struct AroundMeResponse: Codable { + let name, cardName: String + let imageURL: String + let cardUUID: String + + enum CodingKeys: String, CodingKey { + case name, cardName + case imageURL = "imageUrl" + case cardUUID = "cardUuid" + } } diff --git a/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyAPI.swift b/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyAPI.swift index 1a39c6a7..3285cb7d 100644 --- a/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyAPI.swift +++ b/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyAPI.swift @@ -21,8 +21,7 @@ public final class NearbyAPI { let statusCode = response.statusCode let data = response.data - // TODO: datamodel 만들어서 바꾸기 - let networkResult = self.judgeStatus(by: statusCode, data: data, type: UpdateNote.self) + let networkResult = self.judgeStatus(by: statusCode, data: data, type: [AroundMeResponse].self) completion(networkResult) case .failure(let err): print(err) diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift index 34d739b9..489a022c 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift @@ -5,6 +5,7 @@ // Created by Yi Joon Choi on 2023/02/28. // import UIKit +import CoreLocation import RxSwift import RxRelay @@ -20,6 +21,10 @@ final class AroundMeViewController: UIViewController { var viewModel: AroundMeViewModel! private let disposeBag = DisposeBag() var cardsNearBy: [AroundMeResponse]? = [] + var locationManager = CLLocationManager() + + private var latitude: CLLocationDegrees = 0 + private var longitude: CLLocationDegrees = 0 // MARK: - UI Components @@ -57,6 +62,7 @@ final class AroundMeViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() + setLocationManager() setUI() setLayout() setDelegate() @@ -103,6 +109,22 @@ extension AroundMeViewController { // MARK: - Methods + private func setLocationManager() { + locationManager.delegate = self + locationManager.desiredAccuracy = kCLLocationAccuracyBest + locationManager.requestWhenInUseAuthorization() + + DispatchQueue.global().async { + if CLLocationManager.locationServicesEnabled() { + print("location on") + self.locationManager.startUpdatingLocation() + print(self.locationManager.location?.coordinate) + } else { + print("location off") + } + } + } + private func setDelegate() { aroundMeCollectionView.rx.setDelegate(self) .disposed(by: disposeBag) @@ -169,6 +191,26 @@ extension AroundMeViewController: UICollectionViewDelegateFlowLayout { } } +// MARK: - CLLocationManagerDelegate + +extension AroundMeViewController: CLLocationManagerDelegate { + func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { + if let location = locations.first { + print("✅ 위도: ", location.coordinate.latitude) + print("✅ 경도: ", location.coordinate.longitude) + + latitude = location.coordinate.latitude + longitude = location.coordinate.longitude + + cardNearByFetchWithAPI(longitude: longitude, latitude: latitude) + } + } + + func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { + print(error) + } +} + // MARK: - Network extension AroundMeViewController { diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift index a36a10c2..7fe9c924 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift @@ -56,10 +56,10 @@ class AroundMeCollectionViewCell: UICollectionViewCell { // MARK: - Methods public func setData(_ model: AroundMeResponse) { - profileImageView.updateServerImage(model.imageUrl) + profileImageView.updateServerImage(model.imageURL) myNameLabel.text = model.name cardNameLabel.text = model.cardName - cardUUID = model.cardUuid + cardUUID = model.cardUUID } // MARK: - UI & Layout diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift index e9367b82..d621495d 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift @@ -405,7 +405,6 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { extension CardShareBottomSheetViewController: CLLocationManagerDelegate { func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { - print("Location Here") if let location = locations.first { print("✅ 위도: ", location.coordinate.latitude) print("✅ 경도: ", location.coordinate.longitude) From 1311abd684374bf984fe68b22c3961d79c1b24d2 Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Mon, 24 Apr 2023 19:40:56 +0900 Subject: [PATCH 17/25] feat: bind refreshAction (#427) --- .../AroundMe/VC/AroundMeViewController.swift | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift index 489a022c..ad27e14c 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift @@ -67,6 +67,7 @@ final class AroundMeViewController: UIViewController { setLayout() setDelegate() setRegister() + bindActions() bindViewModels() } @@ -150,6 +151,12 @@ extension AroundMeViewController { self.aroundMeCollectionView.reloadData() } + private func bindActions() { + navigationBar.rightButtonAction = { + self.cardNearByFetchWithAPI(longitude: self.longitude, latitude: self.latitude) + } + } + private func bindViewModels() { let input = AroundMeViewModel.Input( viewWillAppearEvent: self.rx.methodInvoked(#selector(UIViewController.viewWillAppear)).map { _ in }, @@ -157,11 +164,11 @@ extension AroundMeViewController { let output = self.viewModel.transform(input: input) output.cardList - .compactMap { $0 } - .withUnretained(self) - .subscribe { owner, list in - owner.setData(cardList: list) - }.disposed(by: self.disposeBag) + .compactMap { $0 } + .withUnretained(self) + .subscribe { owner, list in + owner.setData(cardList: list) + }.disposed(by: self.disposeBag) output.cardList .bind(to: aroundMeCollectionView.rx.items(cellIdentifier: AroundMeCollectionViewCell.className, cellType: AroundMeCollectionViewCell.self)) { _, model, cell in From bfab76f5264bef17b5dece29eedb15e6ec06cac8 Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Mon, 24 Apr 2023 19:47:48 +0900 Subject: [PATCH 18/25] feat: bind refreshAction (#427) --- .../AroundMe/VC/AroundMeViewController.swift | 15 ++++++++++----- .../AroundMe/ViewModel/AroundMeViewModel.swift | 9 --------- .../CustomNavigationBar/CustomNavigationBar.swift | 2 +- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift index ad27e14c..1f5bb066 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift @@ -152,15 +152,20 @@ extension AroundMeViewController { } private func bindActions() { - navigationBar.rightButtonAction = { - self.cardNearByFetchWithAPI(longitude: self.longitude, latitude: self.latitude) - } + navigationBar.rightButton.rx.tap + .withUnretained(self) + .subscribe { owner, _ in + owner.makeVibrate(degree: .medium) + owner.cardNearByFetchWithAPI(longitude: self.longitude, latitude: self.latitude) + }.disposed(by: self.disposeBag) } private func bindViewModels() { let input = AroundMeViewModel.Input( - viewWillAppearEvent: self.rx.methodInvoked(#selector(UIViewController.viewWillAppear)).map { _ in }, - refreshButtonTapEvent: self.rx.methodInvoked(#selector(UIViewController.viewWillAppear)).map { _ in }) + viewWillAppearEvent: self.rx.methodInvoked(#selector(UIViewController.viewWillAppear)).map { _ in + self.cardNearByFetchWithAPI(longitude: self.longitude, latitude: self.latitude) + }, + refreshButtonTapEvent: self.rx.methodInvoked(#selector(UIViewController.viewWillAppear)).map { _ in}) let output = self.viewModel.transform(input: input) output.cardList diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/ViewModel/AroundMeViewModel.swift b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/ViewModel/AroundMeViewModel.swift index bd85a67a..651935bc 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/ViewModel/AroundMeViewModel.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/ViewModel/AroundMeViewModel.swift @@ -39,7 +39,6 @@ final class AroundMeViewModel: ViewModelType { extension AroundMeViewModel { func transform(input: Input) -> Output { let output = Output() -// self.bindOutput(output: output, disposeBag: disposeBag) input.viewWillAppearEvent .withUnretained(self) @@ -60,12 +59,4 @@ extension AroundMeViewModel { return output } - -// private func bindOutput(output: Output, disposeBag: DisposeBag) { -// let cardListRelay = useCase.stadiumList -// -// cardListRelay.subscribe { model in -// output.cardList.accept(model) -// }.disposed(by: self.disposeBag) -// } } diff --git a/NADA-iOS-forRelease/Sources/Views/CustomNavigationBar/CustomNavigationBar.swift b/NADA-iOS-forRelease/Sources/Views/CustomNavigationBar/CustomNavigationBar.swift index 0f248605..0e0bcee5 100644 --- a/NADA-iOS-forRelease/Sources/Views/CustomNavigationBar/CustomNavigationBar.swift +++ b/NADA-iOS-forRelease/Sources/Views/CustomNavigationBar/CustomNavigationBar.swift @@ -38,7 +38,7 @@ class CustomNavigationBar: UIView { private lazy var leftButton = UIButton().then { $0.addTarget(self, action: #selector(touchLeftButton(_:)), for: .touchUpInside) } - private lazy var rightButton = UIButton().then { + lazy var rightButton = UIButton().then { $0.addTarget(self, action: #selector(touchRightButton(_:)), for: .touchUpInside) } From c1835bcaff83b5cbd143a36618e34d305c43aec5 Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Tue, 2 May 2023 14:51:53 +0900 Subject: [PATCH 19/25] =?UTF-8?q?feat:=20=EB=82=B4=20=EA=B7=BC=EC=B2=98?= =?UTF-8?q?=EC=9D=98=20=EB=AA=85=ED=95=A8=20cell=20circle=20(#380)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AroundMe/VC/AroundMeViewController.swift | 64 +++++++++++-------- .../View/AroundMeCollectionViewCell.swift | 3 + .../CardShareBottomSheetViewController.swift | 2 +- 3 files changed, 42 insertions(+), 27 deletions(-) diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift index c3c7375c..3eb910a1 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift @@ -22,7 +22,7 @@ final class AroundMeViewController: UIViewController { var viewModel: AroundMeViewModel! private let disposeBag = DisposeBag() - var cardsNearBy: [AroundMeResponse]? = [] + var cardsNearBy: [AroundMeResponse] = [] var locationManager = CLLocationManager() private var latitude: CLLocationDegrees = 0 @@ -129,19 +129,8 @@ extension AroundMeViewController { } private func setDelegate() { - aroundMeCollectionView.rx.setDelegate(self) - .disposed(by: disposeBag) - - aroundMeCollectionView.rx.modelSelected(AroundMeResponse.self) - .subscribe { [weak self] model in - guard let self = self else { return } - if let game = model.element { -// let playVC = self.moduleFactory.makePlayVC(.replay, type: .disableControl, matchId: game.matchID) -// self.hidesBottomBarWhenPushed = true -// self.navigationController?.pushViewController(playVC, animated: true) - print("Clicked") - } - }.disposed(by: disposeBag) + aroundMeCollectionView.dataSource = self + aroundMeCollectionView.delegate = self } private func setRegister() { @@ -170,18 +159,18 @@ extension AroundMeViewController { refreshButtonTapEvent: self.rx.methodInvoked(#selector(UIViewController.viewWillAppear)).map { _ in}) let output = self.viewModel.transform(input: input) - output.cardList - .compactMap { $0 } - .withUnretained(self) - .subscribe { owner, list in - owner.setData(cardList: list) - }.disposed(by: self.disposeBag) - - output.cardList - .bind(to: aroundMeCollectionView.rx.items(cellIdentifier: AroundMeCollectionViewCell.className, cellType: AroundMeCollectionViewCell.self)) { _, model, cell in - cell.setData(model) - } - .disposed(by: disposeBag) +// output.cardList +// .compactMap { $0 } +// .withUnretained(self) +// .subscribe { owner, list in +// owner.setData(cardList: list) +// }.disposed(by: self.disposeBag) +// +// output.cardList +// .bind(to: aroundMeCollectionView.rx.items(cellIdentifier: AroundMeCollectionViewCell.className, cellType: AroundMeCollectionViewCell.self)) { _, model, cell in +// cell.setData(model) +// } +// .disposed(by: disposeBag) } } @@ -205,6 +194,26 @@ extension AroundMeViewController: UICollectionViewDelegateFlowLayout { } } +// MARK: - UICollectionViewDataSource + +extension AroundMeViewController: UICollectionViewDataSource { + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + return cardsNearBy.count + } + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + guard let cardCell = collectionView.dequeueReusableCell(withReuseIdentifier: AroundMeCollectionViewCell.className, for: indexPath) as? AroundMeCollectionViewCell else { + return UICollectionViewCell() + } + cardCell.setData(cardsNearBy[indexPath.row]) + return cardCell + } + + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + print("selected") + } +} + // MARK: - CLLocationManagerDelegate extension AroundMeViewController: CLLocationManagerDelegate { @@ -235,6 +244,9 @@ extension AroundMeViewController { if let cards = data as? [AroundMeResponse] { self.cardsNearBy = cards print(cards) + if cards.isEmpty { + self.aroundMeCollectionView.isHidden = true + } self.aroundMeCollectionView.reloadData() } print("cardNearByFetchWithAPI - success") diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift index 046391c6..3367f546 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift @@ -23,6 +23,8 @@ class AroundMeCollectionViewCell: UICollectionViewCell { private var profileImageView = UIImageView().then { $0.image = UIImage(named: "imgProfileSmall") + $0.layer.cornerRadius = 33 + $0.clipsToBounds = true } private var myNameLabel = UILabel().then { @@ -80,6 +82,7 @@ class AroundMeCollectionViewCell: UICollectionViewCell { profileImageView.snp.makeConstraints { make in make.top.equalToSuperview().inset(20) make.leading.equalToSuperview().inset(12) + make.width.height.equalTo(66) } myNameLabel.snp.makeConstraints { make in make.centerY.equalTo(profileImageView.snp.centerY) diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift index bfb59b14..91f01b78 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift @@ -205,7 +205,7 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { timer?.invalidate() seconds = 0 nearByTimeLabel.text = "10:00" - + print("✅✅ deactivated") } } From e304a081292b96307a323818c8bd6e1b419427f6 Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Tue, 2 May 2023 14:57:58 +0900 Subject: [PATCH 20/25] =?UTF-8?q?feat:=20+=20=EB=B2=84=ED=8A=BC=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=B9=B4=EB=93=9C=20=EC=B6=94=EA=B0=80=20(#380)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AroundMe/VC/AroundMeViewController.swift | 18 +++++------------- .../View/AroundMeCollectionViewCell.swift | 10 ++++++++++ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift index 3eb910a1..64d5db80 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift @@ -158,19 +158,6 @@ extension AroundMeViewController { }, refreshButtonTapEvent: self.rx.methodInvoked(#selector(UIViewController.viewWillAppear)).map { _ in}) let output = self.viewModel.transform(input: input) - -// output.cardList -// .compactMap { $0 } -// .withUnretained(self) -// .subscribe { owner, list in -// owner.setData(cardList: list) -// }.disposed(by: self.disposeBag) -// -// output.cardList -// .bind(to: aroundMeCollectionView.rx.items(cellIdentifier: AroundMeCollectionViewCell.className, cellType: AroundMeCollectionViewCell.self)) { _, model, cell in -// cell.setData(model) -// } -// .disposed(by: disposeBag) } } @@ -206,6 +193,11 @@ extension AroundMeViewController: UICollectionViewDataSource { return UICollectionViewCell() } cardCell.setData(cardsNearBy[indexPath.row]) + cardCell.addCardMethod = { [weak self] in + let index = indexPath.row + print("\(index) Call Back Method") + // 여기서 카드 추가 API + } return cardCell } diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift index 3367f546..373a7362 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/View/AroundMeCollectionViewCell.swift @@ -14,11 +14,13 @@ class AroundMeCollectionViewCell: UICollectionViewCell { // MARK: - Properties var cardUUID: String = "" + var addCardMethod: (() -> Void)? // MARK: - UI Components private let plusButton = UIButton().then { $0.setImage(UIImage(named: "icnPlusCircle"), for: .normal) + $0.addTarget(self, action: #selector(touchPlusButton), for: .touchUpInside) } private var profileImageView = UIImageView().then { @@ -99,4 +101,12 @@ class AroundMeCollectionViewCell: UICollectionViewCell { make.height.equalTo(1) } } + + // MARK: - @objc + + @objc + private func touchPlusButton() { + addCardMethod?() + } + } From 91f1458e9f52936cf8487bf750264acd5bb87499 Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Tue, 2 May 2023 15:07:08 +0900 Subject: [PATCH 21/25] =?UTF-8?q?feat:=20=EA=B7=BC=EC=B2=98=EC=9D=98=20?= =?UTF-8?q?=EB=82=B4=20=EB=AA=85=ED=95=A8=20=EC=B6=94=EA=B0=80=ED=95=98?= =?UTF-8?q?=EA=B8=B0=20(#380)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AroundMe/VC/AroundMeViewController.swift | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift index 64d5db80..8cdcf6b9 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/AroundMe/VC/AroundMeViewController.swift @@ -17,7 +17,7 @@ import SnapKit import Then final class AroundMeViewController: UIViewController { - + // MARK: - Properties var viewModel: AroundMeViewModel! @@ -72,7 +72,7 @@ final class AroundMeViewController: UIViewController { bindActions() bindViewModels() } - + } extension AroundMeViewController { @@ -84,10 +84,10 @@ extension AroundMeViewController { self.navigationController?.navigationBar.isHidden = true navigationBar.setUI("내 근처의 명함", leftImage: UIImage(named: "iconClear"), rightImage: UIImage(named: "iconRefreshLocation")) navigationBar.leftButtonAction = { - self.dismiss(animated: true) + self.dismiss(animated: true) } navigationBar.rightButtonAction = { - print("리프레시") + print("리프레시") } } @@ -197,6 +197,7 @@ extension AroundMeViewController: UICollectionViewDataSource { let index = indexPath.row print("\(index) Call Back Method") // 여기서 카드 추가 API + self?.cardDetailFetchWithAPI(cardUUID: self?.cardsNearBy[indexPath.row].cardUUID ?? "") } return cardCell } @@ -253,4 +254,34 @@ extension AroundMeViewController { } } } + + func cardDetailFetchWithAPI(cardUUID: String) { + CardAPI.shared.cardDetailFetch(cardUUID: cardUUID) { response in + switch response { + case .success(let data): + if let card = data as? Card { + // TODO: - 자신의 명함 추가하는 경우 예외처리. + // if UserDefaults.standard.string(forKey: Const.UserDefaultsKey.userID) == card.author { + // self.errorImageView.isHidden = false + // self.explainLabel.isHidden = false + // self.explainLabel.text = "자신의 명함은 추가할 수 없습니다." + // } else { + let nextVC = CardResultBottomSheetViewController() + .setTitle(card.userName) + .setHeight(574) + nextVC.cardDataModel = card + nextVC.modalPresentationStyle = .overFullScreen + self.present(nextVC, animated: false, completion: nil) + } + case .requestErr(let message): + print("cardDetailFetchWithAPI - requestErr: \(message)") + case .pathErr: + print("cardDetailFetchWithAPI - pathErr") + case .serverErr: + print("cardDetailFetchWithAPI - serverErr") + case .networkFail: + print("cardDetailFetchWithAPI - networkFail") + } + } + } } From 80ee026f0223c73d01346a2db1a2b08c27d1e63d Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Tue, 2 May 2023 15:25:14 +0900 Subject: [PATCH 22/25] =?UTF-8?q?feat:=20=EB=82=B4=20=EA=B7=BC=EC=B2=98?= =?UTF-8?q?=EC=9D=98=20=EB=AA=85=ED=95=A8=20=EC=A0=95=EB=B3=B4=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20(#380)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NADA-iOS-forRelease.xcodeproj/project.pbxproj | 4 +++ .../NetworkModel/AroundMe/NearByRequest.swift | 20 +++++++++++ .../NetworkService/Nearby/NearbyAPI.swift | 15 +++++++++ .../NetworkService/Nearby/NearbyService.swift | 13 +++++++- .../CardShareBottomSheetViewController.swift | 33 ++++++++++++++++--- 5 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/NearByRequest.swift diff --git a/NADA-iOS-forRelease.xcodeproj/project.pbxproj b/NADA-iOS-forRelease.xcodeproj/project.pbxproj index ca9789bc..388d41db 100644 --- a/NADA-iOS-forRelease.xcodeproj/project.pbxproj +++ b/NADA-iOS-forRelease.xcodeproj/project.pbxproj @@ -82,6 +82,7 @@ 77703157275005AA002CBD19 /* CardResultBottomSheetViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77703156275005AA002CBD19 /* CardResultBottomSheetViewController.swift */; }; 7770315927500C49002CBD19 /* QRScan.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7770315827500C49002CBD19 /* QRScan.storyboard */; }; 7770315B27500C7B002CBD19 /* QRScanViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7770315A27500C7B002CBD19 /* QRScanViewController.swift */; }; + 777B2C222A00E15000A6AB27 /* NearByRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777B2C212A00E15000A6AB27 /* NearByRequest.swift */; }; 777FF89B27359B7800BF69D3 /* Groups.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777FF89A27359B7800BF69D3 /* Groups.swift */; }; 777FF89D2735B16B00BF69D3 /* GroupAddRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777FF89C2735B16B00BF69D3 /* GroupAddRequest.swift */; }; 777FF89F27364B7B00BF69D3 /* GroupEditRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777FF89E27364B7B00BF69D3 /* GroupEditRequest.swift */; }; @@ -333,6 +334,7 @@ 7770315827500C49002CBD19 /* QRScan.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = QRScan.storyboard; sourceTree = ""; }; 7770315A27500C7B002CBD19 /* QRScanViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRScanViewController.swift; sourceTree = ""; }; 777B2C202A00BEB300A6AB27 /* IntentsExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = IntentsExtension.entitlements; sourceTree = ""; }; + 777B2C212A00E15000A6AB27 /* NearByRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NearByRequest.swift; sourceTree = ""; }; 777FF89A27359B7800BF69D3 /* Groups.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Groups.swift; sourceTree = ""; }; 777FF89C2735B16B00BF69D3 /* GroupAddRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupAddRequest.swift; sourceTree = ""; }; 777FF89E27364B7B00BF69D3 /* GroupEditRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupEditRequest.swift; sourceTree = ""; }; @@ -885,6 +887,7 @@ isa = PBXGroup; children = ( 77A4D60029BD708C00367B7C /* AroundMeResponse.swift */, + 777B2C212A00E15000A6AB27 /* NearByRequest.swift */, ); path = AroundMe; sourceTree = ""; @@ -1862,6 +1865,7 @@ F84BAFAD26FDB543004CA335 /* FrontCardCreationCollectionViewCell.swift in Sources */, F8518054275D040C006BD5ED /* OnboardingCollectionViewCell.swift in Sources */, 77703157275005AA002CBD19 /* CardResultBottomSheetViewController.swift in Sources */, + 777B2C222A00E15000A6AB27 /* NearByRequest.swift in Sources */, F8D74DD8276C7FB60071E5FC /* UIImageView+Extension.swift in Sources */, F8F00C3929DD474700A15377 /* UpdateNote.swift in Sources */, 39D13565273FDB9C00B1A148 /* User.swift in Sources */, diff --git a/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/NearByRequest.swift b/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/NearByRequest.swift new file mode 100644 index 00000000..cd5843ae --- /dev/null +++ b/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/NearByRequest.swift @@ -0,0 +1,20 @@ +// +// NearByRequest.swift +// NADA-iOS-forRelease +// +// Created by Yi Joon Choi on 2023/05/02. +// + +import Foundation + +// MARK: - NearByRequest +struct NearByRequest: Codable { + let cardUUID: String + let isActive: Bool + let latitude, longitude: Double + + enum CodingKeys: String, CodingKey { + case cardUUID = "cardUuid" + case isActive, latitude, longitude + } +} diff --git a/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyAPI.swift b/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyAPI.swift index 3285cb7d..317b85c1 100644 --- a/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyAPI.swift +++ b/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyAPI.swift @@ -29,6 +29,21 @@ public final class NearbyAPI { } } + func postNearByCard(nearByRequest: NearByRequest, completion: @escaping(NetworkResult) -> Void) { + nearbyProvider.request(.postNearByCard(nearByRequest: nearByRequest)) { result in + switch result { + case .success(let response): + let statusCode = response.statusCode + let data = response.data + + let networkResult = self.judgeStatus(by: statusCode, data: data, type: String.self) + completion(networkResult) + case .failure(let err): + print(err) + } + } + } + // MARK: - judgeStatus methods private func judgeStatus(by statusCode: Int, data: Data, type: T.Type) -> NetworkResult { diff --git a/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyService.swift b/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyService.swift index 034e5af9..655c4136 100644 --- a/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyService.swift +++ b/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyService.swift @@ -10,6 +10,7 @@ import Moya enum NearbyService { case cardNearByFetch(longitude: Double, latitude: Double) + case postNearByCard(nearByRequest: NearByRequest) } extension NearbyService: TargetType { @@ -25,6 +26,8 @@ extension NearbyService: TargetType { switch self { case .cardNearByFetch(let longitude, let latitude): return "/card/nearby/point/longitude/\(longitude)/latitude/\(latitude)" + case .postNearByCard: + return "/card/nearby" } } @@ -32,6 +35,8 @@ extension NearbyService: TargetType { switch self { case .cardNearByFetch: return .get + case .postNearByCard: + return .post } } @@ -39,12 +44,18 @@ extension NearbyService: TargetType { switch self { case .cardNearByFetch: return .requestPlain + case .postNearByCard(let nearByRequest): + return .requestParameters(parameters: ["cardUuid": nearByRequest.cardUUID, + "isActive": nearByRequest.isActive, + "latitude": nearByRequest.latitude, + "longitude": nearByRequest.longitude], + encoding: JSONEncoding.default) } } var headers: [String: String]? { switch self { - case .cardNearByFetch: + case .cardNearByFetch, .postNearByCard: return Const.Header.bearerHeader() } } diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift index 91f01b78..3411528f 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift @@ -188,17 +188,18 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { _ = isActivate ? lottieImage.play() : lottieImage.stop() // TODO: 여기서 스위치 키면 위치정보 받아오기, 끄면 위치 정보 노출하지 않기 + locationManager.startUpdatingLocation() + latitude = locationManager.location?.coordinate.latitude ?? 0 + longitude = locationManager.location?.coordinate.longitude ?? 0 + if isActivate { //TODO: 여기서 활성화된 명함 정보/위치정보 API로 쏴주기 timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(processTimer), userInfo: nil, repeats: true) - locationManager.startUpdatingLocation() - latitude = locationManager.location?.coordinate.latitude ?? 0 - longitude = locationManager.location?.coordinate.longitude ?? 0 - print("✅ activated") print("✅ latitude: ", latitude) print("✅ longitude: ", longitude) + groupListFetchWithAPI(nearByRequest: NearByRequest(cardUUID: cardDataModel?.cardUUID ?? "", isActive: true, latitude: latitude, longitude: longitude)) } else { // TODO: 여기서 비활성화된 명함 정보/위치정보 API로 쏴주기 @@ -206,6 +207,9 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { seconds = 0 nearByTimeLabel.text = "10:00" print("✅✅ deactivated") + print("✅ latitude: ", latitude) + print("✅ longitude: ", longitude) + groupListFetchWithAPI(nearByRequest: NearByRequest(cardUUID: cardDataModel?.cardUUID ?? "", isActive: false, latitude: latitude, longitude: longitude)) } } @@ -479,3 +483,24 @@ extension CardShareBottomSheetViewController: CLLocationManagerDelegate { print(error) } } + +// MARK: - Network + +extension CardShareBottomSheetViewController { + func groupListFetchWithAPI(nearByRequest: NearByRequest) { + NearbyAPI.shared.postNearByCard(nearByRequest: nearByRequest) { response in + switch response { + case .success: + print("groupListFetchWithAPI - success") + case .requestErr(let message): + print("groupListFetchWithAPI - requestErr: \(message)") + case .pathErr: + print("groupListFetchWithAPI - pathErr") + case .serverErr: + print("groupListFetchWithAPI - serverErr") + case .networkFail: + print("groupListFetchWithAPI - networkFail") + } + } + } +} From ea164442184a5e11bdbf02c3217dbfa590d6d529 Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Tue, 2 May 2023 15:45:43 +0900 Subject: [PATCH 23/25] feat: fetch activated data (#380) --- NADA-iOS-forRelease.xcodeproj/project.pbxproj | 4 +++ .../AroundMe/NearByUUIDResponse.swift | 14 ++++++++++ .../NetworkService/Nearby/NearbyAPI.swift | 15 ++++++++++ .../NetworkService/Nearby/NearbyService.swift | 9 ++++-- .../CardShareBottomSheetViewController.swift | 28 +++++++++++++++++-- 5 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/NearByUUIDResponse.swift diff --git a/NADA-iOS-forRelease.xcodeproj/project.pbxproj b/NADA-iOS-forRelease.xcodeproj/project.pbxproj index 388d41db..27b5352e 100644 --- a/NADA-iOS-forRelease.xcodeproj/project.pbxproj +++ b/NADA-iOS-forRelease.xcodeproj/project.pbxproj @@ -83,6 +83,7 @@ 7770315927500C49002CBD19 /* QRScan.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 7770315827500C49002CBD19 /* QRScan.storyboard */; }; 7770315B27500C7B002CBD19 /* QRScanViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7770315A27500C7B002CBD19 /* QRScanViewController.swift */; }; 777B2C222A00E15000A6AB27 /* NearByRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777B2C212A00E15000A6AB27 /* NearByRequest.swift */; }; + 777B2C242A00E7C700A6AB27 /* NearByUUIDResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777B2C232A00E7C700A6AB27 /* NearByUUIDResponse.swift */; }; 777FF89B27359B7800BF69D3 /* Groups.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777FF89A27359B7800BF69D3 /* Groups.swift */; }; 777FF89D2735B16B00BF69D3 /* GroupAddRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777FF89C2735B16B00BF69D3 /* GroupAddRequest.swift */; }; 777FF89F27364B7B00BF69D3 /* GroupEditRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 777FF89E27364B7B00BF69D3 /* GroupEditRequest.swift */; }; @@ -335,6 +336,7 @@ 7770315A27500C7B002CBD19 /* QRScanViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRScanViewController.swift; sourceTree = ""; }; 777B2C202A00BEB300A6AB27 /* IntentsExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = IntentsExtension.entitlements; sourceTree = ""; }; 777B2C212A00E15000A6AB27 /* NearByRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NearByRequest.swift; sourceTree = ""; }; + 777B2C232A00E7C700A6AB27 /* NearByUUIDResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NearByUUIDResponse.swift; sourceTree = ""; }; 777FF89A27359B7800BF69D3 /* Groups.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Groups.swift; sourceTree = ""; }; 777FF89C2735B16B00BF69D3 /* GroupAddRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupAddRequest.swift; sourceTree = ""; }; 777FF89E27364B7B00BF69D3 /* GroupEditRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupEditRequest.swift; sourceTree = ""; }; @@ -888,6 +890,7 @@ children = ( 77A4D60029BD708C00367B7C /* AroundMeResponse.swift */, 777B2C212A00E15000A6AB27 /* NearByRequest.swift */, + 777B2C232A00E7C700A6AB27 /* NearByUUIDResponse.swift */, ); path = AroundMe; sourceTree = ""; @@ -1885,6 +1888,7 @@ 39C394D4277CD33500DBA566 /* EmptyCardListTableViewCell.swift in Sources */, 77B4E74B2990E50E006098DC /* HomeViewController.swift in Sources */, 7734D5B427778EFB004360E4 /* HarmonyResponse.swift in Sources */, + 777B2C242A00E7C700A6AB27 /* NearByUUIDResponse.swift in Sources */, 397B75132763A916004AEB03 /* OpenSourceTableViewCell.swift in Sources */, F811720027383097002742CF /* ChangeGroupRequest.swift in Sources */, ); diff --git a/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/NearByUUIDResponse.swift b/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/NearByUUIDResponse.swift new file mode 100644 index 00000000..2244c5a9 --- /dev/null +++ b/NADA-iOS-forRelease/Sources/NetworkModel/AroundMe/NearByUUIDResponse.swift @@ -0,0 +1,14 @@ +// +// NearByUUIDResponse.swift +// NADA-iOS-forRelease +// +// Created by Yi Joon Choi on 2023/05/02. +// + +import Foundation + +// MARK: - NearByUUIDResponse +struct NearByUUIDResponse: Codable { + let activeTime, inactiveTime: String + let isActive: Bool +} diff --git a/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyAPI.swift b/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyAPI.swift index 317b85c1..2a553b29 100644 --- a/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyAPI.swift +++ b/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyAPI.swift @@ -44,6 +44,21 @@ public final class NearbyAPI { } } + func nearByUUIDFetch(cardUUID: String, completion: @escaping(NetworkResult) -> Void) { + nearbyProvider.request(.nearByUUIDFetch(cardUUID: cardUUID)) { result in + switch result { + case .success(let response): + let statusCode = response.statusCode + let data = response.data + + let networkResult = self.judgeStatus(by: statusCode, data: data, type: NearByUUIDResponse.self) + completion(networkResult) + case .failure(let err): + print(err) + } + } + } + // MARK: - judgeStatus methods private func judgeStatus(by statusCode: Int, data: Data, type: T.Type) -> NetworkResult { diff --git a/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyService.swift b/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyService.swift index 655c4136..106973ec 100644 --- a/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyService.swift +++ b/NADA-iOS-forRelease/Sources/NetworkService/Nearby/NearbyService.swift @@ -11,6 +11,7 @@ import Moya enum NearbyService { case cardNearByFetch(longitude: Double, latitude: Double) case postNearByCard(nearByRequest: NearByRequest) + case nearByUUIDFetch(cardUUID: String) } extension NearbyService: TargetType { @@ -28,12 +29,14 @@ extension NearbyService: TargetType { return "/card/nearby/point/longitude/\(longitude)/latitude/\(latitude)" case .postNearByCard: return "/card/nearby" + case .nearByUUIDFetch(let cardUUID): + return "/card/nearby/\(cardUUID)" } } var method: Moya.Method { switch self { - case .cardNearByFetch: + case .cardNearByFetch, .nearByUUIDFetch: return .get case .postNearByCard: return .post @@ -42,7 +45,7 @@ extension NearbyService: TargetType { var task: Moya.Task { switch self { - case .cardNearByFetch: + case .cardNearByFetch, .nearByUUIDFetch: return .requestPlain case .postNearByCard(let nearByRequest): return .requestParameters(parameters: ["cardUuid": nearByRequest.cardUUID, @@ -55,7 +58,7 @@ extension NearbyService: TargetType { var headers: [String: String]? { switch self { - case .cardNearByFetch, .postNearByCard: + case .cardNearByFetch, .postNearByCard, .nearByUUIDFetch: return Const.Header.bearerHeader() } } diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift index 3411528f..a771cb12 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift @@ -150,6 +150,7 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { override func viewWillAppear(_ animated: Bool) { setNotification() + nearByUUIDFetchWithAPI(cardUUID: cardDataModel?.cardUUID ?? "") } // MARK: - @Functions @@ -199,7 +200,7 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { print("✅ activated") print("✅ latitude: ", latitude) print("✅ longitude: ", longitude) - groupListFetchWithAPI(nearByRequest: NearByRequest(cardUUID: cardDataModel?.cardUUID ?? "", isActive: true, latitude: latitude, longitude: longitude)) + postNearByCardWithAPI(nearByRequest: NearByRequest(cardUUID: cardDataModel?.cardUUID ?? "", isActive: true, latitude: latitude, longitude: longitude)) } else { // TODO: 여기서 비활성화된 명함 정보/위치정보 API로 쏴주기 @@ -209,7 +210,7 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { print("✅✅ deactivated") print("✅ latitude: ", latitude) print("✅ longitude: ", longitude) - groupListFetchWithAPI(nearByRequest: NearByRequest(cardUUID: cardDataModel?.cardUUID ?? "", isActive: false, latitude: latitude, longitude: longitude)) + postNearByCardWithAPI(nearByRequest: NearByRequest(cardUUID: cardDataModel?.cardUUID ?? "", isActive: false, latitude: latitude, longitude: longitude)) } } @@ -487,7 +488,7 @@ extension CardShareBottomSheetViewController: CLLocationManagerDelegate { // MARK: - Network extension CardShareBottomSheetViewController { - func groupListFetchWithAPI(nearByRequest: NearByRequest) { + func postNearByCardWithAPI(nearByRequest: NearByRequest) { NearbyAPI.shared.postNearByCard(nearByRequest: nearByRequest) { response in switch response { case .success: @@ -503,4 +504,25 @@ extension CardShareBottomSheetViewController { } } } + + func nearByUUIDFetchWithAPI(cardUUID: String) { + NearbyAPI.shared.nearByUUIDFetch(cardUUID: cardUUID) { response in + switch response { + case .success(let data): + if let response = data as? NearByUUIDResponse { + print("✅✅✅") + print(response) + } + print("groupListFetchWithAPI - success") + case .requestErr(let message): + print("groupListFetchWithAPI - requestErr: \(message)") + case .pathErr: + print("groupListFetchWithAPI - pathErr") + case .serverErr: + print("groupListFetchWithAPI - serverErr") + case .networkFail: + print("groupListFetchWithAPI - networkFail") + } + } + } } From e43ad898ac135cf11b63e7302db80983c180db14 Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Tue, 2 May 2023 15:55:44 +0900 Subject: [PATCH 24/25] =?UTF-8?q?feat:=20=EA=B7=BC=EC=B2=98=EC=9D=98=20?= =?UTF-8?q?=EB=AA=85=ED=95=A8=20=EC=83=81=ED=83=9C=20=EC=A0=80=EC=9E=A5=20?= =?UTF-8?q?(#380)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CardShareBottomSheetViewController.swift | 72 ++++++++++++++----- 1 file changed, 55 insertions(+), 17 deletions(-) diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift index a771cb12..4da711d9 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift @@ -168,13 +168,13 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { idLabel.text = cardDataModel?.cardUUID ?? "" - setCardActivationUI(with: isActivate ?? false) + setCardActivationUIWithAPI(with: isActivate ?? false) setupLayout() setQRImage() } - private func setCardActivationUI(with isActivate: Bool) { + private func setCardActivationUIWithAPI(with isActivate: Bool) { nearByBackgroundView.backgroundColor = isActivate ? .mainColorNadaMain.withAlphaComponent(0.15) : .card nearByImage.image = isActivate ? UIImage(named: "icnNearbyOn") : UIImage(named: "icnNearbyOff") @@ -214,6 +214,39 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { } } + private func setCardActivationUI(with isActivate: Bool, response: NearByUUIDResponse) { + nearByBackgroundView.backgroundColor = isActivate ? .mainColorNadaMain.withAlphaComponent(0.15) : .card + + nearByImage.image = isActivate ? UIImage(named: "icnNearbyOn") : UIImage(named: "icnNearbyOff") + + nearByLabel.text = isActivate ? "내 근처의 명함 ON" : "내 근처의 명함 OFF" + nearByLabel.textColor = isActivate ? .mainColorNadaMain : .tertiary + nearByTimeLabel.isHidden = !isActivate + + nearBySwitch.setOn(isActivate, animated: false) + + lottieImage.isHidden = isActivate ? false : true + _ = isActivate ? lottieImage.play() : lottieImage.stop() + + if isActivate { + //TODO: 여기서 활성화된 명함 정보/위치정보 API로 쏴주기 + nearByTimeLabel.text = response.activeTime + timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(processTimer), userInfo: nil, repeats: true) + + print("✅ activated") + print("✅ latitude: ", latitude) + print("✅ longitude: ", longitude) + } else { + // TODO: 여기서 비활성화된 명함 정보/위치정보 API로 쏴주기 + timer?.invalidate() + seconds = 0 + nearByTimeLabel.text = "10:00" + print("✅✅ deactivated") + print("✅ latitude: ", latitude) + print("✅ longitude: ", longitude) + } + } + func setNotification() { NotificationCenter.default.addObserver(self, selector: #selector(applicationDidEnterBackground(_:)), name: UIApplication.didEnterBackgroundNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(applicationWillEnterForeground(_:)), name: UIApplication.willEnterForegroundNotification, object: nil) @@ -233,10 +266,14 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { print(savedTime) print(calculateMinuteTime(sec: calculateMinuteTimeToInt(time: savedTime) - seconds)) print(seconds) - DispatchQueue.main.async { - self.nearByTimeLabel.text = calculateMinuteTime(sec: calculateMinuteTimeToInt(time: self.savedTime) - seconds) + + if seconds >= 600 { + postNearByCardWithAPI(nearByRequest: NearByRequest(cardUUID: cardDataModel?.cardUUID ?? "", isActive: false, latitude: latitude, longitude: longitude)) + } else { + DispatchQueue.main.async { + self.nearByTimeLabel.text = calculateMinuteTime(sec: calculateMinuteTimeToInt(time: self.savedTime) - seconds) + } } - print(nearByTimeLabel.text) } private func setupLayout() { @@ -459,7 +496,7 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { } @objc func touchSwitch(_ sender: UISwitch) { - setCardActivationUI(with: sender.isOn) + setCardActivationUIWithAPI(with: sender.isOn) } @objc @@ -492,15 +529,15 @@ extension CardShareBottomSheetViewController { NearbyAPI.shared.postNearByCard(nearByRequest: nearByRequest) { response in switch response { case .success: - print("groupListFetchWithAPI - success") + print("postNearByCardWithAPI - success") case .requestErr(let message): - print("groupListFetchWithAPI - requestErr: \(message)") + print("postNearByCardWithAPI - requestErr: \(message)") case .pathErr: - print("groupListFetchWithAPI - pathErr") + print("postNearByCardWithAPI - pathErr") case .serverErr: - print("groupListFetchWithAPI - serverErr") + print("postNearByCardWithAPI - serverErr") case .networkFail: - print("groupListFetchWithAPI - networkFail") + print("postNearByCardWithAPI - networkFail") } } } @@ -509,19 +546,20 @@ extension CardShareBottomSheetViewController { NearbyAPI.shared.nearByUUIDFetch(cardUUID: cardUUID) { response in switch response { case .success(let data): - if let response = data as? NearByUUIDResponse { + if let nearByUUIDResponse = data as? NearByUUIDResponse { print("✅✅✅") print(response) + self.setCardActivationUI(with: nearByUUIDResponse.isActive, response: nearByUUIDResponse) } - print("groupListFetchWithAPI - success") + print("nearByUUIDFetchWithAPI - success") case .requestErr(let message): - print("groupListFetchWithAPI - requestErr: \(message)") + print("nearByUUIDFetchWithAPI - requestErr: \(message)") case .pathErr: - print("groupListFetchWithAPI - pathErr") + print("nearByUUIDFetchWithAPI - pathErr") case .serverErr: - print("groupListFetchWithAPI - serverErr") + print("nearByUUIDFetchWithAPI - serverErr") case .networkFail: - print("groupListFetchWithAPI - networkFail") + print("nearByUUIDFetchWithAPI - networkFail") } } } From eb809d3cabfb22f5ea4d450155474099bd58a426 Mon Sep 17 00:00:00 2001 From: dlwns33 Date: Tue, 2 May 2023 19:53:24 +0900 Subject: [PATCH 25/25] =?UTF-8?q?feat:=20=EA=B7=BC=EC=B2=98=EC=9D=98=20?= =?UTF-8?q?=EB=AA=85=ED=95=A8=20=EA=B8=B0=EB=8A=A5=20=EC=83=81=ED=83=9C=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=20(#380)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .swiftlint.yml | 1 + .../Resouces/Utils/calculateTime.swift | 27 +++++++++++++++++++ .../CardShareBottomSheetViewController.swift | 23 +++++++++------- 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index b751133e..28bdb142 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -8,6 +8,7 @@ disabled_rules: - type_body_length - file_length - identifier_name +- large_tuple excluded: - Pods - NADA-iOS-forRelease/Sources/AppDelegate.swift diff --git a/NADA-iOS-forRelease/Resouces/Utils/calculateTime.swift b/NADA-iOS-forRelease/Resouces/Utils/calculateTime.swift index f2bb8599..7a4c6c6a 100644 --- a/NADA-iOS-forRelease/Resouces/Utils/calculateTime.swift +++ b/NADA-iOS-forRelease/Resouces/Utils/calculateTime.swift @@ -28,3 +28,30 @@ func calculateMinuteTimeToInt(time: String) -> Int { let secondsCaculated = minutes*60 + seconds return secondsCaculated } + +extension Date { + + static func - (recent: Date, previous: Date) -> (month: Int?, day: Int?, hour: Int?, minute: Int?, second: Int?) { + let day = Calendar.current.dateComponents([.day], from: previous, to: recent).day + let month = Calendar.current.dateComponents([.month], from: previous, to: recent).month + let hour = Calendar.current.dateComponents([.hour], from: previous, to: recent).hour + let minute = Calendar.current.dateComponents([.minute], from: previous, to: recent).minute + let second = Calendar.current.dateComponents([.second], from: previous, to: recent).second + + return (month: month, day: day, hour: hour, minute: minute, second: second) + } + +} + +extension String { + func toDate() -> Date? { // "yyyy-MM-dd HH:mm:ss" + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss" + dateFormatter.timeZone = TimeZone(identifier: "UTC") + if let date = dateFormatter.date(from: self) { + return date + } else { + return nil + } + } +} diff --git a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift index 4da711d9..dc461672 100644 --- a/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift +++ b/NADA-iOS-forRelease/Sources/ViewControllers/BottomSheet/CardShareBottomSheetViewController.swift @@ -21,7 +21,8 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { public var isActivate: Bool? private weak var timer: Timer? private var seconds = 0 - private var savedTime = "" + private var savedTime = "10:00" + private var timesLeft = 600 private var appDidEnterBackgroundDate: Date? var locationManager = CLLocationManager() @@ -168,7 +169,7 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { idLabel.text = cardDataModel?.cardUUID ?? "" - setCardActivationUIWithAPI(with: isActivate ?? false) + setCardActivationUI(with: isActivate ?? false, secondsLeft: 0) setupLayout() setQRImage() @@ -214,7 +215,7 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { } } - private func setCardActivationUI(with isActivate: Bool, response: NearByUUIDResponse) { + private func setCardActivationUI(with isActivate: Bool, secondsLeft: Int) { nearByBackgroundView.backgroundColor = isActivate ? .mainColorNadaMain.withAlphaComponent(0.15) : .card nearByImage.image = isActivate ? UIImage(named: "icnNearbyOn") : UIImage(named: "icnNearbyOff") @@ -230,7 +231,12 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { if isActivate { //TODO: 여기서 활성화된 명함 정보/위치정보 API로 쏴주기 - nearByTimeLabel.text = response.activeTime + print(calculateMinuteTime(sec: calculateMinuteTimeToInt(time: savedTime) - secondsLeft)) + print(secondsLeft) + + if secondsLeft >= 600 { + postNearByCardWithAPI(nearByRequest: NearByRequest(cardUUID: cardDataModel?.cardUUID ?? "", isActive: false, latitude: latitude, longitude: longitude)) + } timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(processTimer), userInfo: nil, repeats: true) print("✅ activated") @@ -242,8 +248,6 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { seconds = 0 nearByTimeLabel.text = "10:00" print("✅✅ deactivated") - print("✅ latitude: ", latitude) - print("✅ longitude: ", longitude) } } @@ -502,7 +506,7 @@ class CardShareBottomSheetViewController: CommonBottomSheetViewController { @objc func processTimer() { seconds += 1 - nearByTimeLabel.text = calculateMinuteTime(sec: 600 - seconds) + nearByTimeLabel.text = calculateMinuteTime(sec: timesLeft - seconds) } } @@ -548,8 +552,9 @@ extension CardShareBottomSheetViewController { case .success(let data): if let nearByUUIDResponse = data as? NearByUUIDResponse { print("✅✅✅") - print(response) - self.setCardActivationUI(with: nearByUUIDResponse.isActive, response: nearByUUIDResponse) + let interval = Date() - (nearByUUIDResponse.activeTime.toDate() ?? Date()) + self.setCardActivationUI(with: nearByUUIDResponse.isActive, secondsLeft: interval.second ?? 0) + self.timesLeft = interval.second ?? 600 } print("nearByUUIDFetchWithAPI - success") case .requestErr(let message):