From 94a8791c4b8383769805dd33b2dc35441473a64e Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Thu, 18 Jul 2024 13:39:03 +0200 Subject: [PATCH] [WIP]: Add spinner and do something when pressing the button (IOS-241) --- .../NotificationRequestTableViewCell.swift | 53 +++++++++++++++---- ...ificationRequestsTableViewController.swift | 27 +++++++++- .../NotificationView/NotificationView.swift | 2 +- 3 files changed, 69 insertions(+), 13 deletions(-) diff --git a/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestTableViewCell.swift b/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestTableViewCell.swift index 6c6e50419..320379215 100644 --- a/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestTableViewCell.swift +++ b/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestTableViewCell.swift @@ -10,13 +10,16 @@ import MastodonLocalization import MastodonAsset protocol NotificationRequestTableViewCellDelegate: AnyObject { - // reject - // accept + func acceptNotificationRequest(_ cell: NotificationRequestTableViewCell, notificationRequest: Mastodon.Entity.NotificationRequest) + func rejectNotificationRequest(_ cell: NotificationRequestTableViewCell, notificationRequest: Mastodon.Entity.NotificationRequest) } class NotificationRequestTableViewCell: UITableViewCell { static let reuseIdentifier = "NotificationRequestTableViewCell" + var notificationRequest: Mastodon.Entity.NotificationRequest? + weak var delegate: NotificationRequestTableViewCellDelegate? + let nameLabel: MetaLabel let usernameLabel: MetaLabel let avatarButton: AvatarButton @@ -25,15 +28,12 @@ class NotificationRequestTableViewCell: UITableViewCell { private let avatarStackView: UIStackView private let contentStackView: UIStackView -// private let stack - // accept/deny-button - let acceptNotificationRequestButtonShadowBackgroundContainer = ShadowBackgroundContainer() let acceptNotificationRequestButton: HighlightDimmableButton - let acceptNotificationRequestActivityIndicatorView = UIActivityIndicatorView(style: .medium) + let acceptNotificationRequestActivityIndicatorView: UIActivityIndicatorView let rejectNotificationRequestButtonShadowBackgroundContainer = ShadowBackgroundContainer() - let rejectNotificationRequestActivityIndicatorView = UIActivityIndicatorView(style: .medium) + let rejectNotificationRequestActivityIndicatorView: UIActivityIndicatorView let rejectNotificationRequestButton: HighlightDimmableButton private let buttonStackView: UIStackView @@ -69,6 +69,13 @@ class NotificationRequestTableViewCell: UITableViewCell { acceptNotificationRequestButtonShadowBackgroundContainer.shadowAlpha = 0.1 acceptNotificationRequestButtonShadowBackgroundContainer.addSubview(acceptNotificationRequestButton) + acceptNotificationRequestActivityIndicatorView = UIActivityIndicatorView(style: .medium) + acceptNotificationRequestActivityIndicatorView.translatesAutoresizingMaskIntoConstraints = false + acceptNotificationRequestActivityIndicatorView.color = .black + acceptNotificationRequestActivityIndicatorView.hidesWhenStopped = true + acceptNotificationRequestActivityIndicatorView.stopAnimating() + acceptNotificationRequestButton.addSubview(acceptNotificationRequestActivityIndicatorView) + rejectNotificationRequestButton = HighlightDimmableButton() rejectNotificationRequestButton.translatesAutoresizingMaskIntoConstraints = false rejectNotificationRequestButton.titleLabel?.font = UIFont.systemFont(ofSize: 17, weight: .semibold) @@ -87,6 +94,13 @@ class NotificationRequestTableViewCell: UITableViewCell { rejectNotificationRequestButtonShadowBackgroundContainer.shadowAlpha = 0.1 rejectNotificationRequestButtonShadowBackgroundContainer.addSubview(rejectNotificationRequestButton) + rejectNotificationRequestActivityIndicatorView = UIActivityIndicatorView(style: .medium) + rejectNotificationRequestActivityIndicatorView.translatesAutoresizingMaskIntoConstraints = false + rejectNotificationRequestActivityIndicatorView.color = .black + rejectNotificationRequestActivityIndicatorView.hidesWhenStopped = true + rejectNotificationRequestActivityIndicatorView.stopAnimating() + rejectNotificationRequestButton.addSubview(rejectNotificationRequestActivityIndicatorView) + buttonStackView = UIStackView(arrangedSubviews: [acceptNotificationRequestButtonShadowBackgroundContainer, rejectNotificationRequestButtonShadowBackgroundContainer]) buttonStackView.axis = .horizontal buttonStackView.distribution = .fillEqually @@ -106,8 +120,8 @@ class NotificationRequestTableViewCell: UITableViewCell { super.init(style: style, reuseIdentifier: reuseIdentifier) -// acceptNotificationRequestButton.addTarget(self, action: #selector(NotificationView.acceptNotificationRequestButtonDidPressed(_:)), for: .touchUpInside) -// rejectNotificationRequestButton.addTarget(self, action: #selector(NotificationView.rejectNotificationRequestButtonDidPressed(_:)), for: .touchUpInside) + acceptNotificationRequestButton.addTarget(self, action: #selector(NotificationRequestTableViewCell.acceptNotificationRequest(_:)), for: .touchUpInside) + rejectNotificationRequestButton.addTarget(self, action: #selector(NotificationRequestTableViewCell.rejectNotificationRequest(_:)), for: .touchUpInside) contentView.addSubview(contentStackView) setupConstraints() @@ -128,6 +142,12 @@ class NotificationRequestTableViewCell: UITableViewCell { avatarButton.widthAnchor.constraint(equalToConstant: CGSize.authorAvatarButtonSize.width).priority(.required - 1), avatarButton.heightAnchor.constraint(equalToConstant: CGSize.authorAvatarButtonSize.height).priority(.required - 1), + + acceptNotificationRequestActivityIndicatorView.centerXAnchor.constraint(equalTo: acceptNotificationRequestButton.centerXAnchor), + acceptNotificationRequestActivityIndicatorView.centerYAnchor.constraint(equalTo: acceptNotificationRequestButton.centerYAnchor), + rejectNotificationRequestActivityIndicatorView.centerXAnchor.constraint(equalTo: rejectNotificationRequestButton.centerXAnchor), + rejectNotificationRequestActivityIndicatorView.centerYAnchor.constraint(equalTo: rejectNotificationRequestButton.centerYAnchor), + ] NSLayoutConstraint.activate(constraints) @@ -159,9 +179,20 @@ class NotificationRequestTableViewCell: UITableViewCell { let metaUsername = PlaintextMetaContent(string: "@\(account.acct)") usernameLabel.configure(content: metaUsername) + + self.notificationRequest = request } // MARK: - Actions - // reject - // accept + @objc private func acceptNotificationRequest(_ sender: UIButton) { + guard let notificationRequest, let delegate else { return } + + delegate.acceptNotificationRequest(self, notificationRequest: notificationRequest) + } + @objc private func rejectNotificationRequest(_ sender: UIButton) { + guard let notificationRequest, let delegate else { return } + + delegate.rejectNotificationRequest(self, notificationRequest: notificationRequest) + } + } diff --git a/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestsTableViewController.swift b/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestsTableViewController.swift index 15a9912ff..f0b7bfced 100644 --- a/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestsTableViewController.swift +++ b/Mastodon/Scene/Notification/Notification Filtering/Requests/NotificationRequestsTableViewController.swift @@ -28,7 +28,7 @@ class NotificationRequestsTableViewController: UIViewController, NeedsDependency var dataSource: UITableViewDiffableDataSource? init(viewModel: NotificationRequestsViewModel, appContext: AppContext, coordinator: SceneCoordinator) { - //TODO: DataSource, Delegate.... + self.viewModel = viewModel self.context = appContext self.coordinator = coordinator @@ -50,6 +50,7 @@ class NotificationRequestsTableViewController: UIViewController, NeedsDependency let request = viewModel.requests[indexPath.row] cell.configure(with: request) + cell.delegate = self return cell } @@ -91,3 +92,27 @@ extension NotificationRequestsTableViewController: UITableViewDelegate { extension NotificationRequestsTableViewController: AuthContextProvider { var authContext: AuthContext { viewModel.authContext } } + +extension NotificationRequestsTableViewController: NotificationRequestTableViewCellDelegate { + func acceptNotificationRequest(_ cell: NotificationRequestTableViewCell, notificationRequest: MastodonSDK.Mastodon.Entity.NotificationRequest) { + print("accept \(notificationRequest.id)") + cell.acceptNotificationRequestActivityIndicatorView.isHidden = false + cell.acceptNotificationRequestActivityIndicatorView.startAnimating() + + cell.acceptNotificationRequestButton.tintColor = .clear + cell.acceptNotificationRequestButton.setTitleColor(.clear, for: .normal) + + + //TODO: Send request, update cell, reload notification requests AND general notifications + } + + func rejectNotificationRequest(_ cell: NotificationRequestTableViewCell, notificationRequest: MastodonSDK.Mastodon.Entity.NotificationRequest) { + print("reject \(notificationRequest.id)") + + cell.rejectNotificationRequestActivityIndicatorView.isHidden = false + cell.rejectNotificationRequestActivityIndicatorView.startAnimating() + cell.rejectNotificationRequestButton.tintColor = .clear + cell.rejectNotificationRequestButton.setTitleColor(.clear, for: .normal) + + } +} diff --git a/Mastodon/Scene/Notification/NotificationView/NotificationView.swift b/Mastodon/Scene/Notification/NotificationView/NotificationView.swift index 341dd6e72..cf330350b 100644 --- a/Mastodon/Scene/Notification/NotificationView/NotificationView.swift +++ b/Mastodon/Scene/Notification/NotificationView/NotificationView.swift @@ -327,7 +327,7 @@ extension NotificationView { rejectFollowRequestActivityIndicatorView.centerYAnchor.constraint(equalTo: rejectFollowRequestButton.centerYAnchor), ]) rejectFollowRequestActivityIndicatorView.color = .black - acceptFollowRequestActivityIndicatorView.hidesWhenStopped = true + rejectFollowRequestActivityIndicatorView.hidesWhenStopped = true rejectFollowRequestActivityIndicatorView.stopAnimating() // statusView