Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Pinit/Pinit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 5664C7G97A;
DEVELOPMENT_TEAM = UUYBHY988H;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Pinit/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
Expand Down Expand Up @@ -308,7 +308,7 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 5664C7G97A;
DEVELOPMENT_TEAM = UUYBHY988H;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Pinit/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
Expand Down
4 changes: 3 additions & 1 deletion Pinit/Pinit/Service/UseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ final class UseCaseImpl: UseCase {
func fetchAllReviewsByPinID(pinID: UUID, completion: @escaping ([ReviewEntity]) -> Void) {
dbRepository.fetchReviewsByPinId(pinID: pinID) { items in
let reviewEntites = items.compactMap { $0.toReviewEntity() }
completion(reviewEntites)
DispatchQueue.main.async {
completion(reviewEntites)
}
}
}
}
88 changes: 51 additions & 37 deletions Pinit/Pinit/Views/Home/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ class HomeViewController: UIViewController {
setupLayout()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
print("HHH")
// loadAnnotations()
}

private func setupMapLocation() {
locationmanager.delegate = self
mapView.delegate = self
Expand All @@ -80,19 +74,14 @@ class HomeViewController: UIViewController {
mapView.register(CustomAnnotationView.self, forAnnotationViewWithReuseIdentifier: CustomAnnotationView.identifier)
// mapView.register(CustomAnnotationView.self, forAnnotationViewWithReuseIdentifier: "ClusterView")

loadAnnotations(PinEntity.sampleData)
loadAnnotations()
}

private func loadAnnotations(_ samepleData: [PinEntity]? = nil) {
if let sampleData = samepleData { // 테스트용
let annotations = PinEntity.sampleData.map{CustomAnnotation(pinData: $0)}
mapView.addAnnotations(annotations)
}
else {
usecase.fetchAllPins {[weak self] pins in
let annotations = pins.map { CustomAnnotation(pinData: $0) }
self?.mapView.addAnnotations(annotations)
}
private func loadAnnotations() {
usecase.fetchAllPins { pins in
let annotations = pins.map { CustomAnnotation(pinData: $0) }
self.mapView.addAnnotations(annotations)
self.mapView(self.mapView, regionDidChangeAnimated: true)
}
}

Expand Down Expand Up @@ -136,6 +125,7 @@ class HomeViewController: UIViewController {
$0.size.equalTo(circleButtonSize)
}
}

}

// MARK: MapView Delegate
Expand All @@ -154,6 +144,7 @@ extension HomeViewController: MKMapViewDelegate {
return nil

}

private func createCustomAnnotationView(for annotation: CustomAnnotation, in mapView: MKMapView) -> MKAnnotationView {
let identifier = CustomAnnotationView.identifier
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) as? CustomAnnotationView
Expand Down Expand Up @@ -186,16 +177,15 @@ extension HomeViewController: MKMapViewDelegate {

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
if let annotation = view.annotation as? CustomAnnotation {
print("Selected pin ID: \(annotation.pinData.pin_id)")
// 상세 화면 이동
presentPinDetailViewController(selected: annotation.pinData)
}
}
func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
let visibleAnnotations = mapView.annotations(in: mapView.visibleMapRect)
let visibleMarkers = visibleAnnotations.compactMap { $0 as? CustomAnnotation }
// BottomSheet의 CollectionView 업데이트
// adapter?.data = visibleMarkers.map{ $0.pinData }
// bottomSheet.collectionView.reloadData()
adapter?.data = visibleMarkers.map{ $0.pinData }
bottomSheet.collectionView.reloadData()
}
}

Expand Down Expand Up @@ -223,25 +213,50 @@ extension HomeViewController: CLLocationManagerDelegate {
// MARK: PinCollectionViewAdapterDelegate
extension HomeViewController: PinCollectionViewAdapterDelegate {
func selectedItem(selected: PinEntity) {
print("Selected: \(selected)")
// 여기서 화면 이동
let vc = PinDetailViewController(selected, isPin: true)
vc.sendToBack = {[weak self] entity in
guard let entity else { return }
let annotation = CustomAnnotation(pinData: entity)
self?.mapView.removeAnnotation(annotation)
}
present(vc, animated: true)
presentPinDetailViewController(selected: selected)
}

func deletedItem(deleted: PinEntity?) {
print("Deleted: \(deleted?.title ?? "empty")")
// 여기서 CoreData 업데이트
guard let deleted = deleted else { return }
usecase.deletePin(pinID: deleted.pin_id)
let deletedAnnotation = CustomAnnotation(pinData: deleted)
mapView.removeAnnotation(deletedAnnotation)
// 삭제후 현재 위치의 어노테이션이 뭐가 있는지 다시 로드
removePinEntity(pinEntity: deleted)
}
}

// MARK: 화면이동
extension HomeViewController {
private func presentAddPinViewController(lat: Double, lon: Double) {
let vc = PinEditViewController()
vc.modalPresentationStyle = .fullScreen
vc.pinmode = .create(latitude: lat, longtitude: lon)
vc.isAdded = { pin in
let newAnnotation = CustomAnnotation(pinData: pin)
self.usecase.addPin(pin: pin)
self.mapView.addAnnotation(newAnnotation)
self.mapView(self.mapView, regionDidChangeAnimated: true)
}
present(vc, animated: true)
}
private func presentPinDetailViewController(selected: PinEntity) {
let vc = PinDetailViewController(selected, isPin: true)
vc.deletePinNoti = removePinEntity
vc.updatePinNoti = { before, after in
self.removePinEntity(pinEntity: before)
let newAnnotation = CustomAnnotation(pinData: after)
self.mapView.addAnnotation(newAnnotation)
self.mapView(self.mapView, regionDidChangeAnimated: true)
}
present(vc, animated: true)
}

private func removePinEntity(pinEntity: PinEntity) { // 클로저용..
if let annotationToRemove = mapView.annotations.first(
where: { guard let custom = $0 as? CustomAnnotation else { return false }
return custom.pinData.pin_id == pinEntity.pin_id
})
{
mapView.removeAnnotation(annotationToRemove)
}
mapView(mapView, regionDidChangeAnimated: true)
}
}
Expand All @@ -254,8 +269,7 @@ extension HomeViewController {
showAlertAboutLocation()
return
}

print("기록하기 화면으로 이동")
presentAddPinViewController(lat: location.latitude, lon: location.longitude)
}

