diff --git a/kDrive/UI/Controller/Files/Save File/SaveFileViewController+FooterButtonDelegate.swift b/kDrive/UI/Controller/Files/Save File/SaveFileViewController+FooterButtonDelegate.swift
index b4684065d..22de58218 100644
--- a/kDrive/UI/Controller/Files/Save File/SaveFileViewController+FooterButtonDelegate.swift
+++ b/kDrive/UI/Controller/Files/Save File/SaveFileViewController+FooterButtonDelegate.swift
@@ -23,8 +23,6 @@ import kDriveCore
import kDriveResources
import UIKit
-// MARK: - FooterButtonDelegate
-
extension SaveFileViewController: FooterButtonDelegate {
@objc func didClickOnButton(_ sender: AnyObject) {
guard let drive = selectedDriveFileManager?.drive,
diff --git a/kDrive/UI/Controller/Files/Save File/SaveFileViewController+SelectDriveDelegate.swift b/kDrive/UI/Controller/Files/Save File/SaveFileViewController+SelectDriveDelegate.swift
new file mode 100644
index 000000000..9607aa602
--- /dev/null
+++ b/kDrive/UI/Controller/Files/Save File/SaveFileViewController+SelectDriveDelegate.swift
@@ -0,0 +1,34 @@
+/*
+ Infomaniak kDrive - iOS App
+ Copyright (C) 2024 Infomaniak Network SA
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
+
+import Foundation
+import kDriveCore
+
+extension SaveFileViewController: SelectDriveDelegate {
+ func didSelectDrive(_ drive: Drive) {
+ if let selectedDriveFileManager = accountManager.getDriveFileManager(for: drive.id, userId: drive.userId) {
+ self.selectedDriveFileManager = selectedDriveFileManager
+ selectedDirectory = getBestDirectory()
+ sections = [.fileName, .driveSelection, .directorySelection]
+ if itemProvidersContainHeicPhotos {
+ sections.append(.photoFormatOption)
+ }
+ }
+ updateButton()
+ }
+}
diff --git a/kDrive/UI/Controller/Files/Save File/SaveFileViewController+SelectFolderDelegate.swift b/kDrive/UI/Controller/Files/Save File/SaveFileViewController+SelectFolderDelegate.swift
new file mode 100644
index 000000000..d776c0ce6
--- /dev/null
+++ b/kDrive/UI/Controller/Files/Save File/SaveFileViewController+SelectFolderDelegate.swift
@@ -0,0 +1,32 @@
+/*
+ Infomaniak kDrive - iOS App
+ Copyright (C) 2024 Infomaniak Network SA
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
+
+import kDriveCore
+import UIKit
+
+extension SaveFileViewController: SelectFolderDelegate {
+ func didSelectFolder(_ folder: File) {
+ if folder.id == DriveFileManager.constants.rootID {
+ selectedDirectory = selectedDriveFileManager?.getCachedRootFile()
+ } else {
+ selectedDirectory = folder
+ }
+ updateButton()
+ tableView.reloadData()
+ }
+}
diff --git a/kDrive/UI/Controller/Files/Save File/SaveFileViewController+SelectPhotoFormatDelegate.swift b/kDrive/UI/Controller/Files/Save File/SaveFileViewController+SelectPhotoFormatDelegate.swift
new file mode 100644
index 000000000..27a71f4cf
--- /dev/null
+++ b/kDrive/UI/Controller/Files/Save File/SaveFileViewController+SelectPhotoFormatDelegate.swift
@@ -0,0 +1,33 @@
+/*
+ Infomaniak kDrive - iOS App
+ Copyright (C) 2024 Infomaniak Network SA
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
+
+import Foundation
+import kDriveCore
+
+extension SaveFileViewController: SelectPhotoFormatDelegate {
+ func didSelectPhotoFormat(_ format: PhotoFileFormat) {
+ if userPreferredPhotoFormat != format {
+ userPreferredPhotoFormat = format
+ if itemProviders?.isEmpty == false {
+ setItemProviders()
+ } else {
+ setAssetIdentifiers()
+ }
+ }
+ }
+}
diff --git a/kDrive/UI/Controller/Files/Save File/SaveFileViewController+UITableViewDataSource.swift b/kDrive/UI/Controller/Files/Save File/SaveFileViewController+UITableViewDataSource.swift
new file mode 100644
index 000000000..284734cea
--- /dev/null
+++ b/kDrive/UI/Controller/Files/Save File/SaveFileViewController+UITableViewDataSource.swift
@@ -0,0 +1,121 @@
+/*
+ Infomaniak kDrive - iOS App
+ Copyright (C) 2024 Infomaniak Network SA
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
+
+import kDriveResources
+import UIKit
+
+extension SaveFileViewController: UITableViewDataSource {
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
+ let section = sections[section]
+ if section == .fileName {
+ return items.count
+ } else {
+ return 1
+ }
+ }
+
+ func numberOfSections(in tableView: UITableView) -> Int {
+ return sections.count
+ }
+
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
+ switch sections[indexPath.section] {
+ case .alert:
+ let cell = tableView.dequeueReusableCell(type: AlertTableViewCell.self, for: indexPath)
+ cell.configure(with: .warning, message: KDriveResourcesStrings.Localizable.snackBarUploadError(errorCount))
+ return cell
+ case .fileName:
+ let item = items[indexPath.row]
+ if items.count > 1 {
+ let cell = tableView.dequeueReusableCell(type: UploadTableViewCell.self, for: indexPath)
+ cell.initWithPositionAndShadow(
+ isFirst: indexPath.row == 0,
+ isLast: indexPath.row == self.tableView(tableView, numberOfRowsInSection: indexPath.section) - 1
+ )
+ cell.configureWith(importedFile: item)
+ return cell
+ } else {
+ let cell = tableView.dequeueReusableCell(type: FileNameTableViewCell.self, for: indexPath)
+ cell.textField.text = item.name
+ cell.textDidChange = { [weak self] text in
+ guard let self else { return }
+ item.name = text ?? KDriveResourcesStrings.Localizable.allUntitledFileName
+ if let text, !text.isEmpty {
+ updateButton()
+ } else {
+ enableButton = false
+ }
+ }
+ return cell
+ }
+ case .driveSelection:
+ let cell = tableView.dequeueReusableCell(type: LocationTableViewCell.self, for: indexPath)
+ cell.initWithPositionAndShadow(isFirst: true, isLast: true)
+ cell.configure(with: selectedDriveFileManager?.drive)
+ return cell
+ case .directorySelection:
+ let cell = tableView.dequeueReusableCell(type: LocationTableViewCell.self, for: indexPath)
+ cell.initWithPositionAndShadow(isFirst: true, isLast: true)
+ cell.configure(with: selectedDirectory, drive: selectedDriveFileManager!.drive)
+ return cell
+ case .photoFormatOption:
+ let cell = tableView.dequeueReusableCell(type: PhotoFormatTableViewCell.self, for: indexPath)
+ cell.initWithPositionAndShadow(isFirst: true, isLast: true)
+ cell.configure(with: userPreferredPhotoFormat)
+ return cell
+ case .importing:
+ let cell = tableView.dequeueReusableCell(type: ImportingTableViewCell.self, for: indexPath)
+ cell.importationProgressView.observedProgress = importProgress
+ return cell
+ default:
+ fatalError("Not supported by this datasource")
+ }
+ }
+
+ func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
+ switch sections[section] {
+ case .fileName:
+ return HomeTitleView.instantiate(title: "")
+ case .driveSelection:
+ return HomeTitleView.instantiate(title: "kDrive")
+ case .directorySelection:
+ return HomeTitleView.instantiate(title: KDriveResourcesStrings.Localizable.allPathTitle)
+ case .photoFormatOption:
+ return HomeTitleView.instantiate(title: KDriveResourcesStrings.Localizable.photoFormatTitle)
+ default:
+ return nil
+ }
+ }
+
+ func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
+ if section == tableView.numberOfSections - 1 && !importInProgress {
+ return 124
+ }
+ return 32
+ }
+
+ func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
+ if section == tableView.numberOfSections - 1 && !importInProgress {
+ let view = FooterButtonView.instantiate(title: KDriveResourcesStrings.Localizable.buttonSave)
+ view.delegate = self
+ view.footerButton.isEnabled = enableButton
+ return view
+ }
+ return nil
+ }
+}
diff --git a/kDrive/UI/Controller/Files/Save File/SaveFileViewController+UITableViewDelegate.swift b/kDrive/UI/Controller/Files/Save File/SaveFileViewController+UITableViewDelegate.swift
new file mode 100644
index 000000000..b15a6a46c
--- /dev/null
+++ b/kDrive/UI/Controller/Files/Save File/SaveFileViewController+UITableViewDelegate.swift
@@ -0,0 +1,67 @@
+/*
+ Infomaniak kDrive - iOS App
+ Copyright (C) 2024 Infomaniak Network SA
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+ */
+
+import kDriveCore
+import kDriveResources
+import UIKit
+
+extension SaveFileViewController: UITableViewDelegate {
+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
+ tableView.deselectRow(at: indexPath, animated: true)
+ switch sections[indexPath.section] {
+ case .fileName:
+ let item = items[indexPath.row]
+ if items.count > 1 {
+ let alert = AlertFieldViewController(
+ title: KDriveResourcesStrings.Localizable.buttonRename,
+ placeholder: KDriveResourcesStrings.Localizable.hintInputFileName,
+ text: item.name,
+ action: KDriveResourcesStrings.Localizable.buttonSave,
+ loading: false
+ ) { newName in
+ item.name = newName
+ tableView.reloadRows(at: [indexPath], with: .automatic)
+ }
+ alert.textFieldConfiguration = .fileNameConfiguration
+ alert.textFieldConfiguration.selectedRange = item.name
+ .startIndex ..< (item.name.lastIndex { $0 == "." } ?? item.name.endIndex)
+ present(alert, animated: true)
+ }
+ case .driveSelection:
+ let selectDriveViewController = SelectDriveViewController.instantiate()
+ selectDriveViewController.selectedDrive = selectedDriveFileManager?.drive
+ selectDriveViewController.delegate = self
+ navigationController?.pushViewController(selectDriveViewController, animated: true)
+ case .directorySelection:
+ guard let driveFileManager = selectedDriveFileManager else { return }
+ let selectFolderNavigationController = SelectFolderViewController.instantiateInNavigationController(
+ driveFileManager: driveFileManager,
+ startDirectory: selectedDirectory,
+ delegate: self
+ )
+ present(selectFolderNavigationController, animated: true)
+ case .photoFormatOption:
+ let selectPhotoFormatViewController = SelectPhotoFormatViewController
+ .instantiate(selectedFormat: userPreferredPhotoFormat)
+ selectPhotoFormatViewController.delegate = self
+ navigationController?.pushViewController(selectPhotoFormatViewController, animated: true)
+ default:
+ break
+ }
+ }
+}
diff --git a/kDrive/UI/Controller/Files/Save File/SaveFileViewController.swift b/kDrive/UI/Controller/Files/Save File/SaveFileViewController.swift
index 5a099f78c..7db6efa73 100644
--- a/kDrive/UI/Controller/Files/Save File/SaveFileViewController.swift
+++ b/kDrive/UI/Controller/Files/Save File/SaveFileViewController.swift
@@ -16,7 +16,6 @@
along with this program. If not, see .
*/
-import CocoaLumberjackSwift
import InfomaniakCore
import InfomaniakCoreUIKit
import InfomaniakDI
@@ -30,6 +29,16 @@ class SaveFileViewController: UIViewController {
@LazyInjectService var fileImportHelper: FileImportHelper
@LazyInjectService var appContextService: AppContextServiceable
+ private var originalDriveId: Int = {
+ @InjectService var accountManager: AccountManageable
+ return accountManager.currentDriveId
+ }()
+
+ private var originalUserId: Int = {
+ @InjectService var accountManager: AccountManageable
+ return accountManager.currentUserId
+ }()
+
enum SaveFileSection {
case alert
case fileName
@@ -47,16 +56,6 @@ class SaveFileViewController: UIViewController {
var sections: [SaveFileSection] = [.fileName, .driveSelection, .directorySelection]
- private var originalDriveId: Int = {
- @InjectService var accountManager: AccountManageable
- return accountManager.currentDriveId
- }()
-
- private var originalUserId: Int = {
- @InjectService var accountManager: AccountManageable
- return accountManager.currentUserId
- }()
-
var selectedDriveFileManager: DriveFileManager?
var selectedDirectory: File?
var photoFormat = PhotoFileFormat.jpg
@@ -92,9 +91,9 @@ class SaveFileViewController: UIViewController {
return false
}
- private var errorCount = 0
- private var importProgress: Progress?
- private var enableButton = false {
+ var errorCount = 0
+ var importProgress: Progress?
+ var enableButton = false {
didSet {
guard let footer = tableView.footerView(forSection: tableView.numberOfSections - 1) as? FooterButtonView else {
return
@@ -103,7 +102,7 @@ class SaveFileViewController: UIViewController {
}
}
- private var importInProgress: Bool {
+ var importInProgress: Bool {
if let progress = importProgress {
return progress.fractionCompleted < 1
} else {
@@ -159,39 +158,22 @@ class SaveFileViewController: UIViewController {
)
}
- func getBestDirectory() -> File? {
- if lastSelectedDirectory?.driveId == selectedDriveFileManager?.drive.id {
- return lastSelectedDirectory
- }
-
- guard let selectedDriveFileManager else { return nil }
-
- let myFilesDirectory = selectedDriveFileManager.database.fetchResults(ofType: File.self) { lazyFiles in
- lazyFiles.filter("rawVisibility = %@", FileVisibility.isPrivateSpace.rawValue)
- }.first
-
- if let myFilesDirectory {
- return myFilesDirectory.freezeIfNeeded()
- }
-
- // If we are in a shared with me, we only have access to some folders that are shared with the user
- guard selectedDriveFileManager.drive.sharedWithMe else { return nil }
-
- let firstAvailableSharedDriveDirectory = selectedDriveFileManager.database.fetchResults(ofType: File.self) { lazyFiles in
- lazyFiles.filter(
- "rawVisibility = %@ AND driveId == %d",
- FileVisibility.isInSharedSpace.rawValue,
- selectedDriveFileManager.drive.id
- )
- }.first
- return firstAvailableSharedDriveDirectory?.freezeIfNeeded()
- }
-
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
MatomoUtils.track(view: [MatomoUtils.Views.save.displayName, "SaveFile"])
}
+ override func viewWillAppear(_ animated: Bool) {
+ super.viewWillAppear(animated)
+ navigationController?.setInfomaniakAppearanceNavigationBar()
+ tableView.reloadData()
+ }
+
+ deinit {
+ NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillShowNotification, object: nil)
+ NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil)
+ }
+
@objc func keyboardWillShow(_ notification: Notification) {
if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
tableView.contentInset.bottom = keyboardSize.height
@@ -209,25 +191,15 @@ class SaveFileViewController: UIViewController {
}
}
- func dismiss(animated: Bool, clean: Bool = true, completion: (() -> Void)? = nil) {
- Task {
- // Cleanup file that were duplicated to appGroup on extension mode
- if appContextService.isExtension && clean {
- await items.concurrentForEach { item in
- try? FileManager.default.removeItem(at: item.path)
- }
- }
-
- navigationController?.dismiss(animated: animated, completion: completion)
+ @IBAction func close(_ sender: Any) {
+ importProgress?.cancel()
+ dismiss(animated: true)
+ if let extensionContext {
+ extensionContext.completeRequest(returningItems: nil, completionHandler: nil)
}
}
- deinit {
- NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillShowNotification, object: nil)
- NotificationCenter.default.removeObserver(self, name: UIResponder.keyboardWillHideNotification, object: nil)
- }
-
- private func setAssetIdentifiers() {
+ func setAssetIdentifiers() {
guard let assetIdentifiers else { return }
sections = [.importing]
importProgress = fileImportHelper.importAssets(
@@ -246,7 +218,7 @@ class SaveFileViewController: UIViewController {
}
}
- private func setItemProviders() {
+ func setItemProviders() {
guard let itemProviders else { return }
sections = [.importing]
importProgress = fileImportHelper
@@ -264,10 +236,51 @@ class SaveFileViewController: UIViewController {
}
}
- private func updateButton() {
+ func updateButton() {
enableButton = selectedDirectory != nil && items.allSatisfy { !$0.name.isEmpty } && !items.isEmpty && !importInProgress
}
+ func getBestDirectory() -> File? {
+ if lastSelectedDirectory?.driveId == selectedDriveFileManager?.drive.id {
+ return lastSelectedDirectory
+ }
+
+ guard let selectedDriveFileManager else { return nil }
+
+ let myFilesDirectory = selectedDriveFileManager.database.fetchResults(ofType: File.self) { lazyFiles in
+ lazyFiles.filter("rawVisibility = %@", FileVisibility.isPrivateSpace.rawValue)
+ }.first
+
+ if let myFilesDirectory {
+ return myFilesDirectory.freezeIfNeeded()
+ }
+
+ // If we are in a shared with me, we only have access to some folders that are shared with the user
+ guard selectedDriveFileManager.drive.sharedWithMe else { return nil }
+
+ let firstAvailableSharedDriveDirectory = selectedDriveFileManager.database.fetchResults(ofType: File.self) { lazyFiles in
+ lazyFiles.filter(
+ "rawVisibility = %@ AND driveId == %d",
+ FileVisibility.isInSharedSpace.rawValue,
+ selectedDriveFileManager.drive.id
+ )
+ }.first
+ return firstAvailableSharedDriveDirectory?.freezeIfNeeded()
+ }
+
+ func dismiss(animated: Bool, clean: Bool = true, completion: (() -> Void)? = nil) {
+ Task {
+ // Cleanup file that were duplicated to appGroup on extension mode
+ if appContextService.isExtension && clean {
+ await items.concurrentForEach { item in
+ try? FileManager.default.removeItem(at: item.path)
+ }
+ }
+
+ navigationController?.dismiss(animated: animated, completion: completion)
+ }
+ }
+
private func updateTableViewAfterImport() {
guard !importInProgress else { return }
// Update table view
@@ -298,12 +311,6 @@ class SaveFileViewController: UIViewController {
}
}
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- navigationController?.setInfomaniakAppearanceNavigationBar()
- tableView.reloadData()
- }
-
class func instantiate(driveFileManager: DriveFileManager?) -> SaveFileViewController {
let viewController = Storyboard.saveFile
.instantiateViewController(withIdentifier: "SaveFileViewController") as! SaveFileViewController
@@ -321,208 +328,4 @@ class SaveFileViewController: UIViewController {
navigationController.navigationBar.prefersLargeTitles = true
return navigationController
}
-
- @IBAction func close(_ sender: Any) {
- importProgress?.cancel()
- dismiss(animated: true)
- if let extensionContext {
- extensionContext.completeRequest(returningItems: nil, completionHandler: nil)
- }
- }
-}
-
-// MARK: - UITableViewDataSource
-
-extension SaveFileViewController: UITableViewDataSource {
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- let section = sections[section]
- if section == .fileName {
- return items.count
- } else {
- return 1
- }
- }
-
- func numberOfSections(in tableView: UITableView) -> Int {
- return sections.count
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- switch sections[indexPath.section] {
- case .alert:
- let cell = tableView.dequeueReusableCell(type: AlertTableViewCell.self, for: indexPath)
- cell.configure(with: .warning, message: KDriveResourcesStrings.Localizable.snackBarUploadError(errorCount))
- return cell
- case .fileName:
- let item = items[indexPath.row]
- if items.count > 1 {
- let cell = tableView.dequeueReusableCell(type: UploadTableViewCell.self, for: indexPath)
- cell.initWithPositionAndShadow(
- isFirst: indexPath.row == 0,
- isLast: indexPath.row == self.tableView(tableView, numberOfRowsInSection: indexPath.section) - 1
- )
- cell.configureWith(importedFile: item)
- return cell
- } else {
- let cell = tableView.dequeueReusableCell(type: FileNameTableViewCell.self, for: indexPath)
- cell.textField.text = item.name
- cell.textDidChange = { [weak self] text in
- guard let self else { return }
- item.name = text ?? KDriveResourcesStrings.Localizable.allUntitledFileName
- if let text, !text.isEmpty {
- updateButton()
- } else {
- enableButton = false
- }
- }
- return cell
- }
- case .driveSelection:
- let cell = tableView.dequeueReusableCell(type: LocationTableViewCell.self, for: indexPath)
- cell.initWithPositionAndShadow(isFirst: true, isLast: true)
- cell.configure(with: selectedDriveFileManager?.drive)
- return cell
- case .directorySelection:
- let cell = tableView.dequeueReusableCell(type: LocationTableViewCell.self, for: indexPath)
- cell.initWithPositionAndShadow(isFirst: true, isLast: true)
- cell.configure(with: selectedDirectory, drive: selectedDriveFileManager!.drive)
- return cell
- case .photoFormatOption:
- let cell = tableView.dequeueReusableCell(type: PhotoFormatTableViewCell.self, for: indexPath)
- cell.initWithPositionAndShadow(isFirst: true, isLast: true)
- cell.configure(with: userPreferredPhotoFormat)
- return cell
- case .importing:
- let cell = tableView.dequeueReusableCell(type: ImportingTableViewCell.self, for: indexPath)
- cell.importationProgressView.observedProgress = importProgress
- return cell
- default:
- fatalError("Not supported by this datasource")
- }
- }
-
- func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
- switch sections[section] {
- case .fileName:
- return HomeTitleView.instantiate(title: "")
- case .driveSelection:
- return HomeTitleView.instantiate(title: "kDrive")
- case .directorySelection:
- return HomeTitleView.instantiate(title: KDriveResourcesStrings.Localizable.allPathTitle)
- case .photoFormatOption:
- return HomeTitleView.instantiate(title: KDriveResourcesStrings.Localizable.photoFormatTitle)
- default:
- return nil
- }
- }
-
- func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
- if section == tableView.numberOfSections - 1 && !importInProgress {
- return 124
- }
- return 32
- }
-
- func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
- if section == tableView.numberOfSections - 1 && !importInProgress {
- let view = FooterButtonView.instantiate(title: KDriveResourcesStrings.Localizable.buttonSave)
- view.delegate = self
- view.footerButton.isEnabled = enableButton
- return view
- }
- return nil
- }
-}
-
-// MARK: - UITableViewDelegate
-
-extension SaveFileViewController: UITableViewDelegate {
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- tableView.deselectRow(at: indexPath, animated: true)
- switch sections[indexPath.section] {
- case .fileName:
- let item = items[indexPath.row]
- if items.count > 1 {
- let alert = AlertFieldViewController(
- title: KDriveResourcesStrings.Localizable.buttonRename,
- placeholder: KDriveResourcesStrings.Localizable.hintInputFileName,
- text: item.name,
- action: KDriveResourcesStrings.Localizable.buttonSave,
- loading: false
- ) { newName in
- item.name = newName
- tableView.reloadRows(at: [indexPath], with: .automatic)
- }
- alert.textFieldConfiguration = .fileNameConfiguration
- alert.textFieldConfiguration.selectedRange = item.name
- .startIndex ..< (item.name.lastIndex { $0 == "." } ?? item.name.endIndex)
- present(alert, animated: true)
- }
- case .driveSelection:
- let selectDriveViewController = SelectDriveViewController.instantiate()
- selectDriveViewController.selectedDrive = selectedDriveFileManager?.drive
- selectDriveViewController.delegate = self
- navigationController?.pushViewController(selectDriveViewController, animated: true)
- case .directorySelection:
- guard let driveFileManager = selectedDriveFileManager else { return }
- let selectFolderNavigationController = SelectFolderViewController.instantiateInNavigationController(
- driveFileManager: driveFileManager,
- startDirectory: selectedDirectory,
- delegate: self
- )
- present(selectFolderNavigationController, animated: true)
- case .photoFormatOption:
- let selectPhotoFormatViewController = SelectPhotoFormatViewController
- .instantiate(selectedFormat: userPreferredPhotoFormat)
- selectPhotoFormatViewController.delegate = self
- navigationController?.pushViewController(selectPhotoFormatViewController, animated: true)
- default:
- break
- }
- }
-}
-
-// MARK: - SelectFolderDelegate
-
-extension SaveFileViewController: SelectFolderDelegate {
- func didSelectFolder(_ folder: File) {
- if folder.id == DriveFileManager.constants.rootID {
- selectedDirectory = selectedDriveFileManager?.getCachedRootFile()
- } else {
- selectedDirectory = folder
- }
- updateButton()
- tableView.reloadData()
- }
-}
-
-// MARK: - SelectDriveDelegate
-
-extension SaveFileViewController: SelectDriveDelegate {
- func didSelectDrive(_ drive: Drive) {
- if let selectedDriveFileManager = accountManager.getDriveFileManager(for: drive.id, userId: drive.userId) {
- self.selectedDriveFileManager = selectedDriveFileManager
- selectedDirectory = getBestDirectory()
- sections = [.fileName, .driveSelection, .directorySelection]
- if itemProvidersContainHeicPhotos {
- sections.append(.photoFormatOption)
- }
- }
- updateButton()
- }
-}
-
-// MARK: - SelectPhotoFormatDelegate
-
-extension SaveFileViewController: SelectPhotoFormatDelegate {
- func didSelectPhotoFormat(_ format: PhotoFileFormat) {
- if userPreferredPhotoFormat != format {
- userPreferredPhotoFormat = format
- if itemProviders?.isEmpty == false {
- setItemProviders()
- } else {
- setAssetIdentifiers()
- }
- }
- }
}