1
0
mirror of https://github.com/mastodon/mastodon-ios.git synced 2024-12-22 22:28:35 +01:00

chore: adapt notification title label to i18n string

This commit is contained in:
CMK 2021-08-10 18:33:13 +08:00
parent 0e9165f9e8
commit 65ac4c4b2b
6 changed files with 41 additions and 35 deletions

View File

@ -5715,7 +5715,7 @@
repositoryURL = "https://github.com/TwidereProject/MetaTextKit.git";
requirement = {
kind = exactVersion;
version = 2.1.0;
version = 2.1.1;
};
};
DB0E2D2C26833FF600865C3C /* XCRemoteSwiftPackageReference "Nuke-FLAnimatedImage-Plugin" */ = {

View File

@ -12,7 +12,7 @@
<key>CoreDataStack.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>33</integer>
<integer>32</integer>
</dict>
<key>Mastodon - ASDK.xcscheme_^#shared#^_</key>
<dict>
@ -87,7 +87,7 @@
<key>MastodonIntent.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>32</integer>
<integer>34</integer>
</dict>
<key>MastodonIntents.xcscheme_^#shared#^_</key>
<dict>
@ -107,7 +107,7 @@
<key>ShareActionExtension.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>34</integer>
<integer>33</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>

View File

@ -96,8 +96,8 @@
"repositoryURL": "https://github.com/TwidereProject/MetaTextKit.git",
"state": {
"branch": null,
"revision": "ccb54189b31d13868d979c33d43566912b765bbd",
"version": "2.1.0"
"revision": "a5f412b72fc08cd1348e2388fc7ec326365e1823",
"version": "2.1.1"
}
},
{

View File

@ -68,23 +68,37 @@ extension NotificationSection {
.store(in: &cell.disposeBag)
// configure author name, notification description, timestamp
let nameText = notification.account.displayNameWithFallback
let titleLabelText = "\(nameText) \(notification.notificationType.actionText)"
do {
let mastodonContent = MastodonContent(content: notification.account.displayNameWithFallback, emojis: notification.account.emojiMeta)
let nameContent = MastodonContent(content: nameText, emojis: notification.account.emojiMeta)
let nameMetaContent = try MastodonMetaContent.convert(document: nameContent)
let mastodonContent = MastodonContent(content: titleLabelText, emojis: notification.account.emojiMeta)
let metaContent = try MastodonMetaContent.convert(document: mastodonContent)
cell.nameLabel.configure(content: metaContent)
cell.titleLabel.configure(content: metaContent)
if let nameRange = metaContent.string.range(of: nameMetaContent.string) {
let nsRange = NSRange(nameRange, in: metaContent.string)
cell.titleLabel.textStorage.addAttributes([
.font: UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 15, weight: .semibold), maximumPointSize: 20),
.foregroundColor: Asset.Colors.brandBlue.color,
], range: nsRange)
}
} catch {
let metaContent = PlaintextMetaContent(string: notification.account.displayNameWithFallback)
cell.nameLabel.configure(content: metaContent)
let metaContent = PlaintextMetaContent(string: titleLabelText)
cell.titleLabel.configure(content: metaContent)
}
let createAt = notification.createAt
let actionText = notification.notificationType.actionText
cell.actionLabel.text = actionText
cell.timestampLabel.text = createAt.localizedTimeAgoSinceNow
AppContext.shared.timestampUpdatePublisher
.receive(on: DispatchQueue.main)
.sink { [weak cell] _ in
guard let cell = cell else { return }
cell.actionLabel.text = actionText
cell.timestampLabel.text = createAt.localizedTimeAgoSinceNow
}
.store(in: &cell.disposeBag)

View File

