From cbf7837eed94077f3378c7ea826c5c440de379c1 Mon Sep 17 00:00:00 2001 From: "naoto.suzuki" Date: Wed, 27 Jul 2022 20:00:07 +0900 Subject: [PATCH 01/21] test sample ui. --- NohanaImagePicker.xcodeproj/project.pbxproj | 8 ++ .../AssetListSelectableDateSection.storyboard | 4 +- ...tListSelectableDateSectionController.swift | 74 ++++++++++- .../PhotoAuthorizationLimitedCell.swift | 31 +++++ .../PhotoAuthorizationLimitedCell.xib | 120 ++++++++++++++++++ 5 files changed, 228 insertions(+), 9 deletions(-) create mode 100644 NohanaImagePicker/PhotoAuthorizationLimitedCell.swift create mode 100644 NohanaImagePicker/PhotoAuthorizationLimitedCell.xib diff --git a/NohanaImagePicker.xcodeproj/project.pbxproj b/NohanaImagePicker.xcodeproj/project.pbxproj index 93471c5..4fdbb7d 100644 --- a/NohanaImagePicker.xcodeproj/project.pbxproj +++ b/NohanaImagePicker.xcodeproj/project.pbxproj @@ -17,6 +17,8 @@ 6AD1607C27700F0C00A8B066 /* RootViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AD1607B27700F0C00A8B066 /* RootViewController.swift */; }; 6AD1607F2770B23D00A8B066 /* UIApplication+Ex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6AD1607E2770B23D00A8B066 /* UIApplication+Ex.swift */; }; F117F732273B6A2600E11BC7 /* AssetDateSectionCreater.swift in Sources */ = {isa = PBXBuildFile; fileRef = F117F731273B6A2600E11BC7 /* AssetDateSectionCreater.swift */; }; + F145C5E22890F8DC0070A4E2 /* PhotoAuthorizationLimitedCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F145C5E02890F8DC0070A4E2 /* PhotoAuthorizationLimitedCell.swift */; }; + F145C5E32890F8DC0070A4E2 /* PhotoAuthorizationLimitedCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F145C5E12890F8DC0070A4E2 /* PhotoAuthorizationLimitedCell.xib */; }; F181095026A5361A001C2BDE /* MomentDetailListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F181094F26A5361A001C2BDE /* MomentDetailListViewController.swift */; }; F1A26CCD2738DE6A00433E9F /* AssetListSelectableDateSection.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F1A26CCC2738DE6A00433E9F /* AssetListSelectableDateSection.storyboard */; }; F1A26CCF2738E7E400433E9F /* AssetListSelectableDateSectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1A26CCE2738E7E400433E9F /* AssetListSelectableDateSectionController.swift */; }; @@ -99,6 +101,8 @@ 6AD1607B27700F0C00A8B066 /* RootViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootViewController.swift; sourceTree = ""; }; 6AD1607E2770B23D00A8B066 /* UIApplication+Ex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIApplication+Ex.swift"; sourceTree = ""; }; F117F731273B6A2600E11BC7 /* AssetDateSectionCreater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetDateSectionCreater.swift; sourceTree = ""; }; + F145C5E02890F8DC0070A4E2 /* PhotoAuthorizationLimitedCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhotoAuthorizationLimitedCell.swift; sourceTree = ""; }; + F145C5E12890F8DC0070A4E2 /* PhotoAuthorizationLimitedCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PhotoAuthorizationLimitedCell.xib; sourceTree = ""; }; F181094F26A5361A001C2BDE /* MomentDetailListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MomentDetailListViewController.swift; sourceTree = ""; }; F1A26CCC2738DE6A00433E9F /* AssetListSelectableDateSection.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = AssetListSelectableDateSection.storyboard; sourceTree = ""; }; F1A26CCE2738E7E400433E9F /* AssetListSelectableDateSectionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AssetListSelectableDateSectionController.swift; sourceTree = ""; }; @@ -233,6 +237,8 @@ F1A26CCC2738DE6A00433E9F /* AssetListSelectableDateSection.storyboard */, F27029CD1C71C43A001647AB /* NohanaImagePicker.strings */, F237249A1C6DCF96005D1E8A /* NohanaImagePicker.xcassets */, + F145C5E02890F8DC0070A4E2 /* PhotoAuthorizationLimitedCell.swift */, + F145C5E12890F8DC0070A4E2 /* PhotoAuthorizationLimitedCell.xib */, ); name = Resources; sourceTree = ""; @@ -439,6 +445,7 @@ F237249B1C6DCF96005D1E8A /* NohanaImagePicker.xcassets in Resources */, 6A8047FF276C3D77000F3B28 /* AlbumList.storyboard in Resources */, F1A26CCD2738DE6A00433E9F /* AssetListSelectableDateSection.storyboard in Resources */, + F145C5E32890F8DC0070A4E2 /* PhotoAuthorizationLimitedCell.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -479,6 +486,7 @@ F2131F431C79615700797887 /* SwipeInteractionController.swift in Sources */, F2DF3B2D1C6D780100C1C0E4 /* AssetDetailCell.swift in Sources */, F25C69901CA27311005935D6 /* EmptyIndicatable.swift in Sources */, + F145C5E22890F8DC0070A4E2 /* PhotoAuthorizationLimitedCell.swift in Sources */, F117F732273B6A2600E11BC7 /* AssetDateSectionCreater.swift in Sources */, F2DA29771C7749D600B0A8E3 /* NotificationInfo.swift in Sources */, F1A26CCF2738E7E400433E9F /* AssetListSelectableDateSectionController.swift in Sources */, diff --git a/NohanaImagePicker/AssetListSelectableDateSection.storyboard b/NohanaImagePicker/AssetListSelectableDateSection.storyboard index d3a2094..7e0bf44 100644 --- a/NohanaImagePicker/AssetListSelectableDateSection.storyboard +++ b/NohanaImagePicker/AssetListSelectableDateSection.storyboard @@ -1,9 +1,9 @@ - + - + diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index bb619ec..b0b7fda 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -49,6 +49,7 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo setUpToolbarItems() addPickPhotoKitAssetNotificationObservers() setUpActivityIndicator() + collectionView.register(UINib(nibName: "PhotoAuthorizationLimitedCell", bundle: self.nohanaImagePickerController.assetBundle), forCellWithReuseIdentifier: PhotoAuthorizationLimitedCell.defaultReusableId) DispatchQueue.main.async { [weak self] in guard let self = self else { return } self.dateSectionList = AssetDateSectionCreater().createSections(assetList: self.photoKitAssetList.assetList, options: PhotoKitAssetList.fetchOptions(self.photoKitAssetList.mediaType, ascending: false)) @@ -88,21 +89,60 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo updateVisibilityOfActivityIndicator(activityIndicator) } - return dateSectionList.count +// return dateSectionList.count + // DEBUG + return dateSectionList.count + 1 } override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return dateSectionList[section].assetResult.count +// return dateSectionList[section].assetResult.count + // DEBUG + if section == 0 { + return 1 + } else { + return dateSectionList[section - 1].assetResult.count + } } // MARK: - UICollectionViewDelegate override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { +// guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetCell", for: indexPath) as? AssetCell else { +// fatalError("failed to dequeueReusableCellWithIdentifier(\"AssetCell\")") +// } +// +// let asset = PhotoKitAsset(asset: dateSectionList[indexPath.section].assetResult[indexPath.row]) +// cell.tag = indexPath.item +// cell.delegate = self +// cell.update(asset: asset, nohanaImagePickerController: nohanaImagePickerController) +// +// let imageSize = CGSize( +// width: cellSize.width * UIScreen.main.scale, +// height: cellSize.height * UIScreen.main.scale +// ) +// asset.image(targetSize: imageSize) { (imageData) -> Void in +// DispatchQueue.main.async(execute: { () -> Void in +// if let imageData = imageData { +// if cell.tag == indexPath.item { +// cell.imageView.image = imageData.image +// } +// } +// }) +// } +// return (nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, assetListViewController: self, cell: cell, indexPath: indexPath, photoKitAsset: asset.originalAsset)) ?? cell + // DEBUG + if indexPath.section == 0 { + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PhotoAuthorizationLimitedCell.defaultReusableId, for: indexPath) as? PhotoAuthorizationLimitedCell else { + fatalError("failed to dequeueReusableCellWithIdentifier(\"PhotoAuthorizationLimitedCell\")") + } + return cell + } + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetCell", for: indexPath) as? AssetCell else { fatalError("failed to dequeueReusableCellWithIdentifier(\"AssetCell\")") } - - let asset = PhotoKitAsset(asset: dateSectionList[indexPath.section].assetResult[indexPath.row]) + let sectionListIndex = indexPath.section - 1 + let asset = PhotoKitAsset(asset: dateSectionList[sectionListIndex].assetResult[indexPath.row]) cell.tag = indexPath.item cell.delegate = self cell.update(asset: asset, nohanaImagePickerController: nohanaImagePickerController) @@ -126,15 +166,30 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { switch kind { case UICollectionView.elementKindSectionHeader: - let album = dateSectionList[indexPath.section] +// let album = dateSectionList[indexPath.section] +// guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "AssetDateSectionHeader", for: indexPath) as? AssetDateSectionHeaderView else { +// fatalError("failed to create AssetDateSectionHeader") +// } +// header.date = album.creationDate +// header.delegate = self +// let assets = dateSectionList[indexPath.section].assetResult.map { PhotoKitAsset(asset: $0) } +// header.update(assets: assets, indexPath: indexPath, nohanaImagePickerController: nohanaImagePickerController) +// return header + // DEBUG guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "AssetDateSectionHeader", for: indexPath) as? AssetDateSectionHeaderView else { fatalError("failed to create AssetDateSectionHeader") } + if indexPath.section == 0 { + return header + } + let sectionListIndex = indexPath.section - 1 + let album = dateSectionList[sectionListIndex] header.date = album.creationDate header.delegate = self - let assets = dateSectionList[indexPath.section].assetResult.map { PhotoKitAsset(asset: $0) } + let assets = dateSectionList[sectionListIndex].assetResult.map { PhotoKitAsset(asset: $0) } header.update(assets: assets, indexPath: indexPath, nohanaImagePickerController: nohanaImagePickerController) return header + default: fatalError("failed to create AssetDateSectionHeader") } @@ -143,7 +198,12 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo // MARK: - UICollectionViewDelegateFlowLayout func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { - return cellSize +// return cellSize + if indexPath.section == 0 { + return CGSize(width: collectionView.frame.width, height: 300) + } else { + return cellSize + } } // MARK: - ActivityIndicatable diff --git a/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift b/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift new file mode 100644 index 0000000..637454c --- /dev/null +++ b/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift @@ -0,0 +1,31 @@ +// +// PhotoAuthorizationLimitedCell.swift +// NohanaImagePicker +// +// Created by naoto.suzuki on 2022/07/27. +// Copyright © 2022 nohana. All rights reserved. +// + +import UIKit + +class PhotoAuthorizationLimitedCell: UICollectionViewCell { + + static var defaultReusableId: String { + String(describing: self) + } + + @IBOutlet weak private var attentionLabel: UILabel! + @IBOutlet weak private var addPhotoButton: UIButton! + @IBOutlet weak private var authorizeAllPhotoButton: UIButton! + + override func awakeFromNib() { + super.awakeFromNib() + // Initialization code + } + + @IBAction func tappedAddPhotoButton(_ sender: UIButton) { + } + + @IBAction func tappedAuthorizeAllPhotoButton(_ sender: UIButton) { + } +} diff --git a/NohanaImagePicker/PhotoAuthorizationLimitedCell.xib b/NohanaImagePicker/PhotoAuthorizationLimitedCell.xib new file mode 100644 index 0000000..eed3a6d --- /dev/null +++ b/NohanaImagePicker/PhotoAuthorizationLimitedCell.xib @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From f24681fa743e344340afdba94d1b884797c224a2 Mon Sep 17 00:00:00 2001 From: NoodleKim Date: Mon, 8 Aug 2022 16:17:28 +0900 Subject: [PATCH 02/21] Fixed album's UI by camera roll's access permission. --- .../AssetListSelectableDateSection.storyboard | 13 +- ...tListSelectableDateSectionController.swift | 41 +++- .../PhotoAuthorizationLimitedCell.swift | 32 ++- .../PhotoAuthorizationLimitedCell.xib | 186 +++++++++++------- 4 files changed, 186 insertions(+), 86 deletions(-) diff --git a/NohanaImagePicker/AssetListSelectableDateSection.storyboard b/NohanaImagePicker/AssetListSelectableDateSection.storyboard index 7e0bf44..2db981a 100644 --- a/NohanaImagePicker/AssetListSelectableDateSection.storyboard +++ b/NohanaImagePicker/AssetListSelectableDateSection.storyboard @@ -1,9 +1,9 @@ - + - + @@ -73,8 +73,8 @@ - - + + @@ -135,7 +136,7 @@ - + diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index b0b7fda..7a03061 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -82,6 +82,18 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo ], for: .normal) } + private func menuButtonStates() -> (Bool, Bool) { + switch PHPhotoLibrary.authorizationStatus() { + case .notDetermined, .restricted, .denied, .limited: + return (false, false) + case .authorized: + return (true, true) + @unknown default: + fatalError() + } + } + + // MARK: - UICollectionViewDataSource override func numberOfSections(in collectionView: UICollectionView) -> Int { @@ -89,7 +101,7 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo updateVisibilityOfActivityIndicator(activityIndicator) } -// return dateSectionList.count + return dateSectionList.count // DEBUG return dateSectionList.count + 1 } @@ -130,14 +142,17 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo // }) // } // return (nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, assetListViewController: self, cell: cell, indexPath: indexPath, photoKitAsset: asset.originalAsset)) ?? cell + // DEBUG if indexPath.section == 0 { guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PhotoAuthorizationLimitedCell.defaultReusableId, for: indexPath) as? PhotoAuthorizationLimitedCell else { fatalError("failed to dequeueReusableCellWithIdentifier(\"PhotoAuthorizationLimitedCell\")") } + cell.delegate = self + cell.setMenuButtonStates(menuButtonStates()) return cell } - + guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetCell", for: indexPath) as? AssetCell else { fatalError("failed to dequeueReusableCellWithIdentifier(\"AssetCell\")") } @@ -166,6 +181,7 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { switch kind { case UICollectionView.elementKindSectionHeader: + // 既存 // let album = dateSectionList[indexPath.section] // guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "AssetDateSectionHeader", for: indexPath) as? AssetDateSectionHeaderView else { // fatalError("failed to create AssetDateSectionHeader") @@ -200,12 +216,22 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { // return cellSize if indexPath.section == 0 { - return CGSize(width: collectionView.frame.width, height: 300) + // TODO: 文言 + ボタンの数で高さを計算する必要がある + return CGSize(width: collectionView.frame.width, height: 227) } else { return cellSize } } + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { + if section == 0 { + return .zero + } + + return .init(width: .infinity, height: 44.0) + } + + // MARK: - ActivityIndicatable var activityIndicator: UIActivityIndicatorView? @@ -335,3 +361,12 @@ extension AssetListSelectableDateSectionController: AssetCellDelegate { updateDoneBarButtonColor() } } + +extension AssetListSelectableDateSectionController: PhotoAuthorizationLimitedCellDeletate { + func didSelectAddPhotoButton(_ cell: PhotoAuthorizationLimitedCell) { + + } + func didSelectauthorizeAllPhotoButton(_ cell: PhotoAuthorizationLimitedCell) { + + } +} diff --git a/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift b/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift index 637454c..c3c83cf 100644 --- a/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift +++ b/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift @@ -8,15 +8,36 @@ import UIKit +protocol PhotoAuthorizationLimitedCellDeletate { + func didSelectAddPhotoButton(_ cell: PhotoAuthorizationLimitedCell) + func didSelectauthorizeAllPhotoButton(_ cell: PhotoAuthorizationLimitedCell) +} + class PhotoAuthorizationLimitedCell: UICollectionViewCell { static var defaultReusableId: String { String(describing: self) } + var delegate: PhotoAuthorizationLimitedCellDeletate? + @IBOutlet weak private var attentionLabel: UILabel! - @IBOutlet weak private var addPhotoButton: UIButton! - @IBOutlet weak private var authorizeAllPhotoButton: UIButton! + @IBOutlet weak private var addPhotoContainerView: UIView! + @IBOutlet weak private var addPhotoButton: UIButton! { + didSet { + self.addPhotoButton.layer.cornerRadius = 6 + self.addPhotoButton.layer.borderColor = UIColor(red: 187/255, green: 187/255, blue: 187/255, alpha: 1).cgColor + self.addPhotoButton.layer.borderWidth = 1 + } + } + @IBOutlet weak private var authorizeAllPhotoContainerView: UIView! + @IBOutlet weak private var authorizeAllPhotoButton: UIButton! { + didSet { + self.authorizeAllPhotoButton.layer.cornerRadius = 6 + self.authorizeAllPhotoButton.layer.borderColor = UIColor(red: 187/255, green: 187/255, blue: 187/255, alpha: 1).cgColor + self.authorizeAllPhotoButton.layer.borderWidth = 1 + } + } override func awakeFromNib() { super.awakeFromNib() @@ -24,8 +45,15 @@ class PhotoAuthorizationLimitedCell: UICollectionViewCell { } @IBAction func tappedAddPhotoButton(_ sender: UIButton) { + delegate?.didSelectAddPhotoButton(self) } @IBAction func tappedAuthorizeAllPhotoButton(_ sender: UIButton) { + delegate?.didSelectauthorizeAllPhotoButton(self) + } + + func setMenuButtonStates(_ states: (Bool, Bool)) { + addPhotoButton.isHidden = states.0 + authorizeAllPhotoButton.isHidden = states.1 } } diff --git a/NohanaImagePicker/PhotoAuthorizationLimitedCell.xib b/NohanaImagePicker/PhotoAuthorizationLimitedCell.xib index eed3a6d..c0d29bb 100644 --- a/NohanaImagePicker/PhotoAuthorizationLimitedCell.xib +++ b/NohanaImagePicker/PhotoAuthorizationLimitedCell.xib @@ -1,9 +1,9 @@ - + - + @@ -11,87 +11,118 @@ - - + + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + + + @@ -103,18 +134,23 @@ - + + + - + + + + From f07866c3c31f72a13438e48e1dfdc53ccf15df66 Mon Sep 17 00:00:00 2001 From: NoodleKim Date: Mon, 8 Aug 2022 17:47:31 +0900 Subject: [PATCH 03/21] Fixed header cell's height by showing action buttons. --- ...tListSelectableDateSectionController.swift | 88 +++++++------------ .../PhotoAuthorizationLimitedCell.swift | 8 +- .../PhotoAuthorizationLimitedCell.xib | 15 ++-- 3 files changed, 41 insertions(+), 70 deletions(-) diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index 7a03061..17cbc68 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -16,6 +16,7 @@ import Foundation import Photos +import UIKit class AssetListSelectableDateSectionController: UICollectionViewController, UICollectionViewDelegateFlowLayout, ActivityIndicatable { @@ -32,6 +33,18 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo let cellWidth = (view.frame.width - cellMargin * (CGFloat(numberOfColumns) - 1)) / CGFloat(numberOfColumns) return CGSize(width: cellWidth, height: cellWidth) } + + private var isHiddenMenu: Bool { + switch PHPhotoLibrary.authorizationStatus() { + case .notDetermined, .restricted, .denied, .limited: + return false + case .authorized: + return true + @unknown default: + fatalError() + } + } + init?(coder: NSCoder, nohanaImagePickerController: NohanaImagePickerController, photoKitAssetList: PhotoKitAssetList) { self.nohanaImagePickerController = nohanaImagePickerController @@ -82,33 +95,16 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo ], for: .normal) } - private func menuButtonStates() -> (Bool, Bool) { - switch PHPhotoLibrary.authorizationStatus() { - case .notDetermined, .restricted, .denied, .limited: - return (false, false) - case .authorized: - return (true, true) - @unknown default: - fatalError() - } - } - - // MARK: - UICollectionViewDataSource override func numberOfSections(in collectionView: UICollectionView) -> Int { if let activityIndicator = activityIndicator { updateVisibilityOfActivityIndicator(activityIndicator) } - - return dateSectionList.count - // DEBUG return dateSectionList.count + 1 } override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { -// return dateSectionList[section].assetResult.count - // DEBUG if section == 0 { return 1 } else { @@ -119,37 +115,12 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo // MARK: - UICollectionViewDelegate override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { -// guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetCell", for: indexPath) as? AssetCell else { -// fatalError("failed to dequeueReusableCellWithIdentifier(\"AssetCell\")") -// } -// -// let asset = PhotoKitAsset(asset: dateSectionList[indexPath.section].assetResult[indexPath.row]) -// cell.tag = indexPath.item -// cell.delegate = self -// cell.update(asset: asset, nohanaImagePickerController: nohanaImagePickerController) -// -// let imageSize = CGSize( -// width: cellSize.width * UIScreen.main.scale, -// height: cellSize.height * UIScreen.main.scale -// ) -// asset.image(targetSize: imageSize) { (imageData) -> Void in -// DispatchQueue.main.async(execute: { () -> Void in -// if let imageData = imageData { -// if cell.tag == indexPath.item { -// cell.imageView.image = imageData.image -// } -// } -// }) -// } -// return (nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, assetListViewController: self, cell: cell, indexPath: indexPath, photoKitAsset: asset.originalAsset)) ?? cell - - // DEBUG if indexPath.section == 0 { guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PhotoAuthorizationLimitedCell.defaultReusableId, for: indexPath) as? PhotoAuthorizationLimitedCell else { fatalError("failed to dequeueReusableCellWithIdentifier(\"PhotoAuthorizationLimitedCell\")") } cell.delegate = self - cell.setMenuButtonStates(menuButtonStates()) + cell.isHiddenMenu(isHiddenMenu) return cell } @@ -181,17 +152,6 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { switch kind { case UICollectionView.elementKindSectionHeader: - // 既存 -// let album = dateSectionList[indexPath.section] -// guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "AssetDateSectionHeader", for: indexPath) as? AssetDateSectionHeaderView else { -// fatalError("failed to create AssetDateSectionHeader") -// } -// header.date = album.creationDate -// header.delegate = self -// let assets = dateSectionList[indexPath.section].assetResult.map { PhotoKitAsset(asset: $0) } -// header.update(assets: assets, indexPath: indexPath, nohanaImagePickerController: nohanaImagePickerController) -// return header - // DEBUG guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "AssetDateSectionHeader", for: indexPath) as? AssetDateSectionHeaderView else { fatalError("failed to create AssetDateSectionHeader") } @@ -214,10 +174,8 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo // MARK: - UICollectionViewDelegateFlowLayout func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { -// return cellSize if indexPath.section == 0 { - // TODO: 文言 + ボタンの数で高さを計算する必要がある - return CGSize(width: collectionView.frame.width, height: 227) + return CGSize(width: collectionView.frame.width, height: isHiddenMenu ? 84 : 217) } else { return cellSize } @@ -370,3 +328,19 @@ extension AssetListSelectableDateSectionController: PhotoAuthorizationLimitedCel } } + +extension String { + func height(withConstrainedWidth width: CGFloat, font: UIFont = .systemFont(ofSize: 13.5)) -> CGFloat { + let constraintRect = CGSize(width: width, height: .greatestFiniteMagnitude) + let boundingBox = self.boundingRect(with: constraintRect, options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font: font], context: nil) + + return ceil(boundingBox.height) + } + + func width(withConstrainedHeight height: CGFloat, font: UIFont) -> CGFloat { + let constraintRect = CGSize(width: .greatestFiniteMagnitude, height: height) + let boundingBox = self.boundingRect(with: constraintRect, options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font: font], context: nil) + + return ceil(boundingBox.width) + } +} diff --git a/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift b/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift index c3c83cf..55848e7 100644 --- a/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift +++ b/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift @@ -21,8 +21,8 @@ class PhotoAuthorizationLimitedCell: UICollectionViewCell { var delegate: PhotoAuthorizationLimitedCellDeletate? + @IBOutlet weak private var menuContainerView: UIStackView! @IBOutlet weak private var attentionLabel: UILabel! - @IBOutlet weak private var addPhotoContainerView: UIView! @IBOutlet weak private var addPhotoButton: UIButton! { didSet { self.addPhotoButton.layer.cornerRadius = 6 @@ -30,7 +30,6 @@ class PhotoAuthorizationLimitedCell: UICollectionViewCell { self.addPhotoButton.layer.borderWidth = 1 } } - @IBOutlet weak private var authorizeAllPhotoContainerView: UIView! @IBOutlet weak private var authorizeAllPhotoButton: UIButton! { didSet { self.authorizeAllPhotoButton.layer.cornerRadius = 6 @@ -52,8 +51,7 @@ class PhotoAuthorizationLimitedCell: UICollectionViewCell { delegate?.didSelectauthorizeAllPhotoButton(self) } - func setMenuButtonStates(_ states: (Bool, Bool)) { - addPhotoButton.isHidden = states.0 - authorizeAllPhotoButton.isHidden = states.1 + func isHiddenMenu(_ isHidden: Bool) { + menuContainerView.isHidden = isHidden } } diff --git a/NohanaImagePicker/PhotoAuthorizationLimitedCell.xib b/NohanaImagePicker/PhotoAuthorizationLimitedCell.xib index c0d29bb..7bc76e0 100644 --- a/NohanaImagePicker/PhotoAuthorizationLimitedCell.xib +++ b/NohanaImagePicker/PhotoAuthorizationLimitedCell.xib @@ -12,20 +12,20 @@ - + - + - + - + - + @@ -137,10 +137,9 @@ - - + From ef4fd517a7772064e78054af0e5c9503dd80ef74 Mon Sep 17 00:00:00 2001 From: NoodleKim Date: Tue, 9 Aug 2022 11:26:17 +0900 Subject: [PATCH 04/21] Fixed some issues. --- ...tListSelectableDateSectionController.swift | 9 +- .../PhotoAuthorizationLimitedCell.swift | 26 ++- .../PhotoAuthorizationLimitedCell.xib | 201 ++++++++++-------- 3 files changed, 129 insertions(+), 107 deletions(-) diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index 17cbc68..eaa4614 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -36,12 +36,10 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo private var isHiddenMenu: Bool { switch PHPhotoLibrary.authorizationStatus() { - case .notDetermined, .restricted, .denied, .limited: + case .limited: return false - case .authorized: + default: return true - @unknown default: - fatalError() } } @@ -175,7 +173,7 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { if indexPath.section == 0 { - return CGSize(width: collectionView.frame.width, height: isHiddenMenu ? 84 : 217) + return CGSize(width: collectionView.frame.width, height: isHiddenMenu ? 1 : 217) } else { return cellSize } @@ -185,7 +183,6 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo if section == 0 { return .zero } - return .init(width: .infinity, height: 44.0) } diff --git a/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift b/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift index 55848e7..e47d140 100644 --- a/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift +++ b/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift @@ -1,10 +1,18 @@ -// -// PhotoAuthorizationLimitedCell.swift -// NohanaImagePicker -// -// Created by naoto.suzuki on 2022/07/27. -// Copyright © 2022 nohana. All rights reserved. -// +/* + * Copyright (C) 2022 nohana, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import UIKit @@ -21,7 +29,7 @@ class PhotoAuthorizationLimitedCell: UICollectionViewCell { var delegate: PhotoAuthorizationLimitedCellDeletate? - @IBOutlet weak private var menuContainerView: UIStackView! + @IBOutlet weak private var containerView: UIStackView! @IBOutlet weak private var attentionLabel: UILabel! @IBOutlet weak private var addPhotoButton: UIButton! { didSet { @@ -52,6 +60,6 @@ class PhotoAuthorizationLimitedCell: UICollectionViewCell { } func isHiddenMenu(_ isHidden: Bool) { - menuContainerView.isHidden = isHidden + containerView.isHidden = isHidden } } diff --git a/NohanaImagePicker/PhotoAuthorizationLimitedCell.xib b/NohanaImagePicker/PhotoAuthorizationLimitedCell.xib index 7bc76e0..7e0e15c 100644 --- a/NohanaImagePicker/PhotoAuthorizationLimitedCell.xib +++ b/NohanaImagePicker/PhotoAuthorizationLimitedCell.xib @@ -22,107 +22,124 @@ - + - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + - + + + + + + + + - - - - + + + + @@ -139,7 +156,7 @@ - + From fca4cef09153adcfb7457091ed5bfc0020a885a5 Mon Sep 17 00:00:00 2001 From: NoodleKim Date: Tue, 9 Aug 2022 12:01:00 +0900 Subject: [PATCH 05/21] Fixed protocol's naming. --- .../AssetListSelectableDateSectionController.swift | 3 ++- NohanaImagePicker/PhotoAuthorizationLimitedCell.swift | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index eaa4614..d063aa8 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -317,11 +317,12 @@ extension AssetListSelectableDateSectionController: AssetCellDelegate { } } +// MARK: - PhotoAuthorizationLimitedCellDeletate extension AssetListSelectableDateSectionController: PhotoAuthorizationLimitedCellDeletate { func didSelectAddPhotoButton(_ cell: PhotoAuthorizationLimitedCell) { } - func didSelectauthorizeAllPhotoButton(_ cell: PhotoAuthorizationLimitedCell) { + func didSelectAuthorizeAllPhotoButton(_ cell: PhotoAuthorizationLimitedCell) { } } diff --git a/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift b/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift index e47d140..6b902a7 100644 --- a/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift +++ b/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift @@ -18,7 +18,7 @@ import UIKit protocol PhotoAuthorizationLimitedCellDeletate { func didSelectAddPhotoButton(_ cell: PhotoAuthorizationLimitedCell) - func didSelectauthorizeAllPhotoButton(_ cell: PhotoAuthorizationLimitedCell) + func didSelectAuthorizeAllPhotoButton(_ cell: PhotoAuthorizationLimitedCell) } class PhotoAuthorizationLimitedCell: UICollectionViewCell { @@ -56,7 +56,7 @@ class PhotoAuthorizationLimitedCell: UICollectionViewCell { } @IBAction func tappedAuthorizeAllPhotoButton(_ sender: UIButton) { - delegate?.didSelectauthorizeAllPhotoButton(self) + delegate?.didSelectAuthorizeAllPhotoButton(self) } func isHiddenMenu(_ isHidden: Bool) { From 5f0a8be236e3c6a78985c63c90cfc9f06b14d961 Mon Sep 17 00:00:00 2001 From: NoodleKim Date: Tue, 9 Aug 2022 14:27:00 +0900 Subject: [PATCH 06/21] Fixed iOS version dependency issue. --- Demo/DemoListViewController.swift | 8 +++++++- .../AssetListSelectableDateSectionController.swift | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Demo/DemoListViewController.swift b/Demo/DemoListViewController.swift index 277b42f..78ee966 100644 --- a/Demo/DemoListViewController.swift +++ b/Demo/DemoListViewController.swift @@ -72,7 +72,13 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController // MARK: - Photos func checkIfAuthorizedToAccessPhotos(_ handler: @escaping (_ isAuthorized: Bool) -> Void) { - switch PHPhotoLibrary.authorizationStatus() { + let status: PHAuthorizationStatus + if #available(iOS 14, *) { + status = PHPhotoLibrary.authorizationStatus(for: .readWrite) + } else { + status = PHPhotoLibrary.authorizationStatus() + } + switch status { case .notDetermined: PHPhotoLibrary.requestAuthorization { status in DispatchQueue.main.async { diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index d063aa8..bef9b96 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -35,7 +35,13 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo } private var isHiddenMenu: Bool { - switch PHPhotoLibrary.authorizationStatus() { + let status: PHAuthorizationStatus + if #available(iOS 14, *) { + status = PHPhotoLibrary.authorizationStatus(for: .readWrite) + } else { + status = PHPhotoLibrary.authorizationStatus() + } + switch status { case .limited: return false default: From 8afd916d82d6ac552eb1d81e7d930016d099d462 Mon Sep 17 00:00:00 2001 From: NoodleKim Date: Tue, 9 Aug 2022 16:08:15 +0900 Subject: [PATCH 07/21] Fixed an issue that showed the wrong photo on a photo detail view. --- .../AssetListSelectableDateSectionController.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index bef9b96..07d1cad 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -213,12 +213,15 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo // MARK: - UICollectionViewDelegate override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAsset: dateSectionList[indexPath.section].assetResult[indexPath.row]) + + let sectionListIndex = indexPath.section - 1 + + nohanaImagePickerController.delegate?.nohanaImagePicker?(nohanaImagePickerController, didSelectPhotoKitAsset: dateSectionList[sectionListIndex].assetResult[indexPath.row]) } @available(iOS 13.0, *) override func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? { - let asset = PhotoKitAsset(asset: dateSectionList[indexPath.section].assetResult[indexPath.row]) + let asset = PhotoKitAsset(asset: dateSectionList[indexPath.section - 1].assetResult[indexPath.row]) if let cell = collectionView.cellForItem(at: indexPath) as? AssetCell { return UIContextMenuConfiguration(identifier: indexPath as NSCopying, previewProvider: { [weak self] in // Create a preview view controller and return it @@ -268,12 +271,13 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo override func prepare(for segue: UIStoryboardSegue, sender: Any?) { guard let selectedIndexPath = collectionView?.indexPathsForSelectedItems?.first, - selectedIndexPath.section < dateSectionList.count else { + selectedIndexPath.section != 0, + selectedIndexPath.section - 1 < dateSectionList.count else { return } var assetListDetailCurrentRow = 0 - for section in 0..<(selectedIndexPath.section + 1) { - if selectedIndexPath.section == section { + for section in 0..<(selectedIndexPath.section) { + if selectedIndexPath.section == (section + 1) { assetListDetailCurrentRow += selectedIndexPath.row } else { assetListDetailCurrentRow += dateSectionList[section].assetResult.count From 490910bb589f09e731dfc57f8fb37404aa8e5b36 Mon Sep 17 00:00:00 2001 From: NoodleKim Date: Tue, 9 Aug 2022 17:06:24 +0900 Subject: [PATCH 08/21] Fixed a wrong index issue. --- .../AssetListSelectableDateSectionController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index 07d1cad..b4cc907 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -312,7 +312,7 @@ extension AssetListSelectableDateSectionController: AssetCellDelegate { if #available(iOS 9.0, *) { let rowResetIndexPath = IndexPath(row: 0, section: indexPath.section) let header = collectionView.supplementaryView(forElementKind: UICollectionView.elementKindSectionHeader, at: rowResetIndexPath) as? AssetDateSectionHeaderView - let assets = dateSectionList[indexPath.section].assetResult.map { PhotoKitAsset(asset: $0) } + let assets = dateSectionList[indexPath.section - 1].assetResult.map { PhotoKitAsset(asset: $0) } header?.update(assets: assets, indexPath: indexPath, nohanaImagePickerController: nohanaImagePickerController) } else { UIView.animate(withDuration: 0) { [weak self] in From c57bd4a4ed578c685fc91cd90048973f422dfbea Mon Sep 17 00:00:00 2001 From: NoodleKim Date: Tue, 9 Aug 2022 17:27:51 +0900 Subject: [PATCH 09/21] Fixed source code. It would be more understood. --- ...ssetListSelectableDateSectionController.swift | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index b4cc907..b37fb41 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -19,7 +19,11 @@ import Photos import UIKit class AssetListSelectableDateSectionController: UICollectionViewController, UICollectionViewDelegateFlowLayout, ActivityIndicatable { - + + private enum Section: Int { + case photoAuthorizationLimited = 0 + } + private let nohanaImagePickerController: NohanaImagePickerController let photoKitAssetList: PhotoKitAssetList var dateSectionList: [AssetDateSection] = [] @@ -109,7 +113,7 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo } override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - if section == 0 { + if Section(rawValue: section) == .photoAuthorizationLimited { return 1 } else { return dateSectionList[section - 1].assetResult.count @@ -119,7 +123,7 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo // MARK: - UICollectionViewDelegate override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - if indexPath.section == 0 { + if Section(rawValue: indexPath.section) == .photoAuthorizationLimited { guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PhotoAuthorizationLimitedCell.defaultReusableId, for: indexPath) as? PhotoAuthorizationLimitedCell else { fatalError("failed to dequeueReusableCellWithIdentifier(\"PhotoAuthorizationLimitedCell\")") } @@ -159,7 +163,7 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "AssetDateSectionHeader", for: indexPath) as? AssetDateSectionHeaderView else { fatalError("failed to create AssetDateSectionHeader") } - if indexPath.section == 0 { + if Section(rawValue: indexPath.section) == .photoAuthorizationLimited { return header } let sectionListIndex = indexPath.section - 1 @@ -178,7 +182,7 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo // MARK: - UICollectionViewDelegateFlowLayout func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { - if indexPath.section == 0 { + if Section(rawValue: indexPath.section) == .photoAuthorizationLimited { return CGSize(width: collectionView.frame.width, height: isHiddenMenu ? 1 : 217) } else { return cellSize @@ -186,7 +190,7 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { - if section == 0 { + if Section(rawValue: section) == .photoAuthorizationLimited { return .zero } return .init(width: .infinity, height: 44.0) From 5af6e26666c8013baf15bc031834cac3620eecd3 Mon Sep 17 00:00:00 2001 From: NoodleKim Date: Tue, 9 Aug 2022 18:48:55 +0900 Subject: [PATCH 10/21] Fixed an index issue. --- .../AssetListSelectableDateSectionController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index b37fb41..2937a2c 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -135,8 +135,8 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AssetCell", for: indexPath) as? AssetCell else { fatalError("failed to dequeueReusableCellWithIdentifier(\"AssetCell\")") } - let sectionListIndex = indexPath.section - 1 - let asset = PhotoKitAsset(asset: dateSectionList[sectionListIndex].assetResult[indexPath.row]) + let indexPath: IndexPath = .init(row: indexPath.row, section: indexPath.section - 1) + let asset = PhotoKitAsset(asset: dateSectionList[indexPath.section].assetResult[indexPath.row]) cell.tag = indexPath.item cell.delegate = self cell.update(asset: asset, nohanaImagePickerController: nohanaImagePickerController) From 59af823fd984837be619e0f90c7b990b5d0d5145 Mon Sep 17 00:00:00 2001 From: NoodleKim Date: Tue, 9 Aug 2022 14:22:55 +0900 Subject: [PATCH 11/21] Added delegate functions when getting actions from buttons to navigate system camera roll's permission. --- ...setListSelectableDateSectionController.swift | 17 +++++++++++++++-- .../NohanaImagePickerController.swift | 2 ++ NohanaImagePicker/NotificationInfo.swift | 5 +++++ NohanaImagePicker/RootViewController.swift | 11 +++++++++++ NohanaImagePicker/UIViewController+Ex.swift | 6 ++++++ 5 files changed, 39 insertions(+), 2 deletions(-) diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index 2937a2c..447f12a 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -332,12 +332,25 @@ extension AssetListSelectableDateSectionController: AssetCellDelegate { } // MARK: - PhotoAuthorizationLimitedCellDeletate + extension AssetListSelectableDateSectionController: PhotoAuthorizationLimitedCellDeletate { func didSelectAddPhotoButton(_ cell: PhotoAuthorizationLimitedCell) { - + NotificationCenter.default.post( + Notification( + name: NotificationInfo.PhotoAuthorization.didTapAddPhoto, + object: nil, + userInfo: nil + ) + ) } func didSelectAuthorizeAllPhotoButton(_ cell: PhotoAuthorizationLimitedCell) { - + NotificationCenter.default.post( + Notification( + name: NotificationInfo.PhotoAuthorization.didTapAuthorizeAllPhoto, + object: nil, + userInfo: nil + ) + ) } } diff --git a/NohanaImagePicker/NohanaImagePickerController.swift b/NohanaImagePicker/NohanaImagePickerController.swift index 4c98908..e593101 100644 --- a/NohanaImagePicker/NohanaImagePickerController.swift +++ b/NohanaImagePicker/NohanaImagePickerController.swift @@ -35,6 +35,8 @@ public enum MediaType: Int { @objc optional func nohanaImagePicker(_ picker: NohanaImagePickerController, assetListViewController: UICollectionViewController, cell: UICollectionViewCell, indexPath: IndexPath, photoKitAsset: PHAsset) -> UICollectionViewCell @objc optional func nohanaImagePicker(_ picker: NohanaImagePickerController, assetDetailListViewController: UICollectionViewController, cell: UICollectionViewCell, indexPath: IndexPath, photoKitAsset: PHAsset) -> UICollectionViewCell @objc optional func nohanaImagePicker(_ picker: NohanaImagePickerController, assetDetailListViewController: UICollectionViewController, didChangeAssetDetailPage indexPath: IndexPath, photoKitAsset: PHAsset) + @objc optional func nohanaImagePickerDidTapAddPhotoButton(_ picker: NohanaImagePickerController) + @objc optional func nohanaImagePickerDidTapAuthorizeAllPhotoButton(_ picker: NohanaImagePickerController) } open class NohanaImagePickerController: UIViewController { diff --git a/NohanaImagePicker/NotificationInfo.swift b/NohanaImagePicker/NotificationInfo.swift index e7362cb..34917db 100644 --- a/NohanaImagePicker/NotificationInfo.swift +++ b/NohanaImagePicker/NotificationInfo.swift @@ -25,4 +25,9 @@ struct NotificationInfo { static let didDropUserInfoKeyPickedAssetsCount = "pickedAssetsCount" } } + + struct PhotoAuthorization { + static let didTapAddPhoto = Notification.Name("jp.co.nohana.NotificationName.PhotoAuthorization.didTapAddPhoto") + static let didTapAuthorizeAllPhoto = Notification.Name("jp.co.nohana.NotificationName.PhotoAuthorization.didTapAuthorizeAllPhoto") + } } diff --git a/NohanaImagePicker/RootViewController.swift b/NohanaImagePicker/RootViewController.swift index 790c6a0..22083da 100644 --- a/NohanaImagePicker/RootViewController.swift +++ b/NohanaImagePicker/RootViewController.swift @@ -73,6 +73,7 @@ class RootViewController: UIViewController { // Notification addPickPhotoKitAssetNotificationObservers() + addPhotoAuthorizationButtonNotificationObservers() if let assetCollection = nohanaImagePickerController.defaultAssetCollection { showPhotosFromDefaultAlbum(album: assetCollection) @@ -215,6 +216,16 @@ class RootViewController: UIViewController { } }) } + + @objc func didTapAddPhoto(_ notification: Notification) { + print("didTapAddPhoto") + + } + + @objc func didTapAuthorizeAllPhoto(_ notification: Notification) { + print("didTapAuthorizeAllPhoto") + } + // MARK: - IBAction @IBAction func didTapDone(_ sender: AnyObject) { diff --git a/NohanaImagePicker/UIViewController+Ex.swift b/NohanaImagePicker/UIViewController+Ex.swift index bfab9d0..1e53801 100644 --- a/NohanaImagePicker/UIViewController+Ex.swift +++ b/NohanaImagePicker/UIViewController+Ex.swift @@ -99,4 +99,10 @@ extension UIViewController { } setToolbarTitle(picker) } + + @objc func addPhotoAuthorizationButtonNotificationObservers() { + + NotificationCenter.default.addObserver(self, selector: #selector(RootViewController.didTapAddPhoto(_:)), name: NotificationInfo.PhotoAuthorization.didTapAddPhoto, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(RootViewController.didTapAuthorizeAllPhoto(_:)), name: NotificationInfo.PhotoAuthorization.didTapAuthorizeAllPhoto, object: nil) + } } From 79c0d15bc9331cc95cc90f62e1986d12cc632d71 Mon Sep 17 00:00:00 2001 From: NoodleKim Date: Wed, 10 Aug 2022 11:20:00 +0900 Subject: [PATCH 12/21] Fixed a delegate issue. --- .../AssetListSelectableDateSectionController.swift | 1 - NohanaImagePicker/RootViewController.swift | 6 ++---- NohanaImagePicker/UIViewController+Ex.swift | 1 - 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index 447f12a..d9baf7a 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -52,7 +52,6 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo return true } } - init?(coder: NSCoder, nohanaImagePickerController: NohanaImagePickerController, photoKitAssetList: PhotoKitAssetList) { self.nohanaImagePickerController = nohanaImagePickerController diff --git a/NohanaImagePicker/RootViewController.swift b/NohanaImagePicker/RootViewController.swift index 22083da..7b10263 100644 --- a/NohanaImagePicker/RootViewController.swift +++ b/NohanaImagePicker/RootViewController.swift @@ -218,14 +218,12 @@ class RootViewController: UIViewController { } @objc func didTapAddPhoto(_ notification: Notification) { - print("didTapAddPhoto") - + nohanaImagePickerController.delegate?.nohanaImagePickerDidTapAddPhotoButton?(nohanaImagePickerController) } @objc func didTapAuthorizeAllPhoto(_ notification: Notification) { - print("didTapAuthorizeAllPhoto") + nohanaImagePickerController.delegate?.nohanaImagePickerDidTapAuthorizeAllPhotoButton?(nohanaImagePickerController) } - // MARK: - IBAction @IBAction func didTapDone(_ sender: AnyObject) { diff --git a/NohanaImagePicker/UIViewController+Ex.swift b/NohanaImagePicker/UIViewController+Ex.swift index 1e53801..0646ff2 100644 --- a/NohanaImagePicker/UIViewController+Ex.swift +++ b/NohanaImagePicker/UIViewController+Ex.swift @@ -101,7 +101,6 @@ extension UIViewController { } @objc func addPhotoAuthorizationButtonNotificationObservers() { - NotificationCenter.default.addObserver(self, selector: #selector(RootViewController.didTapAddPhoto(_:)), name: NotificationInfo.PhotoAuthorization.didTapAddPhoto, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(RootViewController.didTapAuthorizeAllPhoto(_:)), name: NotificationInfo.PhotoAuthorization.didTapAuthorizeAllPhoto, object: nil) } From fb3cb5e6521019d9974aad43fb4ced72e6ef868e Mon Sep 17 00:00:00 2001 From: NoodleKim Date: Wed, 10 Aug 2022 14:16:41 +0900 Subject: [PATCH 13/21] Exchanged `NotificationCenter`to `nohanaImagePickerController.delegate`. --- ...setListSelectableDateSectionController.swift | 17 +++-------------- NohanaImagePicker/NotificationInfo.swift | 5 ----- NohanaImagePicker/RootViewController.swift | 1 - NohanaImagePicker/UIViewController+Ex.swift | 5 ----- 4 files changed, 3 insertions(+), 25 deletions(-) diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index d9baf7a..ec127d0 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -334,22 +334,11 @@ extension AssetListSelectableDateSectionController: AssetCellDelegate { extension AssetListSelectableDateSectionController: PhotoAuthorizationLimitedCellDeletate { func didSelectAddPhotoButton(_ cell: PhotoAuthorizationLimitedCell) { - NotificationCenter.default.post( - Notification( - name: NotificationInfo.PhotoAuthorization.didTapAddPhoto, - object: nil, - userInfo: nil - ) - ) + nohanaImagePickerController.delegate?.nohanaImagePickerDidTapAddPhotoButton?(nohanaImagePickerController) } + func didSelectAuthorizeAllPhotoButton(_ cell: PhotoAuthorizationLimitedCell) { - NotificationCenter.default.post( - Notification( - name: NotificationInfo.PhotoAuthorization.didTapAuthorizeAllPhoto, - object: nil, - userInfo: nil - ) - ) + nohanaImagePickerController.delegate?.nohanaImagePickerDidTapAuthorizeAllPhotoButton?(nohanaImagePickerController) } } diff --git a/NohanaImagePicker/NotificationInfo.swift b/NohanaImagePicker/NotificationInfo.swift index 34917db..e7362cb 100644 --- a/NohanaImagePicker/NotificationInfo.swift +++ b/NohanaImagePicker/NotificationInfo.swift @@ -25,9 +25,4 @@ struct NotificationInfo { static let didDropUserInfoKeyPickedAssetsCount = "pickedAssetsCount" } } - - struct PhotoAuthorization { - static let didTapAddPhoto = Notification.Name("jp.co.nohana.NotificationName.PhotoAuthorization.didTapAddPhoto") - static let didTapAuthorizeAllPhoto = Notification.Name("jp.co.nohana.NotificationName.PhotoAuthorization.didTapAuthorizeAllPhoto") - } } diff --git a/NohanaImagePicker/RootViewController.swift b/NohanaImagePicker/RootViewController.swift index 7b10263..9f17ae4 100644 --- a/NohanaImagePicker/RootViewController.swift +++ b/NohanaImagePicker/RootViewController.swift @@ -73,7 +73,6 @@ class RootViewController: UIViewController { // Notification addPickPhotoKitAssetNotificationObservers() - addPhotoAuthorizationButtonNotificationObservers() if let assetCollection = nohanaImagePickerController.defaultAssetCollection { showPhotosFromDefaultAlbum(album: assetCollection) diff --git a/NohanaImagePicker/UIViewController+Ex.swift b/NohanaImagePicker/UIViewController+Ex.swift index 0646ff2..bfab9d0 100644 --- a/NohanaImagePicker/UIViewController+Ex.swift +++ b/NohanaImagePicker/UIViewController+Ex.swift @@ -99,9 +99,4 @@ extension UIViewController { } setToolbarTitle(picker) } - - @objc func addPhotoAuthorizationButtonNotificationObservers() { - NotificationCenter.default.addObserver(self, selector: #selector(RootViewController.didTapAddPhoto(_:)), name: NotificationInfo.PhotoAuthorization.didTapAddPhoto, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(RootViewController.didTapAuthorizeAllPhoto(_:)), name: NotificationInfo.PhotoAuthorization.didTapAuthorizeAllPhoto, object: nil) - } } From 0c4ab247cea3df0e14177ac5e68cf97da07c7c1f Mon Sep 17 00:00:00 2001 From: NoodleKim Date: Wed, 10 Aug 2022 14:52:34 +0900 Subject: [PATCH 14/21] Added demo delegate functions. --- Demo/DemoListViewController.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Demo/DemoListViewController.swift b/Demo/DemoListViewController.swift index 78ee966..53c1ba6 100644 --- a/Demo/DemoListViewController.swift +++ b/Demo/DemoListViewController.swift @@ -244,4 +244,12 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController func nohanaImagePicker(_ picker: NohanaImagePickerController, assetDetailListViewController: UICollectionViewController, didChangeAssetDetailPage indexPath: IndexPath, photoKitAsset: PHAsset) { print("🐷\(#function)\n\tindexPath = \(indexPath)") } + + func nohanaImagePickerDidTapAddPhotoButton(_ picker: NohanaImagePickerController) { + print("🐷\(#function)") + } + + func nohanaImagePickerDidTapAuthorizeAllPhotoButton(_ picker: NohanaImagePickerController) { + print("🐷\(#function)") + } } From c494051baae891f9e78006b1c0c27ed0fc671188 Mon Sep 17 00:00:00 2001 From: NoodleKim Date: Wed, 10 Aug 2022 16:41:42 +0900 Subject: [PATCH 15/21] Selected photos synchronized with photo list. --- Demo/DemoListViewController.swift | 10 ++++++++++ .../AssetListSelectableDateSectionController.swift | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/Demo/DemoListViewController.swift b/Demo/DemoListViewController.swift index 53c1ba6..4f7cc78 100644 --- a/Demo/DemoListViewController.swift +++ b/Demo/DemoListViewController.swift @@ -16,6 +16,7 @@ import UIKit import NohanaImagePicker import Photos +import PhotosUI struct Cell { let title: String @@ -247,9 +248,18 @@ class DemoListViewController: UITableViewController, NohanaImagePickerController func nohanaImagePickerDidTapAddPhotoButton(_ picker: NohanaImagePickerController) { print("🐷\(#function)") + if #available(iOS 14, *) { + PHPhotoLibrary.shared().presentLimitedLibraryPicker(from: picker) + } } func nohanaImagePickerDidTapAuthorizeAllPhotoButton(_ picker: NohanaImagePickerController) { print("🐷\(#function)") + guard let url = URL(string: UIApplication.openSettingsURLString), + UIApplication.shared.canOpenURL(url) else { + assertionFailure("Not able to open App privacy settings") + return + } + UIApplication.shared.open(url, options: [:], completionHandler: nil) } } diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index ec127d0..4e3ec8f 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -70,6 +70,7 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo addPickPhotoKitAssetNotificationObservers() setUpActivityIndicator() collectionView.register(UINib(nibName: "PhotoAuthorizationLimitedCell", bundle: self.nohanaImagePickerController.assetBundle), forCellWithReuseIdentifier: PhotoAuthorizationLimitedCell.defaultReusableId) + PHPhotoLibrary.shared().register(self) DispatchQueue.main.async { [weak self] in guard let self = self else { return } self.dateSectionList = AssetDateSectionCreater().createSections(assetList: self.photoKitAssetList.assetList, options: PhotoKitAssetList.fetchOptions(self.photoKitAssetList.mediaType, ascending: false)) @@ -357,3 +358,16 @@ extension String { return ceil(boundingBox.width) } } + +// MARK: - PHPhotoLibraryChangeObserver + +extension AssetListSelectableDateSectionController: PHPhotoLibraryChangeObserver { + func photoLibraryDidChange(_ changeInstance: PHChange) { + DispatchQueue.main.async { [weak self] in + guard let self = self else { return } + self.dateSectionList = AssetDateSectionCreater().createSections(assetList: self.photoKitAssetList.assetList, options: PhotoKitAssetList.fetchOptions(self.photoKitAssetList.mediaType, ascending: false)) + self.isLoading = false + self.collectionView?.reloadData() + } + } +} From 402332304faa1969d3b4db8f9078b977380df115 Mon Sep 17 00:00:00 2001 From: NoodleKim Date: Mon, 15 Aug 2022 11:52:44 +0900 Subject: [PATCH 16/21] Added a property to control hiding a `PhotoAuthorizationLimitedView`. --- Demo/Info.plist | 2 ++ .../AssetListSelectableDateSectionController.swift | 13 +++++++++---- NohanaImagePicker/NohanaImagePickerController.swift | 1 + .../PhotoAuthorizationLimitedCell.swift | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Demo/Info.plist b/Demo/Info.plist index 36e869d..3de749b 100644 --- a/Demo/Info.plist +++ b/Demo/Info.plist @@ -45,5 +45,7 @@ NSPhotoLibraryUsageDescription To pick some photos. + PHPhotoLibraryPreventAutomaticLimitedAccessAlert + diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index 4e3ec8f..823add6 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -38,7 +38,11 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo return CGSize(width: cellWidth, height: cellWidth) } - private var isHiddenMenu: Bool { + private lazy var isHiddenPhotoAuthorizationLimitedCell: Bool = { + guard !nohanaImagePickerController.isHiddenPhotoAuthorizationLimitedView else { + return true + } + let status: PHAuthorizationStatus if #available(iOS 14, *) { status = PHPhotoLibrary.authorizationStatus(for: .readWrite) @@ -51,7 +55,7 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo default: return true } - } + }() init?(coder: NSCoder, nohanaImagePickerController: NohanaImagePickerController, photoKitAssetList: PhotoKitAssetList) { self.nohanaImagePickerController = nohanaImagePickerController @@ -128,7 +132,8 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo fatalError("failed to dequeueReusableCellWithIdentifier(\"PhotoAuthorizationLimitedCell\")") } cell.delegate = self - cell.isHiddenMenu(isHiddenMenu) + let isHidden = isHiddenPhotoAuthorizationLimitedCell + cell.isHiddenCell(isHidden) return cell } @@ -183,7 +188,7 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { if Section(rawValue: indexPath.section) == .photoAuthorizationLimited { - return CGSize(width: collectionView.frame.width, height: isHiddenMenu ? 1 : 217) + return CGSize(width: collectionView.frame.width, height: isHiddenPhotoAuthorizationLimitedCell ? 1 : 217) } else { return cellSize } diff --git a/NohanaImagePicker/NohanaImagePickerController.swift b/NohanaImagePicker/NohanaImagePickerController.swift index e593101..c8b5443 100644 --- a/NohanaImagePicker/NohanaImagePickerController.swift +++ b/NohanaImagePicker/NohanaImagePickerController.swift @@ -59,6 +59,7 @@ open class NohanaImagePickerController: UIViewController { .font: UIFont.systemFont(ofSize: 17, weight: .semibold) ] }() + open var isHiddenPhotoAuthorizationLimitedView: Bool = false lazy var assetBundle: Bundle = { let bundle = Bundle(for: type(of: self)) if let path = bundle.path(forResource: "NohanaImagePicker", ofType: "bundle") { diff --git a/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift b/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift index 6b902a7..9fd3bb1 100644 --- a/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift +++ b/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift @@ -59,7 +59,7 @@ class PhotoAuthorizationLimitedCell: UICollectionViewCell { delegate?.didSelectAuthorizeAllPhotoButton(self) } - func isHiddenMenu(_ isHidden: Bool) { + func isHiddenCell(_ isHidden: Bool) { containerView.isHidden = isHidden } } From f1f82fa32c2837463641f5d207607efd1f94a3d0 Mon Sep 17 00:00:00 2001 From: NoodleKim Date: Mon, 15 Aug 2022 15:53:22 +0900 Subject: [PATCH 17/21] Added localized strings and fixed UI issues caused by localizing. --- ...tListSelectableDateSectionController.swift | 8 +++- .../PhotoAuthorizationLimitedCell.swift | 41 +++++++++++++++++++ .../PhotoAuthorizationLimitedCell.xib | 36 ++++++++++------ .../de.lproj/NohanaImagePicker.strings | 4 ++ .../en.lproj/NohanaImagePicker.strings | 5 +++ .../ja.lproj/NohanaImagePicker.strings | 4 ++ .../ru.lproj/NohanaImagePicker.strings | 4 ++ 7 files changed, 88 insertions(+), 14 deletions(-) diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index 823add6..fd3070c 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -133,7 +133,7 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo } cell.delegate = self let isHidden = isHiddenPhotoAuthorizationLimitedCell - cell.isHiddenCell(isHidden) + cell.update(isHidden, nohanaImagePickerController: nohanaImagePickerController) return cell } @@ -188,7 +188,11 @@ class AssetListSelectableDateSectionController: UICollectionViewController, UICo func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { if Section(rawValue: indexPath.section) == .photoAuthorizationLimited { - return CGSize(width: collectionView.frame.width, height: isHiddenPhotoAuthorizationLimitedCell ? 1 : 217) + if isHiddenPhotoAuthorizationLimitedCell { + return CGSize(width: collectionView.frame.width, height: 1) + } else { + return PhotoAuthorizationLimitedCell.cellSize(nohanaImagePickerController) + } } else { return cellSize } diff --git a/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift b/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift index 9fd3bb1..2384bc0 100644 --- a/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift +++ b/NohanaImagePicker/PhotoAuthorizationLimitedCell.swift @@ -59,7 +59,48 @@ class PhotoAuthorizationLimitedCell: UICollectionViewCell { delegate?.didSelectAuthorizeAllPhotoButton(self) } + func update(_ isHidden: Bool, nohanaImagePickerController: NohanaImagePickerController) { + + containerView.isHidden = isHidden + attentionLabel.text = NSLocalizedString( + "albumlist.menu.description", + tableName: "NohanaImagePicker", + bundle: nohanaImagePickerController.assetBundle, + comment: "" + ) + + addPhotoButton.setTitle( + NSLocalizedString( + "albumlist.menu.addPhoto.title", + tableName: "NohanaImagePicker", + bundle: nohanaImagePickerController.assetBundle, + comment: "" + ), + for: .normal + ) + + authorizeAllPhotoButton.setTitle( + NSLocalizedString( + "albumlist.menu.authorizeAllPhoto.title", + tableName: "NohanaImagePicker", + bundle: nohanaImagePickerController.assetBundle, + comment: "" + ), + for: .normal + ) + } + func isHiddenCell(_ isHidden: Bool) { containerView.isHidden = isHidden } + + static func cellSize(_ nohanaImagePickerController: NohanaImagePickerController) -> CGSize { + let descriptionLabel = UILabel() + descriptionLabel.text = NSLocalizedString("albumlist.menu.description", tableName: "NohanaImagePicker", bundle: nohanaImagePickerController.assetBundle, comment: "") + descriptionLabel.frame = .init(x: 0, y: 0, width: UIScreen.main.bounds.width - 28, height: 0) + descriptionLabel.sizeToFit() + + let height: CGFloat = descriptionLabel.frame.height + 44 * 2 + 10 + 16 * 3 + return .init(width: UIScreen.main.bounds.width, height: height) + } } diff --git a/NohanaImagePicker/PhotoAuthorizationLimitedCell.xib b/NohanaImagePicker/PhotoAuthorizationLimitedCell.xib index 7e0e15c..0068e33 100644 --- a/NohanaImagePicker/PhotoAuthorizationLimitedCell.xib +++ b/NohanaImagePicker/PhotoAuthorizationLimitedCell.xib @@ -30,14 +30,26 @@ - + + + + + + + + + @@ -45,7 +57,7 @@