@@ -17,11 +17,11 @@ struct SelectAlbumView: View {
1717 }
1818
1919 if !model. smartAlbums. isEmpty {
20- SmartAlbums ( model: model, selectedAlbums: $selectedAlbums)
20+ AlbumView ( model: model, selectedAlbums: $selectedAlbums, albums : model . smartAlbums , sectionTitle : " _smart_albums_ " )
2121 }
2222
2323 if !model. userAlbums. isEmpty {
24- UserAlbums ( model: model, selectedAlbums: $selectedAlbums)
24+ AlbumView ( model: model, selectedAlbums: $selectedAlbums, albums : model . userAlbums , sectionTitle : " _albums_ " )
2525 }
2626 }
2727 . onChange ( of: selectedAlbums) { newValue in
@@ -47,32 +47,21 @@ struct SelectAlbumView: View {
4747 SelectAlbumView ( model: AlbumModel ( controller: nil ) )
4848}
4949
50- struct SmartAlbums : View {
50+ struct AlbumView : View {
5151 @ObservedObject var model : AlbumModel
5252 @Binding var selectedAlbums : Set < String >
53+ let albums : [ PHAssetCollection ]
54+ let sectionTitle : String
5355
5456 var body : some View {
55- Section ( NSLocalizedString ( " _smart_albums_ " , comment: " " ) ) {
56- ForEach ( model . smartAlbums , id: \. localIdentifier) { album in
57+ Section ( NSLocalizedString ( sectionTitle , comment: " " ) ) {
58+ ForEach ( albums , id: \. localIdentifier) { album in
5759 SelectionButton ( album: album, isSmartAlbum: true , selection: $selectedAlbums)
5860 }
5961 }
6062 }
6163}
6264
63- struct UserAlbums : View {
64- @ObservedObject var model : AlbumModel
65- @Binding var selectedAlbums : Set < String >
66-
67- var body : some View {
68- Section ( NSLocalizedString ( " _albums_ " , comment: " " ) ) {
69- ForEach ( model. userAlbums, id: \. localIdentifier) { album in
70- SelectionButton ( album: album, isSmartAlbum: false , selection: $selectedAlbums)
71- }
72- }
73- }
74- }
75-
7665struct SelectionButton : View {
7766 let album : PHAssetCollection ?
7867 let isSmartAlbum : Bool
@@ -116,27 +105,3 @@ struct SelectionButton: View {
116105 }
117106 }
118107}
119-
120- @MainActor class ImageLoader : ObservableObject {
121- @Published var image : UIImage ?
122-
123- func loadImage( from album: PHAssetCollection ? , targetSize: CGSize ) {
124- let fetchOptions = PHFetchOptions ( )
125- fetchOptions. sortDescriptors = [ NSSortDescriptor ( key: " creationDate " , ascending: false ) ]
126- fetchOptions. fetchLimit = 1
127-
128- let assets : PHFetchResult < PHAsset >
129-
130- if let album {
131- assets = PHAsset . fetchAssets ( in: album, options: fetchOptions)
132- } else {
133- assets = PHAsset . fetchAssets ( with: fetchOptions)
134- }
135-
136- guard let asset = assets. firstObject else { return }
137-
138- PHImageManager . default ( ) . requestImage ( for: asset, targetSize: targetSize, contentMode: . aspectFill, options: nil ) { [ weak self] image, _ in
139- self ? . image = image
140- }
141- }
142- }
0 commit comments