diff --git a/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift b/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift index 87240a01b..3d7f473de 100644 --- a/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift +++ b/Signal/src/ViewControllers/PhotoLibrary/ImagePickerController.swift @@ -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) diff --git a/Signal/src/ViewControllers/PhotoLibrary/PhotoCollectionPickerController.swift b/Signal/src/ViewControllers/PhotoLibrary/PhotoCollectionPickerController.swift index e9c49bf34..07b2ce7fd 100644 --- a/Signal/src/ViewControllers/PhotoLibrary/PhotoCollectionPickerController.swift +++ b/Signal/src/ViewControllers/PhotoLibrary/PhotoCollectionPickerController.swift @@ -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.. 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]) diff --git a/Signal/src/ViewControllers/PhotoLibrary/PhotoLibrary.swift b/Signal/src/ViewControllers/PhotoLibrary/PhotoLibrary.swift index 390fdf59f..c9b62fc3b 100644 --- a/Signal/src/ViewControllers/PhotoLibrary/PhotoLibrary.swift +++ b/Signal/src/ViewControllers/PhotoLibrary/PhotoLibrary.swift @@ -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 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() @@ -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 } }