From a0e2551033113259513c8598fefd9db1587b2072 Mon Sep 17 00:00:00 2001 From: Jon Petersson Date: Mon, 11 Nov 2024 16:51:07 +0100 Subject: [PATCH] Fix filter apply button being enabled with zero providers --- .../RelayFilter/RelayFilterDataSource.swift | 4 -- .../RelayFilterViewController.swift | 40 +++++++++++++++++-- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/ios/MullvadVPN/View controllers/RelayFilter/RelayFilterDataSource.swift b/ios/MullvadVPN/View controllers/RelayFilter/RelayFilterDataSource.swift index 3b4fadeac9b6..ad36ef12f29f 100644 --- a/ios/MullvadVPN/View controllers/RelayFilter/RelayFilterDataSource.swift +++ b/ios/MullvadVPN/View controllers/RelayFilter/RelayFilterDataSource.swift @@ -285,10 +285,6 @@ extension RelayFilterDataSource: UITableViewDelegate { return nil } - func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { - return UITableView.automaticDimension - } - func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { return UIMetrics.TableView.separatorHeight } diff --git a/ios/MullvadVPN/View controllers/RelayFilter/RelayFilterViewController.swift b/ios/MullvadVPN/View controllers/RelayFilter/RelayFilterViewController.swift index 046e466a802d..c14d41e291a9 100644 --- a/ios/MullvadVPN/View controllers/RelayFilter/RelayFilterViewController.swift +++ b/ios/MullvadVPN/View controllers/RelayFilter/RelayFilterViewController.swift @@ -96,7 +96,18 @@ class RelayFilterViewController: UIViewController { case .any: self?.applyButton.isEnabled = true case let .only(providers): - self?.applyButton.isEnabled = !providers.isEmpty + switch filter.ownership { + case .any: + self?.applyButton.isEnabled = !providers.isEmpty + case .owned: + let filterHasAtLeastOneOwnedProvider = viewModel.ownedProviders + .first(where: { providers.contains($0) }) != nil + self?.applyButton.isEnabled = filterHasAtLeastOneOwnedProvider + case .rented: + let filterHasAtLeastOneRentedProvider = viewModel.rentedProviders + .first(where: { providers.contains($0) }) != nil + self?.applyButton.isEnabled = filterHasAtLeastOneRentedProvider + } } } .store(in: &disposeBag) @@ -105,7 +116,30 @@ class RelayFilterViewController: UIViewController { } @objc private func applyFilter() { - guard let filter = viewModel?.relayFilter else { return } - onApplyFilter?(filter) + guard let viewModel = viewModel else { return } + var relayFilter = viewModel.relayFilter + + switch viewModel.relayFilter.ownership { + case .any: + break + case .owned: + switch relayFilter.providers { + case .any: + break + case let .only(providers): + let ownedProviders = viewModel.ownedProviders.filter { providers.contains($0) } + relayFilter.providers = .only(ownedProviders) + } + case .rented: + switch relayFilter.providers { + case .any: + break + case let .only(providers): + let rentedProviders = viewModel.rentedProviders.filter { providers.contains($0) } + relayFilter.providers = .only(rentedProviders) + } + } + + onApplyFilter?(relayFilter) } }