@objc private func moveToUserLocation() {
Expand Down
16 changes: 12 additions & 4 deletions Pinit/Pinit/Views/PastPin/PastPinViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SnapKit
final class PastPinViewController: UIViewController {

//MARK: - 모든 PinEntity를 가져옵니다.
let pinData = PinEntity.sampleData
var pinData = PinEntity.sampleData

private let usecase: UseCase

Expand Down Expand Up @@ -138,12 +138,20 @@ extension PastPinViewController : FSCalendarDelegate, FSCalendarDataSource, FSCa
extension PastPinViewController : PinCollectionViewAdapterDelegate {

func selectedItem(selected: PinEntity) { //화면 이동
let vc = PinDetailViewController(selected)
self.present(vc, animated: true)
let vc = PinDetailViewController(selected, isPin: true)
vc.deletePinNoti = { pin in
// 여기서 삭제된 핀이 무엇인지 알려주니까 여기서 삭제된 핀 데이터 소스에서 제거하기
}
vc.updatePinNoti = { before, after in
// 여기서 수정된 핀 비포, 애프터로 나오니까 데이터 소스에서 업데이트 하기
}
present(vc, animated: true)
}

func deletedItem(deleted: PinEntity?) { //아이템 삭제 클릭시
print("deletedItem")
guard let deleted = deleted else { return }
usecase.deletePin(pinID: deleted.pin_id)
self.pinData = pinData.filter{ $0.pin_id != deleted.pin_id }
}

}
Expand Down
4 changes: 2 additions & 2 deletions Pinit/Pinit/Views/PinDetail/PinDetailHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ class PinDetailHeader: UIView {
return textView
}()

private lazy var reviewSectionTitle: UILabel = {
public lazy var reviewSectionTitle: UILabel = {
let label = UILabel()
label.text = entity.address == "" ? "방명록" : "리뷰"
label.text = "리뷰"
label.font = DesignSystemFont.Pretendard_Bold20.value
return label
}()
Expand Down
30 changes: 23 additions & 7 deletions Pinit/Pinit/Views/PinDetail/PinDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ final class PinDetailViewController: UIViewController {
private var pinEntity: PinEntity
private var isPin: Bool
private var useCase = DIContainer.usecase
var sendToBack: ((PinEntity?) -> Void)!
var deletePinNoti: ((PinEntity) -> Void)?
var updatePinNoti: ((_ before: PinEntity, _ after: PinEntity) -> Void)?

init(_ entity: PinEntity, isPin: Bool) {
self.pinEntity = entity
Expand Down Expand Up @@ -159,7 +160,12 @@ extension PinDetailViewController {
}

@objc func onCommitButtonTapped() {
var review: ReviewEntity = ReviewEntity(id: UUID(), pinID: pinEntity.pin_id, date: Date(), description: reviewPanelContainer.reviewText.text ?? "")
let review: ReviewEntity = ReviewEntity(
id: UUID(),
pinID: pinEntity.pin_id,
date: Date(),
description: reviewPanelContainer.reviewText.text ?? ""
)

reviewPanelContainer.reviewText.text = ""

Expand All @@ -175,14 +181,21 @@ extension PinDetailViewController {
let editAction = UIAlertAction(title: "수정", style: .default) { _ in
print("수정")
let vc = PinEditViewController()
vc.pinmode = .edit(PinEntity: self.pinEntity)
vc.isAdded = { pin in
self.useCase.updatePin(pin: pin)
self.updatePinNoti!(self.pinEntity, pin)
self.pinEntity = pin
// 디테일 화면 수정
}
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: true, completion: nil)
}
let deleteAction = UIAlertAction(title: "삭제", style: .destructive) {[weak self] _ in
let deleteAction = UIAlertAction(title: "삭제", style: .destructive) { _ in
print("삭제")
self?.useCase.deletePin(pinID: (self?.pinEntity.pin_id)!)
self?.sendToBack(self?.pinEntity)
self?.dismiss(animated: true, completion: nil)
self.useCase.deletePin(pinID: (self.pinEntity.pin_id))
self.deletePinNoti?(self.pinEntity)
self.dismiss(animated: true, completion: nil)
}
let cancelAction = UIAlertAction(title: "취소", style: .cancel, handler: nil)

Expand Down Expand Up @@ -239,7 +252,10 @@ extension PinDetailViewController: UITableViewDataSource, UITableViewDelegate {
// viewForHeaderInSection
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = PinDetailHeader(entity: pinEntity)
if !isPin { header.pinMenuButton.isHidden = true }
if !isPin {
header.pinMenuButton.isHidden = true
header.reviewSectionTitle.text = "방명록"
}
header.pinMenuButton.addTarget(self, action: #selector(pinMenuButtonTapped), for: .touchUpInside)
return header
}
Expand Down
Loading