From 93859ea8a8c5ea8d8f2879f686fef5791c4328c3 Mon Sep 17 00:00:00 2001 From: Momo Ozawa Date: Tue, 17 Oct 2023 17:14:55 +0100 Subject: [PATCH 1/4] remove cell size switcher --- .../Post/PostListViewController.swift | 96 +------------------ .../Post/RestorePostTableViewCell.swift | 13 --- 2 files changed, 1 insertion(+), 108 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Post/PostListViewController.swift b/WordPress/Classes/ViewRelated/Post/PostListViewController.swift index e4463cc97f3b..6bf771bd116b 100644 --- a/WordPress/Classes/ViewRelated/Post/PostListViewController.swift +++ b/WordPress/Classes/ViewRelated/Post/PostListViewController.swift @@ -6,17 +6,10 @@ import UIKit class PostListViewController: AbstractPostListViewController, UIViewControllerRestoration, InteractivePostViewDelegate { - private let postCompactCellIdentifier = "PostCompactCellIdentifier" - private let postCardTextCellIdentifier = "PostCardTextCellIdentifier" private let postCardRestoreCellIdentifier = "PostCardRestoreCellIdentifier" - private let postCompactCellNibName = "PostCompactCell" - private let postCardTextCellNibName = "PostCardCell" private let postCardRestoreCellNibName = "RestorePostTableViewCell" private let statsStoryboardName = "SiteStats" private let currentPostListStatusFilterKey = "CurrentPostListStatusFilterKey" - private var postCellIdentifier: String { - return isCompact ? postCompactCellIdentifier : postCardTextCellIdentifier - } static private let postsViewControllerRestorationKey = "PostsViewControllerRestorationKey" @@ -25,8 +18,6 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe private let postCardEstimatedRowHeight = CGFloat(300.0) private let postListHeightForFooterView = CGFloat(50.0) - private var database: UserPersistentRepository = UserPersistentStoreFactory.instance() - private lazy var _tableViewHandler: PostListTableViewHandler = { let tableViewHandler = PostListTableViewHandler(tableView: tableView) tableViewHandler.cacheRowHeights = false @@ -43,29 +34,14 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe } } - private var postViewIcon: UIImage? { - return isCompact ? UIImage(named: "icon-post-view-card") : .gridicon(.listUnordered) - } - private lazy var postActionSheet: PostActionSheet = { return PostActionSheet(viewController: self, interactivePostViewDelegate: self) }() - private lazy var postsViewButtonItem: UIBarButtonItem = { - return UIBarButtonItem(image: postViewIcon, style: .done, target: self, action: #selector(togglePostsView)) - }() - private var showingJustMyPosts: Bool { return filterSettings.currentPostAuthorFilter() == .mine } - private var isCompact: Bool = false { - didSet { - database.set(isCompact, forKey: Constants.exhibitionModeKey) - showCompactOrDefault() - } - } - /// If set, when the post list appear it will show the tab for this status var initialFilterWithPostStatus: BasePost.Status? @@ -123,10 +99,6 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe title = NSLocalizedString("Posts", comment: "Title of the screen showing the list of posts for a blog.") - updateGhostableTableViewOptions() - - configureNavigationButtons() - configureInitialFilterIfNeeded() listenForAppComingToForeground() @@ -155,12 +127,6 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe } } - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - - configureCompactOrDefault() - } - override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { super.traitCollectionDidChange(previousTraitCollection) toggleCreateButton() @@ -176,47 +142,12 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe } } - func configureNavigationButtons() { - // TODO: Remove - // navigationItem.rightBarButtonItems = [postsViewButtonItem] - } - - @objc func togglePostsView() { - isCompact.toggle() - - WPAppAnalytics.track(.postListToggleButtonPressed, withProperties: ["mode": isCompact ? Constants.compact: Constants.card]) - } - // MARK: - Configuration override func heightForFooterView() -> CGFloat { return postListHeightForFooterView } - override func selectedFilterDidChange(_ filterBar: FilterTabBar) { - updateGhostableTableViewOptions() - super.selectedFilterDidChange(filterBar) - } - - override func refresh(_ sender: AnyObject) { - updateGhostableTableViewOptions() - super.refresh(sender) - } - - /// Update the `GhostOptions` to correctly show compact or default cells - private func updateGhostableTableViewOptions() { - let ghostOptions = GhostOptions(displaysSectionHeader: false, reuseIdentifier: postCellIdentifier, rowsPerSection: [50]) - let style = GhostStyle(beatDuration: GhostStyle.Defaults.beatDuration, - beatStartColor: .placeholderElement, - beatEndColor: .placeholderElementFaded) - ghostableTableView.removeGhostContent() - ghostableTableView.displayGhostContent(options: ghostOptions, style: style) - } - - private func configureCompactOrDefault() { - isCompact = database.object(forKey: Constants.exhibitionModeKey) as? Bool ?? false - } - override func configureTableView() { tableView.accessibilityIdentifier = "PostsTable" tableView.separatorStyle = .none @@ -227,11 +158,6 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe let bundle = Bundle.main // Register the cells - let postCardTextCellNib = UINib(nibName: postCardTextCellNibName, bundle: bundle) - tableView.register(postCardTextCellNib, forCellReuseIdentifier: postCardTextCellIdentifier) - - let postCompactCellNib = UINib(nibName: postCompactCellNibName, bundle: bundle) - tableView.register(postCompactCellNib, forCellReuseIdentifier: postCompactCellIdentifier) let postCardRestoreCellNib = UINib(nibName: postCardRestoreCellNibName, bundle: bundle) tableView.register(postCardRestoreCellNib, forCellReuseIdentifier: postCardRestoreCellIdentifier) @@ -244,26 +170,6 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe super.configureGhostableTableView() ghostingEnabled = true - - // Register the cells - let postCardTextCellNib = UINib(nibName: postCardTextCellNibName, bundle: Bundle.main) - ghostableTableView.register(postCardTextCellNib, forCellReuseIdentifier: postCardTextCellIdentifier) - - let postCompactCellNib = UINib(nibName: postCompactCellNibName, bundle: Bundle.main) - ghostableTableView.register(postCompactCellNib, forCellReuseIdentifier: postCompactCellIdentifier) - } - - func showCompactOrDefault() { - updateGhostableTableViewOptions() - - postsViewButtonItem.accessibilityLabel = NSLocalizedString("List style", comment: "The accessibility label for the list style button in the Post List.") - postsViewButtonItem.accessibilityValue = isCompact ? NSLocalizedString("Compact", comment: "Accessibility indication that the current Post List style is currently Compact.") : NSLocalizedString("Expanded", comment: "Accessibility indication that the current Post List style is currently Expanded.") - postsViewButtonItem.image = postViewIcon - - if isViewOnScreen() { - tableView.reloadSections([0], with: .automatic) - ghostableTableView.reloadSections([0], with: .automatic) - } } private func configureInitialFilterIfNeeded() { @@ -704,6 +610,6 @@ private extension PostListViewController { extension PostListViewController: PostActionSheetDelegate { func showActionSheet(_ postCardStatusViewModel: PostCardStatusViewModel, from view: UIView) { - postActionSheet.show(for: postCardStatusViewModel, from: view, isCompactOrSearching: isCompact) + postActionSheet.show(for: postCardStatusViewModel, from: view) } } diff --git a/WordPress/Classes/ViewRelated/Post/RestorePostTableViewCell.swift b/WordPress/Classes/ViewRelated/Post/RestorePostTableViewCell.swift index 81ecf62681cd..d208b5cd729f 100644 --- a/WordPress/Classes/ViewRelated/Post/RestorePostTableViewCell.swift +++ b/WordPress/Classes/ViewRelated/Post/RestorePostTableViewCell.swift @@ -13,11 +13,6 @@ class RestorePostTableViewCell: UITableViewCell, ConfigurablePostView, Interacti private weak var delegate: InteractivePostViewDelegate? - var isCompact: Bool = false { - didSet { - isCompact ? configureCompact() : configureDefault() - } - } var post: Post? func configure(with post: Post) { @@ -45,14 +40,7 @@ class RestorePostTableViewCell: UITableViewCell, ConfigurablePostView, Interacti restoreButton.setTitle(buttonTitle, for: .normal) restoreButton.setImage(.gridicon(.undo, size: CGSize(width: Constants.imageSize, height: Constants.imageSize)), for: .normal) - } - - private func configureCompact() { - topMargin.constant = Constants.compactMargin - postContentView.layer.borderWidth = 0 - } - private func configureDefault() { topMargin.constant = Constants.defaultMargin postContentView.layer.borderColor = WPStyleGuide.postCardBorderColor.cgColor postContentView.layer.borderWidth = .hairlineBorderWidth @@ -82,7 +70,6 @@ class RestorePostTableViewCell: UITableViewCell, ConfigurablePostView, Interacti private enum Constants { static let defaultMargin: CGFloat = 16 - static let compactMargin: CGFloat = 0 static let imageSize: CGFloat = 18.0 } } From c3b3144b192fd8a51041a96fdf8f1741c4da256b Mon Sep 17 00:00:00 2001 From: Momo Ozawa Date: Tue, 17 Oct 2023 17:24:37 +0100 Subject: [PATCH 2/4] register and display PostListCell --- .../Post/PostListViewController.swift | 45 +++++++------------ 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Post/PostListViewController.swift b/WordPress/Classes/ViewRelated/Post/PostListViewController.swift index 6bf771bd116b..56f95afc58c6 100644 --- a/WordPress/Classes/ViewRelated/Post/PostListViewController.swift +++ b/WordPress/Classes/ViewRelated/Post/PostListViewController.swift @@ -158,6 +158,7 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe let bundle = Bundle.main // Register the cells + tableView.register(PostListCell.self, forCellReuseIdentifier: PostListCell.defaultReuseID) let postCardRestoreCellNib = UINib(nibName: postCardRestoreCellNibName, bundle: bundle) tableView.register(postCardRestoreCellNib, forCellReuseIdentifier: postCardRestoreCellIdentifier) @@ -306,18 +307,22 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe let post = postAtIndexPath(indexPath) - guard let interactivePostView = cell as? InteractivePostView, - let configurablePostView = cell as? ConfigurablePostView else { - fatalError("Cell does not implement the required protocols") +// TODO: Remove later +// guard let interactivePostView = cell as? InteractivePostView, +// let configurablePostView = cell as? ConfigurablePostView else { +// fatalError("Cell does not implement the required protocols") +// } +// +// interactivePostView.setInteractionDelegate(self) +// interactivePostView.setActionSheetDelegate(self) +// +// configurablePostView.configure(with: post) + + // TODO: Hide author if only showing my posts? + guard let cell = cell as? PostListCell else { + return } - - interactivePostView.setInteractionDelegate(self) - interactivePostView.setActionSheetDelegate(self) - - configurablePostView.configure(with: post) - - configurePostCell(cell) - configureRestoreCell(cell) + cell.configure(with: PostListItemViewModel(post: post)) } fileprivate func cellIdentifierForPost(_ post: Post) -> String { @@ -326,28 +331,12 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe if recentlyTrashedPostObjectIDs.contains(post.objectID) == true && filterSettings.currentPostListFilter().filterType != .trashed { identifier = postCardRestoreCellIdentifier } else { - identifier = postCellIdentifier + identifier = PostListCell.defaultReuseID } return identifier } - private func configurePostCell(_ cell: UITableViewCell) { - guard let cell = cell as? PostCardCell else { - return - } - - cell.shouldHideAuthor = showingJustMyPosts - } - - private func configureRestoreCell(_ cell: UITableViewCell) { - guard let cell = cell as? RestorePostTableViewCell else { - return - } - - cell.isCompact = isCompact - } - // MARK: - Post Actions override func createPost() { From 098948329318d9bf210a6cda12edbfd760725fb7 Mon Sep 17 00:00:00 2001 From: Momo Ozawa Date: Tue, 17 Oct 2023 17:52:09 +0100 Subject: [PATCH 3/4] disable ghost table view --- .../Classes/ViewRelated/Post/PostListViewController.swift | 6 ------ 1 file changed, 6 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Post/PostListViewController.swift b/WordPress/Classes/ViewRelated/Post/PostListViewController.swift index 56f95afc58c6..81482fa2934a 100644 --- a/WordPress/Classes/ViewRelated/Post/PostListViewController.swift +++ b/WordPress/Classes/ViewRelated/Post/PostListViewController.swift @@ -167,12 +167,6 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe tableView.register(headerNib, forHeaderFooterViewReuseIdentifier: ActivityListSectionHeaderView.identifier) } - override func configureGhostableTableView() { - super.configureGhostableTableView() - - ghostingEnabled = true - } - private func configureInitialFilterIfNeeded() { guard let initialFilterWithPostStatus = initialFilterWithPostStatus else { return From d7f67cee1a11792c08db91cf45f42a2f7c5c2ff3 Mon Sep 17 00:00:00 2001 From: Momo Ozawa Date: Thu, 19 Oct 2023 12:24:06 +0100 Subject: [PATCH 4/4] remove ghostable unit tests --- .../PostListViewControllerTests.swift | 30 ------------------- 1 file changed, 30 deletions(-) diff --git a/WordPress/WordPressTest/ViewRelated/Post/Controllers/PostListViewControllerTests.swift b/WordPress/WordPressTest/ViewRelated/Post/Controllers/PostListViewControllerTests.swift index 9850ecab5d69..2bc456d9f7b1 100644 --- a/WordPress/WordPressTest/ViewRelated/Post/Controllers/PostListViewControllerTests.swift +++ b/WordPress/WordPressTest/ViewRelated/Post/Controllers/PostListViewControllerTests.swift @@ -6,36 +6,6 @@ import Nimble class PostListViewControllerTests: CoreDataTestCase { - func testShowsGhostableTableView() { - let blog = BlogBuilder(mainContext).build() - let postListViewController = PostListViewController.controllerWithBlog(blog) - let _ = postListViewController.view - - postListViewController.startGhost() - - expect(postListViewController.ghostableTableView.isHidden).to(beFalse()) - } - - func testHidesGhostableTableView() { - let blog = BlogBuilder(mainContext).build() - let postListViewController = PostListViewController.controllerWithBlog(blog) - let _ = postListViewController.view - - postListViewController.stopGhost() - - expect(postListViewController.ghostableTableView.isHidden).to(beTrue()) - } - - func testShowTenMockedItemsInGhostableTableView() { - let blog = BlogBuilder(mainContext).build() - let postListViewController = PostListViewController.controllerWithBlog(blog) - let _ = postListViewController.view - - postListViewController.startGhost() - - expect(postListViewController.ghostableTableView.numberOfRows(inSection: 0)).to(equal(50)) - } - func testItCanHandleNewPostUpdatesEvenIfTheGhostViewIsStillVisible() throws { // This test simulates and proves that the app will no longer crash on these conditions: //