Implement special sheet header (IOS-241)

This commit is contained in:
Nathan Mattes 2024-07-10 12:58:21 +02:00
parent c79e26b7e5
commit 6702f0624c
4 changed files with 76 additions and 25 deletions

View File

@ -163,6 +163,7 @@
D84BB76B2C3BE33800493718 /* NotificationPolicyFilterTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D84BB76A2C3BE33800493718 /* NotificationPolicyFilterTableViewCell.swift */; };
D84BB76D2C3D88B000493718 /* DataSourceFacade+Notifications.swift in Sources */ = {isa = PBXBuildFile; fileRef = D84BB76C2C3D88B000493718 /* DataSourceFacade+Notifications.swift */; };
D84BB76F2C3D8DBC00493718 /* NotificationRequestsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D84BB76E2C3D8DBC00493718 /* NotificationRequestsTableViewController.swift */; };
D84BB7722C3E566C00493718 /* NotificationPolicyHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D84BB7712C3E566C00493718 /* NotificationPolicyHeaderView.swift */; };
D84FA0932AE6915800987F47 /* MBProgressHUD in Frameworks */ = {isa = PBXBuildFile; productRef = D84FA0922AE6915800987F47 /* MBProgressHUD */; };
D852C23C2AC5D02C00309232 /* AboutInstanceViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D852C23B2AC5D02C00309232 /* AboutInstanceViewController.swift */; };
D852C23E2AC5D03300309232 /* InstanceRulesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D852C23D2AC5D03300309232 /* InstanceRulesViewController.swift */; };
@ -800,6 +801,7 @@
D84BB76A2C3BE33800493718 /* NotificationPolicyFilterTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationPolicyFilterTableViewCell.swift; sourceTree = "<group>"; };
D84BB76C2C3D88B000493718 /* DataSourceFacade+Notifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DataSourceFacade+Notifications.swift"; sourceTree = "<group>"; };
D84BB76E2C3D8DBC00493718 /* NotificationRequestsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationRequestsTableViewController.swift; sourceTree = "<group>"; };
D84BB7712C3E566C00493718 /* NotificationPolicyHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationPolicyHeaderView.swift; sourceTree = "<group>"; };
D84C099D2B0F9E33009E685E /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
D84C099F2B0F9E41009E685E /* Setup.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Setup.md; sourceTree = "<group>"; };
D84C09A02B0F9E41009E685E /* How-it-works.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "How-it-works.md"; sourceTree = "<group>"; };
@ -1772,8 +1774,7 @@
D80EC2602C2978CB009724A5 /* Notification Filtering */ = {
isa = PBXGroup;
children = (
D80EC2622C2978EE009724A5 /* NotificationPolicyViewController.swift */,
D84BB76A2C3BE33800493718 /* NotificationPolicyFilterTableViewCell.swift */,
D84BB7702C3E565100493718 /* Policy */,
D84BB76E2C3D8DBC00493718 /* NotificationRequestsTableViewController.swift */,
);
path = "Notification Filtering";
@ -1828,6 +1829,16 @@
path = Shared;
sourceTree = "<group>";
};
D84BB7702C3E565100493718 /* Policy */ = {
isa = PBXGroup;
children = (
D80EC2622C2978EE009724A5 /* NotificationPolicyViewController.swift */,
D84BB76A2C3BE33800493718 /* NotificationPolicyFilterTableViewCell.swift */,
D84BB7712C3E566C00493718 /* NotificationPolicyHeaderView.swift */,
);
path = Policy;
sourceTree = "<group>";
};
D84C099E2B0F9E41009E685E /* Documentation */ = {
isa = PBXGroup;
children = (
@ -3779,6 +3790,7 @@
DB0FCB822796AC78006C02E2 /* UserTimelineViewController+DataSourceProvider.swift in Sources */,
DB0EF72E26FDB24F00347686 /* SidebarListContentView.swift in Sources */,
DBBE1B4525F3474B0081417A /* MastodonPickServerAppearance.swift in Sources */,
D84BB7722C3E566C00493718 /* NotificationPolicyHeaderView.swift in Sources */,
2D7867192625B77500211898 /* NotificationItem.swift in Sources */,
DB45FAB625CA5485005A8AC7 /* UIAlertController.swift in Sources */,
DBE0821525CD382600FD6BBD /* MastodonRegisterViewController.swift in Sources */,

View File

@ -0,0 +1,46 @@
// Copyright © 2024 Mastodon gGmbH. All rights reserved.
import UIKit
class NotificationPolicyHeaderView: UIView {
let titleLabel: UILabel
let closeButton: UIButton
override init(frame: CGRect) {
titleLabel = UILabel()
titleLabel.translatesAutoresizingMaskIntoConstraints = false
titleLabel.font = UIFontMetrics(forTextStyle: .title3).scaledFont(for: .systemFont(ofSize: 20, weight: .bold))
// TODO: Localization
titleLabel.text = "Filter Notifications from..."
closeButton = UIButton()
closeButton.setImage(UIImage(systemName: "xmark.circle.fill"), for: .normal)
closeButton.translatesAutoresizingMaskIntoConstraints = false
closeButton.setInsets(forContentPadding: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10), imageTitlePadding: 0)
closeButton.contentMode = .center
super.init(frame: frame)
addSubview(titleLabel)
addSubview(closeButton)
setupConstraints()
}
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
private func setupConstraints() {
let constraints = [
titleLabel.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 20),
titleLabel.topAnchor.constraint(equalTo: topAnchor, constant: 20),
closeButton.leadingAnchor.constraint(greaterThanOrEqualTo: titleLabel.trailingAnchor, constant: 8),
bottomAnchor.constraint(equalTo: titleLabel.bottomAnchor),
closeButton.centerYAnchor.constraint(equalTo: titleLabel.centerYAnchor),
trailingAnchor.constraint(equalTo: closeButton.trailingAnchor, constant: 20),
bottomAnchor.constraint(greaterThanOrEqualTo: closeButton.bottomAnchor)
]
NSLayoutConstraint.activate(constraints)
}
}

