mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-22 00:01:00 +00:00
Consistently pluralize emoji
This commit is contained in:
parent
fab43da52f
commit
ef8fd98e4b
17 changed files with 45 additions and 45 deletions
|
@ -5,8 +5,8 @@ import Mastodon
|
|||
import UIKit
|
||||
|
||||
extension NSMutableAttributedString {
|
||||
func insert(emoji: [Emoji], view: UIView) {
|
||||
for emoji in emoji {
|
||||
func insert(emojis: [Emoji], view: UIView) {
|
||||
for emoji in emojis {
|
||||
let token = ":\(emoji.shortcode):"
|
||||
|
||||
while let tokenRange = string.range(of: token) {
|
||||
|
|
|
@ -23,7 +23,7 @@ extension String {
|
|||
return attributed
|
||||
}
|
||||
|
||||
func localizedBolding(displayName: String, emoji: [Emoji], label: UILabel) -> NSAttributedString {
|
||||
func localizedBolding(displayName: String, emojis: [Emoji], label: UILabel) -> NSAttributedString {
|
||||
let mutableString = NSMutableAttributedString(
|
||||
string: String.localizedStringWithFormat(
|
||||
NSLocalizedString(self, comment: ""),
|
||||
|
@ -38,7 +38,7 @@ extension String {
|
|||
mutableString.setAttributes([NSAttributedString.Key.font: boldFont], range: range)
|
||||
}
|
||||
|
||||
mutableString.insert(emoji: emoji, view: label)
|
||||
mutableString.insert(emojis: emojis, view: label)
|
||||
mutableString.resizeAttachments(toLineHeight: label.font.lineHeight)
|
||||
|
||||
return mutableString
|
||||
|
|
|
@ -48,7 +48,7 @@ public extension AccountViewModel {
|
|||
|
||||
var note: NSAttributedString { accountService.account.note.attributed }
|
||||
|
||||
var emoji: [Emoji] { accountService.account.emojis }
|
||||
var emojis: [Emoji] { accountService.account.emojis }
|
||||
|
||||
var followingCount: Int { accountService.account.followingCount }
|
||||
|
||||
|
|
|
@ -7,15 +7,15 @@ import ServiceLayer
|
|||
|
||||
public final class StatusViewModel: CollectionItemViewModel, AttachmentsRenderingViewModel, ObservableObject {
|
||||
public let content: NSAttributedString
|
||||
public let contentEmoji: [Emoji]
|
||||
public let contentEmojis: [Emoji]
|
||||
public let displayName: String
|
||||
public let displayNameEmoji: [Emoji]
|
||||
public let displayNameEmojis: [Emoji]
|
||||
public let spoilerText: String
|
||||
public let isReblog: Bool
|
||||
public let rebloggedByDisplayName: String
|
||||
public let rebloggedByDisplayNameEmoji: [Emoji]
|
||||
public let rebloggedByDisplayNameEmojis: [Emoji]
|
||||
public let attachmentViewModels: [AttachmentViewModel]
|
||||
public let pollEmoji: [Emoji]
|
||||
public let pollEmojis: [Emoji]
|
||||
@Published public var pollOptionSelections = Set<Int>()
|
||||
public var configuration = CollectionItem.StatusConfiguration.default
|
||||
public let events: AnyPublisher<AnyPublisher<CollectionItemEvent, Error>, Never>
|
||||
|
@ -28,20 +28,20 @@ public final class StatusViewModel: CollectionItemViewModel, AttachmentsRenderin
|
|||
self.statusService = statusService
|
||||
self.identification = identification
|
||||
content = statusService.status.displayStatus.content.attributed
|
||||
contentEmoji = statusService.status.displayStatus.emojis
|
||||
contentEmojis = statusService.status.displayStatus.emojis
|
||||
displayName = statusService.status.displayStatus.account.displayName.isEmpty
|
||||
? statusService.status.displayStatus.account.username
|
||||
: statusService.status.displayStatus.account.displayName
|
||||
displayNameEmoji = statusService.status.displayStatus.account.emojis
|
||||
displayNameEmojis = statusService.status.displayStatus.account.emojis
|
||||
spoilerText = statusService.status.displayStatus.spoilerText
|
||||
isReblog = statusService.status.reblog != nil
|
||||
rebloggedByDisplayName = statusService.status.account.displayName.isEmpty
|
||||
? statusService.status.account.username
|
||||
: statusService.status.account.displayName
|
||||
rebloggedByDisplayNameEmoji = statusService.status.account.emojis
|
||||
rebloggedByDisplayNameEmojis = statusService.status.account.emojis
|
||||
attachmentViewModels = statusService.status.displayStatus.mediaAttachments
|
||||
.map { AttachmentViewModel(attachment: $0, identification: identification, status: statusService.status) }
|
||||
pollEmoji = statusService.status.displayStatus.poll?.emojis ?? []
|
||||
pollEmojis = statusService.status.displayStatus.poll?.emojis ?? []
|
||||
events = eventsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ final class AccountFieldView: UIView {
|
|||
let valueTextView = TouchFallthroughTextView()
|
||||
|
||||
// swiftlint:disable:next function_body_length
|
||||
init(name: String, value: NSAttributedString, verifiedAt: Date?, emoji: [Emoji]) {
|
||||
init(name: String, value: NSAttributedString, verifiedAt: Date?, emojis: [Emoji]) {
|
||||
super.init(frame: .zero)
|
||||
|
||||
backgroundColor = .systemBackground
|
||||
|
@ -36,7 +36,7 @@ final class AccountFieldView: UIView {
|
|||
|
||||
let mutableName = NSMutableAttributedString(string: name)
|
||||
|
||||
mutableName.insert(emoji: emoji, view: nameLabel)
|
||||
mutableName.insert(emojis: emojis, view: nameLabel)
|
||||
mutableName.resizeAttachments(toLineHeight: nameLabel.font.lineHeight)
|
||||
nameLabel.attributedText = mutableName
|
||||
|
||||
|
@ -66,7 +66,7 @@ final class AccountFieldView: UIView {
|
|||
[.font: valueFont as Any,
|
||||
.foregroundColor: UIColor.label],
|
||||
range: valueRange)
|
||||
mutableValue.insert(emoji: emoji, view: valueTextView)
|
||||
mutableValue.insert(emojis: emojis, view: valueTextView)
|
||||
mutableValue.resizeAttachments(toLineHeight: valueFont.lineHeight)
|
||||
|
||||
valueTextView.attributedText = mutableValue
|
||||
|
|
|
@ -50,7 +50,7 @@ final class AccountHeaderView: UIView {
|
|||
} else {
|
||||
let mutableDisplayName = NSMutableAttributedString(string: accountViewModel.displayName)
|
||||
|
||||
mutableDisplayName.insert(emoji: accountViewModel.emoji, view: displayNameLabel)
|
||||
mutableDisplayName.insert(emojis: accountViewModel.emojis, view: displayNameLabel)
|
||||
mutableDisplayName.resizeAttachments(toLineHeight: displayNameLabel.font.lineHeight)
|
||||
displayNameLabel.attributedText = mutableDisplayName
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ final class AccountHeaderView: UIView {
|
|||
string: identityProof.providerUsername,
|
||||
attributes: [.link: identityProof.profileUrl]),
|
||||
verifiedAt: identityProof.updatedAt,
|
||||
emoji: [])
|
||||
emojis: [])
|
||||
|
||||
fieldView.valueTextView.delegate = self
|
||||
|
||||
|
@ -82,7 +82,7 @@ final class AccountHeaderView: UIView {
|
|||
name: field.name,
|
||||
value: field.value.attributed,
|
||||
verifiedAt: field.verifiedAt,
|
||||
emoji: accountViewModel.emoji)
|
||||
emojis: accountViewModel.emojis)
|
||||
|
||||
fieldView.valueTextView.delegate = self
|
||||
|
||||
|
@ -99,7 +99,7 @@ final class AccountHeaderView: UIView {
|
|||
[.font: noteFont as Any,
|
||||
.foregroundColor: UIColor.label],
|
||||
range: noteRange)
|
||||
mutableNote.insert(emoji: accountViewModel.emoji, view: noteTextView)
|
||||
mutableNote.insert(emojis: accountViewModel.emojis, view: noteTextView)
|
||||
mutableNote.resizeAttachments(toLineHeight: noteFont.lineHeight)
|
||||
noteTextView.attributedText = mutableNote
|
||||
noteTextView.isHidden = false
|
||||
|
|
|
@ -103,7 +103,7 @@ private extension AccountView {
|
|||
} else {
|
||||
let mutableDisplayName = NSMutableAttributedString(string: accountConfiguration.viewModel.displayName)
|
||||
|
||||
mutableDisplayName.insert(emoji: accountConfiguration.viewModel.emoji, view: displayNameLabel)
|
||||
mutableDisplayName.insert(emojis: accountConfiguration.viewModel.emojis, view: displayNameLabel)
|
||||
mutableDisplayName.resizeAttachments(toLineHeight: displayNameLabel.font.lineHeight)
|
||||
displayNameLabel.attributedText = mutableDisplayName
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ private extension AccountView {
|
|||
[.font: noteFont as Any,
|
||||
.foregroundColor: UIColor.label],
|
||||
range: noteRange)
|
||||
mutableNote.insert(emoji: accountConfiguration.viewModel.emoji, view: noteTextView)
|
||||
mutableNote.insert(emojis: accountConfiguration.viewModel.emojis, view: noteTextView)
|
||||
mutableNote.resizeAttachments(toLineHeight: noteFont.lineHeight)
|
||||
|
||||
noteTextView.attributedText = mutableNote
|
||||
|
|
|
@ -88,7 +88,7 @@ private extension ConversationView {
|
|||
let mutableDisplayNames = NSMutableAttributedString(string: displayNames)
|
||||
|
||||
mutableDisplayNames.insert(
|
||||
emoji: viewModel.accountViewModels.map(\.emoji).reduce([], +),
|
||||
emojis: viewModel.accountViewModels.map(\.emojis).reduce([], +),
|
||||
view: displayNamesLabel)
|
||||
mutableDisplayNames.resizeAttachments(toLineHeight: displayNamesLabel.font.lineHeight)
|
||||
|
||||
|
|
|
@ -5,12 +5,12 @@ import struct Mastodon.Emoji
|
|||
|
||||
struct CustomEmojiText: UIViewRepresentable {
|
||||
private let attributedText: NSMutableAttributedString
|
||||
private let emoji: [Emoji]
|
||||
private let emojis: [Emoji]
|
||||
private let textStyle: UIFont.TextStyle
|
||||
|
||||
init(text: String, emoji: [Emoji], textStyle: UIFont.TextStyle) {
|
||||
init(text: String, emojis: [Emoji], textStyle: UIFont.TextStyle) {
|
||||
attributedText = NSMutableAttributedString(string: text)
|
||||
self.emoji = emoji
|
||||
self.emojis = emojis
|
||||
self.textStyle = textStyle
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ struct CustomEmojiText: UIViewRepresentable {
|
|||
let label = UILabel()
|
||||
|
||||
label.font = UIFont.preferredFont(forTextStyle: textStyle)
|
||||
attributedText.insert(emoji: emoji, view: label)
|
||||
attributedText.insert(emojis: emojis, view: label)
|
||||
attributedText.resizeAttachments(toLineHeight: label.font.lineHeight)
|
||||
label.attributedText = attributedText
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ private extension IdentitiesView {
|
|||
if let account = identity.account {
|
||||
CustomEmojiText(
|
||||
text: account.displayName,
|
||||
emoji: account.emojis,
|
||||
emojis: account.emojis,
|
||||
textStyle: .headline)
|
||||
}
|
||||
Text(identity.handle)
|
||||
|
@ -81,7 +81,7 @@ private extension IdentitiesView {
|
|||
if let instance = identity.instance {
|
||||
CustomEmojiText(
|
||||
text: instance.title,
|
||||
emoji: [],
|
||||
emojis: [],
|
||||
textStyle: .headline)
|
||||
Text(instance.uri)
|
||||
.font(.subheadline)
|
||||
|
|
|
@ -130,19 +130,19 @@ private extension NotificationView {
|
|||
case .follow:
|
||||
typeLabel.attributedText = "notifications.followed-you".localizedBolding(
|
||||
displayName: viewModel.accountViewModel.displayName,
|
||||
emoji: viewModel.accountViewModel.emoji,
|
||||
emojis: viewModel.accountViewModel.emojis,
|
||||
label: typeLabel)
|
||||
iconImageView.tintColor = nil
|
||||
case .reblog:
|
||||
typeLabel.attributedText = "notifications.reblogged-your-status".localizedBolding(
|
||||
displayName: viewModel.accountViewModel.displayName,
|
||||
emoji: viewModel.accountViewModel.emoji,
|
||||
emojis: viewModel.accountViewModel.emojis,
|
||||
label: typeLabel)
|
||||
iconImageView.tintColor = .systemGreen
|
||||
case .favourite:
|
||||
typeLabel.attributedText = "notifications.favourited-your-status".localizedBolding(
|
||||
displayName: viewModel.accountViewModel.displayName,
|
||||
emoji: viewModel.accountViewModel.emoji,
|
||||
emojis: viewModel.accountViewModel.emojis,
|
||||
label: typeLabel)
|
||||
iconImageView.tintColor = .systemYellow
|
||||
case .poll:
|
||||
|
@ -155,7 +155,7 @@ private extension NotificationView {
|
|||
default:
|
||||
typeLabel.attributedText = "notifications.unknown".localizedBolding(
|
||||
displayName: viewModel.accountViewModel.displayName,
|
||||
emoji: viewModel.accountViewModel.emoji,
|
||||
emojis: viewModel.accountViewModel.emojis,
|
||||
label: typeLabel)
|
||||
iconImageView.tintColor = nil
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ private extension NotificationView {
|
|||
if viewModel.statusViewModel == nil {
|
||||
let mutableDisplayName = NSMutableAttributedString(string: viewModel.accountViewModel.displayName)
|
||||
|
||||
mutableDisplayName.insert(emoji: viewModel.accountViewModel.emoji, view: displayNameLabel)
|
||||
mutableDisplayName.insert(emojis: viewModel.accountViewModel.emojis, view: displayNameLabel)
|
||||
mutableDisplayName.resizeAttachments(toLineHeight: displayNameLabel.font.lineHeight)
|
||||
displayNameLabel.attributedText = mutableDisplayName
|
||||
accountLabel.text = viewModel.accountViewModel.accountName
|
||||
|
|
|
@ -4,7 +4,7 @@ import Mastodon
|
|||
import UIKit
|
||||
|
||||
final class PollOptionButton: UIButton {
|
||||
init(title: String, emoji: [Emoji], multipleSelection: Bool) {
|
||||
init(title: String, emojis: [Emoji], multipleSelection: Bool) {
|
||||
super.init(frame: .zero)
|
||||
|
||||
titleLabel?.font = .preferredFont(forTextStyle: .callout)
|
||||
|
@ -16,7 +16,7 @@ final class PollOptionButton: UIButton {
|
|||
|
||||
let attributedTitle = NSMutableAttributedString(string: title)
|
||||
|
||||
attributedTitle.insert(emoji: emoji, view: titleLabel!)
|
||||
attributedTitle.insert(emojis: emojis, view: titleLabel!)
|
||||
attributedTitle.resizeAttachments(toLineHeight: titleLabel!.font.lineHeight)
|
||||
setAttributedTitle(attributedTitle, for: .normal)
|
||||
setImage(
|
||||
|
|
|
@ -10,7 +10,7 @@ final class PollResultView: UIView {
|
|||
private let percentLabel = UILabel()
|
||||
private let percentView = UIProgressView()
|
||||
|
||||
init(option: Poll.Option, emoji: [Emoji], selected: Bool, multipleSelection: Bool, votersCount: Int) {
|
||||
init(option: Poll.Option, emojis: [Emoji], selected: Bool, multipleSelection: Bool, votersCount: Int) {
|
||||
super.init(frame: .zero)
|
||||
|
||||
addSubview(verticalStackView)
|
||||
|
@ -45,7 +45,7 @@ final class PollResultView: UIView {
|
|||
|
||||
let attributedTitle = NSMutableAttributedString(string: option.title)
|
||||
|
||||
attributedTitle.insert(emoji: emoji, view: titleLabel)
|
||||
attributedTitle.insert(emojis: emojis, view: titleLabel)
|
||||
attributedTitle.resizeAttachments(toLineHeight: titleLabel.font.lineHeight)
|
||||
titleLabel.attributedText = attributedTitle
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ final class PollView: UIView {
|
|||
for (index, option) in viewModel.pollOptions.enumerated() {
|
||||
let button = PollOptionButton(
|
||||
title: option.title,
|
||||
emoji: viewModel.pollEmoji,
|
||||
emojis: viewModel.pollEmojis,
|
||||
multipleSelection: viewModel.isPollMultipleSelection)
|
||||
|
||||
button.addAction(
|
||||
|
@ -54,7 +54,7 @@ final class PollView: UIView {
|
|||
for (index, option) in viewModel.pollOptions.enumerated() {
|
||||
let resultView = PollResultView(
|
||||
option: option,
|
||||
emoji: viewModel.pollEmoji,
|
||||
emojis: viewModel.pollEmojis,
|
||||
selected: viewModel.pollOwnVotes.contains(index),
|
||||
multipleSelection: viewModel.isPollMultipleSelection,
|
||||
votersCount: viewModel.pollVotersCount)
|
||||
|
|
|
@ -24,7 +24,7 @@ struct SecondaryNavigationView: View {
|
|||
if let account = viewModel.identification.identity.account {
|
||||
CustomEmojiText(
|
||||
text: account.displayName,
|
||||
emoji: account.emojis,
|
||||
emojis: account.emojis,
|
||||
textStyle: .headline)
|
||||
}
|
||||
Text(viewModel.identification.identity.handle)
|
||||
|
|
|
@ -27,12 +27,12 @@ final class StatusBodyView: UIView {
|
|||
mutableContent.addAttributes(
|
||||
[.font: contentFont, .foregroundColor: UIColor.label],
|
||||
range: contentRange)
|
||||
mutableContent.insert(emoji: viewModel.contentEmoji, view: contentTextView)
|
||||
mutableContent.insert(emojis: viewModel.contentEmojis, view: contentTextView)
|
||||
mutableContent.resizeAttachments(toLineHeight: contentFont.lineHeight)
|
||||
contentTextView.attributedText = mutableContent
|
||||
contentTextView.isHidden = contentTextView.text.isEmpty
|
||||
|
||||
mutableSpoilerText.insert(emoji: viewModel.contentEmoji, view: spoilerTextLabel)
|
||||
mutableSpoilerText.insert(emojis: viewModel.contentEmojis, view: spoilerTextLabel)
|
||||
mutableSpoilerText.resizeAttachments(toLineHeight: spoilerTextLabel.font.lineHeight)
|
||||
spoilerTextLabel.font = contentFont
|
||||
spoilerTextLabel.attributedText = mutableSpoilerText
|
||||
|
|
|
@ -301,7 +301,7 @@ private extension StatusView {
|
|||
if viewModel.isReblog {
|
||||
infoLabel.attributedText = "status.reblogged-by".localizedBolding(
|
||||
displayName: viewModel.rebloggedByDisplayName,
|
||||
emoji: viewModel.rebloggedByDisplayNameEmoji,
|
||||
emojis: viewModel.rebloggedByDisplayNameEmojis,
|
||||
label: infoLabel)
|
||||
infoIcon.image = UIImage(
|
||||
systemName: "arrow.2.squarepath",
|
||||
|
@ -320,7 +320,7 @@ private extension StatusView {
|
|||
infoIcon.isHidden = true
|
||||
}
|
||||
|
||||
mutableDisplayName.insert(emoji: viewModel.displayNameEmoji, view: displayNameLabel)
|
||||
mutableDisplayName.insert(emojis: viewModel.displayNameEmojis, view: displayNameLabel)
|
||||
mutableDisplayName.resizeAttachments(toLineHeight: displayNameLabel.font.lineHeight)
|
||||
displayNameLabel.attributedText = mutableDisplayName
|
||||
|
||||
|
|
Loading…
Reference in a new issue