Skip to content

Commit

Permalink
[Feat] #319 - 주소를 불러오지 못했을 경우 뷰 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
EunsuSeo01 committed Dec 31, 2024
1 parent 5436a15 commit fa44118
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
1 change: 1 addition & 0 deletions Hankkijogbo/Hankkijogbo/Global/Consts/StringLiterals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "메뉴 수정/삭제 제보하기"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
)
}
}
}

Expand All @@ -136,6 +153,11 @@ extension DetailMapView {
addMapMarker(latitude: latitude, longitude: longitude)
moveMapCamera(latitude: latitude, longitude: longitude)
}

func handleMapLoadError() {
showMapErrorView()
disableCopyButton()
}
}

// MARK: - Private Func
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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?()
}
}
}
Expand Down

0 comments on commit fa44118

Please sign in to comment.