Dependencyinject ViewModel based on downloaded policy-data (IOS-241)

This commit is contained in:
Nathan Mattes 2024-07-08 12:13:29 +02:00
parent 0b749816dd
commit 94ad86cd66
2 changed files with 21 additions and 9 deletions

View File

@ -60,12 +60,10 @@ class NotificationPolicyViewController: UIViewController {
let tableView: UITableView let tableView: UITableView
var dataSource: UITableViewDiffableDataSource<NotificationFilterSection, NotificationFilterItem>? var dataSource: UITableViewDiffableDataSource<NotificationFilterSection, NotificationFilterItem>?
let items: [NotificationFilterItem] let items: [NotificationFilterItem]
let viewModel: NotificationFilterViewModel var viewModel: NotificationFilterViewModel
init(viewModel: NotificationFilterViewModel) {
init() { self.viewModel = viewModel
//TODO: Dependency Inject Policy ViewModel
viewModel = NotificationFilterViewModel(notFollowing: false, noFollower: false, newAccount: false, privateMentions: false)
items = NotificationFilterItem.allCases items = NotificationFilterItem.allCases
tableView = UITableView(frame: .zero, style: .insetGrouped) tableView = UITableView(frame: .zero, style: .insetGrouped)
@ -128,7 +126,7 @@ class NotificationPolicyViewController: UIViewController {
// MARK: - Action // MARK: - Action
@objc private func save(_ sender: UIBarButtonItem) { @objc private func save(_ sender: UIBarButtonItem) {
//TODO: Save //TODO: Save aka PATH viewModel to API and dismiss
} }
@objc private func cancel(_ sender: UIBarButtonItem) { @objc private func cancel(_ sender: UIBarButtonItem) {
@ -137,11 +135,22 @@ class NotificationPolicyViewController: UIViewController {
} }
extension NotificationPolicyViewController: UITableViewDelegate { extension NotificationPolicyViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
}
} }
extension NotificationPolicyViewController: NotificationPolicyFilterTableViewCellDelegate { extension NotificationPolicyViewController: NotificationPolicyFilterTableViewCellDelegate {
func toggleValueChanged(_ tableViewCell: NotificationPolicyFilterTableViewCell, filterItem: NotificationFilterItem, newValue: Bool) { func toggleValueChanged(_ tableViewCell: NotificationPolicyFilterTableViewCell, filterItem: NotificationFilterItem, newValue: Bool) {
//TODO: Update ViewModel switch filterItem {
case .notFollowing:
viewModel.notFollowing = newValue
case .noFollower:
viewModel.noFollower = newValue
case .newAccount:
viewModel.newAccount = newValue
case .privateMentions:
viewModel.privateMentions = newValue
}
} }
} }

View File

@ -118,8 +118,11 @@ extension NotificationViewController {
//MARK: - Actions //MARK: - Actions
@objc private func showNotificationPolicySettings(_ sender: Any) { @objc private func showNotificationPolicySettings(_ sender: Any) {
guard let policy = viewModel?.notificationPolicy else { return }
let policyViewModel = NotificationFilterViewModel(notFollowing: policy.filterNotFollowing, noFollower: policy.filterNotFollowers, newAccount: policy.filterNewAccounts, privateMentions: policy.filterPrivateMentions)
//TODO: Move to SceneCoordinator //TODO: Move to SceneCoordinator
let notificationPolicyViewController = NotificationPolicyViewController() let notificationPolicyViewController = NotificationPolicyViewController(viewModel: policyViewModel)
notificationPolicyViewController.modalPresentationStyle = .formSheet notificationPolicyViewController.modalPresentationStyle = .formSheet
let navigationController = UINavigationController(rootViewController: notificationPolicyViewController) let navigationController = UINavigationController(rootViewController: notificationPolicyViewController)