@ -13,7 +13,7 @@ extension MetaLabel {
enum Style {
case statusHeader
case statusName
case notificationName
case notificationTitle
case profileFieldName
case profileFieldValue
case recommendAccountName
@ -26,6 +26,7 @@ extension MetaLabel {
self.init()
layer.masksToBounds = true
lineBreakMode = .byTruncatingTail
textContainer.lineBreakMode = .byTruncatingTail
textContainer.lineFragmentPadding = 0
@ -41,9 +42,9 @@ extension MetaLabel {
font = .systemFont(ofSize: 17, weight: .semibold)
textColor = Asset.Colors.Label.primary.color
case .notificationName:
font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 15, weight: .semibold), maximumPointSize: 20)
textColor = Asset.Colors.brandBlue.color
case .notificationTitle:
font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 15, weight: .regular), maximumPointSize: 20)
textColor = Asset.Colors.Label.secondary.color
case .profileFieldName:
font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold), maximumPointSize: 20)
@ -54,7 +55,6 @@ extension MetaLabel {
textColor = Asset.Colors.Label.primary.color
textAlignment = .right
case .titleView:
font = .systemFont(ofSize: 17, weight: .semibold)
textColor = Asset.Colors.Label.primary.color

View File

@ -49,13 +49,8 @@ final class NotificationStatusTableViewCell: UITableViewCell, StatusCell {
let contentStackView = UIStackView()
let actionLabel: UILabel = {
let label = UILabel()
label.textColor = Asset.Colors.Label.secondary.color
label.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 15, weight: .regular), maximumPointSize: 20)
label.lineBreakMode = .byTruncatingTail
return label
}()
let titleLabel = MetaLabel(style: .notificationTitle)
let dotLabel: UILabel = {
let label = UILabel()
label.textColor = Asset.Colors.Label.secondary.color
@ -70,7 +65,6 @@ final class NotificationStatusTableViewCell: UITableViewCell, StatusCell {
return label
}()
let nameLabel = MetaLabel(style: .notificationName)
let buttonStackView = UIStackView()
@ -181,17 +175,15 @@ extension NotificationStatusTableViewCell {
actionStackView.distribution = .fill
actionStackView.spacing = 4
actionStackView.addArrangedSubview(nameLabel)
actionStackView.addArrangedSubview(actionLabel)
actionStackView.addArrangedSubview(titleLabel)
actionStackView.addArrangedSubview(dotLabel)
actionStackView.addArrangedSubview(timestampLabel)
let timestampPaddingView = UIView()
actionStackView.addArrangedSubview(timestampPaddingView)
nameLabel.setContentHuggingPriority(.required - 3, for: .horizontal)
nameLabel.setContentHuggingPriority(.required - 1, for: .vertical)
nameLabel.setContentCompressionResistancePriority(.required - 3, for: .horizontal)
nameLabel.setContentCompressionResistancePriority(.required - 1, for: .vertical)
actionLabel.setContentHuggingPriority(.defaultLow, for: .horizontal)
titleLabel.setContentHuggingPriority(.required - 3, for: .horizontal)
titleLabel.setContentHuggingPriority(.required - 1, for: .vertical)
titleLabel.setContentCompressionResistancePriority(.required - 3, for: .horizontal)
titleLabel.setContentCompressionResistancePriority(.required - 1, for: .vertical)
dotLabel.setContentHuggingPriority(.required - 2, for: .horizontal)
dotLabel.setContentCompressionResistancePriority(.required - 2, for: .horizontal)
timestampLabel.setContentHuggingPriority(.required - 1, for: .horizontal)
@ -255,7 +247,7 @@ extension NotificationStatusTableViewCell {
avatarButton.addTarget(self, action: #selector(NotificationStatusTableViewCell.avatarButtonDidPressed(_:)), for: .touchUpInside)
let authorNameLabelTapGestureRecognizer = UITapGestureRecognizer.singleTapGestureRecognizer
authorNameLabelTapGestureRecognizer.addTarget(self, action: #selector(NotificationStatusTableViewCell.authorNameLabelTapGestureRecognizerHandler(_:)))
nameLabel.addGestureRecognizer(authorNameLabelTapGestureRecognizer)
titleLabel.addGestureRecognizer(authorNameLabelTapGestureRecognizer)
resetSeparatorLineLayout()
@ -303,7 +295,7 @@ extension NotificationStatusTableViewCell {
@objc private func authorNameLabelTapGestureRecognizerHandler(_ sender: UITapGestureRecognizer) {
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
delegate?.notificationStatusTableViewCell(self, authorNameLabelDidPressed: nameLabel)
delegate?.notificationStatusTableViewCell(self, authorNameLabelDidPressed: titleLabel)
}
}