View File

@ -64,6 +64,7 @@ struct NotificationFilterViewModel {
class NotificationPolicyViewController: UIViewController {
let tableView: UITableView
let headerBar: NotificationPolicyHeaderView
var saveItem: UIBarButtonItem?
var dataSource: UITableViewDiffableDataSource<NotificationFilterSection, NotificationFilterItem>?
let items: [NotificationFilterItem]
@ -73,6 +74,9 @@ class NotificationPolicyViewController: UIViewController {
self.viewModel = viewModel
items = NotificationFilterItem.allCases
headerBar = NotificationPolicyHeaderView()
headerBar.translatesAutoresizingMaskIntoConstraints = false
tableView = UITableView(frame: .zero, style: .insetGrouped)
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.register(NotificationPolicyFilterTableViewCell.self, forCellReuseIdentifier: NotificationPolicyFilterTableViewCell.reuseIdentifier)
@ -91,19 +95,14 @@ class NotificationPolicyViewController: UIViewController {
return cell
}
// TODO: Localization
title = "Filter Notifications from"
tableView.dataSource = dataSource
tableView.delegate = self
self.dataSource = dataSource
view.addSubview(headerBar)
view.addSubview(tableView)
view.backgroundColor = .systemGroupedBackground
saveItem = UIBarButtonItem(title: L10n.Common.Controls.Actions.save, style: .done, target: self, action: #selector(NotificationPolicyViewController.save(_:)))
navigationItem.rightBarButtonItem = saveItem
navigationItem.leftBarButtonItem = UIBarButtonItem(title: L10n.Common.Controls.Actions.cancel, style: .done, target: self, action: #selector(NotificationPolicyViewController.cancel(_:)))
headerBar.closeButton.addTarget(self, action: #selector(NotificationPolicyViewController.save(_:)), for: .touchUpInside)
setupConstraints()
}
@ -123,7 +122,11 @@ class NotificationPolicyViewController: UIViewController {
private func setupConstraints() {
let constraints = [
tableView.topAnchor.constraint(equalTo: view.topAnchor),
headerBar.topAnchor.constraint(equalTo: view.topAnchor),
headerBar.leadingAnchor.constraint(equalTo: view.leadingAnchor),
view.trailingAnchor.constraint(equalTo: headerBar.trailingAnchor),
tableView.topAnchor.constraint(equalTo: headerBar.bottomAnchor),
tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
view.trailingAnchor.constraint(equalTo: tableView.trailingAnchor),
view.bottomAnchor.constraint(equalTo: tableView.bottomAnchor),
@ -134,17 +137,11 @@ class NotificationPolicyViewController: UIViewController {
// MARK: - Action
@objc private func save(_ sender: UIBarButtonItem) {
@objc private func save(_ sender: UIButton) {
guard let authenticationBox = viewModel.appContext.authenticationService.mastodonAuthenticationBoxes.first else { return }
navigationItem.leftBarButtonItem?.isEnabled = false
let activityIndicator = UIActivityIndicatorView(style: .medium)
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: activityIndicator)
navigationItem.rightBarButtonItem?.isEnabled = false
activityIndicator.startAnimating()
//TODO: Check if this really works. Garbage collection and stuff
self.dismiss(animated:true)
Task { [weak self] in
guard let self else { return }
@ -158,13 +155,9 @@ class NotificationPolicyViewController: UIViewController {
filterPrivateMentions: viewModel.privateMentions
)
await MainActor.run {
self.dismiss(animated:true)
}
} catch {
navigationItem.rightBarButtonItem = saveItem
navigationItem.rightBarButtonItem?.isEnabled = true
navigationItem.leftBarButtonItem?.isEnabled = true
//TODO: Error Handling
}
}