Respond to CR.

pull/1/head
Matthew Chen 7 years ago
parent ea080eda72
commit 2919e8d780

@ -254,7 +254,7 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
return return
} }
let view = PhotoCollectionPickerController(library: library, let view = PhotoCollectionPickerController(library: library,
lastPhotoCollection: photoCollection, previousPhotoCollection: photoCollection,
collectionDelegate: self) collectionDelegate: self)
let nav = UINavigationController(rootViewController: view) let nav = UINavigationController(rootViewController: view)
self.present(nav, animated: true, completion: nil) self.present(nav, animated: true, completion: nil)

@ -15,14 +15,14 @@ class PhotoCollectionPickerController: OWSTableViewController, PhotoLibraryDeleg
private weak var collectionDelegate: PhotoCollectionPickerDelegate? private weak var collectionDelegate: PhotoCollectionPickerDelegate?
private let library: PhotoLibrary private let library: PhotoLibrary
private let lastPhotoCollection: PhotoCollection private let previousPhotoCollection: PhotoCollection
private var photoCollections: PhotoCollections private var photoCollections: [PhotoCollection]
required init(library: PhotoLibrary, required init(library: PhotoLibrary,
lastPhotoCollection: PhotoCollection, previousPhotoCollection: PhotoCollection,
collectionDelegate: PhotoCollectionPickerDelegate) { collectionDelegate: PhotoCollectionPickerDelegate) {
self.library = library self.library = library
self.lastPhotoCollection = lastPhotoCollection self.previousPhotoCollection = previousPhotoCollection
self.photoCollections = library.allPhotoCollections() self.photoCollections = library.allPhotoCollections()
self.collectionDelegate = collectionDelegate self.collectionDelegate = collectionDelegate
super.init() super.init()
@ -38,7 +38,7 @@ class PhotoCollectionPickerController: OWSTableViewController, PhotoLibraryDeleg
super.viewDidLoad() super.viewDidLoad()
let titleLabel = UILabel() let titleLabel = UILabel()
titleLabel.text = lastPhotoCollection.localizedTitle() titleLabel.text = previousPhotoCollection.localizedTitle()
titleLabel.textColor = Theme.primaryColor titleLabel.textColor = Theme.primaryColor
titleLabel.font = UIFont.ows_dynamicTypeBody.ows_mediumWeight() titleLabel.font = UIFont.ows_dynamicTypeBody.ows_mediumWeight()
@ -67,9 +67,7 @@ class PhotoCollectionPickerController: OWSTableViewController, PhotoLibraryDeleg
photoCollections = library.allPhotoCollections() photoCollections = library.allPhotoCollections()
let section = OWSTableSection() let section = OWSTableSection()
let count = photoCollections.count for collection in photoCollections {
for index in 0..<count {
let collection = photoCollections.collection(at: index)
section.add(OWSTableItem.init(customCellBlock: { () -> UITableViewCell in section.add(OWSTableItem.init(customCellBlock: { () -> UITableViewCell in
let cell = OWSTableItem.newCell() let cell = OWSTableItem.newCell()
@ -94,7 +92,7 @@ class PhotoCollectionPickerController: OWSTableViewController, PhotoLibraryDeleg
let titleLabel = UILabel() let titleLabel = UILabel()
titleLabel.text = collection.localizedTitle() titleLabel.text = collection.localizedTitle()
titleLabel.font = UIFont.ows_regularFont(withSize: 18) titleLabel.font = UIFont.ows_dynamicTypeBody
titleLabel.textColor = Theme.primaryColor titleLabel.textColor = Theme.primaryColor
let stackView = UIStackView(arrangedSubviews: [imageView, titleLabel]) 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 { class PhotoLibrary: NSObject, PHPhotoLibraryChangeObserver {
final class WeakDelegate { typealias WeakDelegate = Weak<PhotoLibraryDelegate>
weak var delegate: PhotoLibraryDelegate?
init(_ value: PhotoLibraryDelegate) {
delegate = value
}
}
var delegates = [WeakDelegate]() var delegates = [WeakDelegate]()
public func add(delegate: PhotoLibraryDelegate) { public func add(delegate: PhotoLibraryDelegate) {
delegates.append(WeakDelegate(delegate)) delegates.append(WeakDelegate(value: delegate))
} }
var assetCollection: PHAssetCollection! var assetCollection: PHAssetCollection!
@ -220,7 +199,7 @@ class PhotoLibrary: NSObject, PHPhotoLibraryChangeObserver {
func photoLibraryDidChange(_ changeInstance: PHChange) { func photoLibraryDidChange(_ changeInstance: PHChange) {
DispatchQueue.main.async { DispatchQueue.main.async {
for weakDelegate in self.delegates { for weakDelegate in self.delegates {
weakDelegate.delegate?.photoLibraryDidChange(self) weakDelegate.value?.photoLibraryDidChange(self)
} }
} }
} }
@ -235,13 +214,13 @@ class PhotoLibrary: NSObject, PHPhotoLibraryChangeObserver {
} }
func defaultPhotoCollection() -> PhotoCollection { func defaultPhotoCollection() -> PhotoCollection {
guard let photoCollection = allPhotoCollections().collections.first else { guard let photoCollection = allPhotoCollections().first else {
owsFail("Could not locate Camera Roll.") owsFail("Could not locate Camera Roll.")
} }
return photoCollection return photoCollection
} }
func allPhotoCollections() -> PhotoCollections { func allPhotoCollections() -> [PhotoCollection] {
var collections = [PhotoCollection]() var collections = [PhotoCollection]()
var collectionIds = Set<String>() var collectionIds = Set<String>()
@ -283,6 +262,6 @@ class PhotoLibrary: NSObject, PHPhotoLibraryChangeObserver {
// Smart albums. // Smart albums.
processPHAssetCollections(PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .albumRegular, options: fetchOptions)) processPHAssetCollections(PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .albumRegular, options: fetchOptions))
return PhotoCollections(collections: collections) return collections
} }
} }

Loading…
Cancel
Save