Add Activities for viewing Feeds and Folders

This commit is contained in:
Maurice Parker 2019-08-27 14:20:34 -05:00
parent 2b206e098a
commit d641223536
4 changed files with 32 additions and 4 deletions

View File

@ -9,6 +9,7 @@
import Foundation
import CoreSpotlight
import CoreServices
import Account
import Articles
import Intents
@ -21,19 +22,34 @@ class ActivityManager {
func selectingToday() {
let title = NSLocalizedString("See articles for Today", comment: "Today")
selectingActivity = makeSmartFeedActivity(type: ActivityType.selectToday, title: title, identifier: "smartfeed.today")
selectingActivity = makeSelectingActivity(type: ActivityType.selectToday, title: title, identifier: "smartfeed.today")
selectingActivity!.becomeCurrent()
}
func selectingAllUnread() {
let title = NSLocalizedString("See articles in All Unread", comment: "All Unread")
selectingActivity = makeSmartFeedActivity(type: ActivityType.selectAllUnread, title: title, identifier: "smartfeed.allUnread")
selectingActivity = makeSelectingActivity(type: ActivityType.selectAllUnread, title: title, identifier: "smartfeed.allUnread")
selectingActivity!.becomeCurrent()
}
func selectingStarred() {
let title = NSLocalizedString("See articles in Starred", comment: "Starred")
selectingActivity = makeSmartFeedActivity(type: ActivityType.selectStarred, title: title, identifier: "smartfeed.starred")
selectingActivity = makeSelectingActivity(type: ActivityType.selectStarred, title: title, identifier: "smartfeed.starred")
selectingActivity!.becomeCurrent()
}
func selectingFolder(_ folder: Folder) {
let localizedText = NSLocalizedString("See articles in “%@”", comment: "See articles in Folder")
let title = NSString.localizedStringWithFormat(localizedText as NSString, folder.nameForDisplay) as String
selectingActivity = makeSelectingActivity(type: ActivityType.selectFolder, title: title, identifier: "folder.\(folder.nameForDisplay)")
selectingActivity!.becomeCurrent()
}
func selectingFeed(_ feed: Feed) {
let localizedText = NSLocalizedString("See articles in “%@”", comment: "See articles in Feed")
let title = NSString.localizedStringWithFormat(localizedText as NSString, feed.nameForDisplay) as String
selectingActivity = makeSelectingActivity(type: ActivityType.selectFeed, title: title, identifier: feed.url)
selectingActivity!.becomeCurrent()
}
@ -51,7 +67,7 @@ class ActivityManager {
private extension ActivityManager {
func makeSmartFeedActivity(type: ActivityType, title: String, identifier: String) -> NSUserActivity {
func makeSelectingActivity(type: ActivityType, title: String, identifier: String) -> NSUserActivity {
let activity = NSUserActivity(activityType: type.rawValue)
activity.title = title
activity.suggestedInvocationPhrase = title

View File

@ -12,5 +12,7 @@ enum ActivityType: String {
case selectToday = "com.ranchero.NetNewsWire.SelectToday"
case selectAllUnread = "com.ranchero.NetNewsWire.SelectAllUnread"
case selectStarred = "com.ranchero.NetNewsWire.SelectStarred"
case selectFolder = "com.ranchero.NetNewsWire.SelectFolder"
case selectFeed = "com.ranchero.NetNewsWire.SelectFeed"
case readArticle = "com.ranchero.NetNewsWire.ReadArticle"
}

View File

@ -253,6 +253,10 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
handleSelectAllUnread()
case .selectStarred:
handleSelectStarred()
case .selectFolder:
print("folder selected")
case .selectFeed:
print("feed selected")
case .readArticle:
handleReadArticle(activity)
}
@ -1193,6 +1197,10 @@ private extension AppCoordinator {
ActivityManager.shared.selectingAllUnread()
case node.representedObject === SmartFeedsController.shared.starredFeed:
ActivityManager.shared.selectingStarred()
case node.representedObject is Folder:
ActivityManager.shared.selectingFolder(node.representedObject as! Folder)
case node.representedObject is Feed:
ActivityManager.shared.selectingFeed(node.representedObject as! Feed)
default:
break
}

View File

@ -49,6 +49,8 @@
<true/>
<key>NSUserActivityTypes</key>
<array>
<string>com.ranchero.NetNewsWire.SelectFeed</string>
<string>com.ranchero.NetNewsWire.SelectFolder</string>
<string>com.ranchero.NetNewsWire.SelectAllUnread</string>
<string>com.ranchero.NetNewsWire.SelectStarred</string>
<string>com.ranchero.NetNewsWire.SelectToday</string>