Skip to content
Draft
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
2 changes: 1 addition & 1 deletion iOSClient/Menu/NCContextMenuMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class NCContextMenuMain: NSObject {

private func makeModifyWithQuickLookAction(metadata: tableMetadata) -> UIAction {
return UIAction(
title: NSLocalizedString("_modify_", comment: ""),
title: NSLocalizedString("_edit_", comment: ""),
image: utility.loadImage(named: "pencil.tip.crop.circle", colors: [NCBrandColor.shared.iconImageColor])
) { _ in
Task {
Expand Down
11 changes: 9 additions & 2 deletions iOSClient/Menu/NCContextMenuViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class NCContextMenuViewer: NSObject {
if !webView,
metadata.isImage,
metadata.isModifiableWithQuickLook,
utilityFileSystem.fileSizeIfExists(metadata) {
NCNetworking.shared.isOnline || utilityFileSystem.fileSizeIfExists(metadata) {
editingActions.append(makeModifyPhoto())
}

Expand Down Expand Up @@ -296,10 +296,17 @@ class NCContextMenuViewer: NSObject {

private func makeModifyPhoto() -> UIAction {
return UIAction(
title: NSLocalizedString("_modify_", comment: ""),
title: NSLocalizedString("_edit_", comment: ""),
image: utility.loadImage(named: "pencil.tip.crop.circle", colors: [NCBrandColor.shared.iconImageColor])
) { _ in
Task {
if !self.utilityFileSystem.fileSizeIfExists(self.metadata) {
// Only a preview is on the device: let the media viewer download the original first.
guard let viewer = self.viewController as? NCMediaViewerHostingController,
await viewer.downloadOriginalForEditing(self.metadata) else {
return
}
}
await NCNetworking.shared.transferDispatcher.notifyAllDelegates { delegate in
delegate.transferChange(
networkingStatus: NCGlobal.shared.networkingStatusDownloaded,
Expand Down
5 changes: 4 additions & 1 deletion iOSClient/Networking/NCNetworking+TransferDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ extension NCNetworking: NCTransferDelegate {
fileName: metadata.fileNameView,
userId: metadata.userId,
urlBase: metadata.urlBase)
let fileNameTemp = NSTemporaryDirectory() + metadata.fileNameView
// One stable copy per photo, so repeated edits overwrite it instead of piling up.
let directoryTemp = NSTemporaryDirectory() + "QuickLookEdit/" + metadata.ocId
try? FileManager.default.createDirectory(atPath: directoryTemp, withIntermediateDirectories: true)
let fileNameTemp = directoryTemp + "/" + metadata.fileNameView
let viewerQuickLook = NCViewerQuickLook(with: URL(fileURLWithPath: fileNameTemp), isEditingEnabled: true, metadata: metadata)
if let image = UIImage(contentsOfFile: fileNamePath) {
if let data = image.jpegData(compressionQuality: 1) {
Expand Down
12 changes: 11 additions & 1 deletion iOSClient/Viewer/NCViewerMedia/Core/NCMediaViewerModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ final class NCMediaViewerModel: ObservableObject {
private var viewerDownloadedLivePhotoOcIds = Set<String>()
// Also serialize a quick close/reopen against the previous viewer's pending removals.
private static var releasingImagesByAccount: [String: [String: Task<Void, Never>]] = [:]
private var isClosed = false
private(set) var isClosed = false
private var previewSelectionID: UUID?
private var thumbnailScrubID: UUID?

Expand Down Expand Up @@ -740,6 +740,16 @@ final class NCMediaViewerModel: ObservableObject {
}

guard thumbnailScrubID == nil else { return }
let isImage = metadata.classFile == NKTypeClassFile.image.rawValue
if isImage {
setState(.downloading(previewURL: previewURL, progress: nil), for: ocId)
}
defer {
if isImage, case .downloading = pageState(for: ocId) {
setState(.image(previewURL: previewURL, localURL: nil, livePhotoURL: nil, progress: nil), for: ocId)
}
}

do {
let downloadedURL = try await loader.downloadMedia(for: metadata, onDownloadStarted: nil)
viewerDownloadedOcIds.insert(ocId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,30 @@ final class NCMediaViewerHostingController: UIHostingController<NCMediaViewerVie
func markItemAsDeleted(ocId: String) {
model.markPageAsDeleted(ocId: ocId)
}

/// Downloads the original of a photo for editing.
/// Returns `true` only if the viewer is still on screen and showing that photo once the download finishes.
func downloadOriginalForEditing(_ metadata: tableMetadata) async -> Bool {
let ocId = metadata.ocId
var isStillViewingPhoto: Bool {
!model.isClosed && viewIfLoaded?.window != nil && model.selectedMetadata?.ocId == ocId
}
guard isStillViewingPhoto else { return false }

do {
// This delegates to loadPageIfNeeded instead of downloading directly.
// NCMediaViewerLoadingPolicy.shouldDownloadOriginalImage controls the fetch
// (enabled by automaticallyDownloadsOriginalImages: true in NCMediaViewerModel+App.swift).
// If the policy skips the original, CancellationError is reported below.
try await model.downloadOriginalImage(for: model.viewerItem(from: metadata))
} catch {
if isStillViewingPhoto {
await showErrorBanner(windowScene: viewIfLoaded?.window?.windowScene, text: "_status_download_error_")
}
return false
}
return isStillViewingPhoto
}
}

// MARK: - Media Viewer Transfer Delegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,19 @@ struct NCMediaViewerPageView: View {
@ViewBuilder
private func downloadingStateView(previewURL: URL?, _ progress: Double?) -> some View {
switch page.metadata?.classFile {
case NKTypeClassFile.image.rawValue:
imageStateView(previewURL: previewURL, localURL: nil, livePhotoURL: nil)
.overlay {
if isSelected {
ProgressView()
.tint(.white)
.padding(12)
.background(.black.opacity(0.65), in: Circle())
.accessibilityLabel(Text(NSLocalizedString("_download_in_progress_", comment: "")))
.allowsHitTesting(false)
}
}

case NKTypeClassFile.video.rawValue:
if isSelected {
videoStateView(localURL: nil, previewURL: previewURL)
Expand Down
12 changes: 5 additions & 7 deletions iOSClient/Viewer/NCViewerQuickLook/NCViewerQuickLook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ public extension NCViewerQuickLookDelegate {
func dismissQuickLook(fileNameSource: String, hasChangesQuickLook: Bool) {}
}

/// Flag indicating If the document has any changes
private var hasChangesQuickLook: Bool = false

@objc class NCViewerQuickLook: QLPreviewController {
/// Flag indicating If the document has any changes
private var hasChangesQuickLook: Bool = false
private let url: URL
private let fileNameSource: String
private var previewItems: [PreviewItem] = []
Expand Down Expand Up @@ -61,7 +60,6 @@ private var hasChangesQuickLook: Bool = false
self.dataSource = self
self.delegate = self
self.currentPreviewItemIndex = 0
hasChangesQuickLook = false
}

override func viewDidLoad() {
Expand Down Expand Up @@ -133,7 +131,7 @@ private var hasChangesQuickLook: Bool = false
} else {
alertController.addAction(UIAlertAction(title: NSLocalizedString("_overwrite_original_", comment: ""), style: .default) { _ in
self.saveModifiedFile(override: true)
self.delegateQuickLook?.dismissQuickLook(fileNameSource: self.fileNameSource, hasChangesQuickLook: hasChangesQuickLook)
self.delegateQuickLook?.dismissQuickLook(fileNameSource: self.fileNameSource, hasChangesQuickLook: self.hasChangesQuickLook)
})
}

Expand All @@ -142,7 +140,7 @@ private var hasChangesQuickLook: Bool = false
if saveAsCopyAlert {
alertController.addAction(UIAlertAction(title: NSLocalizedString("_save_as_copy_", comment: ""), style: .default) { _ in
self.saveModifiedFile(override: false)
self.delegateQuickLook?.dismissQuickLook(fileNameSource: self.fileNameSource, hasChangesQuickLook: hasChangesQuickLook)
self.delegateQuickLook?.dismissQuickLook(fileNameSource: self.fileNameSource, hasChangesQuickLook: self.hasChangesQuickLook)
})
}
alertController.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel) { _ in
Expand All @@ -156,7 +154,7 @@ private var hasChangesQuickLook: Bool = false

@objc private func dismissView(_ sender: Any?) {
dismiss(animated: true) {
if hasChangesQuickLook {
if self.hasChangesQuickLook {
self.showSaveAlert()
}
}
Expand Down