2020-09-09 11:39:56 +00:00
|
|
|
//
|
|
|
|
// Copyright 2020 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
|
|
|
|
|
2020-09-10 11:56:46 +00:00
|
|
|
protocol DirectoryRoomTableViewCellDelegate: class {
|
|
|
|
func directoryRoomTableViewCellDidTapJoin(_ cell: DirectoryRoomTableViewCell)
|
|
|
|
}
|
|
|
|
|
2020-09-09 11:39:56 +00:00
|
|
|
class DirectoryRoomTableViewCell: UITableViewCell {
|
|
|
|
|
|
|
|
@IBOutlet private weak var avatarImageView: MXKImageView! {
|
|
|
|
didSet {
|
|
|
|
avatarImageView.layer.cornerRadius = avatarImageView.frame.width/2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@IBOutlet private weak var displaynameLabel: UILabel!
|
|
|
|
@IBOutlet private weak var numberOfUsersLabel: UILabel!
|
|
|
|
@IBOutlet private weak var topicLabel: UILabel!
|
|
|
|
@IBOutlet private weak var joinButton: UIButton!
|
|
|
|
@IBOutlet private weak var joinActivityIndicator: UIActivityIndicatorView!
|
2020-09-10 11:56:46 +00:00
|
|
|
|
|
|
|
weak var delegate: DirectoryRoomTableViewCellDelegate?
|
2020-09-09 11:39:56 +00:00
|
|
|
|
2020-09-10 11:56:46 +00:00
|
|
|
private var viewModel: DirectoryRoomTableViewCellVM!
|
|
|
|
var indexPath: IndexPath!
|
|
|
|
|
|
|
|
func startJoining() {
|
|
|
|
joinButton.setTitle(nil, for: .normal)
|
|
|
|
joinActivityIndicator.isHidden = false
|
|
|
|
joinActivityIndicator.startAnimating()
|
2020-09-09 11:39:56 +00:00
|
|
|
}
|
2020-09-10 11:56:46 +00:00
|
|
|
|
|
|
|
func configure(withViewModel viewModel: DirectoryRoomTableViewCellVM) {
|
|
|
|
// keep viewModel
|
|
|
|
self.viewModel = viewModel
|
2020-09-09 11:39:56 +00:00
|
|
|
|
2020-09-10 11:56:46 +00:00
|
|
|
displaynameLabel.text = viewModel.title
|
2020-09-09 11:39:56 +00:00
|
|
|
|
2020-09-10 11:56:46 +00:00
|
|
|
if viewModel.numberOfUsers > 0 {
|
2020-09-09 11:39:56 +00:00
|
|
|
numberOfUsersLabel.isHidden = false
|
2020-09-10 11:56:46 +00:00
|
|
|
numberOfUsersLabel.text = String(viewModel.numberOfUsers)
|
2020-09-09 11:39:56 +00:00
|
|
|
} else {
|
|
|
|
numberOfUsersLabel.isHidden = true
|
|
|
|
}
|
|
|
|
|
2020-09-10 11:56:46 +00:00
|
|
|
if let subtitle = viewModel.subtitle {
|
|
|
|
topicLabel.text = subtitle
|
2020-09-09 11:39:56 +00:00
|
|
|
topicLabel.isHidden = false
|
|
|
|
} else {
|
|
|
|
topicLabel.isHidden = true
|
|
|
|
}
|
|
|
|
|
2020-09-10 11:56:46 +00:00
|
|
|
viewModel.setAvatar(in: avatarImageView)
|
2020-09-09 11:39:56 +00:00
|
|
|
|
2020-09-10 11:56:46 +00:00
|
|
|
if viewModel.isJoined {
|
|
|
|
joinButton.setTitle(VectorL10n.joined, for: .normal)
|
|
|
|
joinButton.isUserInteractionEnabled = false
|
2020-09-09 11:39:56 +00:00
|
|
|
} else {
|
2020-09-10 11:56:46 +00:00
|
|
|
joinButton.setTitle(VectorL10n.join, for: .normal)
|
|
|
|
joinButton.isUserInteractionEnabled = true
|
2020-09-09 11:39:56 +00:00
|
|
|
}
|
2020-09-10 11:56:46 +00:00
|
|
|
joinActivityIndicator.stopAnimating()
|
2020-09-09 11:39:56 +00:00
|
|
|
joinActivityIndicator.isHidden = true
|
2020-09-10 11:56:46 +00:00
|
|
|
update(theme: ThemeService.shared().theme)
|
2020-09-09 11:39:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction private func joinButtonTapped(_ sender: UIButton) {
|
2020-09-10 11:56:46 +00:00
|
|
|
delegate?.directoryRoomTableViewCellDidTapJoin(self)
|
2020-09-09 11:39:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extension DirectoryRoomTableViewCell: NibReusable {}
|
|
|
|
|
|
|
|
extension DirectoryRoomTableViewCell: Themable {
|
|
|
|
|
|
|
|
func update(theme: Theme) {
|
|
|
|
backgroundView = UIView()
|
|
|
|
backgroundView?.backgroundColor = theme.backgroundColor
|
|
|
|
|
|
|
|
displaynameLabel.textColor = theme.textPrimaryColor
|
|
|
|
numberOfUsersLabel.textColor = theme.textSecondaryColor
|
|
|
|
topicLabel.textColor = theme.textSecondaryColor
|
|
|
|
|
2021-03-24 08:14:31 +00:00
|
|
|
if let viewModel = viewModel, viewModel.isJoined {
|
2020-09-09 11:39:56 +00:00
|
|
|
joinButton.backgroundColor = theme.backgroundColor
|
|
|
|
joinButton.tintColor = theme.textSecondaryColor
|
|
|
|
joinButton.layer.borderWidth = 1.0
|
|
|
|
joinButton.layer.borderColor = theme.textSecondaryColor.cgColor
|
|
|
|
} else {
|
|
|
|
joinButton.backgroundColor = theme.tintColor
|
|
|
|
joinButton.tintColor = .white
|
|
|
|
joinButton.layer.borderWidth = 0.0
|
|
|
|
joinButton.layer.borderColor = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|