mirror of https://github.com/oxen-io/session-ios
Implement blocking/unblocking
parent
f0ead8ac23
commit
78691c7b65
@ -0,0 +1,69 @@
|
||||
|
||||
final class BlockedModal : Modal {
|
||||
private let publicKey: String
|
||||
|
||||
// MARK: Lifecycle
|
||||
init(publicKey: String) {
|
||||
self.publicKey = publicKey
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
override init(nibName: String?, bundle: Bundle?) {
|
||||
preconditionFailure("Use init(publicKey:) instead.")
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
preconditionFailure("Use init(publicKey:) instead.")
|
||||
}
|
||||
|
||||
override func populateContentView() {
|
||||
// Name
|
||||
let name = OWSProfileManager.shared().profileNameForRecipient(withID: publicKey, avoidingWriteTransaction: true) ?? publicKey
|
||||
// Title
|
||||
let titleLabel = UILabel()
|
||||
titleLabel.textColor = Colors.text
|
||||
titleLabel.font = .boldSystemFont(ofSize: Values.largeFontSize)
|
||||
titleLabel.text = "Unblock \(name)?"
|
||||
titleLabel.textAlignment = .center
|
||||
// Message
|
||||
let messageLabel = UILabel()
|
||||
messageLabel.textColor = Colors.text
|
||||
messageLabel.font = .systemFont(ofSize: Values.smallFontSize)
|
||||
let message = "Are you sure you want to unblock \(name)?"
|
||||
let attributedMessage = NSMutableAttributedString(string: message)
|
||||
attributedMessage.addAttributes([ .font : UIFont.boldSystemFont(ofSize: Values.smallFontSize) ], range: (message as NSString).range(of: name))
|
||||
messageLabel.attributedText = attributedMessage
|
||||
messageLabel.numberOfLines = 0
|
||||
messageLabel.lineBreakMode = .byWordWrapping
|
||||
messageLabel.textAlignment = .center
|
||||
// Unblock button
|
||||
let unblockButton = UIButton()
|
||||
unblockButton.set(.height, to: Values.mediumButtonHeight)
|
||||
unblockButton.layer.cornerRadius = Values.modalButtonCornerRadius
|
||||
unblockButton.backgroundColor = Colors.buttonBackground
|
||||
unblockButton.titleLabel!.font = .systemFont(ofSize: Values.smallFontSize)
|
||||
unblockButton.setTitleColor(Colors.text, for: UIControl.State.normal)
|
||||
unblockButton.setTitle("Unblock", for: UIControl.State.normal)
|
||||
unblockButton.addTarget(self, action: #selector(unblock), for: UIControl.Event.touchUpInside)
|
||||
// Button stack view
|
||||
let buttonStackView = UIStackView(arrangedSubviews: [ cancelButton, unblockButton ])
|
||||
buttonStackView.axis = .horizontal
|
||||
buttonStackView.spacing = Values.mediumSpacing
|
||||
buttonStackView.distribution = .fillEqually
|
||||
// Main stack view
|
||||
let mainStackView = UIStackView(arrangedSubviews: [ titleLabel, messageLabel, buttonStackView ])
|
||||
mainStackView.axis = .vertical
|
||||
mainStackView.spacing = Values.largeSpacing
|
||||
contentView.addSubview(mainStackView)
|
||||
mainStackView.pin(.leading, to: .leading, of: contentView, withInset: Values.largeSpacing)
|
||||
mainStackView.pin(.top, to: .top, of: contentView, withInset: Values.largeSpacing)
|
||||
contentView.pin(.trailing, to: .trailing, of: mainStackView, withInset: Values.largeSpacing)
|
||||
contentView.pin(.bottom, to: .bottom, of: mainStackView, withInset: Values.largeSpacing)
|
||||
}
|
||||
|
||||
// MARK: Interaction
|
||||
@objc private func unblock() {
|
||||
OWSBlockingManager.shared().removeBlockedPhoneNumber(publicKey)
|
||||
presentingViewController?.dismiss(animated: true, completion: nil)
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
|
||||
final class InfoBanner : UIView {
|
||||
private let message: String
|
||||
private let snBackgroundColor: UIColor
|
||||
|
||||
init(message: String, backgroundColor: UIColor) {
|
||||
self.message = message
|
||||
self.snBackgroundColor = backgroundColor
|
||||
super.init(frame: CGRect.zero)
|
||||
setUpViewHierarchy()
|
||||
}
|
||||
|
||||
override init(frame: CGRect) {
|
||||
preconditionFailure("Use init(message:) instead.")
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
preconditionFailure("Use init(coder:) instead.")
|
||||
}
|
||||
|
||||
private func setUpViewHierarchy() {
|
||||
backgroundColor = snBackgroundColor
|
||||
let label = UILabel()
|
||||
label.text = message
|
||||
label.font = .boldSystemFont(ofSize: Values.smallFontSize)
|
||||
label.textColor = .white
|
||||
label.numberOfLines = 0
|
||||
label.textAlignment = .center
|
||||
label.lineBreakMode = .byWordWrapping
|
||||
addSubview(label)
|
||||
label.pin(to: self, withInset: Values.mediumSpacing)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue