Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Session.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8568,7 +8568,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
COMPILE_LIB_SESSION = "";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 676;
CURRENT_PROJECT_VERSION = 678;
ENABLE_BITCODE = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down Expand Up @@ -8649,7 +8649,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Distribution";
COMPILE_LIB_SESSION = "";
CURRENT_PROJECT_VERSION = 676;
CURRENT_PROJECT_VERSION = 678;
ENABLE_BITCODE = NO;
ENABLE_MODULE_VERIFIER = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand Down Expand Up @@ -9349,7 +9349,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer";
COMPILE_LIB_SESSION = YES;
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 676;
CURRENT_PROJECT_VERSION = 678;
ENABLE_BITCODE = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand Down Expand Up @@ -9938,7 +9938,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Distribution";
COMPILE_LIB_SESSION = YES;
CURRENT_PROJECT_VERSION = 676;
CURRENT_PROJECT_VERSION = 678;
ENABLE_BITCODE = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down
28 changes: 25 additions & 3 deletions Session/Media Viewing & Editing/PhotoGridViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public class PhotoGridViewCell: UICollectionViewCell {

return result
}()

private let activityIndictor: UIActivityIndicatorView = {
let result: UIActivityIndicatorView = UIActivityIndicatorView(style: .medium)
result.startAnimating()
result.hidesWhenStopped = true

return result
}()

var item: PhotoGridItem?

Expand Down Expand Up @@ -85,6 +93,7 @@ public class PhotoGridViewCell: UICollectionViewCell {
self.contentView.addSubview(highlightedView)
self.contentView.addSubview(selectedView)
self.contentView.addSubview(selectedBadgeView)
self.contentView.addSubview(activityIndictor)

imageView.pin(to: contentView)
highlightedView.pin(to: contentView)
Expand All @@ -101,6 +110,8 @@ public class PhotoGridViewCell: UICollectionViewCell {
selectedBadgeView.pin(.bottom, to: .bottom, of: contentView, withInset: -Values.verySmallSpacing)
selectedBadgeView.set(.width, to: PhotoGridViewCell.badgeSize.width)
selectedBadgeView.set(.height, to: PhotoGridViewCell.badgeSize.height)

activityIndictor.center(in: self.contentView)
}

@available(*, unavailable, message: "Unimplemented")
Expand All @@ -111,9 +122,20 @@ public class PhotoGridViewCell: UICollectionViewCell {
public func configure(item: PhotoGridItem, using dependencies: Dependencies) {
self.item = item
imageView.setDataManager(dependencies[singleton: .imageDataManager])
imageView.themeBackgroundColor = .textSecondary
imageView.loadImage(item.source) { [weak imageView] buffer in
imageView?.themeBackgroundColor = (buffer != nil ? .clear : .textSecondary)
imageView.themeBackgroundColor = .backgroundSecondary
imageView.loadImage(item.source) { [weak imageView, weak activityIndictor] buffer in
activityIndictor?.stopAnimating()

if buffer == nil {
imageView?.image = UIImage(named: "media_invalid")?.withRenderingMode(.alwaysTemplate)
imageView?.themeTintColor = .textPrimary
imageView?.themeBackgroundColor = .backgroundSecondary
imageView?.contentMode = .center
}
else {
imageView?.themeBackgroundColor = .clear
imageView?.contentMode = .scaleAspectFill
}
}

contentTypeBadgeView.isHidden = !item.isVideo
Expand Down
19 changes: 18 additions & 1 deletion Session/Media Viewing & Editing/PhotoLibrary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,18 @@ class PhotoCollectionContents {
let options = PHImageRequestOptions()
options.deliveryMode = .highQualityFormat
options.isNetworkAccessAllowed = true

options.isSynchronous = false
options.progressHandler = { progress, error, stop, info in
if let error = error {
Log.warn("[PhotoLibrary] iCloud download progress error: \(error)")
}
}

imageManager.requestImageDataAndOrientation(for: asset, options: options) { data, uti, orientation, info in
guard !hasResumed else { return }

guard let data = data, info?[PHImageErrorKey] == nil else {
Log.error("[PhotoLibrary] Failed to retrieve animated image due to error: \(info?[PHImageErrorKey] ?? "Unknown error")")
hasResumed = true
continuation.resume(returning: nil)
return
Expand Down Expand Up @@ -196,6 +203,13 @@ class PhotoCollectionContents {
default:
return await withCheckedContinuation { [imageManager] continuation in
let options = PHImageRequestOptions()
options.isNetworkAccessAllowed = true
options.isSynchronous = false
options.progressHandler = { progress, error, stop, info in
if let error = error {
Log.warn("[PhotoLibrary] iCloud download progress error: \(error)")
}
}

switch size {
case .small: options.deliveryMode = .opportunistic
Expand All @@ -213,6 +227,7 @@ class PhotoCollectionContents {
info?[PHImageErrorKey] == nil,
(info?[PHImageCancelledKey] as? Bool) != true
else {
Log.error("[PhotoLibrary] Failed to retrieve image thumbnail due to error: \(info?[PHImageErrorKey] ?? "Unknown error")")
hasResumed = true
return continuation.resume(returning: nil)
}
Expand Down Expand Up @@ -240,11 +255,13 @@ class PhotoCollectionContents {
let options: PHImageRequestOptions = PHImageRequestOptions()
options.isSynchronous = false
options.isNetworkAccessAllowed = true
options.isSynchronous = false
options.deliveryMode = .highQualityFormat

let pendingAttachment: PendingAttachment = try await withCheckedThrowingContinuation { [imageManager] continuation in
imageManager.requestImageDataAndOrientation(for: asset, options: options) { imageData, dataUTI, orientation, info in
if let error: Error = info?[PHImageErrorKey] as? Error {
Log.error("[PhotoLibrary] Failed to retrieve image due to error: \(error)")
return continuation.resume(throwing: error)
}

Expand Down