-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(SaveFileViewController): Split the class (#1353)
- Loading branch information
Showing
7 changed files
with
361 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
kDrive/UI/Controller/Files/Save File/SaveFileViewController+SelectDriveDelegate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
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() | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
kDrive/UI/Controller/Files/Save File/SaveFileViewController+SelectFolderDelegate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
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() | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
kDrive/UI/Controller/Files/Save File/SaveFileViewController+SelectPhotoFormatDelegate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import Foundation | ||
import kDriveCore | ||
|
||
extension SaveFileViewController: SelectPhotoFormatDelegate { | ||
func didSelectPhotoFormat(_ format: PhotoFileFormat) { | ||
if userPreferredPhotoFormat != format { | ||
userPreferredPhotoFormat = format | ||
if itemProviders?.isEmpty == false { | ||
setItemProviders() | ||
} else { | ||
setAssetIdentifiers() | ||
} | ||
} | ||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
kDrive/UI/Controller/Files/Save File/SaveFileViewController+UITableViewDataSource.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
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 | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
kDrive/UI/Controller/Files/Save File/SaveFileViewController+UITableViewDelegate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
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 | ||
} | ||
} | ||
} |
Oops, something went wrong.