From c4c52479a5ee97b1236809cf60eda7d7cc37f723 Mon Sep 17 00:00:00 2001 From: Baptiste Griva Date: Tue, 24 Sep 2024 17:35:52 +0200 Subject: [PATCH 01/14] feat: SyncMod wifi or mobileData --- .../Menu/ParameterTableViewController.swift | 22 +++--- .../Menu/WifiSyncSettingsViewController.swift | 71 +++++++++++++++++++ .../Utils/DriveUserDefaults+Extension.swift | 14 ++++ kDriveCore/Utils/SyncMod.swift | 52 ++++++++++++++ 4 files changed, 148 insertions(+), 11 deletions(-) create mode 100644 kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift create mode 100644 kDriveCore/Utils/SyncMod.swift diff --git a/kDrive/UI/Controller/Menu/ParameterTableViewController.swift b/kDrive/UI/Controller/Menu/ParameterTableViewController.swift index 5fac606e7..010424ae5 100644 --- a/kDrive/UI/Controller/Menu/ParameterTableViewController.swift +++ b/kDrive/UI/Controller/Menu/ParameterTableViewController.swift @@ -234,16 +234,16 @@ class ParameterTableViewController: BaseGroupedTableViewController { cell.valueLabel.text = getNotificationText() } return cell - case .wifi: - let cell = tableView.dequeueReusableCell(type: ParameterWifiTableViewCell.self, for: indexPath) - cell.initWithPositionAndShadow() - cell.valueSwitch.isOn = UserDefaults.shared.isWifiOnly - cell.switchHandler = { sender in - MatomoUtils.track(eventWithCategory: .settings, name: "onlyWifiTransfer", value: sender.isOn) - UserDefaults.shared.isWifiOnly = sender.isOn - } - return cell - case .security, .storage, .about, .deleteAccount: +// case .wifi: +// let cell = tableView.dequeueReusableCell(type: ParameterWifiTableViewCell.self, for: indexPath) +// cell.initWithPositionAndShadow() +// cell.valueSwitch.isOn = UserDefaults.shared.isWifiOnly +// cell.switchHandler = { sender in +// MatomoUtils.track(eventWithCategory: .settings, name: "onlyWifiTransfer", value: sender.isOn) +// UserDefaults.shared.isWifiOnly = sender.isOn +// } +// return cell + case .wifi, .security, .storage, .about, .deleteAccount: let cell = tableView.dequeueReusableCell(type: ParameterAboutTableViewCell.self, for: indexPath) cell.initWithPositionAndShadow( isFirst: indexPath.row == 0, @@ -316,7 +316,7 @@ class ParameterTableViewController: BaseGroupedTableViewController { case .security: navigationController?.pushViewController(SecurityTableViewController(), animated: true) case .wifi: - break + navigationController?.pushViewController(WifiSyncSettingsViewController(), animated: true) case .about: navigationController?.pushViewController(AboutTableViewController(), animated: true) case .deleteAccount: diff --git a/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift b/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift new file mode 100644 index 000000000..198b320d8 --- /dev/null +++ b/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift @@ -0,0 +1,71 @@ +/* + 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 InfomaniakCoreUI +import InfomaniakDI +import kDriveCore +import kDriveResources +import UIKit + +class WifiSyncSettingsViewController: BaseGroupedTableViewController { + @LazyInjectService private var appNavigable: AppNavigable + + private var tableContent: [SyncMod] = SyncMod.allCases + private var selectedMod: SyncMod! + + override func viewDidLoad() { + super.viewDidLoad() + + title = KDriveResourcesStrings.Localizable.themeSettingsTitle + + tableView.register(cellView: SelectionTableViewCell.self) + tableView.allowsMultipleSelection = false + +// selectedMod = UserDefaults.shared.syncMod + } + + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + MatomoUtils.track(view: [MatomoUtils.Views.menu.displayName, MatomoUtils.Views.settings.displayName, "SelectSyncMode"]) + } + + override func numberOfSections(in tableView: UITableView) -> Int { + return 1 + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return tableContent.count + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(type: SelectionTableViewCell.self, for: indexPath) + let currentMod = tableContent[indexPath.row] + if currentMod == selectedMod { + tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none) + } + cell.label.text = currentMod.selectionTitle + return cell + } + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let mod = tableContent[indexPath.row] + MatomoUtils.track(eventWithCategory: .settings, name: "mod\(mod.rawValue.capitalized)") + UserDefaults.shared.syncMod = mod + navigationController?.popViewController(animated: true) + } +} diff --git a/kDriveCore/Utils/DriveUserDefaults+Extension.swift b/kDriveCore/Utils/DriveUserDefaults+Extension.swift index 1fefb6042..baf0ef764 100644 --- a/kDriveCore/Utils/DriveUserDefaults+Extension.swift +++ b/kDriveCore/Utils/DriveUserDefaults+Extension.swift @@ -49,6 +49,7 @@ extension UserDefaults.Keys { static let selectedHomeIndex = UserDefaults.Keys(rawValue: "selectedHomeIndex") static let fpStorageVersion = UserDefaults.Keys(rawValue: "fpStorageVersion") static let importPhotoFormat = UserDefaults.Keys(rawValue: "importPhotoFormat") + static let syncMod = UserDefaults.Keys(rawValue: "syncMod") } public extension UserDefaults { @@ -336,4 +337,17 @@ public extension UserDefaults { set(newValue.rawValue, forKey: key(.importPhotoFormat)) } } + + var syncMod: SyncMod { + get { + if let rawValue = object(forKey: key(.syncMod)) as? String, + let mod = SyncMod(rawValue: rawValue) { + return mod + } + return .onlyWifi + } + set { + set(newValue.rawValue, forKey: key(.syncMod)) + } + } } diff --git a/kDriveCore/Utils/SyncMod.swift b/kDriveCore/Utils/SyncMod.swift new file mode 100644 index 000000000..7108fdafd --- /dev/null +++ b/kDriveCore/Utils/SyncMod.swift @@ -0,0 +1,52 @@ +/* + 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 + +public enum SyncMod: String, CaseIterable { + case onlyWifi + case wifiAndMobileData + +// public var interfaceStyle: UIUserInterfaceStyle { +// let styles: [Theme: UIUserInterfaceStyle] = [ +// .light: .light, +// .dark: .dark, +// .system: .unspecified +// ] +// return styles[self] ?? .unspecified +// } + + public var title: String { + switch self { + case .onlyWifi: + return KDriveResourcesStrings.Localizable.themeSettingsLightLabel + case .wifiAndMobileData: + return KDriveResourcesStrings.Localizable.themeSettingsDarkLabel + } + } + + public var selectionTitle: String { + switch self { + case .onlyWifi: + return KDriveResourcesStrings.Localizable.settingsOnlyWifiSyncDescription + case .wifiAndMobileData: + return "Wifi et données mobiles (à changer)" + } + } +} From 45ce9238f7b7488cd6f281869b40cffc068e1e3b Mon Sep 17 00:00:00 2001 From: Baptiste Griva Date: Fri, 27 Sep 2024 10:08:50 +0200 Subject: [PATCH 02/14] feat: Front for syncMod wifi or mobileData # Conflicts: # kDrive/Resources/de.lproj/Localizable.strings # kDrive/Resources/en.lproj/Localizable.strings # kDrive/Resources/es.lproj/Localizable.strings # kDrive/Resources/fr.lproj/Localizable.strings # kDrive/Resources/it.lproj/Localizable.strings --- .../Menu/ParameterTableViewController.swift | 22 ++-- .../PhotoSyncSettingsViewController.swift | 22 +++- .../Menu/WifiSyncSettingsViewController.swift | 24 ++++- .../ParameterSyncTableViewCell.swift | 25 +++++ .../Parameters/ParameterSyncTableViewCell.xib | 101 ++++++++++++++++++ .../DriveFileManagerConstants.swift | 16 ++- kDriveCore/Data/Cache/PhotoSyncSettings.swift | 8 +- kDriveCore/Utils/SyncMod.swift | 20 ++-- 8 files changed, 204 insertions(+), 34 deletions(-) create mode 100644 kDrive/UI/View/Menu/Parameters/ParameterSyncTableViewCell.swift create mode 100644 kDrive/UI/View/Menu/Parameters/ParameterSyncTableViewCell.xib diff --git a/kDrive/UI/Controller/Menu/ParameterTableViewController.swift b/kDrive/UI/Controller/Menu/ParameterTableViewController.swift index 010424ae5..558259719 100644 --- a/kDrive/UI/Controller/Menu/ParameterTableViewController.swift +++ b/kDrive/UI/Controller/Menu/ParameterTableViewController.swift @@ -93,7 +93,7 @@ class ParameterTableViewController: BaseGroupedTableViewController { case .security: return KDriveResourcesStrings.Localizable.securityTitle case .wifi: - return KDriveResourcesStrings.Localizable.settingsOnlyWifiSyncTitle + return KDriveResourcesStrings.Localizable.syncWifiSettingsTitle case .storage: return KDriveResourcesStrings.Localizable.manageStorageTitle case .about: @@ -116,6 +116,7 @@ class ParameterTableViewController: BaseGroupedTableViewController { tableView.register(cellView: ParameterTableViewCell.self) tableView.register(cellView: ParameterAboutTableViewCell.self) tableView.register(cellView: ParameterWifiTableViewCell.self) + tableView.register(cellView: AboutDetailTableViewCell.self) navigationItem.hideBackButtonText() checkMykSuiteEnabledAndRefresh() @@ -234,16 +235,8 @@ class ParameterTableViewController: BaseGroupedTableViewController { cell.valueLabel.text = getNotificationText() } return cell -// case .wifi: -// let cell = tableView.dequeueReusableCell(type: ParameterWifiTableViewCell.self, for: indexPath) -// cell.initWithPositionAndShadow() -// cell.valueSwitch.isOn = UserDefaults.shared.isWifiOnly -// cell.switchHandler = { sender in -// MatomoUtils.track(eventWithCategory: .settings, name: "onlyWifiTransfer", value: sender.isOn) -// UserDefaults.shared.isWifiOnly = sender.isOn -// } -// return cell - case .wifi, .security, .storage, .about, .deleteAccount: + + case .security, .storage, .about, .deleteAccount: let cell = tableView.dequeueReusableCell(type: ParameterAboutTableViewCell.self, for: indexPath) cell.initWithPositionAndShadow( isFirst: indexPath.row == 0, @@ -251,6 +244,13 @@ class ParameterTableViewController: BaseGroupedTableViewController { ) cell.titleLabel.text = row.title return cell + + case .wifi: + let cell = tableView.dequeueReusableCell(type: AboutDetailTableViewCell.self, for: indexPath) + cell.initWithPositionAndShadow(isFirst: indexPath.row == 0, isLast: indexPath.row == tableContent.count - 1) + cell.titleLabel.text = UserDefaults.shared.syncMod.title + cell.detailLabel.text = UserDefaults.shared.syncMod.selectionTitle + return cell } } diff --git a/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift b/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift index 5f8bd75cf..7deb714b1 100644 --- a/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift +++ b/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift @@ -55,6 +55,7 @@ final class PhotoSyncSettingsViewController: BaseGroupedTableViewController { case createDatedSubFolders case deleteAssetsAfterImport case photoFormat + case wifiSync } private enum PhotoSyncDeniedRows: CaseIterable { @@ -110,6 +111,7 @@ final class PhotoSyncSettingsViewController: BaseGroupedTableViewController { tableView.register(cellView: PhotoAccessDeniedTableViewCell.self) tableView.register(cellView: PhotoSyncSettingsTableViewCell.self) tableView.register(cellView: PhotoFormatTableViewCell.self) + tableView.register(cellView: AboutDetailTableViewCell.self) let view = FooterButtonView.instantiate(title: KDriveResourcesStrings.Localizable.buttonSave) view.delegate = self @@ -389,6 +391,12 @@ extension PhotoSyncSettingsViewController { cell.initWithPositionAndShadow(isFirst: indexPath.row == 0, isLast: indexPath.row == settingsRows.count - 1) cell.configure(with: liveNewSyncSettings.photoFormat) return cell + case .wifiSync: + let cell = tableView.dequeueReusableCell(type: AboutDetailTableViewCell.self, for: indexPath) + cell.initWithPositionAndShadow(isFirst: indexPath.row == 0, isLast: indexPath.row == settingsRows.count - 1) + cell.titleLabel.text = KDriveResourcesStrings.Localizable.syncWifiPicturesTitle + cell.detailLabel.text = UserDefaults.shared.syncMod.title + return cell } case .syncDenied: switch deniedRows[indexPath.row] { @@ -446,6 +454,11 @@ extension PhotoSyncSettingsViewController { .instantiate(selectedFormat: liveNewSyncSettings.photoFormat) selectPhotoFormatViewController.delegate = self navigationController?.pushViewController(selectPhotoFormatViewController, animated: true) + case .wifiSync: + let wifiSyncSettingsViewController = WifiSyncSettingsViewController + .instantiate(selectedMod: newSyncSettings.wifiSync) + wifiSyncSettingsViewController.delegate = self + navigationController?.pushViewController(wifiSyncSettingsViewController, animated: true) default: break } @@ -480,7 +493,7 @@ extension PhotoSyncSettingsViewController: SelectPhotoFormatDelegate { func didSelectPhotoFormat(_ format: PhotoFileFormat) { liveNewSyncSettings.photoFormat = format updateSaveButtonState() - tableView.reloadData() + tableView.reloadRows(at: [IndexPath(row: 6, section: 2)], with: .fade) } } @@ -517,3 +530,10 @@ extension PhotoSyncSettingsViewController: PhotoSyncSettingsTableViewCellDelegat updateSaveButtonState() } } + +extension PhotoSyncSettingsViewController: WifiSyncSettingsDelegate { + func didSelectSyncMod(_ mod: SyncMod) { + newSyncSettings.wifiSync = mod + tableView.reloadRows(at: [IndexPath(row: 7, section: 2)], with: .fade) + } +} diff --git a/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift b/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift index 198b320d8..051e98798 100644 --- a/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift +++ b/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift @@ -22,21 +22,32 @@ import kDriveCore import kDriveResources import UIKit +protocol WifiSyncSettingsDelegate: AnyObject { + func didSelectSyncMod(_ mod: SyncMod) +} + class WifiSyncSettingsViewController: BaseGroupedTableViewController { @LazyInjectService private var appNavigable: AppNavigable private var tableContent: [SyncMod] = SyncMod.allCases private var selectedMod: SyncMod! + weak var delegate: WifiSyncSettingsDelegate? override func viewDidLoad() { super.viewDidLoad() - title = KDriveResourcesStrings.Localizable.themeSettingsTitle + title = KDriveResourcesStrings.Localizable.syncWifiSettingsTitle - tableView.register(cellView: SelectionTableViewCell.self) + tableView.register(cellView: ParameterSyncTableViewCell.self) tableView.allowsMultipleSelection = false -// selectedMod = UserDefaults.shared.syncMod + selectedMod = UserDefaults.shared.syncMod + } + + static func instantiate(selectedMod: SyncMod) -> WifiSyncSettingsViewController { + let viewController = WifiSyncSettingsViewController() + viewController.selectedMod = selectedMod + return viewController } override func viewDidAppear(_ animated: Bool) { @@ -53,12 +64,14 @@ class WifiSyncSettingsViewController: BaseGroupedTableViewController { } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(type: SelectionTableViewCell.self, for: indexPath) + let cell = tableView.dequeueReusableCell(type: ParameterSyncTableViewCell.self, for: indexPath) + cell.initWithPositionAndShadow(isFirst: true, isLast: true) let currentMod = tableContent[indexPath.row] if currentMod == selectedMod { tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none) } - cell.label.text = currentMod.selectionTitle + cell.syncTitleLabel.text = currentMod.title + cell.syncDetailLabel.text = currentMod.selectionTitle return cell } @@ -66,6 +79,7 @@ class WifiSyncSettingsViewController: BaseGroupedTableViewController { let mod = tableContent[indexPath.row] MatomoUtils.track(eventWithCategory: .settings, name: "mod\(mod.rawValue.capitalized)") UserDefaults.shared.syncMod = mod + delegate?.didSelectSyncMod(tableContent[indexPath.row]) navigationController?.popViewController(animated: true) } } diff --git a/kDrive/UI/View/Menu/Parameters/ParameterSyncTableViewCell.swift b/kDrive/UI/View/Menu/Parameters/ParameterSyncTableViewCell.swift new file mode 100644 index 000000000..dae5cdd6e --- /dev/null +++ b/kDrive/UI/View/Menu/Parameters/ParameterSyncTableViewCell.swift @@ -0,0 +1,25 @@ +/* + 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 InfomaniakCoreUI +import UIKit + +class ParameterSyncTableViewCell: InsetTableViewCell { + @IBOutlet var syncTitleLabel: UILabel! + @IBOutlet var syncDetailLabel: UILabel! +} diff --git a/kDrive/UI/View/Menu/Parameters/ParameterSyncTableViewCell.xib b/kDrive/UI/View/Menu/Parameters/ParameterSyncTableViewCell.xib new file mode 100644 index 000000000..acc02f70e --- /dev/null +++ b/kDrive/UI/View/Menu/Parameters/ParameterSyncTableViewCell.xib @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kDriveCore/Data/Cache/DriveFileManager/DriveFileManagerConstants.swift b/kDriveCore/Data/Cache/DriveFileManager/DriveFileManagerConstants.swift index bfe181e39..ff1d3b588 100644 --- a/kDriveCore/Data/Cache/DriveFileManager/DriveFileManagerConstants.swift +++ b/kDriveCore/Data/Cache/DriveFileManager/DriveFileManagerConstants.swift @@ -25,7 +25,7 @@ import RealmSwift /// Something to centralize schema versioning public enum RealmSchemaVersion { /// Current version of the Upload Realm - static let upload: UInt64 = 21 + static let upload: UInt64 = 22 /// Current version of the Drive Realm static let drive: UInt64 = 13 @@ -204,6 +204,20 @@ public class DriveFileManagerConstants { newObject["uploadingSession"] = nil } } + + // Migration to add syncWifi + if oldSchemaVersion < 22 { + migration.enumerateObjects(ofType: UploadFile.className()) { _, newObject in + guard let newObject else { + return + } + if UserDefaults.shared.isWifiOnly { + newObject["wifiSync"] = SyncMod.onlyWifi + } else { + newObject["wifiSync"] = SyncMod.wifiAndMobileData + } + } + } } /// Path of the upload DB diff --git a/kDriveCore/Data/Cache/PhotoSyncSettings.swift b/kDriveCore/Data/Cache/PhotoSyncSettings.swift index 316f41721..ff0a21919 100644 --- a/kDriveCore/Data/Cache/PhotoSyncSettings.swift +++ b/kDriveCore/Data/Cache/PhotoSyncSettings.swift @@ -50,6 +50,7 @@ public final class PhotoSyncSettings: Object { @Persisted public var createDatedSubFolders = false @Persisted public var deleteAssetsAfterImport = false @Persisted public var photoFormat: PhotoFileFormat = .jpg + @Persisted public var wifiSync: SyncMod = .wifiAndMobileData public init(userId: Int, driveId: Int, @@ -62,7 +63,8 @@ public final class PhotoSyncSettings: Object { syncScreenshots: Bool, createDatedSubFolders: Bool, deleteAssetsAfterImport: Bool, - photoFormat: PhotoFileFormat) { + photoFormat: PhotoFileFormat, + wifiSync: SyncMod) { super.init() self.userId = userId self.driveId = driveId @@ -76,6 +78,7 @@ public final class PhotoSyncSettings: Object { self.createDatedSubFolders = createDatedSubFolders self.deleteAssetsAfterImport = deleteAssetsAfterImport self.photoFormat = photoFormat + self.wifiSync = wifiSync } override public init() { @@ -95,6 +98,7 @@ public final class PhotoSyncSettings: Object { deleteAssetsAfterImport == settings.deleteAssetsAfterImport && syncMode == settings.syncMode && fromDate == settings.fromDate && - photoFormat == settings.photoFormat + photoFormat == settings.photoFormat && + wifiSync == settings.wifiSync } } diff --git a/kDriveCore/Utils/SyncMod.swift b/kDriveCore/Utils/SyncMod.swift index 7108fdafd..eea58c1b1 100644 --- a/kDriveCore/Utils/SyncMod.swift +++ b/kDriveCore/Utils/SyncMod.swift @@ -18,35 +18,27 @@ import kDriveResources import UIKit +import RealmSwift -public enum SyncMod: String, CaseIterable { +public enum SyncMod: String, CaseIterable, PersistableEnum { case onlyWifi case wifiAndMobileData -// public var interfaceStyle: UIUserInterfaceStyle { -// let styles: [Theme: UIUserInterfaceStyle] = [ -// .light: .light, -// .dark: .dark, -// .system: .unspecified -// ] -// return styles[self] ?? .unspecified -// } - public var title: String { switch self { case .onlyWifi: - return KDriveResourcesStrings.Localizable.themeSettingsLightLabel + return KDriveResourcesStrings.Localizable.syncOnlyWifiTitle case .wifiAndMobileData: - return KDriveResourcesStrings.Localizable.themeSettingsDarkLabel + return KDriveResourcesStrings.Localizable.syncWifiAndMobileDataTitle } } public var selectionTitle: String { switch self { case .onlyWifi: - return KDriveResourcesStrings.Localizable.settingsOnlyWifiSyncDescription + return KDriveResourcesStrings.Localizable.syncOnlyWifiDescription case .wifiAndMobileData: - return "Wifi et données mobiles (à changer)" + return KDriveResourcesStrings.Localizable.syncWifiAndMobileDataDescription } } } From da2bd0178081f8861f232688dd744e56ee976214 Mon Sep 17 00:00:00 2001 From: Baptiste Griva Date: Fri, 4 Oct 2024 16:07:31 +0200 Subject: [PATCH 03/14] fix: Add "e" to "syncMod" # Conflicts: # Tuist/Package.resolved --- .../Menu/ParameterTableViewController.swift | 4 ++-- .../Menu/PhotoSyncSettingsViewController.swift | 4 ++-- .../Menu/WifiSyncSettingsViewController.swift | 18 +++++++++--------- .../DriveFileManagerConstants.swift | 4 ++-- kDriveCore/Data/Cache/PhotoSyncSettings.swift | 4 ++-- .../Utils/DriveUserDefaults+Extension.swift | 10 +++++----- .../Utils/{SyncMod.swift => SyncMode.swift} | 2 +- 7 files changed, 23 insertions(+), 23 deletions(-) rename kDriveCore/Utils/{SyncMod.swift => SyncMode.swift} (95%) diff --git a/kDrive/UI/Controller/Menu/ParameterTableViewController.swift b/kDrive/UI/Controller/Menu/ParameterTableViewController.swift index 558259719..401310384 100644 --- a/kDrive/UI/Controller/Menu/ParameterTableViewController.swift +++ b/kDrive/UI/Controller/Menu/ParameterTableViewController.swift @@ -248,8 +248,8 @@ class ParameterTableViewController: BaseGroupedTableViewController { case .wifi: let cell = tableView.dequeueReusableCell(type: AboutDetailTableViewCell.self, for: indexPath) cell.initWithPositionAndShadow(isFirst: indexPath.row == 0, isLast: indexPath.row == tableContent.count - 1) - cell.titleLabel.text = UserDefaults.shared.syncMod.title - cell.detailLabel.text = UserDefaults.shared.syncMod.selectionTitle + cell.titleLabel.text = UserDefaults.shared.syncMode.title + cell.detailLabel.text = UserDefaults.shared.syncMode.selectionTitle return cell } } diff --git a/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift b/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift index 7deb714b1..700488203 100644 --- a/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift +++ b/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift @@ -395,7 +395,7 @@ extension PhotoSyncSettingsViewController { let cell = tableView.dequeueReusableCell(type: AboutDetailTableViewCell.self, for: indexPath) cell.initWithPositionAndShadow(isFirst: indexPath.row == 0, isLast: indexPath.row == settingsRows.count - 1) cell.titleLabel.text = KDriveResourcesStrings.Localizable.syncWifiPicturesTitle - cell.detailLabel.text = UserDefaults.shared.syncMod.title + cell.detailLabel.text = UserDefaults.shared.syncMode.title return cell } case .syncDenied: @@ -532,7 +532,7 @@ extension PhotoSyncSettingsViewController: PhotoSyncSettingsTableViewCellDelegat } extension PhotoSyncSettingsViewController: WifiSyncSettingsDelegate { - func didSelectSyncMod(_ mod: SyncMod) { + func didSelectSyncMode(_ mod: SyncMode) { newSyncSettings.wifiSync = mod tableView.reloadRows(at: [IndexPath(row: 7, section: 2)], with: .fade) } diff --git a/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift b/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift index 051e98798..fe8a721a1 100644 --- a/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift +++ b/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift @@ -23,14 +23,14 @@ import kDriveResources import UIKit protocol WifiSyncSettingsDelegate: AnyObject { - func didSelectSyncMod(_ mod: SyncMod) + func didSelectSyncMode(_ mod: SyncMode) } class WifiSyncSettingsViewController: BaseGroupedTableViewController { @LazyInjectService private var appNavigable: AppNavigable - private var tableContent: [SyncMod] = SyncMod.allCases - private var selectedMod: SyncMod! + private var tableContent: [SyncMode] = SyncMode.allCases + private var selectedMod: SyncMode! weak var delegate: WifiSyncSettingsDelegate? override func viewDidLoad() { @@ -41,10 +41,10 @@ class WifiSyncSettingsViewController: BaseGroupedTableViewController { tableView.register(cellView: ParameterSyncTableViewCell.self) tableView.allowsMultipleSelection = false - selectedMod = UserDefaults.shared.syncMod + selectedMod = UserDefaults.shared.syncMode } - static func instantiate(selectedMod: SyncMod) -> WifiSyncSettingsViewController { + static func instantiate(selectedMod: SyncMode) -> WifiSyncSettingsViewController { let viewController = WifiSyncSettingsViewController() viewController.selectedMod = selectedMod return viewController @@ -76,10 +76,10 @@ class WifiSyncSettingsViewController: BaseGroupedTableViewController { } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - let mod = tableContent[indexPath.row] - MatomoUtils.track(eventWithCategory: .settings, name: "mod\(mod.rawValue.capitalized)") - UserDefaults.shared.syncMod = mod - delegate?.didSelectSyncMod(tableContent[indexPath.row]) + let mode = tableContent[indexPath.row] + MatomoUtils.track(eventWithCategory: .settings, name: "mod\(mode.rawValue.capitalized)") + UserDefaults.shared.syncMode = mode + delegate?.didSelectSyncMode(tableContent[indexPath.row]) navigationController?.popViewController(animated: true) } } diff --git a/kDriveCore/Data/Cache/DriveFileManager/DriveFileManagerConstants.swift b/kDriveCore/Data/Cache/DriveFileManager/DriveFileManagerConstants.swift index ff1d3b588..85a64183e 100644 --- a/kDriveCore/Data/Cache/DriveFileManager/DriveFileManagerConstants.swift +++ b/kDriveCore/Data/Cache/DriveFileManager/DriveFileManagerConstants.swift @@ -212,9 +212,9 @@ public class DriveFileManagerConstants { return } if UserDefaults.shared.isWifiOnly { - newObject["wifiSync"] = SyncMod.onlyWifi + newObject["wifiSync"] = SyncMode.onlyWifi } else { - newObject["wifiSync"] = SyncMod.wifiAndMobileData + newObject["wifiSync"] = SyncMode.wifiAndMobileData } } } diff --git a/kDriveCore/Data/Cache/PhotoSyncSettings.swift b/kDriveCore/Data/Cache/PhotoSyncSettings.swift index ff0a21919..06b90f19a 100644 --- a/kDriveCore/Data/Cache/PhotoSyncSettings.swift +++ b/kDriveCore/Data/Cache/PhotoSyncSettings.swift @@ -50,7 +50,7 @@ public final class PhotoSyncSettings: Object { @Persisted public var createDatedSubFolders = false @Persisted public var deleteAssetsAfterImport = false @Persisted public var photoFormat: PhotoFileFormat = .jpg - @Persisted public var wifiSync: SyncMod = .wifiAndMobileData + @Persisted public var wifiSync: SyncMode = .wifiAndMobileData public init(userId: Int, driveId: Int, @@ -64,7 +64,7 @@ public final class PhotoSyncSettings: Object { createDatedSubFolders: Bool, deleteAssetsAfterImport: Bool, photoFormat: PhotoFileFormat, - wifiSync: SyncMod) { + wifiSync: SyncMode) { super.init() self.userId = userId self.driveId = driveId diff --git a/kDriveCore/Utils/DriveUserDefaults+Extension.swift b/kDriveCore/Utils/DriveUserDefaults+Extension.swift index baf0ef764..823edb3e9 100644 --- a/kDriveCore/Utils/DriveUserDefaults+Extension.swift +++ b/kDriveCore/Utils/DriveUserDefaults+Extension.swift @@ -49,7 +49,7 @@ extension UserDefaults.Keys { static let selectedHomeIndex = UserDefaults.Keys(rawValue: "selectedHomeIndex") static let fpStorageVersion = UserDefaults.Keys(rawValue: "fpStorageVersion") static let importPhotoFormat = UserDefaults.Keys(rawValue: "importPhotoFormat") - static let syncMod = UserDefaults.Keys(rawValue: "syncMod") + static let syncMode = UserDefaults.Keys(rawValue: "syncMode") } public extension UserDefaults { @@ -338,16 +338,16 @@ public extension UserDefaults { } } - var syncMod: SyncMod { + var syncMode: SyncMode { get { - if let rawValue = object(forKey: key(.syncMod)) as? String, - let mod = SyncMod(rawValue: rawValue) { + if let rawValue = object(forKey: key(.syncMode)) as? String, + let mod = SyncMode(rawValue: rawValue) { return mod } return .onlyWifi } set { - set(newValue.rawValue, forKey: key(.syncMod)) + set(newValue.rawValue, forKey: key(.syncMode)) } } } diff --git a/kDriveCore/Utils/SyncMod.swift b/kDriveCore/Utils/SyncMode.swift similarity index 95% rename from kDriveCore/Utils/SyncMod.swift rename to kDriveCore/Utils/SyncMode.swift index eea58c1b1..4d05f98da 100644 --- a/kDriveCore/Utils/SyncMod.swift +++ b/kDriveCore/Utils/SyncMode.swift @@ -20,7 +20,7 @@ import kDriveResources import UIKit import RealmSwift -public enum SyncMod: String, CaseIterable, PersistableEnum { +public enum SyncMode: String, CaseIterable, PersistableEnum { case onlyWifi case wifiAndMobileData From c61241c2772f69341c4aebebc1aa598eda8d2932 Mon Sep 17 00:00:00 2001 From: Baptiste Griva Date: Mon, 21 Oct 2024 12:34:50 +0200 Subject: [PATCH 04/14] fix: Remove hardcode --- .../PhotoSyncSettingsViewController.swift | 41 ++++++++++++++----- .../Menu/WifiSyncSettingsViewController.swift | 20 ++++----- .../Utils/DriveUserDefaults+Extension.swift | 4 +- 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift b/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift index 700488203..0eb7ff4ae 100644 --- a/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift +++ b/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift @@ -31,23 +31,23 @@ final class PhotoSyncSettingsViewController: BaseGroupedTableViewController { @LazyInjectService var photoLibraryUploader: PhotoLibraryUploader @LazyInjectService var freeSpaceService: FreeSpaceService - private enum PhotoSyncSection { + private enum PhotoSyncSection: Int { case syncSwitch case syncLocation case syncSettings case syncDenied } - private enum PhotoSyncSwitchRows: CaseIterable { + private enum PhotoSyncSwitchRows: Int, CaseIterable { case syncSwitch } - private enum PhotoSyncLocationRows: CaseIterable { + private enum PhotoSyncLocationRows: Int, CaseIterable { case driveSelection case folderSelection } - private enum PhotoSyncSettingsRows: CaseIterable { + private enum PhotoSyncSettingsRows: Int, CaseIterable { case syncMode case importPicturesSwitch case importVideosSwitch @@ -456,7 +456,7 @@ extension PhotoSyncSettingsViewController { navigationController?.pushViewController(selectPhotoFormatViewController, animated: true) case .wifiSync: let wifiSyncSettingsViewController = WifiSyncSettingsViewController - .instantiate(selectedMod: newSyncSettings.wifiSync) + .instantiate(selectedMode: newSyncSettings.wifiSync) wifiSyncSettingsViewController.delegate = self navigationController?.pushViewController(wifiSyncSettingsViewController, animated: true) default: @@ -473,7 +473,14 @@ extension PhotoSyncSettingsViewController: SelectDriveDelegate { driveFileManager = accountManager.getDriveFileManager(for: drive.id, userId: drive.userId) selectedDirectory = nil updateSaveButtonState() - tableView.reloadRows(at: [IndexPath(row: 0, section: 1), IndexPath(row: 1, section: 1)], with: .fade) + tableView.reloadRows( + at: [IndexPath(row: PhotoSyncSettingsRows.syncMode.rawValue, section: PhotoSyncSection.syncLocation.rawValue), + IndexPath( + row: PhotoSyncSettingsRows.importPicturesSwitch.rawValue, + section: PhotoSyncSection.syncLocation.rawValue + )], + with: .fade + ) } } @@ -483,7 +490,13 @@ extension PhotoSyncSettingsViewController: SelectFolderDelegate { func didSelectFolder(_ folder: File) { selectedDirectory = folder updateSaveButtonState() - tableView.reloadRows(at: [IndexPath(row: 1, section: 1)], with: .fade) + tableView.reloadRows( + at: [IndexPath( + row: PhotoSyncSettingsRows.importPicturesSwitch.rawValue, + section: PhotoSyncSection.syncLocation.rawValue + )], + with: .fade + ) } } @@ -493,7 +506,10 @@ extension PhotoSyncSettingsViewController: SelectPhotoFormatDelegate { func didSelectPhotoFormat(_ format: PhotoFileFormat) { liveNewSyncSettings.photoFormat = format updateSaveButtonState() - tableView.reloadRows(at: [IndexPath(row: 6, section: 2)], with: .fade) + tableView.reloadRows( + at: [IndexPath(row: PhotoSyncSettingsRows.photoFormat.rawValue, section: PhotoSyncSection.syncSettings.rawValue)], + with: .fade + ) } } @@ -532,8 +548,11 @@ extension PhotoSyncSettingsViewController: PhotoSyncSettingsTableViewCellDelegat } extension PhotoSyncSettingsViewController: WifiSyncSettingsDelegate { - func didSelectSyncMode(_ mod: SyncMode) { - newSyncSettings.wifiSync = mod - tableView.reloadRows(at: [IndexPath(row: 7, section: 2)], with: .fade) + func didSelectSyncMode(_ mode: SyncMode) { + newSyncSettings.wifiSync = mode + tableView.reloadRows( + at: [IndexPath(row: PhotoSyncSettingsRows.wifiSync.rawValue, section: PhotoSyncSection.syncSettings.rawValue)], + with: .fade + ) } } diff --git a/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift b/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift index fe8a721a1..38b8ebe37 100644 --- a/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift +++ b/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift @@ -23,14 +23,14 @@ import kDriveResources import UIKit protocol WifiSyncSettingsDelegate: AnyObject { - func didSelectSyncMode(_ mod: SyncMode) + func didSelectSyncMode(_ mode: SyncMode) } class WifiSyncSettingsViewController: BaseGroupedTableViewController { @LazyInjectService private var appNavigable: AppNavigable private var tableContent: [SyncMode] = SyncMode.allCases - private var selectedMod: SyncMode! + private var selectedMode: SyncMode! weak var delegate: WifiSyncSettingsDelegate? override func viewDidLoad() { @@ -41,12 +41,12 @@ class WifiSyncSettingsViewController: BaseGroupedTableViewController { tableView.register(cellView: ParameterSyncTableViewCell.self) tableView.allowsMultipleSelection = false - selectedMod = UserDefaults.shared.syncMode + selectedMode = UserDefaults.shared.syncMode } - static func instantiate(selectedMod: SyncMode) -> WifiSyncSettingsViewController { + static func instantiate(selectedMode: SyncMode) -> WifiSyncSettingsViewController { let viewController = WifiSyncSettingsViewController() - viewController.selectedMod = selectedMod + viewController.selectedMode = selectedMode return viewController } @@ -66,18 +66,18 @@ class WifiSyncSettingsViewController: BaseGroupedTableViewController { override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(type: ParameterSyncTableViewCell.self, for: indexPath) cell.initWithPositionAndShadow(isFirst: true, isLast: true) - let currentMod = tableContent[indexPath.row] - if currentMod == selectedMod { + let currentMode = tableContent[indexPath.row] + if currentMode == selectedMode { tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none) } - cell.syncTitleLabel.text = currentMod.title - cell.syncDetailLabel.text = currentMod.selectionTitle + cell.syncTitleLabel.text = currentMode.title + cell.syncDetailLabel.text = currentMode.selectionTitle return cell } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let mode = tableContent[indexPath.row] - MatomoUtils.track(eventWithCategory: .settings, name: "mod\(mode.rawValue.capitalized)") + MatomoUtils.track(eventWithCategory: .settings, name: "mode\(mode.rawValue.capitalized)") UserDefaults.shared.syncMode = mode delegate?.didSelectSyncMode(tableContent[indexPath.row]) navigationController?.popViewController(animated: true) diff --git a/kDriveCore/Utils/DriveUserDefaults+Extension.swift b/kDriveCore/Utils/DriveUserDefaults+Extension.swift index 823edb3e9..1a0682295 100644 --- a/kDriveCore/Utils/DriveUserDefaults+Extension.swift +++ b/kDriveCore/Utils/DriveUserDefaults+Extension.swift @@ -341,8 +341,8 @@ public extension UserDefaults { var syncMode: SyncMode { get { if let rawValue = object(forKey: key(.syncMode)) as? String, - let mod = SyncMode(rawValue: rawValue) { - return mod + let mode = SyncMode(rawValue: rawValue) { + return mode } return .onlyWifi } From 8522805b4a735ca745b9b17f60818ad9e1bd03a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Coye=20de=20Brune=CC=81lis?= Date: Thu, 14 Nov 2024 11:58:45 +0100 Subject: [PATCH 05/14] fix: Fix import InfomaniakCoreUIKit --- kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift | 2 +- kDrive/UI/View/Menu/Parameters/ParameterSyncTableViewCell.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift b/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift index 38b8ebe37..c07094505 100644 --- a/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift +++ b/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift @@ -16,7 +16,7 @@ along with this program. If not, see . */ -import InfomaniakCoreUI +import InfomaniakCoreUIKit import InfomaniakDI import kDriveCore import kDriveResources diff --git a/kDrive/UI/View/Menu/Parameters/ParameterSyncTableViewCell.swift b/kDrive/UI/View/Menu/Parameters/ParameterSyncTableViewCell.swift index dae5cdd6e..e576a8a0f 100644 --- a/kDrive/UI/View/Menu/Parameters/ParameterSyncTableViewCell.swift +++ b/kDrive/UI/View/Menu/Parameters/ParameterSyncTableViewCell.swift @@ -16,7 +16,7 @@ along with this program. If not, see . */ -import InfomaniakCoreUI +import InfomaniakCoreUIKit import UIKit class ParameterSyncTableViewCell: InsetTableViewCell { From e05dce6f7dbce158acf1b75e9ce44acf4dabd026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Coye=20de=20Brune=CC=81lis?= Date: Mon, 17 Feb 2025 14:02:14 +0100 Subject: [PATCH 06/14] fix: Resolve issues since merge and cherry-picks --- kDrive/UI/Controller/Menu/ParameterTableViewController.swift | 5 ++++- .../UI/Controller/Menu/PhotoSyncSettingsViewController.swift | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/kDrive/UI/Controller/Menu/ParameterTableViewController.swift b/kDrive/UI/Controller/Menu/ParameterTableViewController.swift index 401310384..e21be9661 100644 --- a/kDrive/UI/Controller/Menu/ParameterTableViewController.swift +++ b/kDrive/UI/Controller/Menu/ParameterTableViewController.swift @@ -247,7 +247,10 @@ class ParameterTableViewController: BaseGroupedTableViewController { case .wifi: let cell = tableView.dequeueReusableCell(type: AboutDetailTableViewCell.self, for: indexPath) - cell.initWithPositionAndShadow(isFirst: indexPath.row == 0, isLast: indexPath.row == tableContent.count - 1) + cell.initWithPositionAndShadow( + isFirst: indexPath.row == 0, + isLast: indexPath.row == GeneralParameterRow.allCases.count - 1 + ) cell.titleLabel.text = UserDefaults.shared.syncMode.title cell.detailLabel.text = UserDefaults.shared.syncMode.selectionTitle return cell diff --git a/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift b/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift index 0eb7ff4ae..a676d0910 100644 --- a/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift +++ b/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift @@ -456,7 +456,7 @@ extension PhotoSyncSettingsViewController { navigationController?.pushViewController(selectPhotoFormatViewController, animated: true) case .wifiSync: let wifiSyncSettingsViewController = WifiSyncSettingsViewController - .instantiate(selectedMode: newSyncSettings.wifiSync) + .instantiate(selectedMode: liveNewSyncSettings.wifiSync) wifiSyncSettingsViewController.delegate = self navigationController?.pushViewController(wifiSyncSettingsViewController, animated: true) default: @@ -549,7 +549,7 @@ extension PhotoSyncSettingsViewController: PhotoSyncSettingsTableViewCellDelegat extension PhotoSyncSettingsViewController: WifiSyncSettingsDelegate { func didSelectSyncMode(_ mode: SyncMode) { - newSyncSettings.wifiSync = mode + liveNewSyncSettings.wifiSync = mode tableView.reloadRows( at: [IndexPath(row: PhotoSyncSettingsRows.wifiSync.rawValue, section: PhotoSyncSection.syncSettings.rawValue)], with: .fade From a3d0bb36cdb623fb0eee1446cb0aebcc2533f029 Mon Sep 17 00:00:00 2001 From: Baptiste Griva Date: Wed, 19 Feb 2025 09:15:34 +0100 Subject: [PATCH 07/14] fix: Remove force unwrap --- kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift | 2 +- kDriveCore/Utils/SyncMode.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift b/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift index c07094505..ff7e029a0 100644 --- a/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift +++ b/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift @@ -30,7 +30,7 @@ class WifiSyncSettingsViewController: BaseGroupedTableViewController { @LazyInjectService private var appNavigable: AppNavigable private var tableContent: [SyncMode] = SyncMode.allCases - private var selectedMode: SyncMode! + private var selectedMode: SyncMode = .onlyWifi weak var delegate: WifiSyncSettingsDelegate? override func viewDidLoad() { diff --git a/kDriveCore/Utils/SyncMode.swift b/kDriveCore/Utils/SyncMode.swift index 4d05f98da..6b3cc858b 100644 --- a/kDriveCore/Utils/SyncMode.swift +++ b/kDriveCore/Utils/SyncMode.swift @@ -17,8 +17,8 @@ */ import kDriveResources -import UIKit import RealmSwift +import UIKit public enum SyncMode: String, CaseIterable, PersistableEnum { case onlyWifi From b2868c4f4bb3f336e392529b6c9c2c3f19fef27e Mon Sep 17 00:00:00 2001 From: Baptiste Griva Date: Fri, 21 Feb 2025 08:26:16 +0100 Subject: [PATCH 08/14] fix: Create init for the selectedMode --- .../Menu/ParameterTableViewController.swift | 5 ++++- .../Menu/WifiSyncSettingsViewController.swift | 12 +++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/kDrive/UI/Controller/Menu/ParameterTableViewController.swift b/kDrive/UI/Controller/Menu/ParameterTableViewController.swift index e21be9661..4310b1bd5 100644 --- a/kDrive/UI/Controller/Menu/ParameterTableViewController.swift +++ b/kDrive/UI/Controller/Menu/ParameterTableViewController.swift @@ -319,7 +319,10 @@ class ParameterTableViewController: BaseGroupedTableViewController { case .security: navigationController?.pushViewController(SecurityTableViewController(), animated: true) case .wifi: - navigationController?.pushViewController(WifiSyncSettingsViewController(), animated: true) + navigationController?.pushViewController( + WifiSyncSettingsViewController(selectedMode: UserDefaults.shared.syncMode), + animated: true + ) case .about: navigationController?.pushViewController(AboutTableViewController(), animated: true) case .deleteAccount: diff --git a/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift b/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift index ff7e029a0..88706c32e 100644 --- a/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift +++ b/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift @@ -30,9 +30,14 @@ class WifiSyncSettingsViewController: BaseGroupedTableViewController { @LazyInjectService private var appNavigable: AppNavigable private var tableContent: [SyncMode] = SyncMode.allCases - private var selectedMode: SyncMode = .onlyWifi + private var selectedMode: SyncMode weak var delegate: WifiSyncSettingsDelegate? + init(selectedMode: SyncMode) { + self.selectedMode = selectedMode + super.init() + } + override func viewDidLoad() { super.viewDidLoad() @@ -40,13 +45,10 @@ class WifiSyncSettingsViewController: BaseGroupedTableViewController { tableView.register(cellView: ParameterSyncTableViewCell.self) tableView.allowsMultipleSelection = false - - selectedMode = UserDefaults.shared.syncMode } static func instantiate(selectedMode: SyncMode) -> WifiSyncSettingsViewController { - let viewController = WifiSyncSettingsViewController() - viewController.selectedMode = selectedMode + let viewController = WifiSyncSettingsViewController(selectedMode: selectedMode) return viewController } From 34edab36ec62d4eb883a1fc6970241f1d19b48f9 Mon Sep 17 00:00:00 2001 From: Baptiste Griva <75640057+BaptGrv@users.noreply.github.com> Date: Fri, 21 Feb 2025 13:16:03 +0100 Subject: [PATCH 09/14] feat: UI for PhotoSync with explicit wifi or 4G (#1441) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Add style on button # Conflicts: # kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift * feat: Link syncOffline with back # Conflicts: # kDrive/UI/Controller/Menu/ParameterTableViewController.swift # kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift # kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift # kDrive/UI/View/Menu/Parameters/ParameterSyncTableViewCell.swift # kDriveCore/Utils/DriveUserDefaults+Extension.swift * feat: Sync photos wifiOnly # Conflicts: # kDrive/Resources/de.lproj/Localizable.strings # kDrive/Resources/en.lproj/Localizable.strings # kDrive/Resources/es.lproj/Localizable.strings # kDrive/Resources/fr.lproj/Localizable.strings # kDrive/Resources/it.lproj/Localizable.strings * fix: Change mode # Conflicts: # kDrive/UI/Controller/Menu/OfflineSyncSettingsViewController.swift # kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift # kDriveCore/Utils/DriveUserDefaults+Extension.swift * feat: Sync wifi # Conflicts: # kDrive/UI/Controller/Files/Upload/UploadQueueViewController.swift # kDrive/UI/Controller/Menu/MenuViewController.swift * feat: Change cells while no Wifi * feat: Apply requested changes + loco # Conflicts: # kDrive/Resources/de.lproj/Localizable.strings # kDrive/Resources/en.lproj/Localizable.strings # kDrive/Resources/es.lproj/Localizable.strings # kDrive/Resources/fr.lproj/Localizable.strings # kDrive/Resources/it.lproj/Localizable.strings * fix: Remove useless reloadData * fix: Resolve issues since merge and cherry-picks * fix: Clean the code according to review * refactor(uploadQueue): Suspension logic * fix: Variable name * refactor: Merge 2 duplicated files in one * fix: Remove literal --------- Co-authored-by: Adrien Coye de Brunélis --- .../Upload/UploadQueueViewController.swift | 39 +++-- .../Controller/Home/RootMenuHeaderView.swift | 44 ++++- .../UI/Controller/Home/RootMenuHeaderView.xib | 2 +- .../Controller/Menu/MenuViewController.swift | 40 ++++- .../Menu/ParameterTableViewController.swift | 14 +- .../PhotoSyncSettingsViewController.swift | 8 +- .../Menu/WifiSyncSettingsViewController.swift | 18 +- .../Upload/ErrorUploadTableViewCell.swift | 40 +++++ .../Files/Upload/ErrorUploadTableViewCell.xib | 164 ++++++++++++++++++ .../Files/Upload/UploadTableViewCell.swift | 9 +- .../Home/UploadsPausedTableViewCell.swift | 30 ++++ .../View/Home/UploadsPausedTableViewCell.xib | 126 ++++++++++++++ .../ParameterSyncTableViewCell.swift | 13 ++ .../DriveFileManagerConstants.swift | 2 +- kDriveCore/Data/Models/DriveError.swift | 7 +- .../Operation/UploadOperation+Error.swift | 3 + .../Operation/UploadOperation+PHAsset.swift | 18 ++ .../Operation/UploadOperation.swift | 5 + .../Data/UploadQueue/Queue/UploadQueue.swift | 3 +- .../Utils/DriveUserDefaults+Extension.swift | 8 +- .../Utils/NotificationName+Extension.swift | 1 + 21 files changed, 548 insertions(+), 46 deletions(-) create mode 100644 kDrive/UI/View/Files/Upload/ErrorUploadTableViewCell.swift create mode 100644 kDrive/UI/View/Files/Upload/ErrorUploadTableViewCell.xib create mode 100644 kDrive/UI/View/Home/UploadsPausedTableViewCell.swift create mode 100644 kDrive/UI/View/Home/UploadsPausedTableViewCell.xib diff --git a/kDrive/UI/Controller/Files/Upload/UploadQueueViewController.swift b/kDrive/UI/Controller/Files/Upload/UploadQueueViewController.swift index 320fb2fa2..e05c3b6f9 100644 --- a/kDrive/UI/Controller/Files/Upload/UploadQueueViewController.swift +++ b/kDrive/UI/Controller/Files/Upload/UploadQueueViewController.swift @@ -45,6 +45,7 @@ final class UploadQueueViewController: UIViewController { navigationItem.hideBackButtonText() tableView.register(cellView: UploadTableViewCell.self) + tableView.register(cellView: ErrorUploadTableViewCell.self) retryButton.accessibilityLabel = KDriveResourcesStrings.Localizable.buttonRetry cancelButton.accessibilityLabel = KDriveResourcesStrings.Localizable.buttonCancel @@ -147,19 +148,35 @@ extension UploadQueueViewController: UITableViewDataSource { } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCell(type: UploadTableViewCell.self, for: indexPath) - let fileWrapper = frozenUploadingFiles[indexPath.row] - let frozenFile = fileWrapper.content - - cell.initWithPositionAndShadow(isFirst: fileWrapper.isFirstInList, - isLast: fileWrapper.isLastInList) + if indexPath.row == 0 && UserDefaults.shared.isWifiOnly && ReachabilityListener.instance.currentStatus == .cellular { + let cell = tableView.dequeueReusableCell(type: ErrorUploadTableViewCell.self, for: indexPath) + cell.initWithPositionAndShadow(isFirst: true, + isLast: true) + cell.delegate = self + return cell + } else { + 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) + + /// Make sure the file is valid + let file = frozenUploadingFiles[indexPath.row].content + if !file.isInvalidated { + let progress: CGFloat? = (file.progress != nil) ? CGFloat(file.progress!) : nil + cell.configureWith(frozenUploadFile: file, progress: progress) + } - if !frozenFile.isInvalidated { - let progress: CGFloat? = (frozenFile.progress != nil) ? CGFloat(frozenFile.progress!) : nil - cell.configureWith(frozenUploadFile: frozenFile, progress: progress) + cell.selectionStyle = .none + return cell } + } +} - cell.selectionStyle = .none - return cell +extension UploadQueueViewController: AccessParametersDelegate { + func parameterButtonTapped() { + navigationController?.pushViewController(PhotoSyncSettingsViewController(), animated: true) } } diff --git a/kDrive/UI/Controller/Home/RootMenuHeaderView.swift b/kDrive/UI/Controller/Home/RootMenuHeaderView.swift index 89b305334..c6b687ec3 100644 --- a/kDrive/UI/Controller/Home/RootMenuHeaderView.swift +++ b/kDrive/UI/Controller/Home/RootMenuHeaderView.swift @@ -35,6 +35,10 @@ class RootMenuHeaderView: UICollectionReusableView { var onUploadCardViewTapped: (() -> Void)? + deinit { + NotificationCenter.default.removeObserver(self) + } + override func awakeFromNib() { super.awakeFromNib() @@ -45,9 +49,7 @@ class RootMenuHeaderView: UICollectionReusableView { radius: 10 ) - uploadCardView.titleLabel.text = KDriveResourcesStrings.Localizable.uploadInProgressTitle - uploadCardView.progressView.setInfomaniakStyle() - uploadCardView.progressView.enableIndeterminate() + updateWifiView() uploadCardView.isHidden = true offlineView.isHidden = true @@ -55,6 +57,13 @@ class RootMenuHeaderView: UICollectionReusableView { let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(didTapOnUploadCardView)) uploadCardView.addGestureRecognizer(tapGestureRecognizer) + + NotificationCenter.default.addObserver( + self, + selector: #selector(reloadWifiView), + name: .reloadWifiView, + object: nil + ) } func configureInCollectionView( @@ -82,6 +91,10 @@ class RootMenuHeaderView: UICollectionReusableView { } } + @objc func reloadWifiView(_ notification: Notification) { + updateWifiView() + } + @objc func didTapOnUploadCardView() { onUploadCardViewTapped?() } @@ -113,11 +126,34 @@ class RootMenuHeaderView: UICollectionReusableView { guard let self else { return } offlineView.isHidden = status != .offline - reloadHeader() + + updateWifiView() } } } + private func updateWifiView() { + if UserDefaults.shared.isWifiOnly && ReachabilityListener.instance.currentStatus == .cellular { + uploadCardView.titleLabel.text = KDriveResourcesStrings.Localizable.uploadPausedTitle + uploadCardView.progressView.isHidden = true + uploadCardView.iconView.image = UIImage(systemName: "exclamationmark.arrow.triangle.2.circlepath") + uploadCardView.iconView.isHidden = false + uploadCardView.iconView.translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint.activate([ + uploadCardView.iconView.widthAnchor.constraint(equalToConstant: 24), + uploadCardView.iconView.heightAnchor.constraint(equalToConstant: 24) + ]) + uploadCardView.iconView.tintColor = .gray + } else { + uploadCardView.titleLabel.text = KDriveResourcesStrings.Localizable.uploadInProgressTitle + uploadCardView.progressView.isHidden = false + uploadCardView.iconView.isHidden = true + uploadCardView.progressView.setInfomaniakStyle() + uploadCardView.progressView.enableIndeterminate() + } + reloadHeader() + } + private func reloadHeader() { hideIfNeeded() diff --git a/kDrive/UI/Controller/Home/RootMenuHeaderView.xib b/kDrive/UI/Controller/Home/RootMenuHeaderView.xib index a4f4a3155..5b7319805 100644 --- a/kDrive/UI/Controller/Home/RootMenuHeaderView.xib +++ b/kDrive/UI/Controller/Home/RootMenuHeaderView.xib @@ -172,7 +172,7 @@ - + diff --git a/kDrive/UI/Controller/Menu/MenuViewController.swift b/kDrive/UI/Controller/Menu/MenuViewController.swift index 2a3765f07..760db98f9 100644 --- a/kDrive/UI/Controller/Menu/MenuViewController.swift +++ b/kDrive/UI/Controller/Menu/MenuViewController.swift @@ -84,6 +84,10 @@ final class MenuViewController: UITableViewController, SelectSwitchDriveDelegate fatalError("init(coder:) has not been implemented") } + deinit { + NotificationCenter.default.removeObserver(self) + } + override func viewDidLoad() { super.viewDidLoad() @@ -92,12 +96,27 @@ final class MenuViewController: UITableViewController, SelectSwitchDriveDelegate tableView.register(cellView: MenuTableViewCell.self) tableView.register(cellView: MenuTopTableViewCell.self) tableView.register(cellView: UploadsInProgressTableViewCell.self) + tableView.register(cellView: UploadsPausedTableViewCell.self) tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: UIConstants.List.paddingBottom, right: 0) updateTableContent() navigationItem.title = KDriveResourcesStrings.Localizable.menuTitle navigationItem.hideBackButtonText() + + NotificationCenter.default.addObserver( + self, + selector: #selector(reloadWifiView), + name: .reloadWifiView, + object: nil + ) + + ReachabilityListener.instance.observeNetworkChange(self) { [weak self] _ in + Task { @MainActor in + let indexPath = IndexPath(row: 0, section: 1) + self?.tableView.reloadRows(at: [indexPath], with: .automatic) + } + } } override func viewWillAppear(_ animated: Bool) { @@ -158,6 +177,10 @@ final class MenuViewController: UITableViewController, SelectSwitchDriveDelegate sections.insert(.uploads, at: 1) } } + + @objc func reloadWifiView(_ notification: Notification) { + reloadData() + } } // MARK: - Table view delegate @@ -189,11 +212,18 @@ extension MenuViewController { cell.switchDriveButton.addTarget(self, action: #selector(switchDriveButtonPressed(_:)), for: .touchUpInside) return cell } else if section == .uploads { - let cell = tableView.dequeueReusableCell(type: UploadsInProgressTableViewCell.self, for: indexPath) - cell.initWithPositionAndShadow(isFirst: true, isLast: true) - cell.progressView.enableIndeterminate() - cell.setUploadCount(uploadCountManager?.uploadCount ?? 0) - return cell + if UserDefaults.shared.isWifiOnly && ReachabilityListener.instance.currentStatus == .cellular { + let cell = tableView.dequeueReusableCell(type: UploadsPausedTableViewCell.self, for: indexPath) + cell.initWithPositionAndShadow(isFirst: true, isLast: true) + cell.setUploadCount(uploadCountManager?.uploadCount ?? 0) + return cell + } else { + let cell = tableView.dequeueReusableCell(type: UploadsInProgressTableViewCell.self, for: indexPath) + cell.initWithPositionAndShadow(isFirst: true, isLast: true) + cell.progressView.enableIndeterminate() + cell.setUploadCount(uploadCountManager?.uploadCount ?? 0) + return cell + } } else { let action = section.actions[indexPath.row] let cell = tableView.dequeueReusableCell(type: MenuTableViewCell.self, for: indexPath) diff --git a/kDrive/UI/Controller/Menu/ParameterTableViewController.swift b/kDrive/UI/Controller/Menu/ParameterTableViewController.swift index 4310b1bd5..8bfac8749 100644 --- a/kDrive/UI/Controller/Menu/ParameterTableViewController.swift +++ b/kDrive/UI/Controller/Menu/ParameterTableViewController.swift @@ -77,7 +77,7 @@ class ParameterTableViewController: BaseGroupedTableViewController { case theme case notifications case security - case wifi + case offlineSync case storage case about case deleteAccount @@ -92,7 +92,7 @@ class ParameterTableViewController: BaseGroupedTableViewController { return KDriveResourcesStrings.Localizable.notificationTitle case .security: return KDriveResourcesStrings.Localizable.securityTitle - case .wifi: + case .offlineSync: return KDriveResourcesStrings.Localizable.syncWifiSettingsTitle case .storage: return KDriveResourcesStrings.Localizable.manageStorageTitle @@ -245,14 +245,14 @@ class ParameterTableViewController: BaseGroupedTableViewController { cell.titleLabel.text = row.title return cell - case .wifi: + case .offlineSync: let cell = tableView.dequeueReusableCell(type: AboutDetailTableViewCell.self, for: indexPath) cell.initWithPositionAndShadow( isFirst: indexPath.row == 0, isLast: indexPath.row == GeneralParameterRow.allCases.count - 1 ) - cell.titleLabel.text = UserDefaults.shared.syncMode.title - cell.detailLabel.text = UserDefaults.shared.syncMode.selectionTitle + cell.titleLabel.text = KDriveResourcesStrings.Localizable.syncWifiSettingsTitle + cell.detailLabel.text = UserDefaults.shared.syncOfflineMode.title return cell } } @@ -318,9 +318,9 @@ class ParameterTableViewController: BaseGroupedTableViewController { navigationController?.pushViewController(NotificationsSettingsTableViewController(), animated: true) case .security: navigationController?.pushViewController(SecurityTableViewController(), animated: true) - case .wifi: + case .offlineSync: navigationController?.pushViewController( - WifiSyncSettingsViewController(selectedMode: UserDefaults.shared.syncMode), + WifiSyncSettingsViewController(selectedMode: UserDefaults.shared.syncOfflineMode, offlineSync: true), animated: true ) case .about: diff --git a/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift b/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift index a676d0910..a874a9915 100644 --- a/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift +++ b/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift @@ -395,7 +395,7 @@ extension PhotoSyncSettingsViewController { let cell = tableView.dequeueReusableCell(type: AboutDetailTableViewCell.self, for: indexPath) cell.initWithPositionAndShadow(isFirst: indexPath.row == 0, isLast: indexPath.row == settingsRows.count - 1) cell.titleLabel.text = KDriveResourcesStrings.Localizable.syncWifiPicturesTitle - cell.detailLabel.text = UserDefaults.shared.syncMode.title + cell.detailLabel.text = liveNewSyncSettings.wifiSync.title return cell } case .syncDenied: @@ -455,8 +455,7 @@ extension PhotoSyncSettingsViewController { selectPhotoFormatViewController.delegate = self navigationController?.pushViewController(selectPhotoFormatViewController, animated: true) case .wifiSync: - let wifiSyncSettingsViewController = WifiSyncSettingsViewController - .instantiate(selectedMode: liveNewSyncSettings.wifiSync) + let wifiSyncSettingsViewController = WifiSyncSettingsViewController(selectedMode: liveNewSyncSettings.wifiSync) wifiSyncSettingsViewController.delegate = self navigationController?.pushViewController(wifiSyncSettingsViewController, animated: true) default: @@ -550,9 +549,12 @@ extension PhotoSyncSettingsViewController: PhotoSyncSettingsTableViewCellDelegat extension PhotoSyncSettingsViewController: WifiSyncSettingsDelegate { func didSelectSyncMode(_ mode: SyncMode) { liveNewSyncSettings.wifiSync = mode + UserDefaults.shared.isWifiOnly = (mode == .onlyWifi) + updateSaveButtonState() tableView.reloadRows( at: [IndexPath(row: PhotoSyncSettingsRows.wifiSync.rawValue, section: PhotoSyncSection.syncSettings.rawValue)], with: .fade ) + NotificationCenter.default.post(name: .reloadWifiView, object: nil) } } diff --git a/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift b/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift index 88706c32e..d83246017 100644 --- a/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift +++ b/kDrive/UI/Controller/Menu/WifiSyncSettingsViewController.swift @@ -31,10 +31,12 @@ class WifiSyncSettingsViewController: BaseGroupedTableViewController { private var tableContent: [SyncMode] = SyncMode.allCases private var selectedMode: SyncMode + private var offlineSync: Bool weak var delegate: WifiSyncSettingsDelegate? - init(selectedMode: SyncMode) { + init(selectedMode: SyncMode, offlineSync: Bool = false) { self.selectedMode = selectedMode + self.offlineSync = offlineSync super.init() } @@ -69,19 +71,23 @@ class WifiSyncSettingsViewController: BaseGroupedTableViewController { let cell = tableView.dequeueReusableCell(type: ParameterSyncTableViewCell.self, for: indexPath) cell.initWithPositionAndShadow(isFirst: true, isLast: true) let currentMode = tableContent[indexPath.row] + cell.syncTitleLabel.text = currentMode.title + cell.syncDetailLabel.text = currentMode.selectionTitle if currentMode == selectedMode { tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none) } - cell.syncTitleLabel.text = currentMode.title - cell.syncDetailLabel.text = currentMode.selectionTitle return cell } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let mode = tableContent[indexPath.row] - MatomoUtils.track(eventWithCategory: .settings, name: "mode\(mode.rawValue.capitalized)") - UserDefaults.shared.syncMode = mode - delegate?.didSelectSyncMode(tableContent[indexPath.row]) + MatomoUtils.track(eventWithCategory: .settings, name: "mod\(mode.rawValue.capitalized)") + if !offlineSync { + delegate?.didSelectSyncMode(mode) + } else { + UserDefaults.shared.syncOfflineMode = mode + } + navigationController?.popViewController(animated: true) } } diff --git a/kDrive/UI/View/Files/Upload/ErrorUploadTableViewCell.swift b/kDrive/UI/View/Files/Upload/ErrorUploadTableViewCell.swift new file mode 100644 index 000000000..ea76aa6a3 --- /dev/null +++ b/kDrive/UI/View/Files/Upload/ErrorUploadTableViewCell.swift @@ -0,0 +1,40 @@ +/* + 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 InfomaniakCoreUIKit +import kDriveCore +import kDriveResources +import UIKit + +protocol AccessParametersDelegate: AnyObject { + func parameterButtonTapped() +} + +class ErrorUploadTableViewCell: InsetTableViewCell { + @IBOutlet var bannerView: UIView! + @IBOutlet var errorIconImageView: UIImageView! + @IBOutlet var errorTitleLabel: UILabel! + @IBOutlet var errorDetailLabel: UILabel! + @IBOutlet var settingButton: UIButton! + + weak var delegate: AccessParametersDelegate? + + @IBAction func updateButtonPressed(_ sender: UIButton) { + delegate?.parameterButtonTapped() + } +} diff --git a/kDrive/UI/View/Files/Upload/ErrorUploadTableViewCell.xib b/kDrive/UI/View/Files/Upload/ErrorUploadTableViewCell.xib new file mode 100644 index 000000000..3bf5e9028 --- /dev/null +++ b/kDrive/UI/View/Files/Upload/ErrorUploadTableViewCell.xib @@ -0,0 +1,164 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kDrive/UI/View/Files/Upload/UploadTableViewCell.swift b/kDrive/UI/View/Files/Upload/UploadTableViewCell.swift index 68ef383b4..0498ed354 100644 --- a/kDrive/UI/View/Files/Upload/UploadTableViewCell.swift +++ b/kDrive/UI/View/Files/Upload/UploadTableViewCell.swift @@ -74,8 +74,13 @@ final class UploadTableViewCell: InsetTableViewCell { if let error = uploadFile.error, error != .taskRescheduled { cardContentView.retryButton?.isHidden = false - cardContentView.detailsLabel.text = KDriveResourcesStrings.Localizable - .errorUpload + " (\(error.localizedDescription))" + if error.localizedDescription == KDriveResourcesStrings.Localizable.uploadOverDataRestrictedError { + cardContentView.detailsLabel.text = error.localizedDescription + } else { + cardContentView.detailsLabel.text = KDriveResourcesStrings.Localizable + .errorUpload + " (\(error.localizedDescription))" + } + } else { cardContentView.retryButton? .isHidden = (uploadFile.maxRetryCount > 0) // Display retry for uploads that reached automatic retry limit diff --git a/kDrive/UI/View/Home/UploadsPausedTableViewCell.swift b/kDrive/UI/View/Home/UploadsPausedTableViewCell.swift new file mode 100644 index 000000000..82c72c3ff --- /dev/null +++ b/kDrive/UI/View/Home/UploadsPausedTableViewCell.swift @@ -0,0 +1,30 @@ +/* + 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 InfomaniakCoreUIKit +import kDriveCore +import kDriveResources +import UIKit + +class UploadsPausedTableViewCell: InsetTableViewCell { + @IBOutlet var subtitleLabel: IKLabel! + + func setUploadCount(_ count: Int) { + subtitleLabel.text = KDriveResourcesStrings.Localizable.uploadInProgressNumberFile(count) + } +} diff --git a/kDrive/UI/View/Home/UploadsPausedTableViewCell.xib b/kDrive/UI/View/Home/UploadsPausedTableViewCell.xib new file mode 100644 index 000000000..f01b4c9ff --- /dev/null +++ b/kDrive/UI/View/Home/UploadsPausedTableViewCell.xib @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kDrive/UI/View/Menu/Parameters/ParameterSyncTableViewCell.swift b/kDrive/UI/View/Menu/Parameters/ParameterSyncTableViewCell.swift index e576a8a0f..1544217af 100644 --- a/kDrive/UI/View/Menu/Parameters/ParameterSyncTableViewCell.swift +++ b/kDrive/UI/View/Menu/Parameters/ParameterSyncTableViewCell.swift @@ -17,9 +17,22 @@ */ import InfomaniakCoreUIKit +import kDriveResources import UIKit class ParameterSyncTableViewCell: InsetTableViewCell { @IBOutlet var syncTitleLabel: UILabel! @IBOutlet var syncDetailLabel: UILabel! + + override func setSelected(_ selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + + contentInsetView.backgroundColor = KDriveResourcesAsset.backgroundCardViewColor.color + if selected { + contentInsetView.borderColor = KDriveResourcesAsset.infomaniakColor.color + contentInsetView.borderWidth = 2 + } else { + contentInsetView.borderWidth = 0 + } + } } diff --git a/kDriveCore/Data/Cache/DriveFileManager/DriveFileManagerConstants.swift b/kDriveCore/Data/Cache/DriveFileManager/DriveFileManagerConstants.swift index 85a64183e..850fdfd09 100644 --- a/kDriveCore/Data/Cache/DriveFileManager/DriveFileManagerConstants.swift +++ b/kDriveCore/Data/Cache/DriveFileManager/DriveFileManagerConstants.swift @@ -207,7 +207,7 @@ public class DriveFileManagerConstants { // Migration to add syncWifi if oldSchemaVersion < 22 { - migration.enumerateObjects(ofType: UploadFile.className()) { _, newObject in + migration.enumerateObjects(ofType: PhotoSyncSettings.className()) { _, newObject in guard let newObject else { return } diff --git a/kDriveCore/Data/Models/DriveError.swift b/kDriveCore/Data/Models/DriveError.swift index f85b04a66..5f18f157d 100644 --- a/kDriveCore/Data/Models/DriveError.swift +++ b/kDriveCore/Data/Models/DriveError.swift @@ -141,6 +141,10 @@ public struct DriveError: Error, Equatable { localizedString: KDriveResourcesStrings.Localizable.errorCache) public static let unknownError = DriveError(type: .localError, code: "unknownError") + public static let uploadOverDataRestrictedError = DriveError(type: .localError, + code: "uploadOverDataRestrictedError", + localizedString: KDriveResourcesStrings.Localizable.uploadOverDataRestrictedError) + // MARK: - Server public static let refreshToken = DriveError(type: .serverError, code: "refreshToken") @@ -261,7 +265,8 @@ public struct DriveError: Error, Equatable { uploadTokenIsNotValid, fileAlreadyExistsError, errorDeviceStorage, - limitExceededError] + limitExceededError, + uploadOverDataRestrictedError] private static let encoder = JSONEncoder() private static let decoder = JSONDecoder() diff --git a/kDriveCore/Data/UploadQueue/Operation/UploadOperation+Error.swift b/kDriveCore/Data/UploadQueue/Operation/UploadOperation+Error.swift index ef974c081..0d94e09c5 100644 --- a/kDriveCore/Data/UploadQueue/Operation/UploadOperation+Error.swift +++ b/kDriveCore/Data/UploadQueue/Operation/UploadOperation+Error.swift @@ -127,6 +127,9 @@ extension UploadOperation { // Silently stop if an UploadFile is no longer in base // _not_ overriding file.error self.cancel() + case .uploadOverDataRestrictedError: + file.error = DriveError.uploadOverDataRestrictedError + self.uploadQueue.suspendAllOperations() } errorHandled = true diff --git a/kDriveCore/Data/UploadQueue/Operation/UploadOperation+PHAsset.swift b/kDriveCore/Data/UploadQueue/Operation/UploadOperation+PHAsset.swift index 5ae8f002c..168adc1c6 100644 --- a/kDriveCore/Data/UploadQueue/Operation/UploadOperation+PHAsset.swift +++ b/kDriveCore/Data/UploadQueue/Operation/UploadOperation+PHAsset.swift @@ -17,6 +17,7 @@ */ import Foundation +import InfomaniakCore extension UploadOperation { func getPhAssetIfNeeded() async throws { @@ -56,4 +57,21 @@ extension UploadOperation { file.pathURL = url } } + + func checkForRestrictedUploadOverDataMode() throws { + let file = try readOnlyFile() + + guard file.type == .phAsset else { + // This UploadFile is not a PHAsset, return silently + return + } + + let status = ReachabilityListener.instance.currentStatus + let canUpload = !(status == .cellular && UserDefaults.shared.isWifiOnly) + + guard !canUpload else { + return + } + throw ErrorDomain.uploadOverDataRestrictedError + } } diff --git a/kDriveCore/Data/UploadQueue/Operation/UploadOperation.swift b/kDriveCore/Data/UploadQueue/Operation/UploadOperation.swift index 3b7d3c60a..c058344fa 100644 --- a/kDriveCore/Data/UploadQueue/Operation/UploadOperation.swift +++ b/kDriveCore/Data/UploadQueue/Operation/UploadOperation.swift @@ -58,6 +58,8 @@ public final class UploadOperation: AsynchronousOperation, UploadOperationable { case operationFinished /// Cannot decrease further retry count, already zero case retryCountIsZero + /// Cannot upload image because we are not in wifi + case uploadOverDataRestrictedError } // MARK: - Attributes @@ -127,6 +129,9 @@ public final class UploadOperation: AsynchronousOperation, UploadOperationable { // Clean existing error if any try self.cleanUploadFileError() + // Pause the upload depending on the status + try self.checkForRestrictedUploadOverDataMode() + // Fetch content from local library if needed try await self.getPhAssetIfNeeded() diff --git a/kDriveCore/Data/UploadQueue/Queue/UploadQueue.swift b/kDriveCore/Data/UploadQueue/Queue/UploadQueue.swift index 56fa6f94a..7893ec57a 100644 --- a/kDriveCore/Data/UploadQueue/Queue/UploadQueue.swift +++ b/kDriveCore/Data/UploadQueue/Queue/UploadQueue.swift @@ -102,7 +102,8 @@ public final class UploadQueue: ParallelismHeuristicDelegate { } let status = ReachabilityListener.instance.currentStatus - return status == .offline || (status != .wifi && UserDefaults.shared.isWifiOnly) + let shouldBeSuspended = status == .offline || !(status == .wifi && UserDefaults.shared.isWifiOnly) + return shouldBeSuspended } /// Should suspend operation queue based on explicit `suspendAllOperations()` call diff --git a/kDriveCore/Utils/DriveUserDefaults+Extension.swift b/kDriveCore/Utils/DriveUserDefaults+Extension.swift index 1a0682295..71a0aa5f3 100644 --- a/kDriveCore/Utils/DriveUserDefaults+Extension.swift +++ b/kDriveCore/Utils/DriveUserDefaults+Extension.swift @@ -49,7 +49,7 @@ extension UserDefaults.Keys { static let selectedHomeIndex = UserDefaults.Keys(rawValue: "selectedHomeIndex") static let fpStorageVersion = UserDefaults.Keys(rawValue: "fpStorageVersion") static let importPhotoFormat = UserDefaults.Keys(rawValue: "importPhotoFormat") - static let syncMode = UserDefaults.Keys(rawValue: "syncMode") + static let syncOfflineMode = UserDefaults.Keys(rawValue: "syncOfflineMode") } public extension UserDefaults { @@ -338,16 +338,16 @@ public extension UserDefaults { } } - var syncMode: SyncMode { + var syncOfflineMode: SyncMode { get { - if let rawValue = object(forKey: key(.syncMode)) as? String, + if let rawValue = object(forKey: key(.syncOfflineMode)) as? String, let mode = SyncMode(rawValue: rawValue) { return mode } return .onlyWifi } set { - set(newValue.rawValue, forKey: key(.syncMode)) + set(newValue.rawValue, forKey: key(.syncOfflineMode)) } } } diff --git a/kDriveCore/Utils/NotificationName+Extension.swift b/kDriveCore/Utils/NotificationName+Extension.swift index a4454d7e0..1711bbc9c 100644 --- a/kDriveCore/Utils/NotificationName+Extension.swift +++ b/kDriveCore/Utils/NotificationName+Extension.swift @@ -21,4 +21,5 @@ import Foundation public extension Notification.Name { static let locateUploadActionTapped = Notification.Name(rawValue: "kDriveLocateUploadActionTapped") static let reloadDrive = Notification.Name(rawValue: "kDriveReloadDrive") + static let reloadWifiView = Notification.Name(rawValue: "kDriveReloadWifiView") } From 1729e6840b28bc08f2db590782367ec061d75cf5 Mon Sep 17 00:00:00 2001 From: Baptiste Griva Date: Fri, 21 Feb 2025 14:46:09 +0100 Subject: [PATCH 10/14] fix: SwiftFormat --- kDriveCore/Data/Models/DriveError.swift | 3 ++- .../Data/UploadQueue/Operation/UploadOperation+Error.swift | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/kDriveCore/Data/Models/DriveError.swift b/kDriveCore/Data/Models/DriveError.swift index 5f18f157d..38073de6e 100644 --- a/kDriveCore/Data/Models/DriveError.swift +++ b/kDriveCore/Data/Models/DriveError.swift @@ -143,7 +143,8 @@ public struct DriveError: Error, Equatable { public static let uploadOverDataRestrictedError = DriveError(type: .localError, code: "uploadOverDataRestrictedError", - localizedString: KDriveResourcesStrings.Localizable.uploadOverDataRestrictedError) + localizedString: KDriveResourcesStrings.Localizable + .uploadOverDataRestrictedError) // MARK: - Server diff --git a/kDriveCore/Data/UploadQueue/Operation/UploadOperation+Error.swift b/kDriveCore/Data/UploadQueue/Operation/UploadOperation+Error.swift index 0d94e09c5..5e0fe99a3 100644 --- a/kDriveCore/Data/UploadQueue/Operation/UploadOperation+Error.swift +++ b/kDriveCore/Data/UploadQueue/Operation/UploadOperation+Error.swift @@ -127,6 +127,7 @@ extension UploadOperation { // Silently stop if an UploadFile is no longer in base // _not_ overriding file.error self.cancel() + case .uploadOverDataRestrictedError: file.error = DriveError.uploadOverDataRestrictedError self.uploadQueue.suspendAllOperations() From 5766c46c3eb03cd9779ae18387324a44290080f1 Mon Sep 17 00:00:00 2001 From: Baptiste Griva Date: Mon, 24 Feb 2025 13:22:47 +0100 Subject: [PATCH 11/14] fix: Wrong condition to suspend queue --- kDriveCore/Data/UploadQueue/Queue/UploadQueue.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kDriveCore/Data/UploadQueue/Queue/UploadQueue.swift b/kDriveCore/Data/UploadQueue/Queue/UploadQueue.swift index 7893ec57a..789ea27a6 100644 --- a/kDriveCore/Data/UploadQueue/Queue/UploadQueue.swift +++ b/kDriveCore/Data/UploadQueue/Queue/UploadQueue.swift @@ -102,7 +102,7 @@ public final class UploadQueue: ParallelismHeuristicDelegate { } let status = ReachabilityListener.instance.currentStatus - let shouldBeSuspended = status == .offline || !(status == .wifi && UserDefaults.shared.isWifiOnly) + let shouldBeSuspended = status == .offline || (status != .wifi && UserDefaults.shared.isWifiOnly) return shouldBeSuspended } From 8d5f25aa6ece70e6a12fc32f391c1d872de5fc6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Coye=20de=20Brune=CC=81lis?= Date: Tue, 25 Feb 2025 16:18:58 +0100 Subject: [PATCH 12/14] feat(UploadQueueViewController): Section support using DiffKit --- .../Upload/UploadQueueViewController.swift | 74 +++++++++++++++---- 1 file changed, 59 insertions(+), 15 deletions(-) diff --git a/kDrive/UI/Controller/Files/Upload/UploadQueueViewController.swift b/kDrive/UI/Controller/Files/Upload/UploadQueueViewController.swift index e05c3b6f9..a8eecb8bd 100644 --- a/kDrive/UI/Controller/Files/Upload/UploadQueueViewController.swift +++ b/kDrive/UI/Controller/Files/Upload/UploadQueueViewController.swift @@ -28,6 +28,12 @@ import UIKit typealias UploadFileDisplayed = CornerCellContainer final class UploadQueueViewController: UIViewController { + private let errorFile = UploadFileDisplayed(isFirstInList: true, isLastInList: true, content: UploadFile()) + + enum SectionModel: Differentiable { + case error, files + } + @IBOutlet var tableView: UITableView! @IBOutlet var retryButton: UIBarButtonItem! @IBOutlet var cancelButton: UIBarButtonItem! @@ -37,6 +43,7 @@ final class UploadQueueViewController: UIViewController { var currentDirectory: File! private var frozenUploadingFiles = [UploadFileDisplayed]() + private lazy var sections = buildSections(files: [UploadFileDisplayed]()) private var notificationToken: NotificationToken? override func viewDidLoad() { @@ -54,7 +61,7 @@ final class UploadQueueViewController: UIViewController { ReachabilityListener.instance.observeNetworkChange(self) { [weak self] _ in Task { @MainActor in - self?.tableView.reloadData() + self?.reloadCollectionView() } } } @@ -95,7 +102,7 @@ final class UploadQueueViewController: UIViewController { } guard let newResults else { - reloadCollectionViewWith([]) + reloadCollectionView(with: []) return } @@ -106,22 +113,52 @@ final class UploadQueueViewController: UIViewController { content: frozenFile) } - reloadCollectionViewWith(wrappedFrozenFiles) + reloadCollectionView(with: wrappedFrozenFiles) } } - func reloadCollectionViewWith(_ frozenFiles: [UploadFileDisplayed]) { - let changeSet = StagedChangeset(source: frozenUploadingFiles, target: frozenFiles) + @MainActor func reloadCollectionView(with frozenFiles: [UploadFileDisplayed]? = nil) { + let newSections: [ArraySection] + if let frozenFiles { + newSections = buildSections(files: frozenFiles) + } else { + newSections = buildSections(files: frozenUploadingFiles) + } + + let changeSet = StagedChangeset(source: sections, target: newSections) + tableView.reload(using: changeSet, with: UITableView.RowAnimation.automatic, interrupt: { $0.changeCount > Endpoint.itemsPerPage }, - setData: { self.frozenUploadingFiles = $0 }) - - if frozenFiles.isEmpty { + setData: { newValues in + if let frozenFiles { + frozenUploadingFiles = frozenFiles + } + sections = newValues + }) + + if let frozenFiles, frozenFiles.isEmpty { navigationController?.popViewController(animated: true) } } + private func buildSections(files: [UploadFileDisplayed]) -> [ArraySection] { + guard !isUploadLimited else { + return [ + ArraySection(model: SectionModel.error, elements: [errorFile]), + ArraySection(model: SectionModel.files, elements: files) + ] + } + + return [ + ArraySection(model: SectionModel.files, elements: files) + ] + } + + private var isUploadLimited: Bool { + UserDefaults.shared.isWifiOnly && ReachabilityListener.instance.currentStatus == .cellular + } + @IBAction func cancelButtonPressed(_ sender: UIBarButtonItem) { uploadQueue.cancelAllOperations(withParent: currentDirectory.id, userId: accountManager.currentUserId, @@ -144,11 +181,18 @@ final class UploadQueueViewController: UIViewController { extension UploadQueueViewController: UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return frozenUploadingFiles.count + guard let rows = sections[safe: section] else { + return 0 + } + return rows.elements.count + } + + func numberOfSections(in tableView: UITableView) -> Int { + return sections.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - if indexPath.row == 0 && UserDefaults.shared.isWifiOnly && ReachabilityListener.instance.currentStatus == .cellular { + if indexPath.section == 0 && isUploadLimited { let cell = tableView.dequeueReusableCell(type: ErrorUploadTableViewCell.self, for: indexPath) cell.initWithPositionAndShadow(isFirst: true, isLast: true) @@ -162,13 +206,13 @@ extension UploadQueueViewController: UITableViewDataSource { numberOfRowsInSection: indexPath.section ) - 1) - /// Make sure the file is valid - let file = frozenUploadingFiles[indexPath.row].content - if !file.isInvalidated { - let progress: CGFloat? = (file.progress != nil) ? CGFloat(file.progress!) : nil - cell.configureWith(frozenUploadFile: file, progress: progress) + guard let frozenUploadingFiles = sections[safe: indexPath.section]?.elements, + let file = frozenUploadingFiles[safe: indexPath.row]?.content, !file.isInvalidated else { + return cell } + let progress: CGFloat? = (file.progress != nil) ? CGFloat(file.progress!) : nil + cell.configureWith(frozenUploadFile: file, progress: progress) cell.selectionStyle = .none return cell } From 2f0c0367764edae33b2727cd31e9f1170fbc468f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Coye=20de=20Brune=CC=81lis?= Date: Wed, 26 Feb 2025 10:35:22 +0100 Subject: [PATCH 13/14] refactor(UploadQueue): New updateQueueSuspension public function --- kDriveCore/Data/UploadQueue/Queue/UploadQueue+Queue.swift | 6 ++++++ kDriveCore/Data/UploadQueue/Queue/UploadQueue.swift | 8 +------- kDriveCore/Data/UploadQueue/Queue/UploadQueueable.swift | 3 +++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/kDriveCore/Data/UploadQueue/Queue/UploadQueue+Queue.swift b/kDriveCore/Data/UploadQueue/Queue/UploadQueue+Queue.swift index 75b1f899f..9f487fcee 100644 --- a/kDriveCore/Data/UploadQueue/Queue/UploadQueue+Queue.swift +++ b/kDriveCore/Data/UploadQueue/Queue/UploadQueue+Queue.swift @@ -561,4 +561,10 @@ extension UploadQueue: UploadQueueable { return operation } + + public func updateQueueSuspension() { + let isSuspended = (shouldSuspendQueue || forceSuspendQueue) + operationQueue.isSuspended = isSuspended + Log.uploadQueue("update isSuspended to :\(isSuspended)") + } } diff --git a/kDriveCore/Data/UploadQueue/Queue/UploadQueue.swift b/kDriveCore/Data/UploadQueue/Queue/UploadQueue.swift index 789ea27a6..03b1644e5 100644 --- a/kDriveCore/Data/UploadQueue/Queue/UploadQueue.swift +++ b/kDriveCore/Data/UploadQueue/Queue/UploadQueue.swift @@ -133,13 +133,7 @@ public final class UploadQueue: ParallelismHeuristicDelegate { // Observe network state change ReachabilityListener.instance.observeNetworkChange(self) { [weak self] _ in - guard let self else { - return - } - - let isSuspended = (shouldSuspendQueue || forceSuspendQueue) - operationQueue.isSuspended = isSuspended - Log.uploadQueue("observeNetworkChange :\(isSuspended)") + self?.updateQueueSuspension() } observeMemoryWarnings() diff --git a/kDriveCore/Data/UploadQueue/Queue/UploadQueueable.swift b/kDriveCore/Data/UploadQueue/Queue/UploadQueueable.swift index f341dfcd9..6c246291a 100644 --- a/kDriveCore/Data/UploadQueue/Queue/UploadQueueable.swift +++ b/kDriveCore/Data/UploadQueue/Queue/UploadQueueable.swift @@ -84,4 +84,7 @@ public protocol UploadQueueable { /// /// Also make sure that UploadFiles initiated in FileManager will restart at next retry. func cleanNetworkAndLocalErrorsForAllOperations() + + /// Update queue suspension state + func updateQueueSuspension() } From c341f8a817d752e4a8973db25934452175d992d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Coye=20de=20Brune=CC=81lis?= Date: Wed, 26 Feb 2025 10:35:57 +0100 Subject: [PATCH 14/14] fix(PhotoSyncSettingsViewController): Update upload queue on save photo sync settings --- .../Controller/Menu/PhotoSyncSettingsViewController.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift b/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift index a874a9915..c84315bc2 100644 --- a/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift +++ b/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift @@ -30,6 +30,7 @@ final class PhotoSyncSettingsViewController: BaseGroupedTableViewController { @LazyInjectService var accountManager: AccountManageable @LazyInjectService var photoLibraryUploader: PhotoLibraryUploader @LazyInjectService var freeSpaceService: FreeSpaceService + @LazyInjectService var uploadQueue: UploadQueue private enum PhotoSyncSection: Int { case syncSwitch @@ -226,6 +227,12 @@ final class PhotoSyncSettingsViewController: BaseGroupedTableViewController { let newSettings = PhotoSyncSettings(value: liveNewSyncSettings) photoLibraryUploader.enableSync(newSettings) + uploadQueue.retryAllOperations( + withParent: newSettings.parentDirectoryId, + userId: newSettings.userId, + driveId: newSettings.driveId + ) + uploadQueue.updateQueueSuspension() } private func requestAuthorization() async -> PHAuthorizationStatus {