Skip to content

Commit

Permalink
Merge pull request #17095 from wordpress-mobile/issue/17087-comment-h…
Browse files Browse the repository at this point in the history
…eader-cell

Comment Detail: Add header cell
  • Loading branch information
dvdchr authored Sep 1, 2021
2 parents 365e11e + e2c33df commit 030466b
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class CommentDetailViewController: UITableViewController {

private var rows = [RowType]()

// MARK: Views

private var headerCell = CommentHeaderTableViewCell()

// MARK: Initialization

@objc required init(comment: Comment) {
Expand All @@ -25,6 +29,7 @@ class CommentDetailViewController: UITableViewController {
super.viewDidLoad()
configureNavigationBar()
configureTable()
configureRows()
}

// MARK: Table view data source
Expand All @@ -37,6 +42,29 @@ 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()
}
}

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
Expand All @@ -58,6 +86,46 @@ 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: 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.
let navigationControllerToPresent = UINavigationController(rootViewController: EditCommentTableViewController(comment: comment))
Expand All @@ -68,3 +136,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")
}
Original file line number Diff line number Diff line change
@@ -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
}

}
14 changes: 14 additions & 0 deletions WordPress/WordPress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -7529,6 +7531,7 @@
FEA088002696E7F600193358 /* ListTableHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListTableHeaderView.swift; sourceTree = "<group>"; };
FEA088022696E81F00193358 /* ListTableHeaderView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ListTableHeaderView.xib; sourceTree = "<group>"; };
FEA088042696F7AA00193358 /* WPStyleGuide+List.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WPStyleGuide+List.swift"; sourceTree = "<group>"; };
FEA7948C26DD136700CEC520 /* CommentHeaderTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentHeaderTableViewCell.swift; sourceTree = "<group>"; };
FEC3B81526C2915A00A395C7 /* SingleButtonTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleButtonTableViewCell.swift; sourceTree = "<group>"; };
FEC3B81626C2915A00A395C7 /* SingleButtonTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SingleButtonTableViewCell.xib; sourceTree = "<group>"; };
FEDA1AD7269D475D0038EC98 /* ListTableViewCell+Comments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ListTableViewCell+Comments.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -12427,6 +12430,7 @@
B56994481B7A82D400FF26FA /* Views */ = {
isa = PBXGroup;
children = (
FEA7948B26DD134400CEC520 /* Detail */,
9835F16D25E492EE002EFF23 /* CommentsList.storyboard */,
B5CEEB8D1B7920BE00E7B7B0 /* CommentsTableViewCell.swift */,
B5CEEB8F1B79244D00E7B7B0 /* CommentsTableViewCell.xib */,
Expand Down Expand Up @@ -14449,6 +14453,14 @@
path = List;
sourceTree = "<group>";
};
FEA7948B26DD134400CEC520 /* Detail */ = {
isa = PBXGroup;
children = (
FEA7948C26DD136700CEC520 /* CommentHeaderTableViewCell.swift */,
);
name = Detail;
sourceTree = "<group>";
};
FF2716901CAAC87B0006E2D4 /* WordPressUITests */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down

0 comments on commit 030466b

Please sign in to comment.