From fa44118d8824e93612b8aa00733140eeb3c73e27 Mon Sep 17 00:00:00 2001 From: EunsuSeo01 Date: Tue, 31 Dec 2024 21:22:22 +0900 Subject: [PATCH] =?UTF-8?q?[Feat]=20#319=20-=20=EC=A3=BC=EC=86=8C=EB=A5=BC?= =?UTF-8?q?=20=EB=B6=88=EB=9F=AC=EC=98=A4=EC=A7=80=20=EB=AA=BB=ED=96=88?= =?UTF-8?q?=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20=EB=B7=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Global/Consts/StringLiterals.swift | 1 + .../HankkiDetail/View/DetailMapView.swift | 51 ++++++++++++++++++- .../View/HankkiDetailViewController.swift | 4 ++ .../ViewModel/HankkiDetailViewModel.swift | 10 ++-- 4 files changed, 59 insertions(+), 7 deletions(-) diff --git a/Hankkijogbo/Hankkijogbo/Global/Consts/StringLiterals.swift b/Hankkijogbo/Hankkijogbo/Global/Consts/StringLiterals.swift index cc7c70a3..5bf2d9fc 100644 --- a/Hankkijogbo/Hankkijogbo/Global/Consts/StringLiterals.swift +++ b/Hankkijogbo/Hankkijogbo/Global/Consts/StringLiterals.swift @@ -146,6 +146,7 @@ enum StringLiterals { static let myZip = "내 족보" static let address = "주소" static let copy = "복사" + static let mapLoadErrorMessage = "주소를 불러오지 못했어요" static let copyToastMessage = "주소를 복사했습니다" static let menu = "메뉴" static let editMenu = "메뉴 수정/삭제 제보하기" diff --git a/Hankkijogbo/Hankkijogbo/Present/HankkiDetail/View/DetailMapView.swift b/Hankkijogbo/Hankkijogbo/Present/HankkiDetail/View/DetailMapView.swift index a734abca..9402de89 100644 --- a/Hankkijogbo/Hankkijogbo/Present/HankkiDetail/View/DetailMapView.swift +++ b/Hankkijogbo/Hankkijogbo/Present/HankkiDetail/View/DetailMapView.swift @@ -19,6 +19,9 @@ final class DetailMapView: BaseView { private let addressLabel: UILabel = UILabel() private let copyButton: UIButton = UIButton() + private let mapErrorView: UIView = UIView() + private let mapErrorLabel: UILabel = UILabel() + // MARK: - Init override init(frame: CGRect) { @@ -83,9 +86,9 @@ final class DetailMapView: BaseView { mapView.do { $0.zoomLevel = 16 $0.clipsToBounds = true - $0.layer.cornerRadius = 12 + $0.layer.cornerRadius = 8 $0.layer.maskedCorners = CACornerMask(arrayLiteral: .layerMinXMinYCorner, .layerMaxXMinYCorner) - $0.makeRoundBorder(cornerRadius: 12, borderWidth: 1, borderColor: .imageLine) + $0.makeRoundBorder(cornerRadius: 8, borderWidth: 1, borderColor: .imageLine) } addressView.do { @@ -124,6 +127,20 @@ final class DetailMapView: BaseView { $0.setAttributedTitle(attributedTitle, for: .normal) } } + + mapErrorView.do { + $0.backgroundColor = .gray100 + $0.makeRoundCorners(corners: [.layerMinXMinYCorner, .layerMaxXMinYCorner], radius: 8) + $0.makeRoundBorder(cornerRadius: 8, borderWidth: 1, borderColor: .imageLine) + } + + mapErrorLabel.do { + $0.attributedText = UILabel.setupAttributedText( + for: PretendardStyle.caption4, + withText: StringLiterals.HankkiDetail.mapLoadErrorMessage, + color: .gray400 + ) + } } } @@ -136,6 +153,11 @@ extension DetailMapView { addMapMarker(latitude: latitude, longitude: longitude) moveMapCamera(latitude: latitude, longitude: longitude) } + + func handleMapLoadError() { + showMapErrorView() + disableCopyButton() + } } // MARK: - Private Func @@ -179,6 +201,31 @@ private extension DetailMapView { mapView.moveCamera(cameraUpdate) } + func showMapErrorView() { + addSubview(mapErrorView) + mapErrorView.addSubview(mapErrorLabel) + + mapErrorView.snp.makeConstraints { + $0.edges.equalTo(mapView) + } + + mapErrorLabel.snp.makeConstraints { + $0.center.equalToSuperview() + } + } + + func disableCopyButton() { + copyButton.isEnabled = false + + if let attributedTitle = UILabel.setupAttributedText( + for: PretendardStyle.caption5, + withText: StringLiterals.HankkiDetail.copy, + color: .gray300 + ) { + copyButton.setAttributedTitle(attributedTitle, for: .normal) + } + } + // MARK: - @objc Func @objc func copyButtonDidTap() { diff --git a/Hankkijogbo/Hankkijogbo/Present/HankkiDetail/View/HankkiDetailViewController.swift b/Hankkijogbo/Hankkijogbo/Present/HankkiDetail/View/HankkiDetailViewController.swift index f1482072..066aa733 100644 --- a/Hankkijogbo/Hankkijogbo/Present/HankkiDetail/View/HankkiDetailViewController.swift +++ b/Hankkijogbo/Hankkijogbo/Present/HankkiDetail/View/HankkiDetailViewController.swift @@ -192,6 +192,10 @@ private extension HankkiDetailViewController { viewModel.handleDeletedHankki = { [weak self] in self?.showBlackToast(message: StringLiterals.Toast.deleteAlready) } + + viewModel.handleMapLoadError = { [weak self] in + self?.detailMapView.handleMapLoadError() + } } func setupRegister() { diff --git a/Hankkijogbo/Hankkijogbo/Present/HankkiDetail/ViewModel/HankkiDetailViewModel.swift b/Hankkijogbo/Hankkijogbo/Present/HankkiDetail/ViewModel/HankkiDetailViewModel.swift index 3b5ea358..1d9bfba2 100644 --- a/Hankkijogbo/Hankkijogbo/Present/HankkiDetail/ViewModel/HankkiDetailViewModel.swift +++ b/Hankkijogbo/Hankkijogbo/Present/HankkiDetail/ViewModel/HankkiDetailViewModel.swift @@ -33,7 +33,7 @@ final class HankkiDetailViewModel { var setHankkiDetailData: (() -> Void)? var showAlert: ((String) -> Void)? var dismiss: (() -> Void)? - var handleMapError: (() -> Void)? + var handleMapLoadError: (() -> Void)? var handleDeletedHankki: (() -> Void)? init(hankkiId: Int) { @@ -89,18 +89,18 @@ private extension HankkiDetailViewModel { guard let detailData = hankkiDetailData else { return } NetworkService.shared.naverMapService.getHankkiAddress(latitude: detailData.latitude, longitude: detailData.longitude) { result in switch result { - case .badRequest, .serverError: - self.handleMapError?() - default: + case .success: result.handleNetworkResult { response in guard let data = response.results.first, let data = data else { - self.address = "-" + self.handleMapLoadError?() return } self.address = self.formatAddress(from: data) } + default: + self.handleMapLoadError?() } } }