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 { ...@@ -66,6 +66,7 @@ public final class HUD {
self.errorView = nil self.errorView = nil
self.animation = nil self.animation = nil
self.window = nil self.window = nil
self.actionButton = nil
self.titleLabel = nil self.titleLabel = nil
switch status { switch status {
......
...@@ -170,6 +170,13 @@ extension Session { ...@@ -170,6 +170,13 @@ extension Session {
contact.authStatus = success ? .requested : .requestFailed contact.authStatus = success ? .requested : .requestFailed
contact = try self.dbManager.saveContact(contact) 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: case .failure:
contact.createdAt = Date() contact.createdAt = Date()
contact.authStatus = .requestFailed contact.authStatus = .requestFailed
......
...@@ -107,7 +107,11 @@ final class SearchLeftViewModel { ...@@ -107,7 +107,11 @@ final class SearchLeftViewModel {
snapshot.appendItems([.stranger(contact)], toSection: .stranger) 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.appendSections([.connections])
snapshot.appendItems(locals.map(SearchItem.connection), toSection: .connections) snapshot.appendItems(locals.map(SearchItem.connection), toSection: .connections)
} }
......
...@@ -965,6 +965,10 @@ public enum Localized { ...@@ -965,6 +965,10 @@ public enum Localized {
public static func resent(_ p1: Any) -> String { public static func resent(_ p1: Any) -> String {
return Localized.tr("Localizable", "requests.sent.toast.resent", String(describing: p1)) 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 @@ ...@@ -353,6 +353,8 @@
= "Search for connections"; = "Search for connections";
"requests.sent.empty" "requests.sent.empty"
= "You haven't sent any requests"; = "You haven't sent any requests";
"requests.sent.toast.sent"
= "Request successfully sent to %@";
"requests.sent.toast.resent" "requests.sent.toast.resent"
= "Request successfully resent to %@"; = "Request successfully resent to %@";
......
import UIKit 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 { public final class AvatarCell: UITableViewCell {
let h1Label = UILabel() let h1Label = UILabel()
...@@ -8,6 +42,10 @@ public final class AvatarCell: UITableViewCell { ...@@ -8,6 +42,10 @@ public final class AvatarCell: UITableViewCell {
let separatorView = UIView() let separatorView = UIView()
let avatarView = AvatarView() let avatarView = AvatarView()
let stackView = UIStackView() let stackView = UIStackView()
let stateButton = AvatarCellButton()
var cancellables = Set<AnyCancellable>()
public var didTapStateButton: (() -> Void)!
public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier) super.init(style: style, reuseIdentifier: reuseIdentifier)
...@@ -38,6 +76,7 @@ public final class AvatarCell: UITableViewCell { ...@@ -38,6 +76,7 @@ public final class AvatarCell: UITableViewCell {
contentView.addSubview(stackView) contentView.addSubview(stackView)
contentView.addSubview(avatarView) contentView.addSubview(avatarView)
contentView.addSubview(stateButton)
contentView.addSubview(separatorView) contentView.addSubview(separatorView)
setupConstraints() setupConstraints()
...@@ -52,7 +91,11 @@ public final class AvatarCell: UITableViewCell { ...@@ -52,7 +91,11 @@ public final class AvatarCell: UITableViewCell {
h3Label.text = nil h3Label.text = nil
h4Label.text = nil h4Label.text = nil
stateButton.imageView.image = nil
stateButton.titleLabel.text = nil
avatarView.prepareForReuse() avatarView.prepareForReuse()
cancellables.removeAll()
} }
public func setup( public func setup(
...@@ -90,6 +133,45 @@ public final class AvatarCell: UITableViewCell { ...@@ -90,6 +133,45 @@ public final class AvatarCell: UITableViewCell {
separatorView.alpha = showSeparator ? 1.0 : 0.0 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() { private func setupConstraints() {
avatarView.snp.makeConstraints { avatarView.snp.makeConstraints {
$0.width.height.equalTo(36) $0.width.height.equalTo(36)
...@@ -112,5 +194,10 @@ public final class AvatarCell: UITableViewCell { ...@@ -112,5 +194,10 @@ public final class AvatarCell: UITableViewCell {
$0.right.equalToSuperview() $0.right.equalToSuperview()
$0.bottom.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.
Please register or to comment