Skip to content

Commit f338663

Browse files
committed
Address PR comments
1 parent ac135bc commit f338663

File tree

4 files changed

+30
-33
lines changed

4 files changed

+30
-33
lines changed

WordPress/Classes/Utility/Media/FaviconService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private func validate(response: URLResponse) throws {
9595
guard let response = response as? HTTPURLResponse else {
9696
return
9797
}
98-
guard (200..<400).contains(response.statusCode) else {
98+
guard (200..<300).contains(response.statusCode) else {
9999
throw FaviconError.unacceptableStatusCode(response.statusCode)
100100
}
101101
}

WordPress/Classes/ViewRelated/Reader/ReaderPostCell.swift

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private final class ReaderPostCellView: UIView {
9999
var isCompact: Bool = true {
100100
didSet {
101101
guard oldValue != isCompact else { return }
102-
update(isCompact: isCompact)
102+
configureLayout(isCompact: isCompact)
103103
}
104104
}
105105

@@ -113,10 +113,10 @@ private final class ReaderPostCellView: UIView {
113113
override init(frame: CGRect) {
114114
super.init(frame: frame)
115115

116-
configureStyle()
117-
configureLayout()
118-
configureActions()
119-
configureAccessibility()
116+
setupStyle()
117+
setupLayout()
118+
setupActions()
119+
setupAccessibility()
120120
}
121121

122122
required init?(coder: NSCoder) {
@@ -127,16 +127,15 @@ private final class ReaderPostCellView: UIView {
127127
cancellables = []
128128
avatarView.prepareForReuse()
129129
imageView.prepareForReuse()
130-
imageView.isHidden = false
131130
}
132131

133-
private func configureStyle() {
134-
avatarView.layer.cornerRadius = 14
132+
private func setupStyle() {
133+
avatarView.layer.cornerRadius = ReaderPostCell.avatarSize / 2
135134
avatarView.layer.masksToBounds = true
136135
avatarView.isErrorViewEnabled = false
137136

138137
buttonAuthor.maximumContentSizeCategory = .accessibilityLarge
139-
configureTimeLabel(timeLabel)
138+
setupTimeLabel(timeLabel)
140139
timeLabel.setContentCompressionResistancePriority(.init(800), for: .horizontal)
141140

142141
titleLabel.font = .preferredFont(forTextStyle: .headline)
@@ -146,7 +145,7 @@ private final class ReaderPostCellView: UIView {
146145
detailsLabel.font = .preferredFont(forTextStyle: .subheadline)
147146
detailsLabel.textColor = .secondaryLabel
148147
detailsLabel.adjustsFontForContentSizeCategory = true
149-
titleLabel.maximumContentSizeCategory = .accessibilityExtraLarge
148+
detailsLabel.maximumContentSizeCategory = .accessibilityExtraLarge
150149

151150
imageView.layer.cornerRadius = 8
152151
imageView.layer.masksToBounds = true
@@ -156,9 +155,9 @@ private final class ReaderPostCellView: UIView {
156155
buttonMore.configuration?.contentInsets = .init(top: 12, leading: 8, bottom: 12, trailing: 20)
157156
}
158157

159-
private func configureLayout() {
158+
private func setupLayout() {
160159
let dot = UILabel()
161-
configureTimeLabel(dot)
160+
setupTimeLabel(dot)
162161
dot.text = " · "
163162

164163
// These seems to be an issue with `lineBreakMode` in `UIButton.Configuration`
@@ -196,17 +195,17 @@ private final class ReaderPostCellView: UIView {
196195
toolbarView.bottomAnchor.constraint(equalTo: bottomAnchor)
197196
])
198197

199-
update(isCompact: isCompact)
198+
configureLayout(isCompact: isCompact)
200199
}
201200

202-
private func configureTimeLabel(_ label: UILabel) {
201+
private func setupTimeLabel(_ label: UILabel) {
203202
label.font = .preferredFont(forTextStyle: .footnote)
204203
label.textColor = .secondaryLabel
205204
label.adjustsFontForContentSizeCategory = true
206205
label.maximumContentSizeCategory = .accessibilityMedium
207206
}
208207

209-
private func update(isCompact: Bool) {
208+
private func configureLayout(isCompact: Bool) {
210209
titleLabel.numberOfLines = 2
211210
detailsLabel.numberOfLines = isCompact ? 3 : 5
212211

@@ -237,7 +236,7 @@ private final class ReaderPostCellView: UIView {
237236

238237
// MARK: Actions
239238

240-
private func configureActions() {
239+
private func setupActions() {
241240
buttonAuthor.addTarget(self, action: #selector(buttonAuthorTapped), for: .primaryActionTriggered)
242241
buttonMore.showsMenuAsPrimaryAction = true
243242
buttonMore.menu = UIMenu(options: .displayInline, children: [
@@ -272,12 +271,11 @@ private final class ReaderPostCellView: UIView {
272271
}
273272

274273
private func makeMoreMenu() -> [UIMenuElement] {
275-
guard let viewModel, let post = viewModel.post,
276-
let viewController = viewModel.viewController else {
274+
guard let viewModel, let viewController = viewModel.viewController else {
277275
return []
278276
}
279277
return ReaderPostMenu(
280-
post: post,
278+
post: viewModel.post,
281279
topic: viewController.readerTopic,
282280
button: buttonMore,
283281
viewController: viewController
@@ -295,10 +293,10 @@ private final class ReaderPostCellView: UIView {
295293

296294
titleLabel.text = viewModel.title
297295
detailsLabel.text = viewModel.details
296+
297+
imageView.isHidden = viewModel.imageURL == nil
298298
if let imageURL = viewModel.imageURL {
299299
imageView.setImage(with: imageURL)
300-
} else {
301-
imageView.isHidden = true
302300
}
303301

304302
buttons.bookmark.configuration = {
@@ -385,13 +383,13 @@ private func makeButton(systemImage: String, font: UIFont = UIFont.preferredFont
385383
}
386384

387385
private func kFormatted(_ count: Int) -> String {
388-
count >= 1000 ? String(format: "%.0fK", Double(count) / 1000) : String(count)
386+
count.formatted(.number.notation(.compactName))
389387
}
390388

391389
// MARK: - ReaderPostCellView (Accessibility)
392390

393391
private extension ReaderPostCellView {
394-
func configureAccessibility() {
392+
func setupAccessibility() {
395393
buttonAuthor.accessibilityHint = NSLocalizedString("reader.post.buttonSite.accessibilityHint", value: "Opens the site details", comment: "Accessibility hint for the site header")
396394
buttonMore.accessibilityLabel = NSLocalizedString("reader.post.moreMenu.accessibilityLabel", value: "More actions", comment: "Button accessibility label")
397395

WordPress/Classes/ViewRelated/Reader/ReaderPostCellViewModel.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class ReaderPostCellViewModel {
2121

2222
weak var viewController: ReaderStreamViewController?
2323

24-
let post: ReaderPost?
24+
let post: ReaderPost
2525
private var faviconTask: Task<Void, Never>?
2626

2727
deinit {
@@ -55,7 +55,7 @@ final class ReaderPostCellViewModel {
5555
if isP2 {
5656
self.avatarURL = post.authorAvatarURL.flatMap(URL.init)
5757
} else if let avatarURL = post.siteIconForDisplay(ofSize: Int(ReaderPostCell.avatarSize)) {
58-
self.avatarURL = avatarURL
58+
self.avatarURL = avatarURL
5959
} else if let blogURL = post.blogURL.flatMap(URL.init) {
6060
if let faviconURL = FaviconService.shared.cachedFavicon(forURL: blogURL) {
6161
self.avatarURL = faviconURL
@@ -68,6 +68,7 @@ final class ReaderPostCellViewModel {
6868
}
6969

7070
private init() {
71+
self.post = ReaderPost.init(entity: NSEntityDescription.entity(forEntityName: ReaderPost.entityName(), in: ContextManager.shared.mainContext)!, insertInto: nil)
7172
self.avatarURL = URL(string: "https://picsum.photos/120/120.jpg")
7273
self.author = "WordPress Mobile Apps"
7374
self.time = "9d ago"
@@ -80,7 +81,6 @@ final class ReaderPostCellViewModel {
8081
self.isCommentsEnabled = true
8182
self.commentCount = 213
8283
self.isLiked = true
83-
self.post = nil
8484
}
8585

8686
static func mock() -> ReaderPostCellViewModel {
@@ -90,27 +90,26 @@ final class ReaderPostCellViewModel {
9090
// MARK: Actions
9191

9292
func showSiteDetails() {
93-
guard let post, let viewController else { return }
93+
guard let viewController else { return }
9494
ReaderHeaderAction().execute(post: post, origin: viewController)
9595
}
9696

9797
func toogleBookmark() {
98-
guard let post, let viewController else { return }
98+
guard let viewController else { return }
9999
ReaderSaveForLaterAction().execute(with: post, origin: .otherStream, viewController: viewController)
100100
}
101101

102102
func reblog() {
103-
guard let post, let viewController else { return }
103+
guard let viewController else { return }
104104
ReaderReblogAction().execute(readerPost: post, origin: viewController, reblogSource: .list)
105105
}
106106

107107
func comment() {
108-
guard let post, let viewController else { return }
108+
guard let viewController else { return }
109109
ReaderCommentAction().execute(post: post, origin: viewController, source: .postCard)
110110
}
111111

112112
func toggleLike() {
113-
guard let post else { return }
114113
ReaderLikeAction().execute(with: post)
115114
}
116115
}

WordPress/Classes/ViewRelated/Reader/Subscriptions/ReaderSubscriptionCell.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,6 @@ private enum Strings {
110110
}
111111

112112
private static func kFormatted(_ count: Int) -> String {
113-
count >= 1000 ? String(format: "%.0fK", Double(count) / 1000) : String(count)
113+
count.formatted(.number.notation(.compactName))
114114
}
115115
}

0 commit comments

Comments
 (0)