Merge pull request #2775 from stuartbreckenridge/context-menu

Adds Context Menus for Add Item and Mark All as Read
This commit is contained in:
Maurice Parker 2021-01-31 18:57:23 -06:00 committed by GitHub
commit 56f1969715
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 168 additions and 52 deletions

View File

@ -157,6 +157,10 @@ struct AppAssets {
return IconImage(UIImage(systemName: "folder.fill")!, isSymbol: true, isBackgroundSupressed: true, preferredColor: AppAssets.secondaryAccentColor.cgColor)
}()
static var masterFolderImageNonIcon: UIImage = {
return UIImage(systemName: "folder.fill")!.withRenderingMode(.alwaysOriginal).withTintColor(.secondaryLabel)
}()
static var moreImage: UIImage = {
return UIImage(systemName: "ellipsis.circle")!
}()
@ -181,6 +185,10 @@ struct AppAssets {
return UIColor(named: "primaryAccentColor")!
}
static var redditOriginal: UIImage = {
return UIImage(named: "redditWhite")!.withRenderingMode(.alwaysOriginal).withTintColor(.secondaryLabel)
}()
static var safariImage: UIImage = {
return UIImage(systemName: "safari")!
}()
@ -240,6 +248,10 @@ struct AppAssets {
return UIImage(systemName: "trash")!
}()
static var twitterOriginal: UIImage = {
return UIImage(named: "twitterWhite")!.withRenderingMode(.alwaysOriginal).withTintColor(.secondaryLabel)
}()
static var unreadFeedImage: IconImage {
let image = UIImage(systemName: "largecircle.fill.circle")!
return IconImage(image, isSymbol: true, isBackgroundSupressed: true, preferredColor: AppAssets.secondaryAccentColor.cgColor)
@ -253,6 +265,7 @@ struct AppAssets {
return UIColor(named: "controlBackgroundColor")!
}()
static func image(for accountType: AccountType) -> UIImage? {
switch accountType {
case .onMyMac:

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17506" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17505"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
<capability name="Named colors" minToolsVersion="9.0"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
@ -138,9 +138,6 @@
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="accLabelText" value="Mark All as Read"/>
</userDefinedRuntimeAttributes>
<connections>
<action selector="markAllAsRead:" destination="Kyk-vK-QRX" id="4nd-Gg-APm"/>
</connections>
</barButtonItem>
<barButtonItem style="plain" systemItem="flexibleSpace" id="53V-wq-bat"/>
<barButtonItem style="plain" systemItem="flexibleSpace" id="93y-8j-WBh"/>
@ -196,9 +193,6 @@
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="accLabelText" value="Add Item"/>
</userDefinedRuntimeAttributes>
<connections>
<action selector="add:" destination="7bK-jq-Zjz" id="d1n-0d-2gR"/>
</connections>
</barButtonItem>
</toolbarItems>
<navigationItem key="navigationItem" title="Feeds" id="Zdf-7t-Un8">
@ -332,7 +326,7 @@
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Article Title" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="iFp-rn-HhQ">
<rect key="frame" x="20" y="74.5" width="136" height="33.5"/>
<rect key="frame" x="20" y="74.5" width="135.5" height="33.5"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle1"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>

View File

@ -17,7 +17,15 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
@IBOutlet weak var filterButton: UIBarButtonItem!
private var refreshProgressView: RefreshProgressView?
@IBOutlet weak var addNewItemButton: UIBarButtonItem!
@IBOutlet weak var addNewItemButton: UIBarButtonItem! {
didSet {
if #available(iOS 14, *) {
addNewItemButton.primaryAction = nil
} else {
addNewItemButton.action = #selector(MasterFeedViewController.add(_:))
}
}
}
private let operationQueue = MainThreadOperationQueue()
lazy var dataSource = makeDataSource()
@ -62,6 +70,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
NotificationCenter.default.addObserver(self, selector: #selector(webFeedSettingDidChange(_:)), name: .WebFeedSettingDidChange, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange), name: UIContentSizeCategory.didChangeNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(willEnterForeground(_:)), name: UIApplication.willEnterForegroundNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(configureContextMenu(_:)), name: .ActiveExtensionPointsDidChange, object: nil)
refreshControl = UIRefreshControl()
refreshControl!.addTarget(self, action: #selector(refreshAccounts(_:)), for: .valueChanged)
@ -394,49 +403,56 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
}
@IBAction func add(_ sender: UIBarButtonItem) {
let title = NSLocalizedString("Add Item", comment: "Add Item")
let alertController = UIAlertController(title: title, message: nil, preferredStyle: .actionSheet)
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
let cancelAction = UIAlertAction(title: cancelTitle, style: .cancel)
if #available(iOS 14, *) {
let addWebFeedActionTitle = NSLocalizedString("Add Web Feed", comment: "Add Web Feed")
let addWebFeedAction = UIAlertAction(title: addWebFeedActionTitle, style: .default) { _ in
self.coordinator.showAddWebFeed()
}
} else {
let title = NSLocalizedString("Add Item", comment: "Add Item")
let alertController = UIAlertController(title: title, message: nil, preferredStyle: .actionSheet)
let addRedditFeedActionTitle = NSLocalizedString("Add Reddit Feed", comment: "Add Reddit Feed")
let addRedditFeedAction = UIAlertAction(title: addRedditFeedActionTitle, style: .default) { _ in
self.coordinator.showAddRedditFeed()
}
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
let cancelAction = UIAlertAction(title: cancelTitle, style: .cancel)
let addTwitterFeedActionTitle = NSLocalizedString("Add Twitter Feed", comment: "Add Twitter Feed")
let addTwitterFeedAction = UIAlertAction(title: addTwitterFeedActionTitle, style: .default) { _ in
self.coordinator.showAddTwitterFeed()
}
let addWebFolderdActionTitle = NSLocalizedString("Add Folder", comment: "Add Folder")
let addWebFolderAction = UIAlertAction(title: addWebFolderdActionTitle, style: .default) { _ in
self.coordinator.showAddFolder()
}
alertController.addAction(addWebFeedAction)
if AccountManager.shared.activeAccounts.contains(where: { $0.type == .onMyMac || $0.type == .cloudKit }) {
if ExtensionPointManager.shared.isRedditEnabled {
alertController.addAction(addRedditFeedAction)
let addWebFeedActionTitle = NSLocalizedString("Add Web Feed", comment: "Add Web Feed")
let addWebFeedAction = UIAlertAction(title: addWebFeedActionTitle, style: .default) { _ in
self.coordinator.showAddWebFeed()
}
if ExtensionPointManager.shared.isTwitterEnabled {
alertController.addAction(addTwitterFeedAction)
let addRedditFeedActionTitle = NSLocalizedString("Add Reddit Feed", comment: "Add Reddit Feed")
let addRedditFeedAction = UIAlertAction(title: addRedditFeedActionTitle, style: .default) { _ in
self.coordinator.showAddRedditFeed()
}
let addTwitterFeedActionTitle = NSLocalizedString("Add Twitter Feed", comment: "Add Twitter Feed")
let addTwitterFeedAction = UIAlertAction(title: addTwitterFeedActionTitle, style: .default) { _ in
self.coordinator.showAddTwitterFeed()
}
let addWebFolderdActionTitle = NSLocalizedString("Add Folder", comment: "Add Folder")
let addWebFolderAction = UIAlertAction(title: addWebFolderdActionTitle, style: .default) { _ in
self.coordinator.showAddFolder()
}
alertController.addAction(addWebFeedAction)
if AccountManager.shared.activeAccounts.contains(where: { $0.type == .onMyMac || $0.type == .cloudKit }) {
if ExtensionPointManager.shared.isRedditEnabled {
alertController.addAction(addRedditFeedAction)
}
if ExtensionPointManager.shared.isTwitterEnabled {
alertController.addAction(addTwitterFeedAction)
}
}
alertController.addAction(addWebFolderAction)
alertController.addAction(cancelAction)
alertController.popoverPresentationController?.barButtonItem = sender
present(alertController, animated: true)
}
alertController.addAction(addWebFolderAction)
alertController.addAction(cancelAction)
alertController.popoverPresentationController?.barButtonItem = sender
present(alertController, animated: true)
}
@objc func toggleSectionHeader(_ sender: UITapGestureRecognizer) {
@ -566,6 +582,48 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner {
}
refreshProgressView?.update()
addNewItemButton?.isEnabled = !AccountManager.shared.activeAccounts.isEmpty
configureContextMenu()
}
@objc
func configureContextMenu(_: Any? = nil) {
if #available(iOS 14.0, *) {
let addWebFeedActionTitle = NSLocalizedString("Add Web Feed", comment: "Add Web Feed")
let addWebFeedAction = UIAction(title: addWebFeedActionTitle, image: AppAssets.faviconTemplateImage.withRenderingMode(.alwaysOriginal).withTintColor(.secondaryLabel)) { _ in
self.coordinator.showAddWebFeed()
}
let addRedditFeedActionTitle = NSLocalizedString("Add Reddit Feed", comment: "Add Reddit Feed")
let addRedditFeedAction = UIAction(title: addRedditFeedActionTitle, image: AppAssets.redditOriginal) { _ in
self.coordinator.showAddRedditFeed()
}
let addTwitterFeedActionTitle = NSLocalizedString("Add Twitter Feed", comment: "Add Twitter Feed")
let addTwitterFeedAction = UIAction(title: addTwitterFeedActionTitle, image: AppAssets.twitterOriginal) { _ in
self.coordinator.showAddTwitterFeed()
}
let addWebFolderdActionTitle = NSLocalizedString("Add Folder", comment: "Add Folder")
let addWebFolderAction = UIAction(title: addWebFolderdActionTitle, image: AppAssets.masterFolderImageNonIcon) { _ in
self.coordinator.showAddFolder()
}
var children = [addWebFolderAction, addWebFeedAction]
if AccountManager.shared.activeAccounts.contains(where: { $0.type == .onMyMac || $0.type == .cloudKit }) {
if ExtensionPointManager.shared.isRedditEnabled {
children.insert(addRedditFeedAction, at: 0)
}
if ExtensionPointManager.shared.isTwitterEnabled {
children.insert(addTwitterFeedAction, at: 0)
}
}
let menu = UIMenu(title: "Add Item", image: nil, identifier: nil, options: [], children: children)
self.addNewItemButton.menu = menu
}
}
func focus() {

View File

@ -47,8 +47,8 @@ struct MarkAsReadAlertController {
let title = NSLocalizedString("Mark As Read", comment: "Mark As Read")
let message = NSLocalizedString("You can turn this confirmation off in settings.",
comment: "You can turn this confirmation off in settings.")
let message = NSLocalizedString("You can turn this confirmation off in Settings.",
comment: "You can turn this confirmation off in Settings.")
let cancelTitle = NSLocalizedString("Cancel", comment: "Cancel")
let settingsTitle = NSLocalizedString("Open Settings", comment: "Open Settings")

View File

@ -19,7 +19,15 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner
private var refreshProgressView: RefreshProgressView?
@IBOutlet weak var markAllAsReadButton: UIBarButtonItem!
@IBOutlet weak var markAllAsReadButton: UIBarButtonItem! {
didSet {
if #available(iOS 14, *) {
markAllAsReadButton.primaryAction = nil
} else {
markAllAsReadButton.action = #selector(MasterTimelineViewController.markAllAsRead(_:))
}
}
}
private var filterButton: UIBarButtonItem!
private var firstUnreadButton: UIBarButtonItem!
@ -655,6 +663,25 @@ private extension MasterTimelineViewController {
setToolbarItems(items, animated: false)
}
}
if #available(iOS 14, *) {
let title = NSLocalizedString("Mark All as Read", comment: "Mark All as Read")
var markAsReadAction: UIAction!
if AppDefaults.shared.confirmMarkAllAsRead {
markAsReadAction = UIAction(title: title, image: AppAssets.markAllAsReadImage, discoverabilityTitle: "in \(self.title!)") { [weak self] action in
self?.coordinator.markAllAsReadInTimeline()
}
let settingsAction = UIAction(title: NSLocalizedString("Settings", comment: "Settings"), image: UIImage(systemName: "gear")!, discoverabilityTitle: NSLocalizedString("You can turn this confirmation off in Settings.", comment: "You can turn this confirmation off in Settings.")) { [weak self] action in
self?.coordinator.showSettings(scrollToArticlesSection: true)
}
markAllAsReadButton.menu = UIMenu(title: NSLocalizedString(title, comment: title), image: nil, identifier: nil, children: [settingsAction, markAsReadAction])
} else {
markAllAsReadButton.action = #selector(MasterTimelineViewController.markAllAsRead(_:))
}
}
}
func updateTitleUnreadCount() {

View File

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "redditWhite.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

View File

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "twitter_white.png",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB