Refactoring

This commit is contained in:
Justin Mazzocchi 2020-10-05 17:33:58 -07:00
parent ce09e8fd7b
commit d80988e6e3
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
5 changed files with 21 additions and 22 deletions

View file

@ -26,3 +26,7 @@ public extension CollectionItem {
}
}
}
public extension CollectionItem.StatusConfiguration {
static let `default` = Self()
}

View file

@ -103,10 +103,7 @@ extension CollectionItemsViewModel: CollectionViewModel {
cache(viewModel: viewModel, forItem: item)
}
viewModel.isContextParent = configuration.isContextParent
viewModel.isPinned = configuration.isPinned
viewModel.isReplyInContext = configuration.isReplyInContext
viewModel.hasReplyFollowing = configuration.hasReplyFollowing
viewModel.configuration = configuration
return viewModel
case let .loadMore(loadMore):

View file

@ -17,10 +17,7 @@ public struct StatusViewModel: CollectionItemViewModel {
public let attachmentViewModels: [AttachmentViewModel]
public let pollOptionTitles: [String]
public let pollEmoji: [Emoji]
public var isPinned = false
public var isContextParent = false
public var isReplyInContext = false
public var hasReplyFollowing = false
public var configuration = CollectionItem.StatusConfiguration.default
public var sensitiveContentToggled = false
public let events: AnyPublisher<AnyPublisher<CollectionItemEvent, Error>, Never>

View file

@ -15,7 +15,7 @@ class StatusListCell: UITableViewCell {
override func layoutSubviews() {
super.layoutSubviews()
if viewModel?.hasReplyFollowing ?? false {
if viewModel?.configuration.hasReplyFollowing ?? false {
separatorInset.right = .greatestFiniteMagnitude
} else {
separatorInset.right = UIDevice.current.userInterfaceIdiom == .phone ? 0 : layoutMargins.right

View file

@ -188,20 +188,21 @@ private extension StatusView {
let mutableContent = NSMutableAttributedString(attributedString: viewModel.content)
let mutableDisplayName = NSMutableAttributedString(string: viewModel.displayName)
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
avatarReplyContextView.isHidden = viewModel.isContextParent
nameDateView.isHidden = viewModel.isContextParent
contextParentAvatarNameView.isHidden = !viewModel.isContextParent
actionButtonsView.isHidden = viewModel.isContextParent
contextParentItems.isHidden = !viewModel.isContextParent
contentTextView.shouldFallthrough = !viewModel.configuration.isContextParent
avatarReplyContextView.isHidden = viewModel.configuration.isContextParent
nameDateView.isHidden = viewModel.configuration.isContextParent
contextParentAvatarNameView.isHidden = !viewModel.configuration.isContextParent
actionButtonsView.isHidden = viewModel.configuration.isContextParent
contextParentItems.isHidden = !viewModel.configuration.isContextParent
let avatarImageView: UIImageView
let displayNameLabel: UILabel
let accountLabel: UILabel
if viewModel.isContextParent {
if viewModel.configuration.isContextParent {
avatarImageView = contextParentAvatarImageView
displayNameLabel = contextParentDisplayNameLabel
accountLabel = contextParentAccountLabel
@ -283,7 +284,7 @@ private extension StatusView {
withConfiguration: UIImage.SymbolConfiguration(scale: .small))
metaLabel.isHidden = false
metaIcon.isHidden = false
} else if viewModel.isPinned {
} else if viewModel.configuration.isPinned {
metaLabel.text = NSLocalizedString("status.pinned-post", comment: "")
metaIcon.image = UIImage(
systemName: "pin",
@ -304,9 +305,9 @@ private extension StatusView {
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
@ -314,7 +315,7 @@ private extension StatusView {
let reblogColor: UIColor = reblogged ? .systemGreen : .secondaryLabel
let reblogButton: UIButton
if statusConfiguration.viewModel.isContextParent {
if statusConfiguration.viewModel.configuration.isContextParent {
reblogButton = contextParentReblogButton
} else {
reblogButton = self.reblogButton
@ -329,7 +330,7 @@ private extension StatusView {
let favoriteButton: UIButton
let scale: UIImage.SymbolScale
if statusConfiguration.viewModel.isContextParent {
if statusConfiguration.viewModel.configuration.isContextParent {
favoriteButton = contextParentFavoriteButton
scale = .medium
} else {