Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment Detail: Add header cell #17095

Merged
merged 5 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I was testing on iPad, I noticed an odd behavior which I think is related to pushFullscreenViewController. The readerViewController tries to appear full screen, then jumps down to split view. I see this is simply copied behavior from CommentViewController, and I did confirm this is an existing issue in the app store version. But maybe we can fix it with this feature? (at some point, not in this PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that makes sense. I'll note this down in #17087 and address this in a separate PR. Thanks! 🙂

}

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(reuseIdentifier: String = CommentHeaderTableViewCell.defaultReuseID) {
dvdchr marked this conversation as resolved.
Show resolved Hide resolved
super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)
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