From ff45070219167092095995a877be05478eafd515 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Mon, 10 Dec 2018 11:57:21 -0700 Subject: [PATCH] Optimize album ordering - remove unnecessary albums --- .../PhotoLibrary/PhotoLibrary.swift | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/Signal/src/ViewControllers/PhotoLibrary/PhotoLibrary.swift b/Signal/src/ViewControllers/PhotoLibrary/PhotoLibrary.swift index d510e5a3a..86a45d86d 100644 --- a/Signal/src/ViewControllers/PhotoLibrary/PhotoLibrary.swift +++ b/Signal/src/ViewControllers/PhotoLibrary/PhotoLibrary.swift @@ -288,11 +288,24 @@ class PhotoLibrary: NSObject, PHPhotoLibraryChangeObserver { guard photoCollection.contents().assetCount > 0 else { return } + collections.append(photoCollection) } let processPHAssetCollections: (PHFetchResult) -> Void = { (fetchResult) in - for index in 0..) -> Void = { (fetchResult) in @@ -302,13 +315,19 @@ class PhotoLibrary: NSObject, PHPhotoLibraryChangeObserver { } let fetchOptions = PHFetchOptions() fetchOptions.sortDescriptors = [NSSortDescriptor(key: "endDate", ascending: true)] + // Try to add "Camera Roll" first. processPHAssetCollections(PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .smartAlbumUserLibrary, options: fetchOptions)) - // User-created albums. - processPHCollections(PHAssetCollection.fetchTopLevelUserCollections(with: fetchOptions)) + + // Favorites + processPHAssetCollections(PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .smartAlbumFavorites, options: fetchOptions)) + // Smart albums. processPHAssetCollections(PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .albumRegular, options: fetchOptions)) + // User-created albums. + processPHCollections(PHAssetCollection.fetchTopLevelUserCollections(with: fetchOptions)) + return collections } }