mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-20 00:24:43 +02:00
Create DM key verification cells.
This commit is contained in:
+159
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
Copyright 2019 New Vector Ltd
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import UIKit
|
||||
import Reusable
|
||||
|
||||
final class KeyVerificationCellInnerContentView: UIView, NibLoadable {
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
private enum Constants {
|
||||
static let cornerRadius: CGFloat = 8.0
|
||||
static let buttonBackgroundColorAlpha: CGFloat = 0.8
|
||||
static let buttonCornerRadius: CGFloat = 6.0
|
||||
}
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Outlets
|
||||
|
||||
@IBOutlet private weak var badgeImageView: UIImageView!
|
||||
@IBOutlet private weak var titleLabel: UILabel!
|
||||
|
||||
@IBOutlet private weak var userInformationsLabel: UILabel!
|
||||
|
||||
@IBOutlet private weak var requestStatusLabel: UILabel!
|
||||
|
||||
@IBOutlet private weak var acceptButton: UIButton!
|
||||
@IBOutlet private weak var declineButton: UIButton!
|
||||
|
||||
// MARK: Public
|
||||
|
||||
var isButtonsHidden: Bool {
|
||||
get {
|
||||
return self.acceptButton.isHidden && self.declineButton.isHidden
|
||||
}
|
||||
set {
|
||||
self.acceptButton.isHidden = newValue
|
||||
self.declineButton.isHidden = newValue
|
||||
}
|
||||
}
|
||||
|
||||
var isRequestStatusHidden: Bool {
|
||||
get {
|
||||
return self.requestStatusLabel.isHidden
|
||||
}
|
||||
set {
|
||||
self.requestStatusLabel.isHidden = newValue
|
||||
}
|
||||
}
|
||||
|
||||
var badgeImage: UIImage? {
|
||||
get {
|
||||
return self.badgeImageView.image
|
||||
}
|
||||
set {
|
||||
self.badgeImageView.image = newValue
|
||||
}
|
||||
}
|
||||
|
||||
var title: String? {
|
||||
get {
|
||||
return self.titleLabel.text
|
||||
}
|
||||
set {
|
||||
self.titleLabel.text = newValue
|
||||
}
|
||||
}
|
||||
|
||||
var requestStatusText: String? {
|
||||
get {
|
||||
return self.requestStatusLabel.text
|
||||
}
|
||||
set {
|
||||
self.requestStatusLabel.text = newValue
|
||||
}
|
||||
}
|
||||
|
||||
var acceptActionHandler: (() -> Void)?
|
||||
|
||||
var declineActionHandler: (() -> Void)?
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
static func instantiate() -> KeyVerificationCellInnerContentView {
|
||||
let view = KeyVerificationCellInnerContentView.loadFromNib()
|
||||
return view
|
||||
}
|
||||
|
||||
// MARK: - Life cycle
|
||||
|
||||
override func awakeFromNib() {
|
||||
super.awakeFromNib()
|
||||
|
||||
self.layer.masksToBounds = true
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
|
||||
self.layer.cornerRadius = Constants.cornerRadius
|
||||
|
||||
if self.isButtonsHidden == false {
|
||||
self.acceptButton.layer.cornerRadius = Constants.buttonCornerRadius
|
||||
self.declineButton.layer.cornerRadius = Constants.buttonCornerRadius
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
func update(theme: Theme) {
|
||||
self.backgroundColor = theme.headerBackgroundColor
|
||||
self.titleLabel.textColor = theme.textPrimaryColor
|
||||
self.userInformationsLabel.textColor = theme.textSecondaryColor
|
||||
|
||||
self.acceptButton.vc_setBackgroundColor(theme.tintColor.withAlphaComponent(Constants.buttonBackgroundColorAlpha), for: .normal)
|
||||
self.declineButton.vc_setBackgroundColor(theme.noticeColor.withAlphaComponent(Constants.buttonBackgroundColorAlpha), for: .normal)
|
||||
}
|
||||
|
||||
func updateSenderInfo(with userId: String, userDisplayName: String?) {
|
||||
self.userInformationsLabel.text = self.buildUserInfoText(with: userId, userDisplayName: userDisplayName)
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func buildUserInfoText(with userId: String, userDisplayName: String?) -> String {
|
||||
|
||||
let userInfoText: String
|
||||
|
||||
if let userDisplayName = userDisplayName {
|
||||
userInfoText = "\(userId) (\(userDisplayName))"
|
||||
} else {
|
||||
userInfoText = userId
|
||||
}
|
||||
|
||||
return userInfoText
|
||||
}
|
||||
|
||||
@IBAction private func declineButtonAction(_ sender: Any) {
|
||||
self.declineActionHandler?()
|
||||
}
|
||||
|
||||
@IBAction private func acceptButtonAction(_ sender: Any) {
|
||||
self.acceptActionHandler?()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user