mirror of https://github.com/oxen-io/session-ios
Implement open group suggestion sheet
parent
9fd556ca3a
commit
5bd2308d26
Binary file not shown.
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{
|
||||||
|
"idiom" : "universal",
|
||||||
|
"filename" : "ChatBubbles.pdf"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"version" : 1,
|
||||||
|
"author" : "xcode"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
|
||||||
|
final class OpenGroupSuggestionSheet : Sheet {
|
||||||
|
|
||||||
|
override func populateContentView() {
|
||||||
|
// Set up image view
|
||||||
|
let imageView = UIImageView(image: #imageLiteral(resourceName: "ChatBubbles"))
|
||||||
|
// Set up title label
|
||||||
|
let titleLabel = UILabel()
|
||||||
|
titleLabel.textColor = Colors.text
|
||||||
|
titleLabel.font = .boldSystemFont(ofSize: Values.largeFontSize)
|
||||||
|
titleLabel.text = NSLocalizedString("No messages yet", comment: "")
|
||||||
|
titleLabel.numberOfLines = 0
|
||||||
|
titleLabel.lineBreakMode = .byWordWrapping
|
||||||
|
titleLabel.textAlignment = .center
|
||||||
|
// Set up top explanation label
|
||||||
|
let topExplanationLabel = UILabel()
|
||||||
|
topExplanationLabel.textColor = Colors.text
|
||||||
|
topExplanationLabel.font = .systemFont(ofSize: Values.mediumFontSize)
|
||||||
|
topExplanationLabel.text = NSLocalizedString("Would you like to join the Session Public Chat?", comment: "")
|
||||||
|
topExplanationLabel.numberOfLines = 0
|
||||||
|
topExplanationLabel.textAlignment = .center
|
||||||
|
topExplanationLabel.lineBreakMode = .byWordWrapping
|
||||||
|
// Set up join button
|
||||||
|
let joinButton = Button(style: .prominentOutline, size: .medium)
|
||||||
|
joinButton.set(.width, to: 240)
|
||||||
|
joinButton.setTitle(NSLocalizedString("Join Public Chat", comment: ""), for: UIControl.State.normal)
|
||||||
|
joinButton.addTarget(self, action: #selector(joinSessionPublicChat), for: UIControl.Event.touchUpInside)
|
||||||
|
// Set up dismiss button
|
||||||
|
let dismissButton = Button(style: .regular, size: .medium)
|
||||||
|
dismissButton.set(.width, to: 240)
|
||||||
|
dismissButton.setTitle(NSLocalizedString("No, thank you", comment: ""), for: UIControl.State.normal)
|
||||||
|
dismissButton.addTarget(self, action: #selector(close), for: UIControl.Event.touchUpInside)
|
||||||
|
// Set up bottom explanation label
|
||||||
|
let bottomExplanationLabel = UILabel()
|
||||||
|
bottomExplanationLabel.textColor = Colors.text.withAlphaComponent(Values.unimportantElementOpacity)
|
||||||
|
bottomExplanationLabel.font = .systemFont(ofSize: Values.verySmallFontSize)
|
||||||
|
bottomExplanationLabel.text = NSLocalizedString("Open groups can be joined by anyone and do not provide full metadata protection", comment: "")
|
||||||
|
bottomExplanationLabel.numberOfLines = 0
|
||||||
|
bottomExplanationLabel.textAlignment = .center
|
||||||
|
bottomExplanationLabel.lineBreakMode = .byWordWrapping
|
||||||
|
// Set up button stack view
|
||||||
|
let bottomStackView = UIStackView(arrangedSubviews: [ joinButton, dismissButton, bottomExplanationLabel ])
|
||||||
|
bottomStackView.axis = .vertical
|
||||||
|
bottomStackView.spacing = Values.mediumSpacing
|
||||||
|
bottomStackView.alignment = .fill
|
||||||
|
// Set up main stack view
|
||||||
|
let stackView = UIStackView(arrangedSubviews: [ imageView, titleLabel, topExplanationLabel, bottomStackView ])
|
||||||
|
stackView.axis = .vertical
|
||||||
|
stackView.spacing = Values.largeSpacing
|
||||||
|
stackView.alignment = .center
|
||||||
|
// Set up constraints
|
||||||
|
contentView.addSubview(stackView)
|
||||||
|
stackView.pin(.leading, to: .leading, of: contentView, withInset: Values.largeSpacing)
|
||||||
|
stackView.pin(.top, to: .top, of: contentView, withInset: Values.largeSpacing)
|
||||||
|
contentView.pin(.trailing, to: .trailing, of: stackView, withInset: Values.largeSpacing)
|
||||||
|
contentView.pin(.bottom, to: .bottom, of: stackView, withInset: Values.veryLargeSpacing + overshoot)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func joinSessionPublicChat() {
|
||||||
|
// TODO: Duplicate of the code in JoinPublicChatVC
|
||||||
|
let channelID: UInt64 = 1
|
||||||
|
let url = "https://chat.getsession.org"
|
||||||
|
let displayName = OWSProfileManager.shared().localProfileName()
|
||||||
|
// TODO: Profile picture & profile key
|
||||||
|
let _ = LokiPublicChatManager.shared.addChat(server: url, channel: channelID).done(on: .main) { _ in
|
||||||
|
let _ = LokiPublicChatAPI.getMessages(for: channelID, on: url)
|
||||||
|
let _ = LokiPublicChatAPI.setDisplayName(to: displayName, on: url)
|
||||||
|
let _ = LokiPublicChatAPI.join(channelID, on: url)
|
||||||
|
}
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
|
||||||
|
override func close() {
|
||||||
|
UserDefaults.standard.set(true, forKey: "hasSeenOpenGroupSuggestionSheet")
|
||||||
|
super.close()
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
|
||||||
|
class Sheet : UIViewController {
|
||||||
|
private(set) var bottomConstraint: NSLayoutConstraint!
|
||||||
|
|
||||||
|
// MARK: Settings
|
||||||
|
let overshoot: CGFloat = 40
|
||||||
|
override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent }
|
||||||
|
|
||||||
|
// MARK: Components
|
||||||
|
lazy var contentView: UIView = {
|
||||||
|
let result = UIView()
|
||||||
|
result.backgroundColor = Colors.modalBackground
|
||||||
|
result.layer.cornerRadius = 24
|
||||||
|
result.layer.masksToBounds = false
|
||||||
|
result.layer.borderColor = Colors.modalBorder.cgColor
|
||||||
|
result.layer.borderWidth = Values.borderThickness
|
||||||
|
result.layer.shadowColor = UIColor.black.cgColor
|
||||||
|
result.layer.shadowRadius = 8
|
||||||
|
result.layer.shadowOpacity = 0.64
|
||||||
|
return result
|
||||||
|
}()
|
||||||
|
|
||||||
|
// MARK: Lifecycle
|
||||||
|
override func viewDidLoad() {
|
||||||
|
super.viewDidLoad()
|
||||||
|
view.backgroundColor = UIColor(hex: 0x000000).withAlphaComponent(Values.modalBackgroundOpacity)
|
||||||
|
let swipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(close))
|
||||||
|
swipeGestureRecognizer.direction = .down
|
||||||
|
view.addGestureRecognizer(swipeGestureRecognizer)
|
||||||
|
setUpViewHierarchy()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setUpViewHierarchy() {
|
||||||
|
view.addSubview(contentView)
|
||||||
|
contentView.pin(.leading, to: .leading, of: view, withInset: -Values.borderThickness)
|
||||||
|
contentView.pin(.trailing, to: .trailing, of: view, withInset: Values.borderThickness)
|
||||||
|
bottomConstraint = contentView.pin(.bottom, to: .bottom, of: view, withInset: overshoot)
|
||||||
|
populateContentView()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// To be overridden by subclasses.
|
||||||
|
func populateContentView() {
|
||||||
|
preconditionFailure("populateContentView() is abstract and must be overridden.")
|
||||||
|
}
|
||||||
|
|
||||||
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
|
super.viewWillAppear(animated)
|
||||||
|
// TODO: Animate
|
||||||
|
// bottomConstraint.constant = contentView.height()
|
||||||
|
// view.layoutIfNeeded()
|
||||||
|
// bottomConstraint.constant = overshoot
|
||||||
|
// UIView.animate(withDuration: 0.25) {
|
||||||
|
// self.view.layoutIfNeeded()
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Interaction
|
||||||
|
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||||
|
let touch = touches.first!
|
||||||
|
let location = touch.location(in: view)
|
||||||
|
if contentView.frame.contains(location) {
|
||||||
|
super.touchesBegan(touches, with: event)
|
||||||
|
} else {
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func close() {
|
||||||
|
dismiss(animated: true, completion: nil)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue