Respond to CR.
This commit is contained in:
parent
ea080eda72
commit
2919e8d780
@ -254,7 +254,7 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
|
||||
return
|
||||
}
|
||||
let view = PhotoCollectionPickerController(library: library,
|
||||
lastPhotoCollection: photoCollection,
|
||||
previousPhotoCollection: photoCollection,
|
||||
collectionDelegate: self)
|
||||
let nav = UINavigationController(rootViewController: view)
|
||||
self.present(nav, animated: true, completion: nil)
|
||||
|
||||
@ -15,14 +15,14 @@ class PhotoCollectionPickerController: OWSTableViewController, PhotoLibraryDeleg
|
||||
private weak var collectionDelegate: PhotoCollectionPickerDelegate?
|
||||
|
||||
private let library: PhotoLibrary
|
||||
private let lastPhotoCollection: PhotoCollection
|
||||
private var photoCollections: PhotoCollections
|
||||
private let previousPhotoCollection: PhotoCollection
|
||||
private var photoCollections: [PhotoCollection]
|
||||
|
||||
required init(library: PhotoLibrary,
|
||||
lastPhotoCollection: PhotoCollection,
|
||||
previousPhotoCollection: PhotoCollection,
|
||||
collectionDelegate: PhotoCollectionPickerDelegate) {
|
||||
self.library = library
|
||||
self.lastPhotoCollection = lastPhotoCollection
|
||||
self.previousPhotoCollection = previousPhotoCollection
|
||||
self.photoCollections = library.allPhotoCollections()
|
||||
self.collectionDelegate = collectionDelegate
|
||||
super.init()
|
||||
@ -38,7 +38,7 @@ class PhotoCollectionPickerController: OWSTableViewController, PhotoLibraryDeleg
|
||||
super.viewDidLoad()
|
||||
|
||||
let titleLabel = UILabel()
|
||||
titleLabel.text = lastPhotoCollection.localizedTitle()
|
||||
titleLabel.text = previousPhotoCollection.localizedTitle()
|
||||
titleLabel.textColor = Theme.primaryColor
|
||||
titleLabel.font = UIFont.ows_dynamicTypeBody.ows_mediumWeight()
|
||||
|
||||
@ -67,9 +67,7 @@ class PhotoCollectionPickerController: OWSTableViewController, PhotoLibraryDeleg
|
||||
photoCollections = library.allPhotoCollections()
|
||||
|
||||
let section = OWSTableSection()
|
||||
let count = photoCollections.count
|
||||
for index in 0..<count {
|
||||
let collection = photoCollections.collection(at: index)
|
||||
for collection in photoCollections {
|
||||
section.add(OWSTableItem.init(customCellBlock: { () -> UITableViewCell in
|
||||
let cell = OWSTableItem.newCell()
|
||||
|
||||
@ -94,7 +92,7 @@ class PhotoCollectionPickerController: OWSTableViewController, PhotoLibraryDeleg
|
||||
|
||||
let titleLabel = UILabel()
|
||||
titleLabel.text = collection.localizedTitle()
|
||||
titleLabel.font = UIFont.ows_regularFont(withSize: 18)
|
||||
titleLabel.font = UIFont.ows_dynamicTypeBody
|
||||
titleLabel.textColor = Theme.primaryColor
|
||||
|
||||
let stackView = UIStackView(arrangedSubviews: [imageView, titleLabel])
|
||||
|
||||
@ -186,33 +186,12 @@ class PhotoCollection {
|
||||
}
|
||||
}
|
||||
|
||||
class PhotoCollections {
|
||||
let collections: [PhotoCollection]
|
||||
|
||||
init(collections: [PhotoCollection]) {
|
||||
self.collections = collections
|
||||
}
|
||||
|
||||
var count: Int {
|
||||
return collections.count
|
||||
}
|
||||
|
||||
func collection(at index: Int) -> PhotoCollection {
|
||||
return collections[index]
|
||||
}
|
||||
}
|
||||
|
||||
class PhotoLibrary: NSObject, PHPhotoLibraryChangeObserver {
|
||||
final class WeakDelegate {
|
||||
weak var delegate: PhotoLibraryDelegate?
|
||||
init(_ value: PhotoLibraryDelegate) {
|
||||
delegate = value
|
||||
}
|
||||
}
|
||||
typealias WeakDelegate = Weak<PhotoLibraryDelegate>
|
||||
var delegates = [WeakDelegate]()
|
||||
|
||||
public func add(delegate: PhotoLibraryDelegate) {
|
||||
delegates.append(WeakDelegate(delegate))
|
||||
delegates.append(WeakDelegate(value: delegate))
|
||||
}
|
||||
|
||||
var assetCollection: PHAssetCollection!
|
||||
@ -220,7 +199,7 @@ class PhotoLibrary: NSObject, PHPhotoLibraryChangeObserver {
|
||||
func photoLibraryDidChange(_ changeInstance: PHChange) {
|
||||
DispatchQueue.main.async {
|
||||
for weakDelegate in self.delegates {
|
||||
weakDelegate.delegate?.photoLibraryDidChange(self)
|
||||
weakDelegate.value?.photoLibraryDidChange(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -235,13 +214,13 @@ class PhotoLibrary: NSObject, PHPhotoLibraryChangeObserver {
|
||||
}
|
||||
|
||||
func defaultPhotoCollection() -> PhotoCollection {
|
||||
guard let photoCollection = allPhotoCollections().collections.first else {
|
||||
guard let photoCollection = allPhotoCollections().first else {
|
||||
owsFail("Could not locate Camera Roll.")
|
||||
}
|
||||
return photoCollection
|
||||
}
|
||||
|
||||
func allPhotoCollections() -> PhotoCollections {
|
||||
func allPhotoCollections() -> [PhotoCollection] {
|
||||
var collections = [PhotoCollection]()
|
||||
var collectionIds = Set<String>()
|
||||
|
||||
@ -283,6 +262,6 @@ class PhotoLibrary: NSObject, PHPhotoLibraryChangeObserver {
|
||||
// Smart albums.
|
||||
processPHAssetCollections(PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .albumRegular, options: fetchOptions))
|
||||
|
||||
return PhotoCollections(collections: collections)
|
||||
return collections
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user