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
3 changes: 2 additions & 1 deletion Pinit/Pinit/Extensions/Extension_UIViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ extension UIViewController {

// Container view for the toast
let containerView = UIView()
containerView.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.6)
// containerView.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.6)
containerView.backgroundColor = DesignSystemColor.Lavender.value.withAlphaComponent(0.9)
containerView.layer.cornerRadius = 4
containerView.clipsToBounds = true
blockingView.addSubview(containerView)
Expand Down
8 changes: 5 additions & 3 deletions Pinit/Pinit/Views/Home/CustomBottomSheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ import UIKit

final class CustomBottomSheet: UIView {
var collectionView = UICollectionView(frame: .zero, collectionViewLayout: .init())

let grabber: UIView = {
let grabber = UIView()
grabber.layer.cornerRadius = 4
grabber.backgroundColor = .black
grabber.backgroundColor = DesignSystemColor.Purple.value
grabber.layer.borderColor = UIColor.white.cgColor
grabber.layer.borderWidth = 1
grabber.clipsToBounds = true
grabber.isUserInteractionEnabled = false //Grabber는 Guide용으로만 사용
return grabber
}()

init() {
super.init(frame: .zero)
setupLayout()
Expand All @@ -36,7 +38,7 @@ final class CustomBottomSheet: UIView {
self.layer.maskedCorners = .init(arrayLiteral: [.layerMaxXMinYCorner, .layerMinXMinYCorner])

addSubviews(collectionView, grabber)

grabber.snp.makeConstraints {
$0.centerX.equalToSuperview()
$0.top.equalToSuperview().offset(8)
Expand All @@ -45,7 +47,7 @@ final class CustomBottomSheet: UIView {
}

collectionView.snp.makeConstraints {
$0.top.equalToSuperview().offset(cornerRadius*1.5)
$0.top.equalToSuperview().offset(cornerRadius*1.8)
$0.leading.trailing.bottom.equalToSuperview()
}
}
Expand Down
32 changes: 24 additions & 8 deletions Pinit/Pinit/Views/Home/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class HomeViewController: UIViewController {
let image = UIImage(systemName: "pencil.line")
button.setImage(UIImage(systemName: "pencil.line"), for: .normal)
button.backgroundColor = .secondarySystemBackground
button.tintColor = DesignSystemColor.Purple.value
button.layer.cornerRadius = circleButtonSize / 2
button.clipsToBounds = true
return button
Expand All @@ -34,6 +35,7 @@ class HomeViewController: UIViewController {
let button = UIButton()
button.setImage(UIImage(systemName: "dot.scope"), for: .normal)
button.backgroundColor = .secondarySystemBackground
button.tintColor = DesignSystemColor.Purple.value
button.layer.cornerRadius = circleButtonSize / 2
button.clipsToBounds = true
return button
Expand All @@ -56,6 +58,11 @@ class HomeViewController: UIViewController {
setupLayout()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
loadAnnotations()
}

private func setupMapLocation() {
locationmanager.delegate = self
mapView.delegate = self
Expand All @@ -71,18 +78,21 @@ class HomeViewController: UIViewController {
animated: true
)
mapView.isRotateEnabled = false
// mapView.register(CustomAnnotationView.self, forAnnotationViewWithReuseIdentifier: CustomAnnotationView.identifier)
// mapView.register(CustomAnnotationView.self, forAnnotationViewWithReuseIdentifier: CustomAnnotationView.identifier)
mapView.register(MKMarkerAnnotationView.self, forAnnotationViewWithReuseIdentifier: "annotation")
mapView.register(CustomClusterAnnotationView.self, forAnnotationViewWithReuseIdentifier: CustomClusterAnnotationView.identifier)

loadAnnotations()
}

private func loadAnnotations() {
mapView.removeAnnotations(mapView.annotations)
usecase.fetchAllPins { pins in
let annotations = pins.map { CustomAnnotation(pinData: $0) }
self.mapView.addAnnotations(annotations)
self.mapView(self.mapView, regionDidChangeAnimated: true)
self.adapter?.data = pins.sorted(by: { $0.date > $1.date })
self.bottomSheet.collectionView.reloadData()
}
}

Expand Down Expand Up @@ -150,7 +160,7 @@ extension HomeViewController: MKMapViewDelegate {
let view = mapView.dequeueReusableAnnotationView(withIdentifier: "annotation", for: annotation) as! MKMarkerAnnotationView
view.annotation = annotation
view.clusteringIdentifier = "pinCluster" // 클러스터링 가능하게

return view
}

Expand All @@ -174,10 +184,14 @@ extension HomeViewController: MKMapViewDelegate {
}
func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
let visibleAnnotations = mapView.annotations(in: mapView.visibleMapRect)
let visibleMarkers = visibleAnnotations.compactMap { $0 as? CustomAnnotation }
// let visibleClusters = visibleAnnotations.compactMap{ $0 as? MKClusterAnnotation } // 할필요없음
// BottomSheet의 CollectionView 업데이트
adapter?.data = visibleMarkers.map{ $0.pinData }
let visibleMarkers = visibleAnnotations.compactMap { ($0 as? CustomAnnotation)?.pinData }

guard let adapterData = adapter?.data else { return }
let adapterSet = Set(adapterData.map(\.pin_id))
let temp = Set(visibleMarkers.map{$0.pin_id}).symmetricDifference(adapterSet).count
guard temp != 0 else { return }

adapter?.data = visibleMarkers.sorted(by: { $0.date > $1.date })
bottomSheet.collectionView.reloadData()
}
}
Expand Down Expand Up @@ -205,11 +219,11 @@ extension HomeViewController: CLLocationManagerDelegate {

// MARK: PinCollectionViewAdapterDelegate
extension HomeViewController: PinCollectionViewAdapterDelegate {
func selectedItem(selected: PinEntity) {
func selectedItem(selected: PinEntity, indexPath: IndexPath) {
presentPinDetailViewController(selected: selected)
}

func deletedItem(deleted: PinEntity?) {
func deletedItem(deleted: PinEntity?, indexPath: IndexPath) {
guard let deleted = deleted else { return }
usecase.deletePin(pinID: deleted.pin_id)
removePinEntity(pinEntity: deleted)
Expand Down Expand Up @@ -251,6 +265,8 @@ extension HomeViewController {
mapView.removeAnnotation(annotationToRemove)
}
mapView(mapView, regionDidChangeAnimated: true)
adapter?.data = adapter?.data.filter{$0.pin_id != pinEntity.pin_id} ?? []
bottomSheet.collectionView.reloadData()
}
}

Expand Down
9 changes: 5 additions & 4 deletions Pinit/Pinit/Views/Home/PinCollectionViewAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import UIKit
// MARK: CollectionView Adapter Delegate
protocol PinCollectionViewAdapterDelegate: AnyObject {
// 선택된 아이템 넘겨줌
func selectedItem(selected: PinEntity)
func selectedItem(selected: PinEntity, indexPath: IndexPath)
// 삭제된 아이템 넘겨줌 (id만 넘겨줄지 고민중 CoreData에서 id에 따라 삭제하는거 말고는 필요 없어서)
func deletedItem(deleted: PinEntity?)
func deletedItem(deleted: PinEntity?, indexPath: IndexPath)
}

// MARK: CollectionView Adapter
Expand Down Expand Up @@ -49,6 +49,7 @@ extension PinCollectionViewAdapter: UICollectionViewDataSource {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as? PinRecordCell
else { return UICollectionViewCell() }

cell.thumbnailImageView.image = nil
cell.configure(model: data[indexPath.row])
cell.layoutIfNeeded()

Expand All @@ -59,7 +60,7 @@ extension PinCollectionViewAdapter: UICollectionViewDataSource {
// MARK: CollectionView Delegate
extension PinCollectionViewAdapter: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
delegate?.selectedItem(selected: data[indexPath.row]) // 선택된 아이템 delegate로 보냄
delegate?.selectedItem(selected: data[indexPath.row], indexPath: indexPath) // 선택된 아이템 delegate로 보냄
}

func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemsAt indexPaths: [IndexPath], point: CGPoint) -> UIContextMenuConfiguration? {
Expand All @@ -69,7 +70,7 @@ extension PinCollectionViewAdapter: UICollectionViewDelegate {
return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { elements in
let deleteAction = UIAction(title: "삭제", image: UIImage(systemName: "trash"), attributes: .destructive) {[weak self] action in
let deleted = self?.data.remove(at: indexPath.row)
self?.delegate?.deletedItem(deleted: deleted) // 삭제된 아이템 delegate로 보냄
self?.delegate?.deletedItem(deleted: deleted, indexPath: indexPath) // 삭제된 아이템 delegate로 보냄
}
return UIMenu(title: "", children: [deleteAction])
}
Expand Down
4 changes: 2 additions & 2 deletions Pinit/Pinit/Views/Home/PinRecordCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ final class PinRecordCell: UICollectionViewCell {
view.layer.shadowOffset = CGSize(width: 0, height: 4)
return view
}()
private lazy var thumbnailImageView: UIImageView = {
public lazy var thumbnailImageView: UIImageView = {
let imageView = UIImageView()
imageView.contentMode = .scaleAspectFit
imageView.contentMode = .scaleToFill
imageView.backgroundColor = .lightGray
return imageView
}()
Expand Down
4 changes: 2 additions & 2 deletions Pinit/Pinit/Views/MainTabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class MainTabBarController: UITabBarController {
appearance.shadowColor = UIColor.clear

// set tabbar background color
appearance.backgroundColor = .white
appearance.backgroundColor = .secondarySystemBackground

tabBar.standardAppearance = appearance

Expand All @@ -34,7 +34,7 @@ final class MainTabBarController: UITabBarController {
}

// set tabbar tintColor
tabBar.tintColor = .black
tabBar.tintColor = DesignSystemColor.Purple.value

// set tabbar shadow
tabBar.layer.masksToBounds = false
Expand Down
10 changes: 6 additions & 4 deletions Pinit/Pinit/Views/PastPin/PastPinViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,20 @@ extension PastPinViewController : FSCalendarDelegate, FSCalendarDataSource, FSCa
//MARK: - extension
extension PastPinViewController : PinCollectionViewAdapterDelegate {

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

func deletedItem(deleted: PinEntity?) { //아이템 삭제 클릭시
func deletedItem(deleted: PinEntity?, indexPath: IndexPath) { //아이템 삭제 클릭시
guard let deleted = deleted else { return }
usecase.deletePin(pinID: deleted.pin_id)
self.pinData = pinData.filter{ $0.pin_id != deleted.pin_id }
Expand Down
5 changes: 5 additions & 0 deletions Pinit/Pinit/Views/PinDetail/PinDetailHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ class PinDetailHeader: UIView {
private lazy var pinImageView: UIImageView = {
let imageView = UIImageView()
imageView.image = entity.mediaPath
imageView.backgroundColor = DesignSystemColor.Lavender.value
// imageView.layer.borderWidth = 4
// imageView.layer.borderColor = DesignSystemColor.Purple.value.cgColor
imageView.layer.cornerRadius = 8
imageView.contentMode = .scaleAspectFit
imageView.clipsToBounds = true
return imageView
}()

Expand Down
8 changes: 6 additions & 2 deletions Pinit/Pinit/Views/PinDetail/PinDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,21 @@ extension PinDetailViewController {
self.useCase.updatePin(pin: pin)
self.updatePinNoti!(self.pinEntity, pin)
self.pinEntity = pin
// 디테일 화면 수정
#warning("업데이트 후 헤더 업데이트 해줘야함ㅇㅇ")
}
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: true, completion: nil)
}

let deleteAction = UIAlertAction(title: "삭제", style: .destructive) { _ in
print("삭제")
self.useCase.deletePin(pinID: (self.pinEntity.pin_id))
self.deletePinNoti?(self.pinEntity)
self.dismiss(animated: true, completion: nil)
self.dismiss(animated: true){
self.showToast(message: "삭제가 완료되었습니다.")
}
}

let cancelAction = UIAlertAction(title: "취소", style: .cancel, handler: nil)

actionSheet.addAction(editAction)
Expand Down
31 changes: 26 additions & 5 deletions Pinit/Pinit/Views/PinEdit/PinEditViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ final class PinEditViewController: UIViewController, UITextViewDelegate {
var pinEntity: PinEntity?
var pinmode: PinMode?
var isAdded: ((PinEntity) -> Void)? // 핀추가가 됐을때 호출되는 클로저 (홈에서만 사용)
private var pickedImage: UIImage?

public lazy var mapView: MKMapView = {
var map = MKMapView()
Expand Down Expand Up @@ -247,9 +248,16 @@ final class PinEditViewController: UIViewController, UITextViewDelegate {

//MARK: 저장버튼 눌림
@objc private func saveButtonTapped() {
guard let text = titleTextField.text, !text.isEmpty else {
self.showToast(message: "제목을 입력해주세요.")
return
}

pinEntity?.title = titleTextField.text ?? ""
pinEntity?.description = contentTextView.text ?? ""
// pinEntity?.mediaPath = image ????

pinEntity?.mediaPath = pickedImage

isAdded?(pinEntity!)
dismiss(animated: true)
}
Expand All @@ -269,6 +277,7 @@ final class PinEditViewController: UIViewController, UITextViewDelegate {
self.presentImagePicker(sourceType: .photoLibrary)
}
let cancelAction = UIAlertAction(title: "취소", style: .cancel, handler: nil)

actionSheet.addAction(cameraAction)
actionSheet.addAction(galleryAction)
actionSheet.addAction(cancelAction)
Expand All @@ -282,7 +291,7 @@ final class PinEditViewController: UIViewController, UITextViewDelegate {
let imagePicker = UIImagePickerController()
imagePicker.sourceType = sourceType
imagePicker.delegate = self
imagePicker.allowsEditing = true
// imagePicker.allowsEditing = true

present(imagePicker, animated: true, completion: nil)
}
Expand Down Expand Up @@ -332,10 +341,22 @@ final class PinEditViewController: UIViewController, UITextViewDelegate {

//MARK: - PinEditViewController 내에서 사진 선택 기능을 쉽게 사용
extension PinEditViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let selectedImage = info[.editedImage] as? UIImage ?? info[.originalImage] as? UIImage {
// Handle the selected image (save, display, etc.)
print("Selected Image: \(selectedImage)")
self.pickedImage = selectedImage
cameraButton.backgroundColor = .clear
cameraButton.setImage(nil, for: .normal)
//
// // 이미지를 버튼 크기에 맞게 조정하여 설정
// let resizedImage = resizeImage(image: pickedImage, targetSize: CGSize(width: 150, height: 150))

cameraButton.clipsToBounds = true
cameraButton.layer.cornerRadius = 75
cameraButton.setBackgroundImage(pickedImage, for: .normal)

// 선택한 이미지를 pinEntity에 저장 (나중에 경로로 변환하는 로직 추가 필요)
// pinEntity?.mediaPath = ...
}
picker.dismiss(animated: true, completion: nil)
}
Expand All @@ -348,5 +369,5 @@ extension PinEditViewController: UIImagePickerControllerDelegate, UINavigationCo
#Preview{

PinEditViewController()

}