Skip to content

Commit e5f733c

Browse files
authored
Merge pull request #34 from kut7728/feature/#33
[FEAT] Fix almost errors and data handling with HMM
2 parents 4208e77 + b68eee9 commit e5f733c

10 files changed

Lines changed: 83 additions & 31 deletions

Pinit/Pinit/Extensions/Extension_UIViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ extension UIViewController {
3535

3636
// Container view for the toast
3737
let containerView = UIView()
38-
containerView.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.6)
38+
// containerView.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.6)
39+
containerView.backgroundColor = DesignSystemColor.Lavender.value.withAlphaComponent(0.9)
3940
containerView.layer.cornerRadius = 4
4041
containerView.clipsToBounds = true
4142
blockingView.addSubview(containerView)

Pinit/Pinit/Views/Home/CustomBottomSheet.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ import UIKit
99

1010
final class CustomBottomSheet: UIView {
1111
var collectionView = UICollectionView(frame: .zero, collectionViewLayout: .init())
12+
1213
let grabber: UIView = {
1314
let grabber = UIView()
1415
grabber.layer.cornerRadius = 4
15-
grabber.backgroundColor = .black
16+
grabber.backgroundColor = DesignSystemColor.Purple.value
1617
grabber.layer.borderColor = UIColor.white.cgColor
1718
grabber.layer.borderWidth = 1
1819
grabber.clipsToBounds = true
1920
grabber.isUserInteractionEnabled = false //Grabber는 Guide용으로만 사용
2021
return grabber
2122
}()
23+
2224
init() {
2325
super.init(frame: .zero)
2426
setupLayout()
@@ -36,7 +38,7 @@ final class CustomBottomSheet: UIView {
3638
self.layer.maskedCorners = .init(arrayLiteral: [.layerMaxXMinYCorner, .layerMinXMinYCorner])
3739

3840
addSubviews(collectionView, grabber)
39-
41+
4042
grabber.snp.makeConstraints {
4143
$0.centerX.equalToSuperview()
4244
$0.top.equalToSuperview().offset(8)
@@ -45,7 +47,7 @@ final class CustomBottomSheet: UIView {
4547
}
4648

4749
collectionView.snp.makeConstraints {
48-
$0.top.equalToSuperview().offset(cornerRadius*1.5)
50+
$0.top.equalToSuperview().offset(cornerRadius*1.8)
4951
$0.leading.trailing.bottom.equalToSuperview()
5052
}
5153
}

Pinit/Pinit/Views/Home/HomeViewController.swift

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class HomeViewController: UIViewController {
2626
let image = UIImage(systemName: "pencil.line")
2727
button.setImage(UIImage(systemName: "pencil.line"), for: .normal)
2828
button.backgroundColor = .secondarySystemBackground
29+
button.tintColor = DesignSystemColor.Purple.value
2930
button.layer.cornerRadius = circleButtonSize / 2
3031
button.clipsToBounds = true
3132
return button
@@ -34,6 +35,7 @@ class HomeViewController: UIViewController {
3435
let button = UIButton()
3536
button.setImage(UIImage(systemName: "dot.scope"), for: .normal)
3637
button.backgroundColor = .secondarySystemBackground
38+
button.tintColor = DesignSystemColor.Purple.value
3739
button.layer.cornerRadius = circleButtonSize / 2
3840
button.clipsToBounds = true
3941
return button
@@ -56,6 +58,11 @@ class HomeViewController: UIViewController {
5658
setupLayout()
5759
}
5860

61+
override func viewWillAppear(_ animated: Bool) {
62+
super.viewWillAppear(animated)
63+
loadAnnotations()
64+
}
65+
5966
private func setupMapLocation() {
6067
locationmanager.delegate = self
6168
mapView.delegate = self
@@ -71,18 +78,21 @@ class HomeViewController: UIViewController {
7178
animated: true
7279
)
7380
mapView.isRotateEnabled = false
74-
// mapView.register(CustomAnnotationView.self, forAnnotationViewWithReuseIdentifier: CustomAnnotationView.identifier)
81+
// mapView.register(CustomAnnotationView.self, forAnnotationViewWithReuseIdentifier: CustomAnnotationView.identifier)
7582
mapView.register(MKMarkerAnnotationView.self, forAnnotationViewWithReuseIdentifier: "annotation")
7683
mapView.register(CustomClusterAnnotationView.self, forAnnotationViewWithReuseIdentifier: CustomClusterAnnotationView.identifier)
7784

7885
loadAnnotations()
7986
}
8087

8188
private func loadAnnotations() {
89+
mapView.removeAnnotations(mapView.annotations)
8290
usecase.fetchAllPins { pins in
8391
let annotations = pins.map { CustomAnnotation(pinData: $0) }
8492
self.mapView.addAnnotations(annotations)
8593
self.mapView(self.mapView, regionDidChangeAnimated: true)
94+
self.adapter?.data = pins.sorted(by: { $0.date > $1.date })
95+
self.bottomSheet.collectionView.reloadData()
8696
}
8797
}
8898

@@ -150,7 +160,7 @@ extension HomeViewController: MKMapViewDelegate {
150160
let view = mapView.dequeueReusableAnnotationView(withIdentifier: "annotation", for: annotation) as! MKMarkerAnnotationView
151161
view.annotation = annotation
152162
view.clusteringIdentifier = "pinCluster" // 클러스터링 가능하게
153-
163+
154164
return view
155165
}
156166

@@ -174,10 +184,14 @@ extension HomeViewController: MKMapViewDelegate {
174184
}
175185
func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
176186
let visibleAnnotations = mapView.annotations(in: mapView.visibleMapRect)
177-
let visibleMarkers = visibleAnnotations.compactMap { $0 as? CustomAnnotation }
178-
// let visibleClusters = visibleAnnotations.compactMap{ $0 as? MKClusterAnnotation } // 할필요없음
179-
// BottomSheet의 CollectionView 업데이트
180-
adapter?.data = visibleMarkers.map{ $0.pinData }
187+
let visibleMarkers = visibleAnnotations.compactMap { ($0 as? CustomAnnotation)?.pinData }
188+
189+
guard let adapterData = adapter?.data else { return }
190+
let adapterSet = Set(adapterData.map(\.pin_id))
191+
let temp = Set(visibleMarkers.map{$0.pin_id}).symmetricDifference(adapterSet).count
192+
guard temp != 0 else { return }
193+
194+
adapter?.data = visibleMarkers.sorted(by: { $0.date > $1.date })
181195
bottomSheet.collectionView.reloadData()
182196
}
183197
}
@@ -205,11 +219,11 @@ extension HomeViewController: CLLocationManagerDelegate {
205219

206220
// MARK: PinCollectionViewAdapterDelegate
207221
extension HomeViewController: PinCollectionViewAdapterDelegate {
208-
func selectedItem(selected: PinEntity) {
222+
func selectedItem(selected: PinEntity, indexPath: IndexPath) {
209223
presentPinDetailViewController(selected: selected)
210224
}
211225

212-
func deletedItem(deleted: PinEntity?) {
226+
func deletedItem(deleted: PinEntity?, indexPath: IndexPath) {
213227
guard let deleted = deleted else { return }
214228
usecase.deletePin(pinID: deleted.pin_id)
215229
removePinEntity(pinEntity: deleted)
@@ -251,6 +265,8 @@ extension HomeViewController {
251265
mapView.removeAnnotation(annotationToRemove)
252266
}
253267
mapView(mapView, regionDidChangeAnimated: true)
268+
adapter?.data = adapter?.data.filter{$0.pin_id != pinEntity.pin_id} ?? []
269+
bottomSheet.collectionView.reloadData()
254270
}
255271
}
256272

Pinit/Pinit/Views/Home/PinCollectionViewAdapter.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import UIKit
1010
// MARK: CollectionView Adapter Delegate
1111
protocol PinCollectionViewAdapterDelegate: AnyObject {
1212
// 선택된 아이템 넘겨줌
13-
func selectedItem(selected: PinEntity)
13+
func selectedItem(selected: PinEntity, indexPath: IndexPath)
1414
// 삭제된 아이템 넘겨줌 (id만 넘겨줄지 고민중 CoreData에서 id에 따라 삭제하는거 말고는 필요 없어서)
15-
func deletedItem(deleted: PinEntity?)
15+
func deletedItem(deleted: PinEntity?, indexPath: IndexPath)
1616
}
1717

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

52+
cell.thumbnailImageView.image = nil
5253
cell.configure(model: data[indexPath.row])
5354
cell.layoutIfNeeded()
5455

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

6566
func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemsAt indexPaths: [IndexPath], point: CGPoint) -> UIContextMenuConfiguration? {
@@ -69,7 +70,7 @@ extension PinCollectionViewAdapter: UICollectionViewDelegate {
6970
return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { elements in
7071
let deleteAction = UIAction(title: "삭제", image: UIImage(systemName: "trash"), attributes: .destructive) {[weak self] action in
7172
let deleted = self?.data.remove(at: indexPath.row)
72-
self?.delegate?.deletedItem(deleted: deleted) // 삭제된 아이템 delegate로 보냄
73+
self?.delegate?.deletedItem(deleted: deleted, indexPath: indexPath) // 삭제된 아이템 delegate로 보냄
7374
}
7475
return UIMenu(title: "", children: [deleteAction])
7576
}

Pinit/Pinit/Views/Home/PinRecordCell.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ final class PinRecordCell: UICollectionViewCell {
1919
view.layer.shadowOffset = CGSize(width: 0, height: 4)
2020
return view
2121
}()
22-
private lazy var thumbnailImageView: UIImageView = {
22+
public lazy var thumbnailImageView: UIImageView = {
2323
let imageView = UIImageView()
24-
imageView.contentMode = .scaleAspectFit
24+
imageView.contentMode = .scaleToFill
2525
imageView.backgroundColor = .lightGray
2626
return imageView
2727
}()

Pinit/Pinit/Views/MainTabBarController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class MainTabBarController: UITabBarController {
2424
appearance.shadowColor = UIColor.clear
2525

2626
// set tabbar background color
27-
appearance.backgroundColor = .white
27+
appearance.backgroundColor = .secondarySystemBackground
2828

2929
tabBar.standardAppearance = appearance
3030

@@ -34,7 +34,7 @@ final class MainTabBarController: UITabBarController {
3434
}
3535

3636
// set tabbar tintColor
37-
tabBar.tintColor = .black
37+
tabBar.tintColor = DesignSystemColor.Purple.value
3838

3939
// set tabbar shadow
4040
tabBar.layer.masksToBounds = false

Pinit/Pinit/Views/PastPin/PastPinViewController.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,20 @@ extension PastPinViewController : FSCalendarDelegate, FSCalendarDataSource, FSCa
149149
//MARK: - extension
150150
extension PastPinViewController : PinCollectionViewAdapterDelegate {
151151

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

163-
func deletedItem(deleted: PinEntity?) { //아이템 삭제 클릭시
165+
func deletedItem(deleted: PinEntity?, indexPath: IndexPath) { //아이템 삭제 클릭시
164166
guard let deleted = deleted else { return }
165167
usecase.deletePin(pinID: deleted.pin_id)
166168
self.pinData = pinData.filter{ $0.pin_id != deleted.pin_id }

Pinit/Pinit/Views/PinDetail/PinDetailHeader.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ class PinDetailHeader: UIView {
6969
private lazy var pinImageView: UIImageView = {
7070
let imageView = UIImageView()
7171
imageView.image = entity.mediaPath
72+
imageView.backgroundColor = DesignSystemColor.Lavender.value
73+
// imageView.layer.borderWidth = 4
74+
// imageView.layer.borderColor = DesignSystemColor.Purple.value.cgColor
75+
imageView.layer.cornerRadius = 8
7276
imageView.contentMode = .scaleAspectFit
77+
imageView.clipsToBounds = true
7378
return imageView
7479
}()
7580

Pinit/Pinit/Views/PinDetail/PinDetailViewController.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,21 @@ extension PinDetailViewController {
186186
self.useCase.updatePin(pin: pin)
187187
self.updatePinNoti!(self.pinEntity, pin)
188188
self.pinEntity = pin
189-
// 디테일 화면 수정
189+
#warning("업데이트 후 헤더 업데이트 해줘야함ㅇㅇ")
190190
}
191191
vc.modalPresentationStyle = .fullScreen
192192
self.present(vc, animated: true, completion: nil)
193193
}
194+
194195
let deleteAction = UIAlertAction(title: "삭제", style: .destructive) { _ in
195196
print("삭제")
196197
self.useCase.deletePin(pinID: (self.pinEntity.pin_id))
197198
self.deletePinNoti?(self.pinEntity)
198-
self.dismiss(animated: true, completion: nil)
199+
self.dismiss(animated: true){
200+
self.showToast(message: "삭제가 완료되었습니다.")
201+
}
199202
}
203+
200204
let cancelAction = UIAlertAction(title: "취소", style: .cancel, handler: nil)
201205

202206
actionSheet.addAction(editAction)

Pinit/Pinit/Views/PinEdit/PinEditViewController.swift

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ final class PinEditViewController: UIViewController, UITextViewDelegate {
2020
var pinEntity: PinEntity?
2121
var pinmode: PinMode?
2222
var isAdded: ((PinEntity) -> Void)? // 핀추가가 됐을때 호출되는 클로저 (홈에서만 사용)
23+
private var pickedImage: UIImage?
2324

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

248249
//MARK: 저장버튼 눌림
249250
@objc private func saveButtonTapped() {
251+
guard let text = titleTextField.text, !text.isEmpty else {
252+
self.showToast(message: "제목을 입력해주세요.")
253+
return
254+
}
255+
250256
pinEntity?.title = titleTextField.text ?? ""
251257
pinEntity?.description = contentTextView.text ?? ""
252-
// pinEntity?.mediaPath = image ????
258+
259+
pinEntity?.mediaPath = pickedImage
260+
253261
isAdded?(pinEntity!)
254262
dismiss(animated: true)
255263
}
@@ -269,6 +277,7 @@ final class PinEditViewController: UIViewController, UITextViewDelegate {
269277
self.presentImagePicker(sourceType: .photoLibrary)
270278
}
271279
let cancelAction = UIAlertAction(title: "취소", style: .cancel, handler: nil)
280+
272281
actionSheet.addAction(cameraAction)
273282
actionSheet.addAction(galleryAction)
274283
actionSheet.addAction(cancelAction)
@@ -282,7 +291,7 @@ final class PinEditViewController: UIViewController, UITextViewDelegate {
282291
let imagePicker = UIImagePickerController()
283292
imagePicker.sourceType = sourceType
284293
imagePicker.delegate = self
285-
imagePicker.allowsEditing = true
294+
// imagePicker.allowsEditing = true
286295

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

333342
//MARK: - PinEditViewController 내에서 사진 선택 기능을 쉽게 사용
334343
extension PinEditViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
344+
335345
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
336346
if let selectedImage = info[.editedImage] as? UIImage ?? info[.originalImage] as? UIImage {
337-
// Handle the selected image (save, display, etc.)
338-
print("Selected Image: \(selectedImage)")
347+
self.pickedImage = selectedImage
348+
cameraButton.backgroundColor = .clear
349+
cameraButton.setImage(nil, for: .normal)
350+
//
351+
// // 이미지를 버튼 크기에 맞게 조정하여 설정
352+
// let resizedImage = resizeImage(image: pickedImage, targetSize: CGSize(width: 150, height: 150))
353+
354+
cameraButton.clipsToBounds = true
355+
cameraButton.layer.cornerRadius = 75
356+
cameraButton.setBackgroundImage(pickedImage, for: .normal)
357+
358+
// 선택한 이미지를 pinEntity에 저장 (나중에 경로로 변환하는 로직 추가 필요)
359+
// pinEntity?.mediaPath = ...
339360
}
340361
picker.dismiss(animated: true, completion: nil)
341362
}
@@ -348,5 +369,5 @@ extension PinEditViewController: UIImagePickerControllerDelegate, UINavigationCo
348369
#Preview{
349370

350371
PinEditViewController()
351-
372+
352373
}

0 commit comments

Comments
 (0)