From 6dd2d2e72f9fb01708c8c2c44fa109cfb55b8903 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Tue, 19 Jan 2021 14:12:32 +1100 Subject: [PATCH] Put up a notice if the user is creating a very large group --- Session/Closed Groups/NewClosedGroupVC.swift | 3 +- .../ConversationViewController.m | 1 + ...ModalActivityIndicatorViewController.swift | 53 ++++++++++++------- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/Session/Closed Groups/NewClosedGroupVC.swift b/Session/Closed Groups/NewClosedGroupVC.swift index 6cb1e10d3..0880b2b3f 100644 --- a/Session/Closed Groups/NewClosedGroupVC.swift +++ b/Session/Closed Groups/NewClosedGroupVC.swift @@ -167,7 +167,8 @@ final class NewClosedGroupVC : BaseVC, UITableViewDataSource, UITableViewDelegat return showError(title: NSLocalizedString("vc_create_closed_group_too_many_group_members_error", comment: "")) } let selectedContacts = self.selectedContacts - ModalActivityIndicatorViewController.present(fromViewController: navigationController!, canCancel: false) { [weak self] _ in + let message: String? = (selectedContacts.count > 20) ? "Please wait while the group is created..." : nil + ModalActivityIndicatorViewController.present(fromViewController: navigationController!, message: message) { [weak self] _ in var promise: Promise! Storage.writeSync { transaction in promise = MessageSender.createV2ClosedGroup(name: name, members: selectedContacts, transaction: transaction) diff --git a/Session/Conversations/ConversationViewController.m b/Session/Conversations/ConversationViewController.m index 7dd831377..0bbb517eb 100644 --- a/Session/Conversations/ConversationViewController.m +++ b/Session/Conversations/ConversationViewController.m @@ -2537,6 +2537,7 @@ typedef enum : NSUInteger { [ModalActivityIndicatorViewController presentFromViewController:self canCancel:YES + message:nil backgroundBlock:^(ModalActivityIndicatorViewController *modalActivityIndicator) { DataSource *dataSource = [DataSourcePath dataSourceWithURL:movieURL shouldDeleteOnDeallocation:NO]; diff --git a/SignalUtilitiesKit/Shared View Controllers/ModalActivityIndicatorViewController.swift b/SignalUtilitiesKit/Shared View Controllers/ModalActivityIndicatorViewController.swift index 0ee8d9088..b9dc3fe64 100644 --- a/SignalUtilitiesKit/Shared View Controllers/ModalActivityIndicatorViewController.swift +++ b/SignalUtilitiesKit/Shared View Controllers/ModalActivityIndicatorViewController.swift @@ -4,14 +4,15 @@ import Foundation import MediaPlayer - +import SessionUIKit // A modal view that be used during blocking interactions (e.g. waiting on response from // service or on the completion of a long-running local operation). @objc public class ModalActivityIndicatorViewController: OWSViewController { - let canCancel: Bool + + let message: String? @objc public var wasCancelled: Bool = false @@ -29,25 +30,26 @@ public class ModalActivityIndicatorViewController: OWSViewController { notImplemented() } - public required init(canCancel: Bool) { + public required init(canCancel: Bool = false, message: String? = nil) { self.canCancel = canCancel + self.message = message super.init(nibName: nil, bundle: nil) } @objc - public class func present(fromViewController: UIViewController, - canCancel: Bool, backgroundBlock : @escaping (ModalActivityIndicatorViewController) -> Void) { + public class func present(fromViewController: UIViewController, canCancel: Bool = false, message: String? = nil, + backgroundBlock : @escaping (ModalActivityIndicatorViewController) -> Void) { AssertIsOnMainThread() - let view = ModalActivityIndicatorViewController(canCancel: canCancel) + let view = ModalActivityIndicatorViewController(canCancel: canCancel, message: message) // Present this modal _over_ the current view contents. view.modalPresentationStyle = .overFullScreen view.modalTransitionStyle = .crossDissolve - fromViewController.present(view, - animated: false) { - DispatchQueue.global().async { - backgroundBlock(view) - } + fromViewController.present(view, animated: false) { + DispatchQueue.global().async { + backgroundBlock(view) + + } } } @@ -70,15 +72,31 @@ public class ModalActivityIndicatorViewController: OWSViewController { public override func loadView() { super.loadView() - self.view.backgroundColor = (Theme.isDarkThemeEnabled - ? UIColor(white: 0, alpha: 0.5) - : UIColor(white: 0, alpha: 0.5)) + self.view.backgroundColor = UIColor(white: 0, alpha: 0.5) self.view.isOpaque = false let activityIndicator = UIActivityIndicatorView(style: .whiteLarge) self.activityIndicator = activityIndicator - self.view.addSubview(activityIndicator) - activityIndicator.autoCenterInSuperview() + + if let message = message { + let messageLabel = UILabel() + messageLabel.text = message + messageLabel.font = .systemFont(ofSize: Values.mediumFontSize) + messageLabel.textColor = UIColor.white + messageLabel.numberOfLines = 0 + messageLabel.textAlignment = .center + messageLabel.lineBreakMode = .byWordWrapping + messageLabel.set(.width, to: UIScreen.main.bounds.width - 2 * Values.mediumSpacing) + let stackView = UIStackView(arrangedSubviews: [ messageLabel, activityIndicator ]) + stackView.axis = .vertical + stackView.spacing = Values.largeSpacing + stackView.alignment = .center + self.view.addSubview(stackView) + stackView.center(in: self.view) + } else { + self.view.addSubview(activityIndicator) + activityIndicator.autoCenterInSuperview() + } if canCancel { let cancelButton = UIButton(type: .custom) @@ -152,7 +170,6 @@ public class ModalActivityIndicatorViewController: OWSViewController { wasCancelled = true - dismiss { - } + dismiss { } } }