diff --git a/WordPress/Classes/ViewRelated/Reader/ReaderHelpers.swift b/WordPress/Classes/ViewRelated/Reader/ReaderHelpers.swift index d43ea891f6b4..9eb5531f24f6 100644 --- a/WordPress/Classes/ViewRelated/Reader/ReaderHelpers.swift +++ b/WordPress/Classes/ViewRelated/Reader/ReaderHelpers.swift @@ -22,6 +22,8 @@ extension NSNotification.Name { static let ReaderUserBlockingWillBegin = NSNotification.Name(rawValue: "ReaderUserBlockingWillBegin") // Sent when the user blocking request is complete static let ReaderUserBlockingDidEnd = NSNotification.Name(rawValue: "ReaderUserBlockingDidEnd") + // Sent when the filter from a feed is updated + static let ReaderFilterUpdated = NSNotification.Name(rawValue: "ReaderFilterUpdated") } struct ReaderNotificationKeys { diff --git a/WordPress/Classes/ViewRelated/Reader/ReaderPost+Display.swift b/WordPress/Classes/ViewRelated/Reader/ReaderPost+Display.swift index fc4a935209f8..5dc74feb13eb 100644 --- a/WordPress/Classes/ViewRelated/Reader/ReaderPost+Display.swift +++ b/WordPress/Classes/ViewRelated/Reader/ReaderPost+Display.swift @@ -24,42 +24,8 @@ extension ReaderPost { } func summaryForDisplay(isPad: Bool = false) -> String? { - if featuredImageURLForDisplay() == nil || isPad { - let content = contentForDisplay()? - .stringByDecodingXMLCharacters() - .replacingOccurrences(of: "
", with: "\n") - .strippingHTML() - .replacingOccurrences(of: "^\n+", with: "", options: .regularExpression) - .replacingOccurrences(of: "\n{2,}", with: "\n\n", options: .regularExpression) - .trim() - if let content { - let maxContentLength = isPad ? 4000 : 500 - return String(content.prefix(maxContentLength)) - } - } - return contentPreviewForDisplay() - } - - func countsForDisplay(isLoggedIn: Bool) -> String? { - let likes: String? = { - guard isLikesEnabled(isLoggedIn: isLoggedIn), - let count = likeCount()?.intValue, - count > 0 else { - return nil - } - return WPStyleGuide.likeCountForDisplay(count) - }() - let comments: String? = { - guard isCommentsEnabled, - let count = commentCount()?.intValue, - count > 0 else { - return nil - } - return WPStyleGuide.commentCountForDisplay(count) - }() - - let countStrings = [likes, comments].compactMap { $0 } - return countStrings.count > 0 ? countStrings.joined(separator: " • ") : nil + return contentPreviewForDisplay()? + .replacingOccurrences(of: "\n{2,}", with: "\n\n", options: .regularExpression) } } diff --git a/WordPress/Classes/ViewRelated/Reader/ReaderTagCardCell.swift b/WordPress/Classes/ViewRelated/Reader/ReaderTagCardCell.swift index d84b1d2b3c2c..bc8ca24c7bab 100644 --- a/WordPress/Classes/ViewRelated/Reader/ReaderTagCardCell.swift +++ b/WordPress/Classes/ViewRelated/Reader/ReaderTagCardCell.swift @@ -84,10 +84,10 @@ class ReaderTagCardCell: UITableViewCell { } struct Constants { - static let phoneDefaultCellSize = CGSize(width: 240, height: 297) - static let phoneLargeCellSize = CGSize(width: 240, height: 500) - static let padDefaultCellSize = CGSize(width: 480, height: 600) - static let padLargeCellSize = CGSize(width: 480, height: 900) + static let phoneDefaultCellSize = CGSize(width: 300, height: 150) + static let phoneLargeCellSize = CGSize(width: 300, height: 300) + static let padDefaultCellSize = CGSize(width: 480, height: 206) + static let padLargeCellSize = CGSize(width: 480, height: 400) } } diff --git a/WordPress/Classes/ViewRelated/Reader/ReaderTagCardCell.xib b/WordPress/Classes/ViewRelated/Reader/ReaderTagCardCell.xib index 210c8fdec766..6c00eeb63be1 100644 --- a/WordPress/Classes/ViewRelated/Reader/ReaderTagCardCell.xib +++ b/WordPress/Classes/ViewRelated/Reader/ReaderTagCardCell.xib @@ -1,6 +1,6 @@ - + @@ -12,11 +12,11 @@ - + - + - + + + - - + + diff --git a/WordPress/Classes/ViewRelated/Reader/ReaderTagCardCellViewModel.swift b/WordPress/Classes/ViewRelated/Reader/ReaderTagCardCellViewModel.swift index 8d6c5951c02b..518e081d15ca 100644 --- a/WordPress/Classes/ViewRelated/Reader/ReaderTagCardCellViewModel.swift +++ b/WordPress/Classes/ViewRelated/Reader/ReaderTagCardCellViewModel.swift @@ -36,6 +36,7 @@ class ReaderTagCardCellViewModel: NSObject { let slug: String weak var viewDelegate: ReaderTagCardCellViewModelDelegate? = nil + private let tag: ReaderAbstractTopic private let coreDataStack: CoreDataStackSwift private weak var parentViewController: UIViewController? private weak var collectionView: UICollectionView? @@ -78,6 +79,7 @@ class ReaderTagCardCellViewModel: NSObject { cellSize: @escaping @autoclosure () -> CGSize?) { self.parentViewController = parent self.slug = tag.slug + self.tag = tag self.collectionView = collectionView self.isLoggedIn = isLoggedIn self.viewDelegate = viewDelegate @@ -115,11 +117,18 @@ class ReaderTagCardCellViewModel: NSObject { } func onTagButtonTapped(source: TagButtonSource) { - let controller = ReaderStreamViewController.controllerWithTagSlug(slug) - controller.statSource = .tagsFeed + switch source { + case .footer: + let controller = ReaderStreamViewController.controllerWithTagSlug(slug) + controller.statSource = .tagsFeed + parentViewController?.navigationController?.pushViewController(controller, animated: true) + case .header: + NotificationCenter.default.post(name: .ReaderFilterUpdated, + object: nil, + userInfo: [ReaderNotificationKeys.topic: tag]) + } WPAnalytics.track(source.event) - parentViewController?.navigationController?.pushViewController(controller, animated: true) } struct Constants { diff --git a/WordPress/Classes/ViewRelated/Reader/ReaderTagCardEmptyCell.swift b/WordPress/Classes/ViewRelated/Reader/ReaderTagCardEmptyCell.swift index 3a9516e8f6c2..699ab8707ecf 100644 --- a/WordPress/Classes/ViewRelated/Reader/ReaderTagCardEmptyCell.swift +++ b/WordPress/Classes/ViewRelated/Reader/ReaderTagCardEmptyCell.swift @@ -55,7 +55,7 @@ private struct ReaderTagCardEmptyCellView: View { private var iconLength = 32.0 var body: some View { - VStack(spacing: .DS.Padding.double) { + VStack(spacing: .DS.Padding.single) { Image(systemName: "wifi.slash") .resizable() .frame(width: iconLength, height: iconLength) @@ -64,7 +64,7 @@ private struct ReaderTagCardEmptyCellView: View { // added to double the padding between the Image and the VStack. Spacer().frame(height: .hairlineBorderWidth) - VStack(spacing: .DS.Padding.single) { + VStack(spacing: .DS.Padding.half) { Text(Strings.title) .font(.callout) .fontWeight(.semibold) @@ -73,6 +73,7 @@ private struct ReaderTagCardEmptyCellView: View { .font(.callout) .foregroundStyle(.secondary) .multilineTextAlignment(.center) + .fixedSize(horizontal: false, vertical: true) } Button { diff --git a/WordPress/Classes/ViewRelated/Reader/ReaderTagCell.swift b/WordPress/Classes/ViewRelated/Reader/ReaderTagCell.swift index 59e55baf4d97..1465d134b7a2 100644 --- a/WordPress/Classes/ViewRelated/Reader/ReaderTagCell.swift +++ b/WordPress/Classes/ViewRelated/Reader/ReaderTagCell.swift @@ -10,12 +10,14 @@ class ReaderTagCell: UICollectionViewCell { @IBOutlet private weak var postDateLabel: UILabel! @IBOutlet private weak var titleLabel: UILabel! @IBOutlet private weak var summaryLabel: UILabel! + @IBOutlet private weak var featuredImageViewContainer: UIView! @IBOutlet private weak var featuredImageView: CachedAnimatedImageView! - @IBOutlet private weak var countsLabel: UILabel! @IBOutlet private weak var likeButton: UIButton! @IBOutlet private weak var menuButton: UIButton! @IBOutlet weak var spacerView: UIView! + @IBOutlet weak var titleSpacerView: UIView! @IBOutlet weak var countsLabelSpacerView: UIView! + @IBOutlet private var contentBoundsConstraints: [NSLayoutConstraint]! private lazy var imageLoader = ImageLoader(imageView: featuredImageView) private var viewModel: ReaderTagCellViewModel? @@ -28,13 +30,17 @@ class ReaderTagCell: UICollectionViewCell { headerStackView.addGestureRecognizer(tapGesture) spacerView.isGhostableDisabled = true + titleSpacerView.isGhostableDisabled = true countsLabelSpacerView.isGhostableDisabled = true + + updateContentConstraints() } override func prepareForReuse() { super.prepareForReuse() imageLoader.prepareForReuse() resetHiddenViews() + updateContentConstraints() } func configure(parent: UIViewController?, post: ReaderPost, isLoggedIn: Bool) { @@ -80,8 +86,6 @@ private extension ReaderTagCell { postDateLabel.textColor = .secondaryLabel titleLabel.font = WPStyleGuide.fontForTextStyle(.headline, fontWeight: .semibold) summaryLabel.font = WPStyleGuide.fontForTextStyle(.footnote) - countsLabel.font = WPStyleGuide.fontForTextStyle(.footnote) - countsLabel.textColor = .secondaryLabel likeButton.tintColor = .secondaryLabel likeButton.titleLabel?.font = WPStyleGuide.fontForTextStyle(.footnote) menuButton.tintColor = .secondaryLabel @@ -90,6 +94,7 @@ private extension ReaderTagCell { func loadFeaturedImage(with post: ReaderPost) { guard let url = post.featuredImageURLForDisplay() else { + featuredImageViewContainer.isHidden = true featuredImageView.isHidden = true return } @@ -105,8 +110,8 @@ private extension ReaderTagCell { siteLabel.isHidden = false titleLabel.isHidden = false summaryLabel.isHidden = false + featuredImageViewContainer.isHidden = false featuredImageView.isHidden = false - countsLabel.isHidden = false likeButton.isHidden = false } @@ -124,29 +129,30 @@ private extension ReaderTagCell { let postDate = post.shortDateForDisplay() let postTitle = post.titleForDisplay() let postSummary = post.summaryForDisplay(isPad: traitCollection.userInterfaceIdiom == .pad) - let postCounts = post.countsForDisplay(isLoggedIn: isLoggedIn) siteLabel.text = blogName postDateLabel.text = postDate titleLabel.text = postTitle summaryLabel.text = postSummary - countsLabel.text = postCounts siteLabel.isHidden = blogName == nil postDateLabel.isHidden = postDate == nil titleLabel.isHidden = postTitle == nil summaryLabel.isHidden = postSummary == nil - countsLabel.isHidden = postCounts == nil headerStackView.isAccessibilityElement = true headerStackView.accessibilityLabel = [blogName, postDate].compactMap { $0 }.joined(separator: ", ") headerStackView.accessibilityHint = AccessibilityConstants.siteStackViewHint headerStackView.accessibilityTraits = .button - countsLabel.accessibilityLabel = postCounts?.replacingOccurrences(of: " • ", with: ", ") menuButton.accessibilityLabel = AccessibilityConstants.menuButtonLabel menuButton.accessibilityHint = AccessibilityConstants.menuButtonHint } + func updateContentConstraints() { + let isExtraLargeCategory = traitCollection.preferredContentSizeCategory >= .extraLarge + contentBoundsConstraints.forEach { $0.isActive = !isExtraLargeCategory } + } + } extension ReaderTagCell: GhostableView { diff --git a/WordPress/Classes/ViewRelated/Reader/ReaderTagCell.xib b/WordPress/Classes/ViewRelated/Reader/ReaderTagCell.xib index fe227266f4a1..66227cbdbca8 100644 --- a/WordPress/Classes/ViewRelated/Reader/ReaderTagCell.xib +++ b/WordPress/Classes/ViewRelated/Reader/ReaderTagCell.xib @@ -1,6 +1,6 @@ - + @@ -12,23 +12,23 @@ - + - - + + - + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + - - - - - + - + - +