[WIP]: Add spinner and do something when pressing the button (IOS-241)

This commit is contained in:
Nathan Mattes 2024-07-18 13:39:03 +02:00
parent e645bc1fd1
commit 94a8791c4b
3 changed files with 69 additions and 13 deletions

View File

@ -10,13 +10,16 @@ import MastodonLocalization
import MastodonAsset import MastodonAsset
protocol NotificationRequestTableViewCellDelegate: AnyObject { protocol NotificationRequestTableViewCellDelegate: AnyObject {
// reject func acceptNotificationRequest(_ cell: NotificationRequestTableViewCell, notificationRequest: Mastodon.Entity.NotificationRequest)
// accept func rejectNotificationRequest(_ cell: NotificationRequestTableViewCell, notificationRequest: Mastodon.Entity.NotificationRequest)
} }
class NotificationRequestTableViewCell: UITableViewCell { class NotificationRequestTableViewCell: UITableViewCell {
static let reuseIdentifier = "NotificationRequestTableViewCell" static let reuseIdentifier = "NotificationRequestTableViewCell"
var notificationRequest: Mastodon.Entity.NotificationRequest?
weak var delegate: NotificationRequestTableViewCellDelegate?
let nameLabel: MetaLabel let nameLabel: MetaLabel
let usernameLabel: MetaLabel let usernameLabel: MetaLabel
let avatarButton: AvatarButton let avatarButton: AvatarButton
@ -25,15 +28,12 @@ class NotificationRequestTableViewCell: UITableViewCell {
private let avatarStackView: UIStackView private let avatarStackView: UIStackView
private let contentStackView: UIStackView private let contentStackView: UIStackView
// private let stack
// accept/deny-button
let acceptNotificationRequestButtonShadowBackgroundContainer = ShadowBackgroundContainer() let acceptNotificationRequestButtonShadowBackgroundContainer = ShadowBackgroundContainer()
let acceptNotificationRequestButton: HighlightDimmableButton let acceptNotificationRequestButton: HighlightDimmableButton
let acceptNotificationRequestActivityIndicatorView = UIActivityIndicatorView(style: .medium) let acceptNotificationRequestActivityIndicatorView: UIActivityIndicatorView
let rejectNotificationRequestButtonShadowBackgroundContainer = ShadowBackgroundContainer() let rejectNotificationRequestButtonShadowBackgroundContainer = ShadowBackgroundContainer()
let rejectNotificationRequestActivityIndicatorView = UIActivityIndicatorView(style: .medium) let rejectNotificationRequestActivityIndicatorView: UIActivityIndicatorView
let rejectNotificationRequestButton: HighlightDimmableButton let rejectNotificationRequestButton: HighlightDimmableButton
private let buttonStackView: UIStackView private let buttonStackView: UIStackView
@ -69,6 +69,13 @@ class NotificationRequestTableViewCell: UITableViewCell {
acceptNotificationRequestButtonShadowBackgroundContainer.shadowAlpha = 0.1 acceptNotificationRequestButtonShadowBackgroundContainer.shadowAlpha = 0.1
acceptNotificationRequestButtonShadowBackgroundContainer.addSubview(acceptNotificationRequestButton) acceptNotificationRequestButtonShadowBackgroundContainer.addSubview(acceptNotificationRequestButton)
acceptNotificationRequestActivityIndicatorView = UIActivityIndicatorView(style: .medium)
acceptNotificationRequestActivityIndicatorView.translatesAutoresizingMaskIntoConstraints = false
acceptNotificationRequestActivityIndicatorView.color = .black
acceptNotificationRequestActivityIndicatorView.hidesWhenStopped = true
acceptNotificationRequestActivityIndicatorView.stopAnimating()
acceptNotificationRequestButton.addSubview(acceptNotificationRequestActivityIndicatorView)
rejectNotificationRequestButton = HighlightDimmableButton() rejectNotificationRequestButton = HighlightDimmableButton()
rejectNotificationRequestButton.translatesAutoresizingMaskIntoConstraints = false rejectNotificationRequestButton.translatesAutoresizingMaskIntoConstraints = false
rejectNotificationRequestButton.titleLabel?.font = UIFont.systemFont(ofSize: 17, weight: .semibold) rejectNotificationRequestButton.titleLabel?.font = UIFont.systemFont(ofSize: 17, weight: .semibold)
@ -87,6 +94,13 @@ class NotificationRequestTableViewCell: UITableViewCell {
rejectNotificationRequestButtonShadowBackgroundContainer.shadowAlpha = 0.1 rejectNotificationRequestButtonShadowBackgroundContainer.shadowAlpha = 0.1
rejectNotificationRequestButtonShadowBackgroundContainer.addSubview(rejectNotificationRequestButton) 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 = UIStackView(arrangedSubviews: [acceptNotificationRequestButtonShadowBackgroundContainer, rejectNotificationRequestButtonShadowBackgroundContainer])
buttonStackView.axis = .horizontal buttonStackView.axis = .horizontal
buttonStackView.distribution = .fillEqually buttonStackView.distribution = .fillEqually
@ -106,8 +120,8 @@ class NotificationRequestTableViewCell: UITableViewCell {
super.init(style: style, reuseIdentifier: reuseIdentifier) super.init(style: style, reuseIdentifier: reuseIdentifier)
// acceptNotificationRequestButton.addTarget(self, action: #selector(NotificationView.acceptNotificationRequestButtonDidPressed(_:)), for: .touchUpInside) acceptNotificationRequestButton.addTarget(self, action: #selector(NotificationRequestTableViewCell.acceptNotificationRequest(_:)), for: .touchUpInside)
// rejectNotificationRequestButton.addTarget(self, action: #selector(NotificationView.rejectNotificationRequestButtonDidPressed(_:)), for: .touchUpInside) rejectNotificationRequestButton.addTarget(self, action: #selector(NotificationRequestTableViewCell.rejectNotificationRequest(_:)), for: .touchUpInside)
contentView.addSubview(contentStackView) contentView.addSubview(contentStackView)
setupConstraints() setupConstraints()
@ -128,6 +142,12 @@ class NotificationRequestTableViewCell: UITableViewCell {
avatarButton.widthAnchor.constraint(equalToConstant: CGSize.authorAvatarButtonSize.width).priority(.required - 1), avatarButton.widthAnchor.constraint(equalToConstant: CGSize.authorAvatarButtonSize.width).priority(.required - 1),
avatarButton.heightAnchor.constraint(equalToConstant: CGSize.authorAvatarButtonSize.height).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) NSLayoutConstraint.activate(constraints)
@ -159,9 +179,20 @@ class NotificationRequestTableViewCell: UITableViewCell {
let metaUsername = PlaintextMetaContent(string: "@\(account.acct)") let metaUsername = PlaintextMetaContent(string: "@\(account.acct)")
usernameLabel.configure(content: metaUsername) usernameLabel.configure(content: metaUsername)
self.notificationRequest = request
} }
// MARK: - Actions // MARK: - Actions
// reject @objc private func acceptNotificationRequest(_ sender: UIButton) {
// accept 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)
}
} }

View File

@ -28,7 +28,7 @@ class NotificationRequestsTableViewController: UIViewController, NeedsDependency
var dataSource: UITableViewDiffableDataSource<NotificationRequestsSection, NotificationRequestItem>? var dataSource: UITableViewDiffableDataSource<NotificationRequestsSection, NotificationRequestItem>?
init(viewModel: NotificationRequestsViewModel, appContext: AppContext, coordinator: SceneCoordinator) { init(viewModel: NotificationRequestsViewModel, appContext: AppContext, coordinator: SceneCoordinator) {
//TODO: DataSource, Delegate....
self.viewModel = viewModel self.viewModel = viewModel
self.context = appContext self.context = appContext
self.coordinator = coordinator self.coordinator = coordinator
@ -50,6 +50,7 @@ class NotificationRequestsTableViewController: UIViewController, NeedsDependency
let request = viewModel.requests[indexPath.row] let request = viewModel.requests[indexPath.row]
cell.configure(with: request) cell.configure(with: request)
cell.delegate = self
return cell return cell
} }
@ -91,3 +92,27 @@ extension NotificationRequestsTableViewController: UITableViewDelegate {
extension NotificationRequestsTableViewController: AuthContextProvider { extension NotificationRequestsTableViewController: AuthContextProvider {
var authContext: AuthContext { viewModel.authContext } 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)
}
}

View File

@ -327,7 +327,7 @@ extension NotificationView {
rejectFollowRequestActivityIndicatorView.centerYAnchor.constraint(equalTo: rejectFollowRequestButton.centerYAnchor), rejectFollowRequestActivityIndicatorView.centerYAnchor.constraint(equalTo: rejectFollowRequestButton.centerYAnchor),
]) ])
rejectFollowRequestActivityIndicatorView.color = .black rejectFollowRequestActivityIndicatorView.color = .black
acceptFollowRequestActivityIndicatorView.hidesWhenStopped = true rejectFollowRequestActivityIndicatorView.hidesWhenStopped = true
rejectFollowRequestActivityIndicatorView.stopAnimating() rejectFollowRequestActivityIndicatorView.stopAnimating()
// statusView // statusView