From 0b558c877f6c1df508bf5a6abe6f4a81e9f5de7e Mon Sep 17 00:00:00 2001 From: Giorgio Ruscigno Date: Mon, 23 May 2022 17:16:48 -0500 Subject: [PATCH 1/8] Update CategorySection and conforming types, add caption property --- .../Layout Picker/CategorySectionTableViewCell.swift | 1 + .../Layout Picker/GutenbergLayoutPickerViewController.swift | 2 ++ .../Site Creation/Design Selection/SiteDesignSection.swift | 4 +++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/CategorySectionTableViewCell.swift b/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/CategorySectionTableViewCell.swift index f8e415c59fe0..aa44782f5797 100644 --- a/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/CategorySectionTableViewCell.swift +++ b/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/CategorySectionTableViewCell.swift @@ -17,6 +17,7 @@ protocol Thumbnail { protocol CategorySection { var categorySlug: String { get } + var caption: String? { get } var title: String { get } var emoji: String? { get } var description: String? { get } diff --git a/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/GutenbergLayoutPickerViewController.swift b/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/GutenbergLayoutPickerViewController.swift index 974713b0b5fc..2d65fc455ebe 100644 --- a/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/GutenbergLayoutPickerViewController.swift +++ b/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/GutenbergLayoutPickerViewController.swift @@ -9,6 +9,8 @@ extension PageTemplateLayout: Thumbnail { } class GutenbergLayoutSection: CategorySection { + var caption: String? + var section: PageTemplateCategory var layouts: [PageTemplateLayout] var scrollOffset: CGPoint diff --git a/WordPress/Classes/ViewRelated/Site Creation/Design Selection/SiteDesignSection.swift b/WordPress/Classes/ViewRelated/Site Creation/Design Selection/SiteDesignSection.swift index f245e47f4d3b..99c7f9d8f135 100644 --- a/WordPress/Classes/ViewRelated/Site Creation/Design Selection/SiteDesignSection.swift +++ b/WordPress/Classes/ViewRelated/Site Creation/Design Selection/SiteDesignSection.swift @@ -4,6 +4,7 @@ struct SiteDesignSection: CategorySection { var designs: [RemoteSiteDesign] var thumbnailSize: CGSize + var caption: String? var categorySlug: String var title: String var emoji: String? @@ -13,13 +14,14 @@ struct SiteDesignSection: CategorySection { } extension SiteDesignSection { - init(category: RemoteSiteDesignCategory, designs: [RemoteSiteDesign], thumbnailSize: CGSize) { + init(category: RemoteSiteDesignCategory, designs: [RemoteSiteDesign], thumbnailSize: CGSize, caption: String? = nil) { self.designs = designs self.thumbnailSize = thumbnailSize self.categorySlug = category.slug self.title = category.title self.emoji = category.emoji self.description = category.description + self.caption = caption } } From 0c7286d58129a0f2f7652553218557cad9f4c989 Mon Sep 17 00:00:00 2001 From: Giorgio Ruscigno Date: Mon, 23 May 2022 17:17:28 -0500 Subject: [PATCH 2/8] Update CategorySectionTableViewCell.xib, add caption label --- .../CategorySectionTableViewCell.xib | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/CategorySectionTableViewCell.xib b/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/CategorySectionTableViewCell.xib index 0654da40fdb6..b9d196274157 100644 --- a/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/CategorySectionTableViewCell.xib +++ b/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/CategorySectionTableViewCell.xib @@ -14,12 +14,12 @@ - + - + @@ -35,37 +35,52 @@ - + + + + + + + - - - + + + + - + + + + From a44835c3a5bcb6d121ce096902b89fd1317f5984 Mon Sep 17 00:00:00 2001 From: Giorgio Ruscigno Date: Mon, 23 May 2022 17:19:10 -0500 Subject: [PATCH 3/8] Update CategorySectionTableViewCell, add property categoryCaptionLabel and related configuration methods --- .../CategorySectionTableViewCell.swift | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/CategorySectionTableViewCell.swift b/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/CategorySectionTableViewCell.swift index aa44782f5797..8570bf799187 100644 --- a/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/CategorySectionTableViewCell.swift +++ b/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/CategorySectionTableViewCell.swift @@ -36,6 +36,7 @@ class CategorySectionTableViewCell: UITableViewCell { @IBOutlet weak var categoryTitle: UILabel! @IBOutlet weak var collectionView: UICollectionView! @IBOutlet weak var collectionViewHeight: NSLayoutConstraint! + @IBOutlet weak var categoryCaptionLabel: UILabel! weak var delegate: CategorySectionTableViewCellDelegate? @@ -64,6 +65,22 @@ class CategorySectionTableViewCell: UITableViewCell { } } + var categoryCaption: String? { + didSet { + setCaption() + } + } + + private func setCaption() { + guard let caption = categoryCaption else { + categoryCaptionLabel.isHidden = true + return + } + + categoryCaptionLabel.isHidden = false + categoryCaptionLabel.setText(caption) + } + var isGhostCell: Bool = false var ghostThumbnailSize: CGSize = defaultThumbnailSize { didSet { @@ -79,6 +96,7 @@ class CategorySectionTableViewCell: UITableViewCell { super.prepareForReuse() collectionView.contentOffset.x = 0 categoryTitleFont = nil + categoryCaption = nil } override func awakeFromNib() { @@ -87,6 +105,8 @@ class CategorySectionTableViewCell: UITableViewCell { categoryTitle.font = categoryTitleFont ?? WPStyleGuide.serifFontForTextStyle(UIFont.TextStyle.headline, fontWeight: .semibold) categoryTitle.layer.masksToBounds = true categoryTitle.layer.cornerRadius = 4 + categoryCaptionLabel.font = WPStyleGuide.fontForTextStyle(.subheadline, fontWeight: .semibold) + setCaption() } private func deselectItem(_ indexPath: IndexPath) { From c1243a9349abf2a28fa51f6cbd418591319fa796 Mon Sep 17 00:00:00 2001 From: Giorgio Ruscigno Date: Mon, 23 May 2022 17:21:22 -0500 Subject: [PATCH 4/8] Update SiteDesignContentCollectionViewController, configure category caption in tableView(_:cellForRowAt:) --- .../SiteDesignContentCollectionViewController.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/Classes/ViewRelated/Site Creation/Design Selection/SiteDesignContentCollectionViewController.swift b/WordPress/Classes/ViewRelated/Site Creation/Design Selection/SiteDesignContentCollectionViewController.swift index 6b554f5b1fe5..a745a7c00178 100644 --- a/WordPress/Classes/ViewRelated/Site Creation/Design Selection/SiteDesignContentCollectionViewController.swift +++ b/WordPress/Classes/ViewRelated/Site Creation/Design Selection/SiteDesignContentCollectionViewController.swift @@ -289,6 +289,7 @@ extension SiteDesignContentCollectionViewController: UITableViewDataSource { cell.clipsToBounds = false cell.collectionView.allowsSelection = !isLoading cell.categoryTitleFont = WPStyleGuide.serifFontForTextStyle(.title2, fontWeight: .semibold) + cell.categoryCaption = sections[safe: indexPath.row]?.caption return cell } } From 6e9f43efb2101674497f22555053d4db4997a535 Mon Sep 17 00:00:00 2001 From: Giorgio Ruscigno Date: Mon, 23 May 2022 17:22:48 -0500 Subject: [PATCH 5/8] Update SiteDesignSectionLoader, assign section caption if it's a recommended section * also reorganized strings in enum TextContent --- .../SiteDesignSectionLoader.swift | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Site Creation/Design Selection/SiteDesignSectionLoader.swift b/WordPress/Classes/ViewRelated/Site Creation/Design Selection/SiteDesignSectionLoader.swift index f91f47bd50c0..8c95fdb42e15 100644 --- a/WordPress/Classes/ViewRelated/Site Creation/Design Selection/SiteDesignSectionLoader.swift +++ b/WordPress/Classes/ViewRelated/Site Creation/Design Selection/SiteDesignSectionLoader.swift @@ -2,7 +2,6 @@ import Foundation import WordPressKit struct SiteDesignSectionLoader { - static let recommendedTitle = NSLocalizedString("Best for %@", comment: "Title for a section of recommended site designs. The %@ will be replaced with the related site intent topic, such as Food or Blogging.") static func fetchSections(vertical: SiteIntentVertical?, completion: @escaping (Result<[SiteDesignSection], Error>) -> Void) { typealias TemplateGroup = SiteDesignRequest.TemplateGroup @@ -48,8 +47,9 @@ struct SiteDesignSectionLoader { return SiteDesignSection( designs: designsForVertical, thumbnailSize: SiteDesignCategoryThumbnailSize.recommended.value, + caption: TextContent.recommendedCaption, categorySlug: "recommended_" + vertical.slug, - title: String(format: recommendedTitle, vertical.localizedTitle) + title: String(format: TextContent.recommendedTitle, vertical.localizedTitle) ) } @@ -81,8 +81,9 @@ struct SiteDesignSectionLoader { if var recommendedFallback = categorySections.first(where: { $0.categorySlug.lowercased() == "blog" }) { // Recommended designs for the vertical weren't found, so we used the fallback category - recommendedFallback.title = String(format: recommendedTitle, "Blogging") + recommendedFallback.title = String(format: TextContent.recommendedTitle, "Blogging") recommendedFallback.thumbnailSize = SiteDesignCategoryThumbnailSize.recommended.value + recommendedFallback.caption = TextContent.recommendedCaption return [recommendedFallback] + categorySections.filter { $0 != recommendedFallback } } @@ -90,3 +91,13 @@ struct SiteDesignSectionLoader { return categorySections } } + +private extension SiteDesignSectionLoader { + + enum TextContent { + static let recommendedTitle = NSLocalizedString("Best for %@", + comment: "Title for a section of recommended site designs. The %@ will be replaced with the related site intent topic, such as Food or Blogging.") + static let recommendedCaption = NSLocalizedString("PICKED FOR YOU", + comment: "Caption for the recommended sections in site designs.") + } +} From b1794acd17f9c8bd9d4b011460702ca348b8f9e2 Mon Sep 17 00:00:00 2001 From: Giorgio Ruscigno Date: Tue, 24 May 2022 12:26:09 -0500 Subject: [PATCH 6/8] Update SiteDesignContentCollectionViewController, minor refactor --- .../SiteDesignContentCollectionViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/Classes/ViewRelated/Site Creation/Design Selection/SiteDesignContentCollectionViewController.swift b/WordPress/Classes/ViewRelated/Site Creation/Design Selection/SiteDesignContentCollectionViewController.swift index a745a7c00178..6678799409f7 100644 --- a/WordPress/Classes/ViewRelated/Site Creation/Design Selection/SiteDesignContentCollectionViewController.swift +++ b/WordPress/Classes/ViewRelated/Site Creation/Design Selection/SiteDesignContentCollectionViewController.swift @@ -289,7 +289,7 @@ extension SiteDesignContentCollectionViewController: UITableViewDataSource { cell.clipsToBounds = false cell.collectionView.allowsSelection = !isLoading cell.categoryTitleFont = WPStyleGuide.serifFontForTextStyle(.title2, fontWeight: .semibold) - cell.categoryCaption = sections[safe: indexPath.row]?.caption + cell.categoryCaption = cell.section?.caption return cell } } From 31d0bae95cc5404ea3dacd3fd74af055f607ad6c Mon Sep 17 00:00:00 2001 From: Giorgio Ruscigno Date: Tue, 24 May 2022 17:09:39 -0500 Subject: [PATCH 7/8] Update CategorySectionTableViewCell, refactor method setCaption() to read the caption from the section property --- .../Layout Picker/CategorySectionTableViewCell.swift | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/CategorySectionTableViewCell.swift b/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/CategorySectionTableViewCell.swift index 8570bf799187..0660d17488f5 100644 --- a/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/CategorySectionTableViewCell.swift +++ b/WordPress/Classes/ViewRelated/Gutenberg/Layout Picker/CategorySectionTableViewCell.swift @@ -51,6 +51,7 @@ class CategorySectionTableViewCell: UITableViewCell { thumbnails = section?.thumbnails ?? [] categoryTitle.text = section?.title collectionView.contentOffset = section?.scrollOffset ?? .zero + setCaption() if let section = section { collectionViewHeight.constant = section.thumbnailSize.height @@ -65,14 +66,8 @@ class CategorySectionTableViewCell: UITableViewCell { } } - var categoryCaption: String? { - didSet { - setCaption() - } - } - private func setCaption() { - guard let caption = categoryCaption else { + guard let caption = section?.caption else { categoryCaptionLabel.isHidden = true return } @@ -96,7 +91,6 @@ class CategorySectionTableViewCell: UITableViewCell { super.prepareForReuse() collectionView.contentOffset.x = 0 categoryTitleFont = nil - categoryCaption = nil } override func awakeFromNib() { From 760d80fb73c808d597cfae143e66f79b896046c5 Mon Sep 17 00:00:00 2001 From: Giorgio Ruscigno Date: Tue, 24 May 2022 17:10:59 -0500 Subject: [PATCH 8/8] Update SiteDesignContentCollectionViewController, refactor tableview(_:cellForRowAt:), remove unnecessary call to set the cell caption --- .../SiteDesignContentCollectionViewController.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/Classes/ViewRelated/Site Creation/Design Selection/SiteDesignContentCollectionViewController.swift b/WordPress/Classes/ViewRelated/Site Creation/Design Selection/SiteDesignContentCollectionViewController.swift index 6678799409f7..6b554f5b1fe5 100644 --- a/WordPress/Classes/ViewRelated/Site Creation/Design Selection/SiteDesignContentCollectionViewController.swift +++ b/WordPress/Classes/ViewRelated/Site Creation/Design Selection/SiteDesignContentCollectionViewController.swift @@ -289,7 +289,6 @@ extension SiteDesignContentCollectionViewController: UITableViewDataSource { cell.clipsToBounds = false cell.collectionView.allowsSelection = !isLoading cell.categoryTitleFont = WPStyleGuide.serifFontForTextStyle(.title2, fontWeight: .semibold) - cell.categoryCaption = cell.section?.caption return cell } }