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

Fixed toast localization for sent request

parent 5881ccd2
No related branches found
No related tags found
2 merge requests!54Releasing 1.1.4,!50Search UI 2.0
......@@ -66,6 +66,7 @@ public final class HUD {
self.errorView = nil
self.animation = nil
self.window = nil
self.actionButton = nil
self.titleLabel = nil
switch status {
......
......@@ -170,6 +170,13 @@ extension Session {
contact.authStatus = success ? .requested : .requestFailed
contact = try self.dbManager.saveContact(contact)
let name = contact.nickname ?? contact.username
self.toastController.enqueueToast(model: .init(
title: Localized.Requests.Sent.Toast.sent(name ?? ""),
leftImage: Asset.sharedSuccess.image
))
case .failure:
contact.createdAt = Date()
contact.authStatus = .requestFailed
......
......@@ -107,7 +107,11 @@ final class SearchLeftViewModel {
snapshot.appendItems([.stranger(contact)], toSection: .stranger)
}
if let locals = try? session.dbManager.fetchContacts(Contact.Query(username: stateSubject.value.input)), locals.count > 0 {
let localsQuery = Contact.Query(text: stateSubject.value.input)
if let locals = try? session.dbManager.fetchContacts(localsQuery), locals.count > 0 {
// TODO: Remove myself
//
snapshot.appendSections([.connections])
snapshot.appendItems(locals.map(SearchItem.connection), toSection: .connections)
}
......
......@@ -965,6 +965,10 @@ public enum Localized {
public static func resent(_ p1: Any) -> String {
return Localized.tr("Localizable", "requests.sent.toast.resent", String(describing: p1))
}
/// Request successfully sent to %@
public static func sent(_ p1: Any) -> String {
return Localized.tr("Localizable", "requests.sent.toast.sent", String(describing: p1))
}
}
}
}
......
......@@ -353,6 +353,8 @@
= "Search for connections";
"requests.sent.empty"
= "You haven't sent any requests";
"requests.sent.toast.sent"
= "Request successfully sent to %@";
"requests.sent.toast.resent"
= "Request successfully resent to %@";
......
import UIKit
import Combine
final class AvatarCellButton: UIControl {
let titleLabel = UILabel()
let imageView = UIImageView()
init() {
super.init(frame: .zero)
titleLabel.numberOfLines = 0
titleLabel.textAlignment = .right
titleLabel.font = Fonts.Mulish.semiBold.font(size: 13.0)
addSubview(imageView)
addSubview(titleLabel)
imageView.snp.makeConstraints {
$0.top.greaterThanOrEqualToSuperview()
$0.left.equalToSuperview()
$0.centerY.equalToSuperview()
$0.bottom.lessThanOrEqualToSuperview()
}
titleLabel.snp.makeConstraints {
$0.top.greaterThanOrEqualToSuperview()
$0.left.equalTo(imageView.snp.right).offset(5)
$0.centerY.equalToSuperview()
$0.right.equalToSuperview()
$0.width.equalTo(60)
$0.bottom.lessThanOrEqualToSuperview()
}
}
required init?(coder: NSCoder) { nil }
}
public final class AvatarCell: UITableViewCell {
let h1Label = UILabel()
......@@ -8,6 +42,10 @@ public final class AvatarCell: UITableViewCell {
let separatorView = UIView()
let avatarView = AvatarView()
let stackView = UIStackView()
let stateButton = AvatarCellButton()
var cancellables = Set<AnyCancellable>()
public var didTapStateButton: (() -> Void)!
public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
......@@ -38,6 +76,7 @@ public final class AvatarCell: UITableViewCell {
contentView.addSubview(stackView)
contentView.addSubview(avatarView)
contentView.addSubview(stateButton)
contentView.addSubview(separatorView)
setupConstraints()
......@@ -52,7 +91,11 @@ public final class AvatarCell: UITableViewCell {
h3Label.text = nil
h4Label.text = nil
stateButton.imageView.image = nil
stateButton.titleLabel.text = nil
avatarView.prepareForReuse()
cancellables.removeAll()
}
public func setup(
......@@ -90,6 +133,45 @@ public final class AvatarCell: UITableViewCell {
separatorView.alpha = showSeparator ? 1.0 : 0.0
}
public func setupForRequestSent(resent: Bool) {
cancellables.removeAll()
var buttonTitle: String? = nil
var buttonImage: UIImage? = nil
var buttonTitleColor: UIColor? = nil
if resent {
buttonTitle = Localized.Requests.Cell.resent
buttonImage = Asset.requestsResent.image
buttonTitleColor = Asset.neutralWeak.color
} else {
buttonTitle = Localized.Requests.Cell.requested
buttonImage = Asset.requestsResend.image
buttonTitleColor = Asset.brandPrimary.color
}
setupStateButton(
image: buttonImage,
title: buttonTitle,
color: buttonTitleColor
)
}
private func setupStateButton(
image: UIImage?,
title: String?,
color: UIColor?
) {
stateButton.imageView.image = image
stateButton.titleLabel.text = title
stateButton.titleLabel.textColor = color
stateButton
.publisher(for: .touchUpInside)
.sink { [unowned self] in didTapStateButton() }
.store(in: &cancellables)
}
private func setupConstraints() {
avatarView.snp.makeConstraints {
$0.width.height.equalTo(36)
......@@ -112,5 +194,10 @@ public final class AvatarCell: UITableViewCell {
$0.right.equalToSuperview()
$0.bottom.equalToSuperview()
}
stateButton.snp.makeConstraints {
$0.centerY.equalTo(stackView)
$0.right.equalToSuperview().offset(-24)
}
}
}
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