mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-28 19:11:30 +00:00
Refactoring
This commit is contained in:
parent
ce09e8fd7b
commit
d80988e6e3
5 changed files with 21 additions and 22 deletions
|
@ -26,3 +26,7 @@ public extension CollectionItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public extension CollectionItem.StatusConfiguration {
|
||||||
|
static let `default` = Self()
|
||||||
|
}
|
||||||
|
|
|
@ -103,10 +103,7 @@ extension CollectionItemsViewModel: CollectionViewModel {
|
||||||
cache(viewModel: viewModel, forItem: item)
|
cache(viewModel: viewModel, forItem: item)
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.isContextParent = configuration.isContextParent
|
viewModel.configuration = configuration
|
||||||
viewModel.isPinned = configuration.isPinned
|
|
||||||
viewModel.isReplyInContext = configuration.isReplyInContext
|
|
||||||
viewModel.hasReplyFollowing = configuration.hasReplyFollowing
|
|
||||||
|
|
||||||
return viewModel
|
return viewModel
|
||||||
case let .loadMore(loadMore):
|
case let .loadMore(loadMore):
|
||||||
|
|
|
@ -17,10 +17,7 @@ public struct StatusViewModel: CollectionItemViewModel {
|
||||||
public let attachmentViewModels: [AttachmentViewModel]
|
public let attachmentViewModels: [AttachmentViewModel]
|
||||||
public let pollOptionTitles: [String]
|
public let pollOptionTitles: [String]
|
||||||
public let pollEmoji: [Emoji]
|
public let pollEmoji: [Emoji]
|
||||||
public var isPinned = false
|
public var configuration = CollectionItem.StatusConfiguration.default
|
||||||
public var isContextParent = false
|
|
||||||
public var isReplyInContext = false
|
|
||||||
public var hasReplyFollowing = false
|
|
||||||
public var sensitiveContentToggled = false
|
public var sensitiveContentToggled = false
|
||||||
public let events: AnyPublisher<AnyPublisher<CollectionItemEvent, Error>, Never>
|
public let events: AnyPublisher<AnyPublisher<CollectionItemEvent, Error>, Never>
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ class StatusListCell: UITableViewCell {
|
||||||
override func layoutSubviews() {
|
override func layoutSubviews() {
|
||||||
super.layoutSubviews()
|
super.layoutSubviews()
|
||||||
|
|
||||||
if viewModel?.hasReplyFollowing ?? false {
|
if viewModel?.configuration.hasReplyFollowing ?? false {
|
||||||
separatorInset.right = .greatestFiniteMagnitude
|
separatorInset.right = .greatestFiniteMagnitude
|
||||||
} else {
|
} else {
|
||||||
separatorInset.right = UIDevice.current.userInterfaceIdiom == .phone ? 0 : layoutMargins.right
|
separatorInset.right = UIDevice.current.userInterfaceIdiom == .phone ? 0 : layoutMargins.right
|
||||||
|
|
|
@ -188,20 +188,21 @@ private extension StatusView {
|
||||||
let mutableContent = NSMutableAttributedString(attributedString: viewModel.content)
|
let mutableContent = NSMutableAttributedString(attributedString: viewModel.content)
|
||||||
let mutableDisplayName = NSMutableAttributedString(string: viewModel.displayName)
|
let mutableDisplayName = NSMutableAttributedString(string: viewModel.displayName)
|
||||||
let mutableSpoilerText = NSMutableAttributedString(string: viewModel.spoilerText)
|
let mutableSpoilerText = NSMutableAttributedString(string: viewModel.spoilerText)
|
||||||
let contentFont = UIFont.preferredFont(forTextStyle: viewModel.isContextParent ? .title3 : .callout)
|
let contentTextStyle: UIFont.TextStyle = viewModel.configuration.isContextParent ? .title3 : .callout
|
||||||
|
let contentFont = UIFont.preferredFont(forTextStyle: contentTextStyle)
|
||||||
|
|
||||||
contentTextView.shouldFallthrough = !viewModel.isContextParent
|
contentTextView.shouldFallthrough = !viewModel.configuration.isContextParent
|
||||||
avatarReplyContextView.isHidden = viewModel.isContextParent
|
avatarReplyContextView.isHidden = viewModel.configuration.isContextParent
|
||||||
nameDateView.isHidden = viewModel.isContextParent
|
nameDateView.isHidden = viewModel.configuration.isContextParent
|
||||||
contextParentAvatarNameView.isHidden = !viewModel.isContextParent
|
contextParentAvatarNameView.isHidden = !viewModel.configuration.isContextParent
|
||||||
actionButtonsView.isHidden = viewModel.isContextParent
|
actionButtonsView.isHidden = viewModel.configuration.isContextParent
|
||||||
contextParentItems.isHidden = !viewModel.isContextParent
|
contextParentItems.isHidden = !viewModel.configuration.isContextParent
|
||||||
|
|
||||||
let avatarImageView: UIImageView
|
let avatarImageView: UIImageView
|
||||||
let displayNameLabel: UILabel
|
let displayNameLabel: UILabel
|
||||||
let accountLabel: UILabel
|
let accountLabel: UILabel
|
||||||
|
|
||||||
if viewModel.isContextParent {
|
if viewModel.configuration.isContextParent {
|
||||||
avatarImageView = contextParentAvatarImageView
|
avatarImageView = contextParentAvatarImageView
|
||||||
displayNameLabel = contextParentDisplayNameLabel
|
displayNameLabel = contextParentDisplayNameLabel
|
||||||
accountLabel = contextParentAccountLabel
|
accountLabel = contextParentAccountLabel
|
||||||
|
@ -283,7 +284,7 @@ private extension StatusView {
|
||||||
withConfiguration: UIImage.SymbolConfiguration(scale: .small))
|
withConfiguration: UIImage.SymbolConfiguration(scale: .small))
|
||||||
metaLabel.isHidden = false
|
metaLabel.isHidden = false
|
||||||
metaIcon.isHidden = false
|
metaIcon.isHidden = false
|
||||||
} else if viewModel.isPinned {
|
} else if viewModel.configuration.isPinned {
|
||||||
metaLabel.text = NSLocalizedString("status.pinned-post", comment: "")
|
metaLabel.text = NSLocalizedString("status.pinned-post", comment: "")
|
||||||
metaIcon.image = UIImage(
|
metaIcon.image = UIImage(
|
||||||
systemName: "pin",
|
systemName: "pin",
|
||||||
|
@ -304,9 +305,9 @@ private extension StatusView {
|
||||||
|
|
||||||
sensitiveContentView.isHidden = !viewModel.shouldDisplaySensitiveContent
|
sensitiveContentView.isHidden = !viewModel.shouldDisplaySensitiveContent
|
||||||
|
|
||||||
inReplyToView.isHidden = !viewModel.isReplyInContext
|
inReplyToView.isHidden = !viewModel.configuration.isReplyInContext
|
||||||
|
|
||||||
hasReplyFollowingView.isHidden = !viewModel.hasReplyFollowing
|
hasReplyFollowingView.isHidden = !viewModel.configuration.hasReplyFollowing
|
||||||
}
|
}
|
||||||
// swiftlint:enable function_body_length
|
// swiftlint:enable function_body_length
|
||||||
|
|
||||||
|
@ -314,7 +315,7 @@ private extension StatusView {
|
||||||
let reblogColor: UIColor = reblogged ? .systemGreen : .secondaryLabel
|
let reblogColor: UIColor = reblogged ? .systemGreen : .secondaryLabel
|
||||||
let reblogButton: UIButton
|
let reblogButton: UIButton
|
||||||
|
|
||||||
if statusConfiguration.viewModel.isContextParent {
|
if statusConfiguration.viewModel.configuration.isContextParent {
|
||||||
reblogButton = contextParentReblogButton
|
reblogButton = contextParentReblogButton
|
||||||
} else {
|
} else {
|
||||||
reblogButton = self.reblogButton
|
reblogButton = self.reblogButton
|
||||||
|
@ -329,7 +330,7 @@ private extension StatusView {
|
||||||
let favoriteButton: UIButton
|
let favoriteButton: UIButton
|
||||||
let scale: UIImage.SymbolScale
|
let scale: UIImage.SymbolScale
|
||||||
|
|
||||||
if statusConfiguration.viewModel.isContextParent {
|
if statusConfiguration.viewModel.configuration.isContextParent {
|
||||||
favoriteButton = contextParentFavoriteButton
|
favoriteButton = contextParentFavoriteButton
|
||||||
scale = .medium
|
scale = .medium
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue