|
@@ -10,7 +10,7 @@ import Foundation
|
|
|
import UIKit
|
|
|
|
|
|
class PhotoCollectionViewAdapter: NSObject {
|
|
|
- var list:[String:[Photo]]?
|
|
|
+ var list:[(String,[Photo])]?
|
|
|
//체크 확인용
|
|
|
var selectedArr = Set<IndexPath>()
|
|
|
|
|
@@ -26,17 +26,16 @@ extension PhotoCollectionViewAdapter:UICollectionViewDataSource, UICollectionVie
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
|
//리스트에서 키값을 얻어온다
|
|
|
guard let list = list else{ return 0 }
|
|
|
- let key = Array(list.keys)[section]
|
|
|
-
|
|
|
- //해당 키값의 데이터 수를 카운트
|
|
|
- return list[key]?.count ?? 0
|
|
|
+ return list[section].1.count
|
|
|
}
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
|
|
|
//타이틀 뷰의 생성
|
|
|
let view = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "PhotoCollectionViewReusableView", for: indexPath) as! PhotoCollectionViewReusableView
|
|
|
guard let list = list else{ return view }
|
|
|
- let key = Array(list.keys)[indexPath.section]
|
|
|
+
|
|
|
+ let key = list[indexPath.first ?? 0].0
|
|
|
+
|
|
|
//키값을 새탕
|
|
|
view.title.text = key
|
|
|
|
|
@@ -47,13 +46,12 @@ extension PhotoCollectionViewAdapter:UICollectionViewDataSource, UICollectionVie
|
|
|
//앨범 이미지 셀을 생성
|
|
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! PhotoCollectionViewCell
|
|
|
guard let list = list else{ return cell }
|
|
|
- let key = Array(list.keys)[indexPath.section]
|
|
|
|
|
|
//해당 키값의 파일정보를 얻어 이미지를 불러온다
|
|
|
- guard let path = list[key]?[indexPath.row].file, let image = getImage(path: path) else{
|
|
|
+ guard let path = list[indexPath.first ?? 0].1[indexPath.row].file, let image = getImage(path: path) else{
|
|
|
return cell
|
|
|
}
|
|
|
- if list[key]?[indexPath.row].isSended == true{
|
|
|
+ if list[indexPath.first ?? 0].1[indexPath.row].isSended == true{
|
|
|
cell.album.borderWidth = 3.0
|
|
|
}else{
|
|
|
cell.album.borderWidth = 0
|
|
@@ -69,21 +67,23 @@ extension PhotoCollectionViewAdapter:UICollectionViewDataSource, UICollectionVie
|
|
|
|
|
|
//길게 누를 경우 이벤트
|
|
|
cell.addLongPressGestureRecognizer { [weak self] in
|
|
|
-
|
|
|
+ guard let `self` = self else{ return }
|
|
|
let app = UIApplication.shared.delegate as! AppDelegate
|
|
|
- let nav = app.visibleViewController?.navigationController as! UINavigationController
|
|
|
+ guard let nav = app.visibleViewController?.navigationController as? UINavigationController else{ return }
|
|
|
|
|
|
let alert = UIAlertController(title: "선택", message: "", preferredStyle: .actionSheet)
|
|
|
|
|
|
//개별 앨범 이미지를 삭제한다
|
|
|
alert.addAction(UIAlertAction(title: "삭제", style: .destructive){ [weak collectionView](action) in
|
|
|
- if let photo = list[key]?[indexPath.row]{
|
|
|
- self?.list?[key]?.remove(at: indexPath.row)
|
|
|
+ do {
|
|
|
+ let photos = list[indexPath.first ?? 0].1
|
|
|
+ let photo = photos[indexPath.row]
|
|
|
if let file = photo.file{
|
|
|
- self?.fileDelete(file: file)
|
|
|
+ self.fileDelete(file: file)
|
|
|
}
|
|
|
let _ = photo.delete()
|
|
|
- collectionView?.reloadData()
|
|
|
+ self.selectedArr = self.selectedArr.filter({$0 != indexPath})
|
|
|
+ CustomCameraViewController.photoProcessCommit.value = nil
|
|
|
}
|
|
|
|
|
|
})
|
|
@@ -93,7 +93,9 @@ extension PhotoCollectionViewAdapter:UICollectionViewDataSource, UICollectionVie
|
|
|
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
|
|
|
let VC = storyBoard.instantiateViewController(withIdentifier: "PhotoDetailViewController") as! PhotoDetailViewController
|
|
|
VC.image = image
|
|
|
- if let photo = list[key]?[indexPath.row]{
|
|
|
+ do {
|
|
|
+ let photos = list[indexPath.first ?? 0].1
|
|
|
+ let photo = photos[indexPath.row]
|
|
|
VC.photo = photo
|
|
|
VC.callBack = { [weak collectionView] in
|
|
|
collectionView?.reloadData()
|