Skip to content
Snippets Groups Projects
Commit cc201056 authored by Bruno Muniz's avatar Bruno Muniz :apple:
Browse files

Added extra information to avatar cell

parent 00c19ae1
No related branches found
No related tags found
2 merge requests!54Releasing 1.1.4,!50Search UI 2.0
......@@ -30,7 +30,7 @@ final class ContactListTableController: UITableViewController {
private func setupTableView() {
tableView.separatorStyle = .none
tableView.register(SmallAvatarAndTitleCell.self)
tableView.register(AvatarCell.self)
tableView.backgroundColor = Asset.neutralWhite.color
tableView.sectionIndexColor = Asset.neutralDark.color
tableView.contentInset = UIEdgeInsets(top: -20, left: 0, bottom: 0, right: 0)
......@@ -45,11 +45,11 @@ final class ContactListTableController: UITableViewController {
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: SmallAvatarAndTitleCell = tableView.dequeueReusableCell(forIndexPath: indexPath)
let cell: AvatarCell = tableView.dequeueReusableCell(forIndexPath: indexPath)
let contact = sections[indexPath.section][indexPath.row]
let name = (contact.nickname ?? contact.username) ?? "Fetching username..."
cell.titleLabel.text = name
cell.avatarView.setupProfile(title: name, image: contact.photo, size: .medium)
cell.setup(title: name, image: contact.photo)
return cell
}
......
......@@ -66,7 +66,7 @@ public final class CreateGroupController: UIViewController {
private func setupTableAndCollection() {
screenView.tableView.rowHeight = 64.0
screenView.tableView.register(SmallAvatarAndTitleCell.self)
screenView.tableView.register(AvatarCell.self)
screenView.collectionView.register(CreateGroupCollectionCell.self)
collectionDataSource = UICollectionViewDiffableDataSource<SectionId, Contact>(
......@@ -84,10 +84,10 @@ public final class CreateGroupController: UIViewController {
tableDataSource = DiffEditableDataSource<SectionId, Contact>(
tableView: screenView.tableView
) { [weak self] tableView, indexPath, contact in
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath, ofType: SmallAvatarAndTitleCell.self)
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath, ofType: AvatarCell.self)
let title = (contact.nickname ?? contact.username) ?? ""
cell.titleLabel.text = title
cell.avatarView.setupProfile(title: title, image: contact.photo, size: .medium)
cell.setup(title: title, image: contact.photo)
if let selectedElements = self?.selectedElements, selectedElements.contains(contact) {
tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none)
......
......@@ -38,7 +38,7 @@ final class SearchUsernameController: UIViewController {
private func setupTableView() {
screenView.tableView.separatorStyle = .none
screenView.tableView.tableFooterView = UIView()
screenView.tableView.register(SmallAvatarAndTitleCell.self)
screenView.tableView.register(AvatarCell.self)
screenView.tableView.dataSource = dataSource
screenView.tableView.delegate = self
......@@ -46,7 +46,7 @@ final class SearchUsernameController: UIViewController {
tableView: screenView.tableView
) { tableView, indexPath, item in
let contact: Contact
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath, ofType: SmallAvatarAndTitleCell.self)
let cell = tableView.dequeueReusableCell(forIndexPath: indexPath, ofType: AvatarCell.self)
switch item {
case .stranger(let stranger):
......@@ -56,8 +56,15 @@ final class SearchUsernameController: UIViewController {
}
let title = (contact.nickname ?? contact.username) ?? ""
cell.titleLabel.text = title
cell.avatarView.setupProfile(title: title, image: contact.photo, size: .medium)
cell.setup(
title: title,
image: contact.photo,
firstSubtitle: contact.username,
secondSubtitle: contact.email,
thirdSubtitle: contact.phone,
showSeparator: false
)
return cell
}
}
......
......@@ -31,7 +31,7 @@ final class SearchUsernameView: UIView {
}
tableView.snp.makeConstraints {
$0.top.equalTo(inputField.snp.bottom)
$0.top.equalTo(inputField.snp.bottom).offset(20)
$0.left.equalToSuperview()
$0.right.equalToSuperview()
$0.bottom.equalToSuperview()
......
import UIKit
public final class SmallAvatarAndTitleCell: UITableViewCell {
public final class AvatarCell: UITableViewCell {
let h1Label = UILabel()
let h2Label = UILabel()
let h3Label = UILabel()
let h4Label = UILabel()
let separatorView = UIView()
public let titleLabel = UILabel()
public let avatarView = AvatarView()
let avatarView = AvatarView()
let stackView = UIStackView()
public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
......@@ -12,39 +16,101 @@ public final class SmallAvatarAndTitleCell: UITableViewCell {
multipleSelectionBackgroundView = UIView()
backgroundColor = Asset.neutralWhite.color
titleLabel.textColor = Asset.neutralActive.color
titleLabel.font = Fonts.Mulish.semiBold.font(size: 14.0)
h1Label.textColor = Asset.neutralActive.color
h2Label.textColor = Asset.neutralSecondaryAlternative.color
h3Label.textColor = Asset.neutralSecondaryAlternative.color
h4Label.textColor = Asset.neutralSecondaryAlternative.color
h1Label.font = Fonts.Mulish.semiBold.font(size: 14.0)
h2Label.font = Fonts.Mulish.regular.font(size: 14.0)
h3Label.font = Fonts.Mulish.regular.font(size: 14.0)
h4Label.font = Fonts.Mulish.regular.font(size: 14.0)
stackView.spacing = 4
stackView.axis = .vertical
stackView.addArrangedSubview(h1Label)
stackView.addArrangedSubview(h2Label)
stackView.addArrangedSubview(h3Label)
stackView.addArrangedSubview(h4Label)
separatorView.backgroundColor = Asset.neutralLine.color
contentView.addSubview(titleLabel)
contentView.addSubview(stackView)
contentView.addSubview(avatarView)
contentView.addSubview(separatorView)
setupConstraints()
}
required init?(coder: NSCoder) { nil }
public override func prepareForReuse() {
super.prepareForReuse()
h1Label.text = nil
h2Label.text = nil
h3Label.text = nil
h4Label.text = nil
avatarView.prepareForReuse()
}
public func setup(
title: String,
image: Data?,
firstSubtitle: String? = nil,
secondSubtitle: String? = nil,
thirdSubtitle: String? = nil,
showSeparator: Bool = true
) {
h1Label.text = title
if let firstSubtitle = firstSubtitle {
h2Label.isHidden = false
h2Label.text = firstSubtitle
} else {
h2Label.isHidden = true
}
if let secondSubtitle = secondSubtitle {
h3Label.isHidden = false
h3Label.text = secondSubtitle
} else {
h3Label.isHidden = true
}
if let thirdSubtitle = thirdSubtitle {
h4Label.isHidden = false
h4Label.text = thirdSubtitle
} else {
h4Label.isHidden = true
}
avatarView.setupProfile(title: title, image: image, size: .medium)
separatorView.alpha = showSeparator ? 1.0 : 0.0
}
private func setupConstraints() {
avatarView.snp.makeConstraints {
$0.width.height.equalTo(36)
$0.left.equalToSuperview().offset(27)
$0.centerY.equalToSuperview()
}
titleLabel.snp.makeConstraints {
$0.centerY.equalTo(avatarView)
stackView.snp.makeConstraints {
$0.top.equalTo(avatarView)
$0.left.equalTo(avatarView.snp.right).offset(14)
$0.right.lessThanOrEqualToSuperview().offset(-10)
$0.bottom.greaterThanOrEqualTo(avatarView)
$0.bottom.lessThanOrEqualToSuperview()
}
separatorView.snp.makeConstraints {
$0.height.equalTo(1)
$0.top.greaterThanOrEqualTo(stackView.snp.bottom).offset(10)
$0.left.equalToSuperview().offset(25)
$0.right.equalToSuperview()
$0.bottom.equalToSuperview()
}
}
required init?(coder: NSCoder) { nil }
public override func prepareForReuse() {
super.prepareForReuse()
titleLabel.text = nil
avatarView.prepareForReuse()
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment