Skip to content
Open
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
112 changes: 38 additions & 74 deletions Share/NCShareExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later

import UIKit
import UniformTypeIdentifiers
import NextcloudKit
import LucidBanner
import SwiftUI
Expand Down Expand Up @@ -50,8 +49,8 @@ class NCShareExtension: UIViewController {
let global = NCGlobal.shared
var maintenanceMode: Bool = false
var token: Int?
var banner: LucidBanner?
var sceneIdentifier: String = UUID().uuidString
var banner: LucidBanner?

// MARK: - View Life Cycle

Expand Down Expand Up @@ -82,7 +81,7 @@ class NCShareExtension: UIViewController {
uploadView.layer.cornerRadius = 10

uploadLabel.text = NSLocalizedString("_upload_", comment: "")
uploadLabel.textColor = .systemBlue
uploadLabel.textColor = NCBrandColor.shared.label
let uploadGesture = UITapGestureRecognizer(target: self, action: #selector(actionUpload(_:)))
uploadView.addGestureRecognizer(uploadGesture)

Expand All @@ -93,13 +92,6 @@ class NCShareExtension: UIViewController {

NCBrandColor.shared.createUserColors()

registerForTraitChanges([UITraitUserInterfaceStyle.self]) { (self: Self, _) in
guard !self.maintenanceMode else {
return
}
self.updateAppearance()
}

NotificationCenter.default.addObserver(forName: UIApplication.willEnterForegroundNotification, object: nil, queue: nil) { _ in
if NCPreferences().presentPasscode {
NCPasscode.shared.presentPasscode(viewController: self, delegate: self) {
Expand All @@ -123,7 +115,7 @@ class NCShareExtension: UIViewController {
}

NCNetworking.shared.setupScene(sceneIdentifier: sceneIdentifier, controller: self)

if let windowScene = view.window?.windowScene {
banner = LucidBannerRegistry.shared.banner(for: windowScene)
}
Expand Down Expand Up @@ -151,33 +143,20 @@ class NCShareExtension: UIViewController {
return
}

// Keep the Share extension visually hidden until we know whether this is
// an Assistant text handoff or a normal file upload flow. This avoids the
// visible open-and-close flash when the extension only needs to redirect text.
view.alpha = 0

Task { @MainActor in
if await handleAssistantSharedTextIfNeeded(inputItems: inputItems) {
return
NCFilesExtensionHandler(items: inputItems) { fileNames in
self.filesName = fileNames
DispatchQueue.main.async {
self.setCommandView()
}
}

self.view.alpha = 1

NCFilesExtensionHandler(items: inputItems) { fileNames in
self.filesName = fileNames
DispatchQueue.main.async {
self.setCommandView()
}
if NCPreferences().presentPasscode {
NCPasscode.shared.presentPasscode(viewController: self, delegate: self) {
NCPasscode.shared.enableTouchFaceID()
}

if NCPreferences().presentPasscode {
NCPasscode.shared.presentPasscode(viewController: self, delegate: self) {
NCPasscode.shared.enableTouchFaceID()
}
}

self.collectionView.reloadData()
}

self.collectionView.reloadData()
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
Expand All @@ -188,9 +167,13 @@ class NCShareExtension: UIViewController {
}
}

private func updateAppearance() {
collectionView.visibleCells.forEach { $0.setNeedsLayout() }
tableView.visibleCells.forEach { $0.setNeedsLayout() }
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)

if !maintenanceMode {
collectionView.reloadData()
tableView.reloadData()
}
}

// MARK: -
Expand All @@ -199,7 +182,7 @@ class NCShareExtension: UIViewController {
if let error {
extensionContext?.cancelRequest(withError: error)
} else {
extensionContext?.completeRequest(returningItems: extensionContext?.inputItems, completionHandler: nil)
self.extensionContext?.completeRequest(returningItems: self.extensionContext?.inputItems, completionHandler: nil)
}
}

Expand All @@ -223,11 +206,11 @@ class NCShareExtension: UIViewController {

// BACK BUTTON
let backButton = UIButton(type: .custom)
backButton.setImage(UIImage(named: "back"), for: .normal)
backButton.tintColor = .systemBlue
backButton.setImage(UIImage(named: "back")?.withTintColor(NCBrandColor.shared.iconImageColor), for: .normal)
backButton.tintColor = NCBrandColor.shared.label
backButton.semanticContentAttribute = .forceLeftToRight
backButton.setTitle(" " + NSLocalizedString("_back_", comment: ""), for: .normal)
backButton.setTitleColor(.systemBlue, for: .normal)
backButton.setTitleColor(NCBrandColor.shared.label, for: .normal)
backButton.action(for: .touchUpInside) { _ in
while self.serverUrl.last != "/" { self.serverUrl.removeLast() }
self.serverUrl.removeLast()
Expand All @@ -241,34 +224,8 @@ class NCShareExtension: UIViewController {
self.setNavigationBar(navigationTitle: navigationTitle)
}

let image = utility.loadUserImage(for: tblAccount.user, displayName: tblAccount.displayName, urlBase: tblAccount.urlBase)
let profileButton = UIButton(type: .custom)
profileButton.setImage(image, for: .normal)

if serverUrl == utilityFileSystem.getHomeServer(session: session) {
var title = " "
if !tblAccount.alias.isEmpty {
title += tblAccount.alias
} else {
title += tblAccount.displayName
}

profileButton.setTitle(title, for: .normal)
profileButton.setTitleColor(.systemBlue, for: .normal)
}

profileButton.semanticContentAttribute = .forceLeftToRight
profileButton.sizeToFit()
profileButton.action(for: .touchUpInside) { _ in
self.showAccountPicker()
}
var navItems = [UIBarButtonItem(customView: profileButton)]
if serverUrl != utilityFileSystem.getHomeServer(session: session) {
let space = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
space.width = 20
navItems.append(contentsOf: [UIBarButtonItem(customView: backButton), space])
}
navigationItem.setLeftBarButtonItems(navItems, animated: true)
// navigationItem.setLeftBarButtonItems(navItems, animated: true)
navigationItem.setLeftBarButtonItems([UIBarButtonItem(customView: backButton)], animated: true)
}

func setCommandView() {
Expand Down Expand Up @@ -297,7 +254,7 @@ class NCShareExtension: UIViewController {
guard let capabilities = NCNetworking.shared.capabilities[session.account] else {
return
}
let alertController = UIAlertController.createFolderWith(serverUrl: serverUrl, session: session, capabilities: capabilities) { error in
let alertController = UIAlertController.createFolder(serverUrl: serverUrl, session: session, capabilities: capabilities, scene: self.view.window?.windowScene) { error in
if error == .success {
Task {
await self.loadFolder()
Expand Down Expand Up @@ -396,8 +353,14 @@ extension NCShareExtension {
guard let window = self.view.window else {
return
}
let horizontalLayout = horizontalLayoutBanner(bounds: window.bounds,
safeAreaInsets: window.safeAreaInsets,
idiom: window.traitCollection.userInterfaceIdiom)

let payload = LucidBannerPayload(stage: .button,
backgroundColor: Color(.systemBackground),
vPosition: .center,
horizontalLayout: horizontalLayout,
blocksTouches: true)
(banner, token) = showUploadBanner(windowScene: window.windowScene,
payload: payload,
Expand Down Expand Up @@ -427,10 +390,11 @@ extension NCShareExtension {
banner?.update(payload: LucidBannerPayload.Update(subtitle: error?.errorDescription, stage: .error), for: self.token)
}

Task { @MainActor in
try? await Task.sleep(for: .seconds(2))
banner?.dismiss()
extensionContext?.completeRequest(returningItems: extensionContext?.inputItems, completionHandler: nil)
if let banner, let token {
Task { @MainActor in
try? await Task.sleep(for: .seconds(2))
banner.dismiss()
}
}
}

Expand Down
Loading