Localize and style resend-button (#690)

This commit is contained in:
Nathan Mattes 2022-12-29 22:35:21 +01:00
parent de87424f53
commit ade95302ca
5 changed files with 47 additions and 9 deletions

View File

@ -408,6 +408,11 @@
"description": "We just sent you an email. Check your junk folder if you havent.",
"mail": "Mail",
"open_email_client": "Open Email Client"
},
"didnt_get_link": {
"prefix": "Didn't get a Link?",
"resend_in": "Resend (%@)",
"resend_now": "Resend now."
}
},
"home_timeline": {

View File

@ -43,8 +43,18 @@ final class MastodonConfirmEmailViewController: UIViewController, NeedsDependenc
}()
let resendEmailButton: UIButton = {
let boldFont = UIFontMetrics(forTextStyle: .subheadline).scaledFont(for: .systemFont(ofSize: 15, weight: .bold))
let regularFont = UIFontMetrics(forTextStyle: .subheadline).scaledFont(for: .systemFont(ofSize: 15, weight: .regular))
var buttonConfiguration = UIButton.Configuration.plain()
buttonConfiguration.attributedTitle = try! AttributedString(markdown: "Didn't get a link? **Resend (10)**")
var boldResendString = AttributedString(L10n.Scene.ConfirmEmail.DidntGetLink.resendIn(60), attributes: .init([.font: boldFont]))
var attributedTitle = AttributedString(L10n.Scene.ConfirmEmail.DidntGetLink.prefix, attributes: .init([.font: regularFont]))
attributedTitle.append(AttributedString(" "))
attributedTitle.append(boldResendString)
buttonConfiguration.attributedTitle = attributedTitle
let button = UIButton(configuration: buttonConfiguration)
button.translatesAutoresizingMaskIntoConstraints = false
@ -141,16 +151,21 @@ extension MastodonConfirmEmailViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// start timer
let nowIn60Seconds = Date().addingTimeInterval(10)
let nowIn60Seconds = Date().addingTimeInterval(60)
let boldFont = UIFontMetrics(forTextStyle: .subheadline).scaledFont(for: .systemFont(ofSize: 15, weight: .bold))
let regularFont = UIFontMetrics(forTextStyle: .subheadline).scaledFont(for: .systemFont(ofSize: 15, weight: .regular))
let timer = Timer(timeInterval: 1.0, repeats: true) { [weak self] in
guard Date() < nowIn60Seconds else {
// enable button
self?.resendEmailButton.isEnabled = true
var configuration = self?.resendEmailButton.configuration
let attributedTitle = try! AttributedString(markdown: "Didn't get a link? **Resend**")
let boldResendString = AttributedString(L10n.Scene.ConfirmEmail.DidntGetLink.resendNow, attributes: .init([.font: boldFont]))
var attributedTitle = AttributedString(L10n.Scene.ConfirmEmail.DidntGetLink.prefix, attributes: .init([.font: regularFont]))
attributedTitle.append(AttributedString(" "))
attributedTitle.append(boldResendString)
configuration?.attributedTitle = attributedTitle
self?.resendEmailButton.configuration = configuration
@ -160,10 +175,13 @@ extension MastodonConfirmEmailViewController {
return
}
//TODO: @zeitschlag Add localization
//TODO: @zeitschlag Add styling
var configuration = self?.resendEmailButton.configuration
let attributedTitle = try! AttributedString(markdown: "Didn't get a link? **Resend (\(Int(nowIn60Seconds.timeIntervalSinceNow) + 1))**")
let boldResendString = AttributedString(L10n.Scene.ConfirmEmail.DidntGetLink.resendIn(Int(nowIn60Seconds.timeIntervalSinceNow) + 1), attributes: .init([.font: boldFont]))
var attributedTitle = AttributedString(L10n.Scene.ConfirmEmail.DidntGetLink.prefix, attributes: .init([.font: regularFont]))
attributedTitle.append(AttributedString(" "))
attributedTitle.append(boldResendString)
configuration?.attributedTitle = attributedTitle
self?.resendEmailButton.configuration = configuration
@ -171,7 +189,6 @@ extension MastodonConfirmEmailViewController {
}
RunLoop.main.add(timer, forMode: .default)
// self.resendButtonTimer = timer
}
}

View File

@ -630,6 +630,16 @@ public enum L10n {
/// Resend
public static let resend = L10n.tr("Localizable", "Scene.ConfirmEmail.Button.Resend", fallback: "Resend")
}
public enum DidntGetLink {
/// Didn't get a Link?
public static let `prefix` = L10n.tr("Localizable", "Scene.ConfirmEmail.DidntGetLink.Prefix", fallback: "Didn't get a Link?")
/// Resend (%@)
public static func resendIn(_ p1: Any) -> String {
return L10n.tr("Localizable", "Scene.ConfirmEmail.DidntGetLink.ResendIn", String(describing: p1), fallback: "Resend (%@)")
}
/// Resend now.
public static let resendNow = L10n.tr("Localizable", "Scene.ConfirmEmail.DidntGetLink.ResendNow", fallback: "Resend now.")
}
public enum DontReceiveEmail {
/// Check if your email address is correct as well as your junk folder if you havent.
public static let description = L10n.tr("Localizable", "Scene.ConfirmEmail.DontReceiveEmail.Description", fallback: "Check if your email address is correct as well as your junk folder if you havent.")

View File

@ -234,6 +234,9 @@ uploaded to Mastodon.";
"Scene.ConfirmEmail.OpenEmailApp.Title" = "Check your inbox.";
"Scene.ConfirmEmail.TapTheLinkWeEmailedToYouToVerifyYourAccount" = "Tap the link we sent you to verify %@. We'll wait right here.";
"Scene.ConfirmEmail.Title" = "Check Your Inbox";
"Scene.ConfirmEmail.DidntGetLink.Prefix" = "Didn't get a Link?";
"Scene.ConfirmEmail.DidntGetLink.ResendIn" = "Resend (%@)";
"Scene.ConfirmEmail.DidntGetLink.ResendNow" = "Resend now.";
"Scene.Discovery.Intro" = "These are the posts gaining traction in your corner of Mastodon.";
"Scene.Discovery.Tabs.Community" = "Community";
"Scene.Discovery.Tabs.ForYou" = "For You";

View File

@ -230,6 +230,9 @@ uploaded to Mastodon.";
"Scene.ConfirmEmail.Subtitle" = "Tap the link we emailed to you to verify your account.";
"Scene.ConfirmEmail.TapTheLinkWeEmailedToYouToVerifyYourAccount" = "Tap the link we sent you to verify %@. We'll wait right here.";
"Scene.ConfirmEmail.Title" = "Check Your Inbox";
"Scene.ConfirmEmail.DidntGetLink.Prefix" = "Didn't get a Link?";
"Scene.ConfirmEmail.DidntGetLink.ResendIn" = "Resend (%@)";
"Scene.ConfirmEmail.DidntGetLink.ResendNow" = "Resend now.";
"Scene.Discovery.Intro" = "These are the posts gaining traction in your corner of Mastodon.";
"Scene.Discovery.Tabs.Community" = "Community";
"Scene.Discovery.Tabs.ForYou" = "For You";