diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2023-04-19 17:52:11 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2023-04-19 17:52:39 +0200 |
| commit | 9dffc1f90ed79b337378262117025217183929ad (patch) | |
| tree | 6f79a76cf7aa38ffa2ca4ba672d86275e0ff7feb | |
| parent | d1cb72ca9c886f7f2170853e85fd180bff249664 (diff) | |
| download | mullvadvpn-9dffc1f90ed79b337378262117025217183929ad.tar.xz mullvadvpn-9dffc1f90ed79b337378262117025217183929ad.zip | |
Reduce code duplication by providing cell reuse identifier per data source item
5 files changed, 25 insertions, 48 deletions
diff --git a/ios/MullvadVPN/View controllers/Preferences/PreferencesCellFactory.swift b/ios/MullvadVPN/View controllers/Preferences/PreferencesCellFactory.swift index 8f160d3fdc..8f78abd844 100644 --- a/ios/MullvadVPN/View controllers/Preferences/PreferencesCellFactory.swift +++ b/ios/MullvadVPN/View controllers/Preferences/PreferencesCellFactory.swift @@ -26,36 +26,14 @@ final class PreferencesCellFactory: CellFactoryProtocol { } func makeCell(for item: PreferencesDataSource.Item, indexPath: IndexPath) -> UITableViewCell { - let cell: UITableViewCell - - switch item { - case .addDNSServer: - cell = tableView.dequeueReusableCell( - withIdentifier: PreferencesDataSource.CellReuseIdentifiers.addDNSServer.rawValue, - for: indexPath - ) - case .dnsServer: - cell = tableView.dequeueReusableCell( - withIdentifier: PreferencesDataSource.CellReuseIdentifiers.dnsServer.rawValue, - for: indexPath - ) - default: - cell = tableView.dequeueReusableCell( - withIdentifier: PreferencesDataSource.CellReuseIdentifiers.settingSwitch.rawValue, - for: indexPath - ) - } + let cell = tableView.dequeueReusableCell(withIdentifier: item.reuseIdentifier.rawValue, for: indexPath) configureCell(cell, item: item, indexPath: indexPath) return cell } - func configureCell( - _ cell: UITableViewCell, - item: PreferencesDataSource.Item, - indexPath: IndexPath - ) { + func configureCell(_ cell: UITableViewCell, item: PreferencesDataSource.Item, indexPath: IndexPath) { switch item { case .blockAdvertising: guard let cell = cell as? SettingsSwitchCell else { return } diff --git a/ios/MullvadVPN/View controllers/Preferences/PreferencesDataSource.swift b/ios/MullvadVPN/View controllers/Preferences/PreferencesDataSource.swift index 20e0bbc892..b750f5cb68 100644 --- a/ios/MullvadVPN/View controllers/Preferences/PreferencesDataSource.swift +++ b/ios/MullvadVPN/View controllers/Preferences/PreferencesDataSource.swift @@ -86,6 +86,17 @@ final class PreferencesDataSource: UITableViewDiffableDataSource< return false } } + + var reuseIdentifier: PreferencesDataSource.CellReuseIdentifiers { + switch self { + case .addDNSServer: + return .addDNSServer + case .dnsServer: + return .dnsServer + default: + return .settingSwitch + } + } } private var isEditing = false diff --git a/ios/MullvadVPN/View controllers/SelectLocation/LocationCellFactory.swift b/ios/MullvadVPN/View controllers/SelectLocation/LocationCellFactory.swift index fa3915f175..a6ff5e4979 100644 --- a/ios/MullvadVPN/View controllers/SelectLocation/LocationCellFactory.swift +++ b/ios/MullvadVPN/View controllers/SelectLocation/LocationCellFactory.swift @@ -34,11 +34,7 @@ final class LocationCellFactory: CellFactoryProtocol { return cell } - func configureCell( - _ cell: UITableViewCell, - item: RelayLocation, - indexPath: IndexPath - ) { + func configureCell(_ cell: UITableViewCell, item: RelayLocation, indexPath: IndexPath) { guard let cell = cell as? SelectLocationCell, let node = nodeByLocation[item] else { return } diff --git a/ios/MullvadVPN/View controllers/Settings/SettingsCellFactory.swift b/ios/MullvadVPN/View controllers/Settings/SettingsCellFactory.swift index b0d8ea2385..4aef9175bc 100644 --- a/ios/MullvadVPN/View controllers/Settings/SettingsCellFactory.swift +++ b/ios/MullvadVPN/View controllers/Settings/SettingsCellFactory.swift @@ -18,31 +18,14 @@ struct SettingsCellFactory: CellFactoryProtocol { } func makeCell(for item: SettingsDataSource.Item, indexPath: IndexPath) -> UITableViewCell { - let cell: UITableViewCell - - switch item { - case .account: - cell = tableView.dequeueReusableCell( - withIdentifier: SettingsDataSource.CellReuseIdentifiers.accountCell.rawValue, - for: indexPath - ) - default: - cell = tableView.dequeueReusableCell( - withIdentifier: SettingsDataSource.CellReuseIdentifiers.basicCell.rawValue, - for: indexPath - ) - } + let cell = tableView.dequeueReusableCell(withIdentifier: item.reuseIdentifier.rawValue, for: indexPath) configureCell(cell, item: item, indexPath: indexPath) return cell } - func configureCell( - _ cell: UITableViewCell, - item: SettingsDataSource.Item, - indexPath: IndexPath - ) { + func configureCell(_ cell: UITableViewCell, item: SettingsDataSource.Item, indexPath: IndexPath) { switch item { case .account: guard let cell = cell as? SettingsAccountCell else { return } diff --git a/ios/MullvadVPN/View controllers/Settings/SettingsDataSource.swift b/ios/MullvadVPN/View controllers/Settings/SettingsDataSource.swift index 96466cf6f2..cc460e596b 100644 --- a/ios/MullvadVPN/View controllers/Settings/SettingsDataSource.swift +++ b/ios/MullvadVPN/View controllers/Settings/SettingsDataSource.swift @@ -49,6 +49,15 @@ final class SettingsDataSource: UITableViewDiffableDataSource< case version case problemReport case faq + + var reuseIdentifier: CellReuseIdentifiers { + switch self { + case .account: + return .accountCell + default: + return .basicCell + } + } } private let interactor: SettingsInteractor |
