From 3487b5dc7d10a4045f70e8b99bae07391d24b641 Mon Sep 17 00:00:00 2001 From: kean Date: Fri, 13 Oct 2023 21:29:50 -0400 Subject: [PATCH 1/2] Move authors filter button to navigation bar --- .../Pages/PageListViewController.swift | 8 ++ .../Post/AbstractPostListViewController.swift | 87 +++++++++--------- .../ViewRelated/Post/AuthorFilterButton.swift | 65 ++----------- .../Post/AuthorFilterViewController.swift | 4 +- .../Post/PostListViewController.swift | 3 +- .../ViewRelated/System/FilterTabBar.swift | 15 --- .../icon-people.imageset/Contents.json | 12 +++ .../icon-people.imageset/icon-people.pdf | Bin 0 -> 2777 bytes 8 files changed, 73 insertions(+), 121 deletions(-) create mode 100644 WordPress/Resources/AppImages.xcassets/icon-people.imageset/Contents.json create mode 100644 WordPress/Resources/AppImages.xcassets/icon-people.imageset/icon-people.pdf diff --git a/WordPress/Classes/ViewRelated/Pages/PageListViewController.swift b/WordPress/Classes/ViewRelated/Pages/PageListViewController.swift index 0fa1bd1b5ecb..8e95fb97a3f1 100644 --- a/WordPress/Classes/ViewRelated/Pages/PageListViewController.swift +++ b/WordPress/Classes/ViewRelated/Pages/PageListViewController.swift @@ -324,6 +324,14 @@ class PageListViewController: AbstractPostListViewController, UIViewControllerRe predicates.append(filterPredicate) } + if filterSettings.shouldShowOnlyMyPosts() { + let myAuthorID = blogUserID() ?? 0 + + // Brand new local drafts have an authorID of 0. + let authorPredicate = NSPredicate(format: "authorID = %@ || authorID = 0", myAuthorID) + predicates.append(authorPredicate) + } + if let predicate = PostSearchViewModel.makeHomepagePredicate(for: blog) { predicates.append(predicate) } diff --git a/WordPress/Classes/ViewRelated/Post/AbstractPostListViewController.swift b/WordPress/Classes/ViewRelated/Post/AbstractPostListViewController.swift index 6e1401f2fb33..3168a9d48731 100644 --- a/WordPress/Classes/ViewRelated/Post/AbstractPostListViewController.swift +++ b/WordPress/Classes/ViewRelated/Post/AbstractPostListViewController.swift @@ -52,6 +52,8 @@ class AbstractPostListViewController: UIViewController, } } + private let buttonAuthorFilter = AuthorFilterButton() + let refreshControl = UIRefreshControl() @objc lazy var tableViewHandler: WPTableViewHandler = { @@ -252,18 +254,6 @@ class AbstractPostListViewController: UIViewController, } } - private func configureAuthorFilter() { - guard filterSettings.canFilterByAuthor() else { - return - } - - let authorFilter = AuthorFilterButton() - authorFilter.addTarget(self, action: #selector(showAuthorSelectionPopover(_:)), for: .touchUpInside) - filterTabBar.accessoryView = authorFilter - - updateAuthorFilter() - } - private func configureSearchController() { searchController.delegate = self searchController.searchResultsUpdater = searchResultsViewController @@ -316,6 +306,46 @@ class AbstractPostListViewController: UIViewController, return properties } + // MARK: - Author Filter + + private func configureAuthorFilter() { + guard filterSettings.canFilterByAuthor() else { + return + } + buttonAuthorFilter.sizeToFit() + navigationItem.rightBarButtonItem = UIBarButtonItem(customView: buttonAuthorFilter) + + buttonAuthorFilter.addTarget(self, action: #selector(showAuthorSelectionPopover(_:)), for: .touchUpInside) + updateAuthorFilter() + } + + private func updateAuthorFilter() { + if filterSettings.currentPostAuthorFilter() == .everyone { + buttonAuthorFilter.filterType = .everyone + } else { + buttonAuthorFilter.filterType = .user(gravatarEmail: blog.account?.email) + } + } + + @objc private func showAuthorSelectionPopover(_ sender: UIView) { + let filterController = AuthorFilterViewController(initialSelection: filterSettings.currentPostAuthorFilter(), gravatarEmail: blog.account?.email) { [weak self] filter in + if filter != self?.filterSettings.currentPostAuthorFilter() { + UIAccessibility.post(notification: UIAccessibility.Notification.screenChanged, argument: sender) + } + + self?.filterSettings.setCurrentPostAuthorFilter(filter) + self?.updateAuthorFilter() + self?.refreshAndReload() + self?.syncItemsWithUserInteraction(false) + self?.dismiss(animated: true) + } + + ForcePopoverPresenter.configurePresentationControllerForViewController(filterController, presentingFromView: sender) + filterController.popoverPresentationController?.permittedArrowDirections = .up + + present(filterController, animated: true) + } + // MARK: - GUI: No results view logic func hideNoResultsView() { @@ -501,39 +531,6 @@ class AbstractPostListViewController: UIViewController, WPAnalytics.track(.postListPullToRefresh, withProperties: propertiesForAnalytics()) } - @objc - private func showAuthorSelectionPopover(_ sender: UIView) { - let filterController = AuthorFilterViewController(initialSelection: filterSettings.currentPostAuthorFilter(), - gravatarEmail: blog.account?.email) { [weak self] filter in - if filter != self?.filterSettings.currentPostAuthorFilter() { - UIAccessibility.post(notification: UIAccessibility.Notification.screenChanged, argument: sender) - } - - self?.filterSettings.setCurrentPostAuthorFilter(filter) - self?.updateAuthorFilter() - self?.refreshAndReload() - self?.syncItemsWithUserInteraction(false) - self?.dismiss(animated: true) - } - - ForcePopoverPresenter.configurePresentationControllerForViewController(filterController, presentingFromView: sender) - filterController.popoverPresentationController?.permittedArrowDirections = .up - - present(filterController, animated: true) - } - - private func updateAuthorFilter() { - guard let accessoryView = filterTabBar.accessoryView as? AuthorFilterButton else { - return - } - - if filterSettings.currentPostAuthorFilter() == .everyone { - accessoryView.filterType = .everyone - } else { - accessoryView.filterType = .user(gravatarEmail: blog.account?.email) - } - } - // MARK: - Synching @objc func automaticallySyncIfAppropriate() { diff --git a/WordPress/Classes/ViewRelated/Post/AuthorFilterButton.swift b/WordPress/Classes/ViewRelated/Post/AuthorFilterButton.swift index fea2e21f82a1..f6c6ade2f73f 100644 --- a/WordPress/Classes/ViewRelated/Post/AuthorFilterButton.swift +++ b/WordPress/Classes/ViewRelated/Post/AuthorFilterButton.swift @@ -17,39 +17,15 @@ private extension AuthorFilterType { } } -/// Displays an author gravatar image with a dropdown arrow. -/// -class AuthorFilterButton: UIControl { +final class AuthorFilterButton: UIControl { private let authorImageView: CircularImageView = { let imageView = CircularImageView(image: UIImage.gravatarPlaceholderImage) imageView.translatesAutoresizingMaskIntoConstraints = false imageView.setContentHuggingPriority(.required, for: .horizontal) - imageView.backgroundColor = .neutral(.shade10) imageView.tintColor = .neutral(.shade70) - - return imageView - }() - - private let chevronImageView: UIImageView = { - let imageView = UIImageView(image: UIImage.makeChevronDownImage(with: .neutral(.shade40), size: Metrics.chevronSize)) - imageView.translatesAutoresizingMaskIntoConstraints = false - imageView.setContentHuggingPriority(.required, for: .horizontal) - imageView.contentMode = .bottom - return imageView }() - private let stackView: UIStackView = { - let stackView = UIStackView() - stackView.translatesAutoresizingMaskIntoConstraints = false - stackView.axis = .horizontal - stackView.alignment = .center - stackView.spacing = Metrics.stackViewSpacing - stackView.isUserInteractionEnabled = false - - return stackView - }() - override var intrinsicContentSize: CGSize { return Metrics.contentSize } @@ -58,7 +34,7 @@ class AuthorFilterButton: UIControl { didSet { switch filterType { case .everyone: - authorImageView.image = .gridicon(.multipleUsers, size: Metrics.multipleUsersGravatarSize) + authorImageView.image = UIImage(named: "icon-people") authorImageView.contentMode = .center case .user(let email): authorImageView.contentMode = .scaleAspectFill @@ -86,17 +62,14 @@ class AuthorFilterButton: UIControl { } private func commonInit() { - stackView.addArrangedSubview(authorImageView) - stackView.addArrangedSubview(chevronImageView) - addSubview(stackView) + addSubview(authorImageView) NSLayoutConstraint.activate([ - stackView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: Metrics.leadingPadding), - stackView.centerYAnchor.constraint(equalTo: centerYAnchor), + authorImageView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: Metrics.leadingPadding), + authorImageView.centerYAnchor.constraint(equalTo: centerYAnchor), authorImageView.widthAnchor.constraint(equalToConstant: Metrics.gravatarSize.width), authorImageView.heightAnchor.constraint(equalToConstant: Metrics.gravatarSize.height), - widthAnchor.constraint(equalToConstant: intrinsicContentSize.width), - chevronImageView.heightAnchor.constraint(equalToConstant: Metrics.chevronSize.height + Metrics.chevronVerticalPadding) - ]) + widthAnchor.constraint(equalToConstant: intrinsicContentSize.width) + ]) authorImageView.image = gravatarPlaceholder @@ -106,12 +79,8 @@ class AuthorFilterButton: UIControl { private let gravatarPlaceholder: UIImage = .gridicon(.user, size: Metrics.gravatarSize) private enum Metrics { - static let chevronSize = CGSize(width: 10.0, height: 5.0) - static let contentSize = CGSize(width: 72.0, height: 44.0) + static let contentSize = CGSize(width: 44.0, height: 44.0) static let gravatarSize = CGSize(width: 28.0, height: 28.0) - static let multipleUsersGravatarSize = CGSize(width: 20.0, height: 20.0) - static let stackViewSpacing: CGFloat = 7.0 - static let chevronVerticalPadding: CGFloat = 2.0 static let leadingPadding: CGFloat = 12.0 } } @@ -125,21 +94,3 @@ extension AuthorFilterButton: Accessible { accessibilityValue = filterType.accessibilityValue } } - -private extension UIImage { - // Draws a small down facing arrow - static func makeChevronDownImage(with color: UIColor, size: CGSize) -> UIImage { - let renderer = UIGraphicsImageRenderer(size: size) - let image = renderer.image { context in - color.setFill() - color.setStroke() - let path = UIBezierPath() - path.move(to: .zero) - path.addLine(to: CGPoint(x: size.width, y: 0)) - path.addLine(to: CGPoint(x: size.width / 2, y: size.height)) - path.close() - path.fill() - } - return image - } -} diff --git a/WordPress/Classes/ViewRelated/Post/AuthorFilterViewController.swift b/WordPress/Classes/ViewRelated/Post/AuthorFilterViewController.swift index e8182a810192..d2b7c5e1153c 100644 --- a/WordPress/Classes/ViewRelated/Post/AuthorFilterViewController.swift +++ b/WordPress/Classes/ViewRelated/Post/AuthorFilterViewController.swift @@ -155,7 +155,6 @@ private class AuthorFilterCell: UITableViewCell { imageView.translatesAutoresizingMaskIntoConstraints = false imageView.setContentHuggingPriority(.required, for: .horizontal) imageView.setContentCompressionResistancePriority(.required, for: .horizontal) - imageView.backgroundColor = Appearance.placeholderBackgroundColor imageView.tintColor = Appearance.placeholderTintColor return imageView }() @@ -231,7 +230,7 @@ private class AuthorFilterCell: UITableViewCell { didSet { switch filterType { case .everyone: - gravatarImageView.image = .gridicon(.multipleUsers, size: Metrics.multipleGravatarSize) + gravatarImageView.image = UIImage(named: "icon-people") gravatarImageView.contentMode = .center accessibilityHint = NSLocalizedString("Select to show everyone's posts.", comment: "Voiceover accessibility hint, informing the user they can select an item to show posts written by all users on the site") case .user(let email): @@ -258,7 +257,6 @@ private class AuthorFilterCell: UITableViewCell { private enum Appearance { static let textColor = UIColor.neutral(.shade70) static let placeholderTintColor = UIColor.neutral(.shade70) - static let placeholderBackgroundColor = UIColor.neutral(.shade10) } private enum Metrics { diff --git a/WordPress/Classes/ViewRelated/Post/PostListViewController.swift b/WordPress/Classes/ViewRelated/Post/PostListViewController.swift index 18fe8c184685..1e0e4a9d9268 100644 --- a/WordPress/Classes/ViewRelated/Post/PostListViewController.swift +++ b/WordPress/Classes/ViewRelated/Post/PostListViewController.swift @@ -186,7 +186,8 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe } func configureNavigationButtons() { - navigationItem.rightBarButtonItems = [postsViewButtonItem] + // TODO: Remove + // navigationItem.rightBarButtonItems = [postsViewButtonItem] } @objc func togglePostsView() { diff --git a/WordPress/Classes/ViewRelated/System/FilterTabBar.swift b/WordPress/Classes/ViewRelated/System/FilterTabBar.swift index fa3c698387ef..c9e6dd53205e 100644 --- a/WordPress/Classes/ViewRelated/System/FilterTabBar.swift +++ b/WordPress/Classes/ViewRelated/System/FilterTabBar.swift @@ -153,21 +153,6 @@ class FilterTabBar: UIControl { } } - /// Accessory view displayed on the leading end of the tab bar. - /// - var accessoryView: UIView? = nil { - didSet { - if let oldValue = oldValue { - oldValue.removeFromSuperview() - } - - if let accessoryView = accessoryView { - accessoryView.setContentCompressionResistancePriority(.required, for: .horizontal) - stackView.insertArrangedSubview(accessoryView, at: 0) - } - } - } - // MARK: - Tab Sizing private var stackViewEdgeConstraints: [NSLayoutConstraint]! { diff --git a/WordPress/Resources/AppImages.xcassets/icon-people.imageset/Contents.json b/WordPress/Resources/AppImages.xcassets/icon-people.imageset/Contents.json new file mode 100644 index 000000000000..c6cd050129de --- /dev/null +++ b/WordPress/Resources/AppImages.xcassets/icon-people.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images" : [ + { + "filename" : "icon-people.pdf", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/WordPress/Resources/AppImages.xcassets/icon-people.imageset/icon-people.pdf b/WordPress/Resources/AppImages.xcassets/icon-people.imageset/icon-people.pdf new file mode 100644 index 0000000000000000000000000000000000000000..93c3f10e3b5867508d3ffbb0a93cedacd6c0a9da GIT binary patch literal 2777 zcmcJRU2oGc6o&8pE6&ZN4XH`QbmlUTtRJo45#RwiUGrG#MKFdX5wOwbvp| znnW(9^qKvh51(`5qpOR{nT!e{Bqh{+`!0x1PwDJTH0{d#6e{HLho-$7?kQ!sG^_ey z*Hl{(Uo^kgb+deXPK)dCSKW)BLPp8>P~u)@c*FnFsL*B=$<(c?w<3w8Eb^@2t@|&1 z-3rOBPrD$v6)Ygrq>${nQ<7PvtUBw=RaufpDjNTlP%S)6qp}<|yqbm@tOD`YBuev9 z8F225LJTCZ2`1qhq;wAb#nB;P_RPCQ6kV0WxygjpkWVNKGCEzIe!opjl&F zXVp??!e=t<}UDA z?oM}wZrIH1ek;==WOo`jf)>-b-;!!PdLLP3obJV2bAUo}Jq_`x;ml-{a?g1h_#-h2p5)t8C~(3(MaFp?9b}E?k!>oU$+7!v zIeW^QTtCy;^Yz2jE1(`m`v-*@M1^_|7`z|*@THlzC;ogJ7A_c!jxCqf{#?%whJWS~ zhL)&B>V`F#I#2?EJ=3Mu9!5HpaDK1{VtT@UlEC0Olt2P|_d+}GLARb^Ug~M&^SE}^ z2`@lukxe5yScOu65(w;>Z0*l+C}G&c9!Sl8j-L+gKM9BiUj&fA9;Ujvh1e^GyN{Tw z$8=9oGR<*K$${$iNE~*(NKI<-8B|`Y*y>)ynCb@KRtaZWNr*8 zyg8+1({~TMy6MSWn3h&<(X~Uoa z9w4O@d$EVI`98`N=jQ3EZ0yK22@cEX(Ay9-Xoao=s56FOe6PNt;9%dQ*91Ux1< azFz-n*!%GkTJ4509Hq4uM@MfyUH%2S*)FXB literal 0 HcmV?d00001 From c9cfffd30cee750ae437b3f29bd74241b8287a44 Mon Sep 17 00:00:00 2001 From: kean Date: Mon, 16 Oct 2023 14:43:01 -0400 Subject: [PATCH 2/2] Authors filter now defaults to Everyone --- .../ViewRelated/Post/PostListFilterSettings.swift | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Post/PostListFilterSettings.swift b/WordPress/Classes/ViewRelated/Post/PostListFilterSettings.swift index 319305c3f6ed..1bfdd5a166f3 100644 --- a/WordPress/Classes/ViewRelated/Post/PostListFilterSettings.swift +++ b/WordPress/Classes/ViewRelated/Post/PostListFilterSettings.swift @@ -147,13 +147,12 @@ class PostListFilterSettings: NSObject { return .everyone } - if let filter = UserPersistentStoreFactory.instance().object(forKey: type(of: self).currentPostAuthorFilterKey) { - if (filter as AnyObject).uintValue == AuthorFilter.everyone.rawValue { - return .everyone - } + if let rawValue = UserPersistentStoreFactory.instance().object(forKey: type(of: self).currentPostAuthorFilterKey), + let filter = AuthorFilter(rawValue: (rawValue as AnyObject).uintValue) { + return filter } - return .mine + return .everyone } /// currentPostListFilter: stores the last active AuthorFilter