[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
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)
}
}

View File

@ -28,7 +28,7 @@ class NotificationRequestsTableViewController: UIViewController, NeedsDependency
var dataSource: UITableViewDiffableDataSource<NotificationRequestsSection, NotificationRequestItem>?
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)
}
}

View File

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