From 048e988f8600ede1304c093cb62c690b89bfd360 Mon Sep 17 00:00:00 2001 From: David Christiandy <1299411+dvdchr@users.noreply.github.com> Date: Mon, 30 Aug 2021 20:35:54 +0700 Subject: [PATCH 1/5] Add table view cell for comment header --- .../Comments/CommentHeaderTableViewCell.swift | 30 +++++++++++++++++++ WordPress/WordPress.xcodeproj/project.pbxproj | 14 +++++++++ 2 files changed, 44 insertions(+) create mode 100644 WordPress/Classes/ViewRelated/Comments/CommentHeaderTableViewCell.swift diff --git a/WordPress/Classes/ViewRelated/Comments/CommentHeaderTableViewCell.swift b/WordPress/Classes/ViewRelated/Comments/CommentHeaderTableViewCell.swift new file mode 100644 index 000000000000..95cf7b9341a1 --- /dev/null +++ b/WordPress/Classes/ViewRelated/Comments/CommentHeaderTableViewCell.swift @@ -0,0 +1,30 @@ +import UIKit + +class CommentHeaderTableViewCell: UITableViewCell, Reusable { + + // MARK: Initialization + + required init() { + super.init(style: .subtitle, reuseIdentifier: Self.defaultReuseID) + configureStyle() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + // MARK: Helpers + + private func configureStyle() { + accessoryType = .disclosureIndicator + + textLabel?.font = WPStyleGuide.fontForTextStyle(.footnote) + textLabel?.textColor = .textSubtle + textLabel?.numberOfLines = 2 + + detailTextLabel?.font = WPStyleGuide.fontForTextStyle(.subheadline) + detailTextLabel?.textColor = .text + detailTextLabel?.numberOfLines = 1 + } + +} diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index 5796ad8cd2db..9494a14f4047 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -4357,6 +4357,8 @@ FEA088012696E7F600193358 /* ListTableHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FEA088002696E7F600193358 /* ListTableHeaderView.swift */; }; FEA088032696E81F00193358 /* ListTableHeaderView.xib in Resources */ = {isa = PBXBuildFile; fileRef = FEA088022696E81F00193358 /* ListTableHeaderView.xib */; }; FEA088052696F7AA00193358 /* WPStyleGuide+List.swift in Sources */ = {isa = PBXBuildFile; fileRef = FEA088042696F7AA00193358 /* WPStyleGuide+List.swift */; }; + FEA7948D26DD136700CEC520 /* CommentHeaderTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = FEA7948C26DD136700CEC520 /* CommentHeaderTableViewCell.swift */; }; + FEA7948E26DD136700CEC520 /* CommentHeaderTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = FEA7948C26DD136700CEC520 /* CommentHeaderTableViewCell.swift */; }; FEC3B81726C2915A00A395C7 /* SingleButtonTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = FEC3B81526C2915A00A395C7 /* SingleButtonTableViewCell.swift */; }; FEC3B81826C2915A00A395C7 /* SingleButtonTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = FEC3B81526C2915A00A395C7 /* SingleButtonTableViewCell.swift */; }; FEC3B81926C2915A00A395C7 /* SingleButtonTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = FEC3B81626C2915A00A395C7 /* SingleButtonTableViewCell.xib */; }; @@ -7529,6 +7531,7 @@ FEA088002696E7F600193358 /* ListTableHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListTableHeaderView.swift; sourceTree = ""; }; FEA088022696E81F00193358 /* ListTableHeaderView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ListTableHeaderView.xib; sourceTree = ""; }; FEA088042696F7AA00193358 /* WPStyleGuide+List.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WPStyleGuide+List.swift"; sourceTree = ""; }; + FEA7948C26DD136700CEC520 /* CommentHeaderTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentHeaderTableViewCell.swift; sourceTree = ""; }; FEC3B81526C2915A00A395C7 /* SingleButtonTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleButtonTableViewCell.swift; sourceTree = ""; }; FEC3B81626C2915A00A395C7 /* SingleButtonTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleButtonTableViewCell.xib; sourceTree = ""; }; FEDA1AD7269D475D0038EC98 /* ListTableViewCell+Comments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ListTableViewCell+Comments.swift"; sourceTree = ""; }; @@ -12427,6 +12430,7 @@ B56994481B7A82D400FF26FA /* Views */ = { isa = PBXGroup; children = ( + FEA7948B26DD134400CEC520 /* Detail */, 9835F16D25E492EE002EFF23 /* CommentsList.storyboard */, B5CEEB8D1B7920BE00E7B7B0 /* CommentsTableViewCell.swift */, B5CEEB8F1B79244D00E7B7B0 /* CommentsTableViewCell.xib */, @@ -14449,6 +14453,14 @@ path = List; sourceTree = ""; }; + FEA7948B26DD134400CEC520 /* Detail */ = { + isa = PBXGroup; + children = ( + FEA7948C26DD136700CEC520 /* CommentHeaderTableViewCell.swift */, + ); + name = Detail; + sourceTree = ""; + }; FF2716901CAAC87B0006E2D4 /* WordPressUITests */ = { isa = PBXGroup; children = ( @@ -17881,6 +17893,7 @@ 400A2C832217A985000A8A59 /* TopViewedVideoStatsRecordValue+CoreDataClass.swift in Sources */, F1C740BF26B18E42005D0809 /* StoreSandboxSecretScreen.swift in Sources */, 5D42A3E2175E7452005CFF05 /* ReaderPost.m in Sources */, + FEA7948D26DD136700CEC520 /* CommentHeaderTableViewCell.swift in Sources */, D80BC79C207464D200614A59 /* MediaLibraryMediaPickingCoordinator.swift in Sources */, 46183CF4251BD658004F9AFD /* PageTemplateLayout+CoreDataClass.swift in Sources */, 982A4C3520227D6700B5518E /* NoResultsViewController.swift in Sources */, @@ -19455,6 +19468,7 @@ FABB22AF2602FC2C00C8785C /* MenusService.m in Sources */, FABB22B02602FC2C00C8785C /* QuickStartChecklistHeader.swift in Sources */, FABB22B12602FC2C00C8785C /* ReaderDetailFeaturedImageView.swift in Sources */, + FEA7948E26DD136700CEC520 /* CommentHeaderTableViewCell.swift in Sources */, FABB22B22602FC2C00C8785C /* StatsDataHelper.swift in Sources */, FABB22B32602FC2C00C8785C /* PrepublishingViewController.swift in Sources */, FABB22B42602FC2C00C8785C /* PageListTableViewHandler.swift in Sources */, From fe68faf43e9cc39b413a57b1eebaf00a8ad67a59 Mon Sep 17 00:00:00 2001 From: David Christiandy <1299411+dvdchr@users.noreply.github.com> Date: Mon, 30 Aug 2021 21:14:11 +0700 Subject: [PATCH 2/5] Show comment header cell in detail view --- .../CommentDetailViewController.swift | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/WordPress/Classes/ViewRelated/Comments/CommentDetailViewController.swift b/WordPress/Classes/ViewRelated/Comments/CommentDetailViewController.swift index 41ac01107cb0..cf9045a000f9 100644 --- a/WordPress/Classes/ViewRelated/Comments/CommentDetailViewController.swift +++ b/WordPress/Classes/ViewRelated/Comments/CommentDetailViewController.swift @@ -8,6 +8,10 @@ class CommentDetailViewController: UITableViewController { private var rows = [RowType]() + // MARK: Views + + private var headerCell = CommentHeaderTableViewCell() + // MARK: Initialization @objc required init(comment: Comment) { @@ -25,6 +29,7 @@ class CommentDetailViewController: UITableViewController { super.viewDidLoad() configureNavigationBar() configureTable() + configureRows() } // MARK: Table view data source @@ -37,6 +42,17 @@ class CommentDetailViewController: UITableViewController { return rows.count } + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + switch rows[indexPath.row] { + case .header: + configureHeaderCell() + return headerCell + + default: + return .init() + } + } + } // MARK: - Private Helpers @@ -58,6 +74,21 @@ private extension CommentDetailViewController { tableView.tableFooterView = UIView(frame: .zero) } + func configureRows() { + rows = [.header] + } + + // MARK: Cell configuration + + func configureHeaderCell() { + // TODO: detect if the comment is a reply. + + headerCell.textLabel?.text = .postCommentTitleText + headerCell.detailTextLabel?.text = comment.titleForDisplay() + } + + // MARK: Button actions + @objc func editButtonTapped() { // NOTE: This depends on the new edit comment feature, which is still ongoing. let navigationControllerToPresent = UINavigationController(rootViewController: EditCommentTableViewController(comment: comment)) @@ -68,3 +99,11 @@ private extension CommentDetailViewController { } } + +// MARK: - Localization + +private extension String { + static let postCommentTitleText = NSLocalizedString("Comment on", comment: "Provides hint that the current screen displays a comment on a post. " + + "The title of the post will displayed below this string. " + + "Example: Comment on \n My First Post") +} From 1c9fc994ef7926c11b4ddd7a7fba9d2623d2185d Mon Sep 17 00:00:00 2001 From: David Christiandy <1299411+dvdchr@users.noreply.github.com> Date: Mon, 30 Aug 2021 21:43:24 +0700 Subject: [PATCH 3/5] Implement tap action for the header cell --- .../CommentDetailViewController.swift | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/WordPress/Classes/ViewRelated/Comments/CommentDetailViewController.swift b/WordPress/Classes/ViewRelated/Comments/CommentDetailViewController.swift index cf9045a000f9..3d86a74309df 100644 --- a/WordPress/Classes/ViewRelated/Comments/CommentDetailViewController.swift +++ b/WordPress/Classes/ViewRelated/Comments/CommentDetailViewController.swift @@ -53,6 +53,18 @@ class CommentDetailViewController: UITableViewController { } } + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + tableView.deselectRow(at: indexPath, animated: true) + + switch rows[indexPath.row] { + case .header: + navigateToPost() + + default: + break + } + } + } // MARK: - Private Helpers @@ -87,7 +99,32 @@ private extension CommentDetailViewController { headerCell.detailTextLabel?.text = comment.titleForDisplay() } - // MARK: Button actions + // MARK: Actions and navigations + + func navigateToPost() { + guard let blog = comment.blog, + let siteID = blog.dotComID, + blog.supports(.wpComRESTAPI) else { + viewPostInWebView() + return + } + + let readerViewController = ReaderDetailViewController.controllerWithPostID(NSNumber(value: comment.postID), siteID: siteID, isFeed: false) + navigationController?.pushFullscreenViewController(readerViewController, animated: true) + } + + func viewPostInWebView() { + guard let post = comment.post, + let permalink = post.permaLink, + let url = URL(string: permalink) else { + return + } + + let viewController = WebViewControllerFactory.controllerAuthenticatedWithDefaultAccount(url: url) + let navigationControllerToPresent = UINavigationController(rootViewController: viewController) + + present(navigationControllerToPresent, animated: true, completion: nil) + } @objc func editButtonTapped() { // NOTE: This depends on the new edit comment feature, which is still ongoing. From d85271894c90527c2d3f60619a584d7f4f929439 Mon Sep 17 00:00:00 2001 From: David Christiandy <1299411+dvdchr@users.noreply.github.com> Date: Mon, 30 Aug 2021 21:57:56 +0700 Subject: [PATCH 4/5] Allow cell reuse identifier to be parameterized --- .../ViewRelated/Comments/CommentHeaderTableViewCell.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Comments/CommentHeaderTableViewCell.swift b/WordPress/Classes/ViewRelated/Comments/CommentHeaderTableViewCell.swift index 95cf7b9341a1..c4c14e33bffc 100644 --- a/WordPress/Classes/ViewRelated/Comments/CommentHeaderTableViewCell.swift +++ b/WordPress/Classes/ViewRelated/Comments/CommentHeaderTableViewCell.swift @@ -4,8 +4,8 @@ class CommentHeaderTableViewCell: UITableViewCell, Reusable { // MARK: Initialization - required init() { - super.init(style: .subtitle, reuseIdentifier: Self.defaultReuseID) + required init(reuseIdentifier: String = CommentHeaderTableViewCell.defaultReuseID) { + super.init(style: .subtitle, reuseIdentifier: reuseIdentifier) configureStyle() } From e2c33df7d059541b8aa688fe8e4b98839aa114d6 Mon Sep 17 00:00:00 2001 From: David Christiandy <1299411+dvdchr@users.noreply.github.com> Date: Wed, 1 Sep 2021 14:03:12 +0700 Subject: [PATCH 5/5] Remove reuseIdentifier parameter --- .../ViewRelated/Comments/CommentHeaderTableViewCell.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Comments/CommentHeaderTableViewCell.swift b/WordPress/Classes/ViewRelated/Comments/CommentHeaderTableViewCell.swift index c4c14e33bffc..95cf7b9341a1 100644 --- a/WordPress/Classes/ViewRelated/Comments/CommentHeaderTableViewCell.swift +++ b/WordPress/Classes/ViewRelated/Comments/CommentHeaderTableViewCell.swift @@ -4,8 +4,8 @@ class CommentHeaderTableViewCell: UITableViewCell, Reusable { // MARK: Initialization - required init(reuseIdentifier: String = CommentHeaderTableViewCell.defaultReuseID) { - super.init(style: .subtitle, reuseIdentifier: reuseIdentifier) + required init() { + super.init(style: .subtitle, reuseIdentifier: Self.defaultReuseID) configureStyle() }