Skip to content

Commit 525b7a1

Browse files
committed
PR suggestions
Signed-off-by: Milen Pivchev <milen.pivchev@gmail.com>
1 parent 81920e9 commit 525b7a1

File tree

3 files changed

+46
-42
lines changed

3 files changed

+46
-42
lines changed

Nextcloud.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
F3BB464D2A39ADCC00461F6E /* NCMoreAppSuggestionsCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = F3BB464C2A39ADCC00461F6E /* NCMoreAppSuggestionsCell.xib */; };
173173
F3BB46522A39EC4900461F6E /* NCMoreAppSuggestionsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3BB46512A39EC4900461F6E /* NCMoreAppSuggestionsCell.swift */; };
174174
F3BB46542A3A1E9D00461F6E /* CCCellMore.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3BB46532A3A1E9D00461F6E /* CCCellMore.swift */; };
175+
F3C587AE2D47E4FE004532DB /* ImageLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3C587AD2D47E4FE004532DB /* ImageLoader.swift */; };
175176
F3CA337D2D0B2B6C00672333 /* AlbumModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3CA337C2D0B2B6A00672333 /* AlbumModel.swift */; };
176177
F3CA33842D10726E00672333 /* NCLoginPollModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3CA33832D10726E00672333 /* NCLoginPollModel.swift */; };
177178
F3E173B02C9AF637006D177A /* ScreenAwakeManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F3E173AF2C9AF637006D177A /* ScreenAwakeManager.swift */; };
@@ -1255,6 +1256,7 @@
12551256
F3BB464C2A39ADCC00461F6E /* NCMoreAppSuggestionsCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NCMoreAppSuggestionsCell.xib; sourceTree = "<group>"; };
12561257
F3BB46512A39EC4900461F6E /* NCMoreAppSuggestionsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCMoreAppSuggestionsCell.swift; sourceTree = "<group>"; };
12571258
F3BB46532A3A1E9D00461F6E /* CCCellMore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CCCellMore.swift; sourceTree = "<group>"; };
1259+
F3C587AD2D47E4FE004532DB /* ImageLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageLoader.swift; sourceTree = "<group>"; };
12581260
F3CA337C2D0B2B6A00672333 /* AlbumModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlbumModel.swift; sourceTree = "<group>"; };
12591261
F3CA33832D10726E00672333 /* NCLoginPollModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCLoginPollModel.swift; sourceTree = "<group>"; };
12601262
F3E173AF2C9AF637006D177A /* ScreenAwakeManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenAwakeManager.swift; sourceTree = "<group>"; };
@@ -2038,6 +2040,7 @@
20382040
children = (
20392041
F3CA337C2D0B2B6A00672333 /* AlbumModel.swift */,
20402042
F389C9F42CEE383300049762 /* SelectAlbumView.swift */,
2043+
F3C587AD2D47E4FE004532DB /* ImageLoader.swift */,
20412044
);
20422045
path = SelectAlbum;
20432046
sourceTree = "<group>";
@@ -4503,6 +4506,7 @@
45034506
F7E7AEA52BA32C6500512E52 /* NCCollectionViewDownloadThumbnail.swift in Sources */,
45044507
AF730AF827834B1400B7520E /* NCShare+NCCellDelegate.swift in Sources */,
45054508
F70460522499061800BB98A7 /* NotificationCenter+MainThread.swift in Sources */,
4509+
F3C587AE2D47E4FE004532DB /* ImageLoader.swift in Sources */,
45064510
F78F74362163781100C2ADAD /* NCTrash.swift in Sources */,
45074511
F39298972A3B12CB00509762 /* BaseNCMoreCell.swift in Sources */,
45084512
AF2D7C7C2742556F00ADF566 /* NCShareLinkCell.swift in Sources */,
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// ImageLoader.swift
3+
// Nextcloud
4+
//
5+
// Created by Milen Pivchev on 27.01.25.
6+
// Copyright © 2025 Marino Faggiana. All rights reserved.
7+
//
8+
9+
10+
import SwiftUI
11+
import Photos
12+
13+
@MainActor class ImageLoader: ObservableObject {
14+
@Published var image: UIImage?
15+
16+
func loadImage(from album: PHAssetCollection?, targetSize: CGSize) {
17+
let fetchOptions = PHFetchOptions()
18+
fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
19+
fetchOptions.fetchLimit = 1
20+
21+
let assets: PHFetchResult<PHAsset>
22+
23+
if let album {
24+
assets = PHAsset.fetchAssets(in: album, options: fetchOptions)
25+
} else {
26+
assets = PHAsset.fetchAssets(with: fetchOptions)
27+
}
28+
29+
guard let asset = assets.firstObject else { return }
30+
31+
PHImageManager.default().requestImage(for: asset, targetSize: targetSize, contentMode: .aspectFill, options: nil) { [weak self] image, _ in
32+
self?.image = image
33+
}
34+
}
35+
}

iOSClient/Settings/SelectAlbum/SelectAlbumView.swift

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
7665
struct 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

Comments
 (0)