diff --git a/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift b/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift index ab006eabd..9fb79f767 100644 --- a/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift +++ b/kDrive/UI/Controller/Menu/PhotoSyncSettingsViewController.swift @@ -30,23 +30,23 @@ final class PhotoSyncSettingsViewController: BaseGroupedTableViewController { @LazyInjectService var accountManager: AccountManageable @LazyInjectService var photoLibraryUploader: PhotoLibraryUploader - 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 @@ -495,7 +495,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: @@ -512,7 +512,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 + ) } } @@ -522,7 +529,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 + ) } } @@ -532,7 +545,10 @@ extension PhotoSyncSettingsViewController: SelectPhotoFormatDelegate { func didSelectPhotoFormat(_ format: PhotoFileFormat) { newSyncSettings.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 + ) } } @@ -566,8 +582,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 }