mirror of https://github.com/oxen-io/session-ios
Implement open group invitations UI
parent
9c5ceecc85
commit
bd04775cbf
@ -0,0 +1,78 @@
|
|||||||
|
|
||||||
|
final class OpenGroupInvitationView : UIView {
|
||||||
|
private let name: String
|
||||||
|
private let rawURL: String
|
||||||
|
private let textColor: UIColor
|
||||||
|
|
||||||
|
private lazy var url: String = {
|
||||||
|
if let range = rawURL.range(of: "?public_key=") {
|
||||||
|
return String(rawURL[..<range.lowerBound])
|
||||||
|
} else {
|
||||||
|
return rawURL
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// MARK: Settings
|
||||||
|
private static let iconSize: CGFloat = 24
|
||||||
|
private static let iconImageViewSize: CGFloat = 48
|
||||||
|
|
||||||
|
// MARK: Lifecycle
|
||||||
|
init(name: String, url: String, textColor: UIColor) {
|
||||||
|
self.name = name
|
||||||
|
self.rawURL = url
|
||||||
|
self.textColor = textColor
|
||||||
|
super.init(frame: CGRect.zero)
|
||||||
|
setUpViewHierarchy()
|
||||||
|
}
|
||||||
|
|
||||||
|
override init(frame: CGRect) {
|
||||||
|
preconditionFailure("Use init(name:url:textColor:) instead.")
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder: NSCoder) {
|
||||||
|
preconditionFailure("Use init(name:url:textColor:) instead.")
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setUpViewHierarchy() {
|
||||||
|
// Title
|
||||||
|
let titleLabel = UILabel()
|
||||||
|
titleLabel.lineBreakMode = .byTruncatingTail
|
||||||
|
titleLabel.text = name
|
||||||
|
titleLabel.textColor = textColor
|
||||||
|
titleLabel.font = .boldSystemFont(ofSize: Values.largeFontSize)
|
||||||
|
// Subtitle
|
||||||
|
let subtitleLabel = UILabel()
|
||||||
|
subtitleLabel.lineBreakMode = .byTruncatingTail
|
||||||
|
subtitleLabel.text = "Open group invitation"
|
||||||
|
subtitleLabel.textColor = textColor
|
||||||
|
subtitleLabel.font = .systemFont(ofSize: Values.smallFontSize)
|
||||||
|
// URL
|
||||||
|
let urlLabel = UILabel()
|
||||||
|
urlLabel.lineBreakMode = .byCharWrapping
|
||||||
|
urlLabel.text = url
|
||||||
|
urlLabel.textColor = textColor
|
||||||
|
urlLabel.numberOfLines = 0
|
||||||
|
urlLabel.font = .systemFont(ofSize: Values.verySmallFontSize)
|
||||||
|
// Label stack
|
||||||
|
let labelStackView = UIStackView(arrangedSubviews: [ titleLabel, UIView.vSpacer(2), subtitleLabel, UIView.vSpacer(4), urlLabel ])
|
||||||
|
labelStackView.axis = .vertical
|
||||||
|
// Icon
|
||||||
|
let iconSize = OpenGroupInvitationView.iconSize
|
||||||
|
let icon = UIImage(named: "Plus")?.withTint(.white)?.resizedImage(to: CGSize(width: iconSize, height: iconSize))
|
||||||
|
let iconImageViewSize = OpenGroupInvitationView.iconImageViewSize
|
||||||
|
let iconImageView = UIImageView(image: icon)
|
||||||
|
iconImageView.contentMode = .center
|
||||||
|
iconImageView.layer.cornerRadius = iconImageViewSize / 2
|
||||||
|
iconImageView.layer.masksToBounds = true
|
||||||
|
iconImageView.backgroundColor = Colors.accent
|
||||||
|
iconImageView.set(.width, to: iconImageViewSize)
|
||||||
|
iconImageView.set(.height, to: iconImageViewSize)
|
||||||
|
// Main stack
|
||||||
|
let mainStackView = UIStackView(arrangedSubviews: [ iconImageView, labelStackView ])
|
||||||
|
mainStackView.axis = .horizontal
|
||||||
|
mainStackView.spacing = Values.mediumSpacing
|
||||||
|
mainStackView.alignment = .center
|
||||||
|
addSubview(mainStackView)
|
||||||
|
mainStackView.pin(to: self, withInset: Values.mediumSpacing)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
import SessionUtilitiesKit
|
||||||
|
|
||||||
|
public extension VisibleMessage {
|
||||||
|
|
||||||
|
@objc(SNOpenGroupInvitation)
|
||||||
|
class OpenGroupInvitation : NSObject, NSCoding {
|
||||||
|
public var name: String?
|
||||||
|
public var url: String?
|
||||||
|
|
||||||
|
internal init(name: String, url: String) {
|
||||||
|
self.name = name
|
||||||
|
self.url = url
|
||||||
|
}
|
||||||
|
|
||||||
|
public required init?(coder: NSCoder) {
|
||||||
|
if let name = coder.decodeObject(forKey: "name") as! String? { self.name = name }
|
||||||
|
if let url = coder.decodeObject(forKey: "url") as! String? { self.url = url }
|
||||||
|
}
|
||||||
|
|
||||||
|
public func encode(with coder: NSCoder) {
|
||||||
|
coder.encode(name, forKey: "name")
|
||||||
|
coder.encode(url, forKey: "url")
|
||||||
|
}
|
||||||
|
|
||||||
|
public static func fromProto(_ proto: SNProtoDataMessage) -> Profile? {
|
||||||
|
notImplemented()
|
||||||
|
}
|
||||||
|
|
||||||
|
public func toProto() -> SNProtoDataMessage? {
|
||||||
|
notImplemented()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Description
|
||||||
|
public override var description: String {
|
||||||
|
"""
|
||||||
|
OpenGroupInvitation(
|
||||||
|
name: \(name ?? "null"),
|
||||||
|
url: \(url ?? "null")
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue